Changeset 1574

Show
Ignore:
Timestamp:
03/23/07 14:22:13 (2 years ago)
Author:
msnyder
Message:

Added Reference policy browser to SystemPage? when creating a new system. Added checks to the system name in system page and project
name in new project page. Made the default reference policy when creating a new project blank for now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/framework-plugin/src/com/tresys/framework/compiler/dictionary/Dictionary.java

    r1396 r1574  
    6666                        errorHandler.CriticalError(e.toString() 
    6767                                + "\nCritical error opening file: " + dictFilename 
    68                               + " not found"); 
     68                              + " not found"); 
    6969                } catch (Exception e) { 
    7070                        errorHandler.CriticalError(e.toString() 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/builder/FrameworkBuilder.java

    r1567 r1574  
    1212 
    1313import java.io.StringReader; 
     14import java.util.Collection; 
    1415import java.util.Iterator; 
    1516import java.util.Map; 
     
    214215                { 
    215216                        getProject ().refreshLocal (IResource.DEPTH_INFINITE, null); 
    216                         Vector systems = FrameworkNature.getNature (getProject ()).getSystems (); 
    217                         for (int i = 0; i < systems.size (); i++) 
    218                         { 
    219                                 buildSystem ((SELinuxSystem) systems.elementAt (i)); 
     217                        Collection systems = FrameworkNature.getNature (getProject ()).getSystems (); 
     218                        for (Iterator itr = systems.iterator(); itr.hasNext(); ) 
     219                        { 
     220                                SELinuxSystem sys = (SELinuxSystem) itr.next(); 
     221                                buildSystem(sys); 
    220222                        } 
    221223                } 
     
    282284                FrameworkNature.deleteMarkers(getProject ()); 
    283285                nature.forceDictionaryReload (); 
    284                 if (nature.getSystems () != null) 
    285                 { 
    286                         for (int i = 0; i < nature.getSystems ().size (); i++) 
    287                         { 
    288                                 ((SELinuxSystem) nature.getSystems ().elementAt (i)).forcePolicyReload (); 
    289                                 ((SELinuxSystem) nature.getSystems ().elementAt (i)).forceLinkageReload (); 
    290                                 ((SELinuxSystem) nature.getSystems ().elementAt (i)).forceSystemResourcesReload (); 
     286                Collection systems = nature.getSystems(); 
     287                if (systems  != null) 
     288                { 
     289                        for (Iterator itr = systems.iterator(); itr.hasNext(); ) 
     290                        { 
     291                                SELinuxSystem sys = (SELinuxSystem) itr.next(); 
     292                                sys.forcePolicyReload (); 
     293                                sys.forceLinkageReload (); 
     294                                sys.forceSystemResourcesReload (); 
    291295                        } 
    292296                } 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/builder/FrameworkNature.java

    r1567 r1574  
    1717import java.io.InputStreamReader; 
    1818import java.net.URL; 
     19import java.util.Collection; 
    1920import java.util.Enumeration; 
     21import java.util.HashSet; 
    2022import java.util.Iterator; 
     23import java.util.Set; 
    2124import java.util.Vector; 
    2225 
     
    7881        private IProject m_project; 
    7982 
    80         private Vector/*<IFile>*/ m_systems; 
     83        private Set/*<IFile>*/ m_systems; 
    8184 
    8285        public final static String m_makeFile = "Makefile"; 
     
    276279                                { 
    277280                                        // Add the dictionary on the IProject so that it can be used elsewhere 
    278                                         Vector systems = getSystems (); 
    279                                         for (int i = 0; i < systems.size (); i++) 
     281                                        Collection systems = getSystems (); 
     282                                         
     283 
     284                                        for (Iterator itr1 = systems.iterator(); itr1.hasNext(); ) 
    280285                                        { 
    281                                                 ((SELinuxSystem) systems.elementAt (i)).forcePolicyReload(); //setPolicy (null); 
    282                                                 ((SELinuxSystem) systems.elementAt (i)).forceSystemResourcesReload(); //setSystemResources (null); 
     286                                                SELinuxSystem sys = (SELinuxSystem) itr1.next(); 
     287                                                sys.forcePolicyReload(); //setPolicy (null); 
     288                                                sys.forceSystemResourcesReload(); //setSystemResources (null); 
    283289                                        } 
    284290                                } 
     
    378384         
    379385         
    380         public Vector getSystems()  
     386        public Collection getSystems()  
    381387        { 
    382388                if (m_systems == null) 
    383389                { 
    384                         m_systems = new Vector (); 
     390                        m_systems = new HashSet (); 
    385391                        try 
    386392                        { 
     
    418424        public SELinuxSystem getSystem (IResource i_res) 
    419425        { 
    420                 Vector vec = getSystems(); 
     426                Collection vec = getSystems(); 
    421427                if (vec == null) 
    422428                        return null; 
     
    441447        public void addSystem(SELinuxSystem system)  
    442448        { 
    443                 m_systems.add(system); 
     449                Collection systems = getSystems(); 
     450                 
     451                systems.add(system); 
    444452        } 
    445453         
    446454        public void removeSystem (SELinuxSystem i_system) 
    447455        { 
     456                Collection systems = getSystems(); 
    448457                m_systems.remove(i_system); 
    449458        } 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/editor/policy/graphic/commands/messages.properties

    r1530 r1574  
    1414enter_deletion=entry connection deletion 
    1515enter_move_end=move entryConnection ending point 
     16enter_move_start=move entryConnection starting point 
    1617access_move_start=move connection starting point 
    1718access_move_end=move connection endpoint 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/preferences/PreferenceInitializer.java

    r1512 r1574  
    5353                        String basePath = Platform.asLocalURL(basePathURL).getPath(); 
    5454                        store.setDefault(SEFPreferencePage.BASE_DICT_PATH, basePath + "resources/dictionary/dictionary.fdic"); 
    55                         store.setDefault(SEFPreferencePage.BASE_POLICY_PATH, basePath + "refpolicy"); 
     55                        //store.setDefault(SEFPreferencePage.BASE_POLICY_PATH, basePath + "refpolicy"); 
     56                        store.setDefault(SEFPreferencePage.BASE_POLICY_PATH, ""); 
    5657                         
    5758                }  
  • trunk/framework-plugin/src/com/tresys/framework/plugin/wizards/Messages.java

    r1517 r1574  
    2323        public static String system_name_label; 
    2424        public static String err_specify_project; 
    25         public static String err_speicfy_system; 
     25        public static String err_specify_system; 
    2626 
    2727         
     
    3232        public static String dictionary_label; 
    3333        public static String reference_policy_label; 
     34        public static String err_spaces_in_name; 
     35        public static String err_slash_in_name; 
     36        public static String err_decimal_in_name; 
    3437        public static String err_specify_dictionary; 
    3538        public static String err_dict_not_file; 
     
    5861        public static String file_copy_wait_message; 
    5962        public static String please_wait; 
     63        public static String system_exists; 
    6064 
    6165        static 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/wizards/NewProjectPage.java

    r1502 r1574  
    146146                if (!super.validatePage ()) 
    147147                        return false; 
    148  
     148                 
     149                //Additional check: system name does not contain any spaces 
     150                String projName = getProjectName(); 
     151                char[] projNameChars = new char[projName.length()]; 
     152                projName.getChars(0, projName.length(), projNameChars, 0); 
     153                 
     154                for (int i = 0; i < projNameChars.length; i++) 
     155                { 
     156                        if (Character.isSpaceChar(projNameChars[i])) 
     157                        { 
     158                                setErrorMessage(Messages.err_spaces_in_name); 
     159                                return false; 
     160                        } 
     161                } 
     162                 
     163                //Strings to check the dictionary and refrence policy  
    149164                String dictFileName = getDictFileName (); 
    150165                String refPolName = getRefPolName (); 
  • trunk/framework-plugin/src/com/tresys/framework/plugin/wizards/NewSystemPage.java

    r1336 r1574  
    1313package com.tresys.framework.plugin.wizards; 
    1414 
     15import java.io.File; 
    1516import java.util.Vector; 
    1617 
    1718import org.eclipse.core.runtime.CoreException; 
     19import org.eclipse.core.runtime.preferences.IEclipsePreferences; 
     20import org.eclipse.core.runtime.preferences.IScopeContext; 
    1821import org.eclipse.jface.wizard.WizardPage; 
    1922import org.eclipse.swt.SWT; 
    2023 
     24import org.eclipse.core.resources.IFolder; 
    2125import org.eclipse.core.resources.IProject; 
    2226import org.eclipse.core.resources.IWorkspaceRoot; 
     27import org.eclipse.core.resources.ProjectScope; 
    2328import org.eclipse.core.resources.ResourcesPlugin; 
    2429 
     
    3136import org.eclipse.swt.layout.GridLayout; 
    3237 
     38import org.eclipse.swt.widgets.Button; 
    3339import org.eclipse.swt.widgets.Combo; 
    3440import org.eclipse.swt.widgets.Composite; 
     
    3642import org.eclipse.swt.widgets.Text; 
    3743 
     44import com.tresys.framework.plugin.SEFramework_Plugin; 
    3845import com.tresys.framework.plugin.builder.FrameworkNature; 
     46import com.tresys.framework.plugin.preferences.SEFPreferencePage; 
     47import com.tresys.slide.plugin.nature.PolicyProjectNature; 
     48import com.tresys.slide.utility.DialogUtil; 
    3949 
    4050public class NewSystemPage  
    4151        extends WizardPage 
    4252{ 
    43          
    44         Text ProjectName = null; 
    45         Text txtSystemName = null; 
    46          
    47         Text dictName; 
    48         Text refPolName; 
    49          
     53        private Text txtSystemName = null; 
     54        private Text refPolFileName; 
     55         
     56        private Button refPolSearchButton; 
     57                 
    5058        private IProject selected_project; 
    5159        private Vector availableProjects; 
     
    7886        public void createControl(Composite parent)  
    7987        {        
     88                //Composite used for Project and System Name layout 
    8089                Composite composite = new Composite (parent, SWT.NONE); 
    81                 GridLayout layout = new GridLayout();  
    82                 composite.setLayout(layout); 
    83                 layout.numColumns = 2; 
    84                 layout.verticalSpacing = 7; 
    85  
    86                 //Setting up project drop-down menu 
     90                composite.setLayout(new GridLayout (2, false)); 
     91                composite.setLayoutData(new GridData (GridData.HORIZONTAL_ALIGN_FILL)); 
     92 
     93                //SETTING UP PROJECT DROP-DOWN MENU--------------------------------------- 
    8794                { 
    8895                        Label label = new Label (composite, SWT.NULL); 
     
    101108                                } 
    102109                        } 
    103                  
    104                         GridData data = new GridData(); 
    105                         data.widthHint = 150; 
    106                         comboProject.setLayoutData(data); 
    107110                } 
    108111                                         
    109                 //Name of system  
     112                //GETTING THE NAME OF THE SYSTEM---------------------------------------- 
    110113                { 
    111114                        Label label = new Label (composite, SWT.NULL); 
     
    117120                } 
    118121                 
    119                  
     122                //Setting data layout for project and system name 
     123                GridData data = new GridData(); 
     124                data.widthHint = 300; 
     125                data.grabExcessHorizontalSpace = true; 
     126                comboProject.setLayoutData(data); 
     127                txtSystemName.setLayoutData(data); 
     128                 
     129                //GET THE LOCATION FOR THE REFERENCE POLICY----------------------------- 
     130                //Composite for Reference Policy data area 
     131                Composite dataArea = new Composite (composite, SWT.NONE); 
     132 
     133                dataArea.setLayout (new GridLayout (3, false)); 
     134                dataArea.setLayoutData (new GridData (GridData.FILL_HORIZONTAL)); 
     135 
     136                { 
     137                        Label refPolDirLabel = new Label (dataArea, SWT.NONE); 
     138                        refPolDirLabel.setText (Messages.reference_policy_label); 
     139                        refPolDirLabel.setLayoutData(new GridData()); 
     140         
     141                        refPolFileName = new Text (dataArea, SWT.SINGLE | SWT.BORDER); 
     142                        refPolFileName.setLayoutData(new GridData (GridData.FILL_HORIZONTAL)); 
     143                         
     144                        refPolSearchButton = new Button (dataArea, SWT.PUSH); 
     145                        refPolSearchButton.setText (Messages.browse); 
     146                        refPolSearchButton.setLayoutData(new GridData ()); 
     147                        refPolSearchButton.addSelectionListener (new SelectionAdapter ()  
     148                         
     149                        { 
     150                                public void widgetSelected (SelectionEvent e) 
     151                                { 
     152                                        refPolFileName.setText (DialogUtil.DirectorySelector (getShell (),refPolFileName.getText ())); 
     153                                } 
     154                        }); 
     155                         
     156                } 
     157                 
     158                //Setting up layout for data information for reference policy directory 
     159                GridData theData = new GridData (GridData.HORIZONTAL_ALIGN_FILL); 
     160                theData.minimumWidth = 300; 
     161                theData.grabExcessHorizontalSpace = true; 
     162                refPolFileName.setLayoutData(theData); 
     163 
     164                //Add listeners to the system name, project, and reference policy directory 
    120165                txtSystemName.addModifyListener(m_modifyText); 
    121166                comboProject.addModifyListener(m_modifyText); 
     
    125170                        } 
    126171                }); 
    127  
     172                 
     173                refPolFileName.addModifyListener(m_modifyText); 
     174                PullPrefsFromWorkspace(); 
     175                 
    128176                setControl(composite);                   
    129177                updateStatus(null); 
     
    132180         
    133181        /** 
     182         * Copy the preference to the workspace --- The Base Policy Path 
     183         *  
     184         */ 
     185        protected void PullPrefsFromWorkspace () 
     186        { 
     187                IScopeContext currProjScope = new ProjectScope (selected_project); 
     188                IEclipsePreferences projPrefs = currProjScope.getNode (SEFramework_Plugin.PLUGIN_ID); 
     189                 
     190                refPolFileName.setText(projPrefs.get(SEFPreferencePage.BASE_POLICY_PATH, null)); 
     191        } 
     192 
     193        /** 
    134194         * populate the m_projects array 
    135195         * 
     
    158218        } 
    159219         
    160         /*Verify that a project has been selected and a system name entered*/ 
     220        /** 
     221         * Verify that a project has been selected, a system name entered(and same name does not exist), and 
     222         * that a reference policy directory has been selected that 
     223         * */ 
    161224        public void DialogChanged() 
    162225        { 
    163226                IProject selectedProj = getProject(); 
    164                 String theSystemName = getSystemName(); 
    165                  
     227                String sysName = getSystemName(); 
     228                String refPolName = getRefPolFileName(); 
     229                 
     230                //Check that a project was selected ------------------------------------ 
    166231                if ( selectedProj == null ) 
    167232                { 
     
    171236                } 
    172237                 
    173                 if ( theSystemName.length() == 0 ) 
    174                 { 
    175                         updateStatus(Messages.err_speicfy_system); 
     238                //Check the System name information ----------------------------------- 
     239                 
     240                //Check that a name was entered for the system  
     241                if ( sysName.length() == 0 ) 
     242                { 
     243                        updateStatus(Messages.err_specify_system); 
    176244                        setPageComplete(false); 
    177245                        return; 
    178                 }        
     246                } 
     247                 
     248                //Check that the system name has not been used yet for the project 
     249                if ( systemNameExists(sysName) ) 
     250                { 
     251                        updateStatus(Messages.system_exists); 
     252                        setPageComplete(false); 
     253                        return; 
     254                } 
     255                 
     256                //Check that the system name does not include '/' '\' or ' ' or start with a '.' 
     257                char[] sysNameChars = new char[sysName.length()]; 
     258                sysName.getChars(0, sysName.length(), sysNameChars, 0); 
     259                 
     260                if ( sysNameChars[0] == '.') 
     261                { 
     262                        updateStatus(Messages.err_decimal_in_name); 
     263                        setPageComplete(false); 
     264                        return; 
     265                } 
     266                 
     267                for (int i = 0; i < sysNameChars.length; i++) 
     268                { 
     269                        if (Character.isSpaceChar(sysNameChars[i])) 
     270                        { 
     271                                updateStatus(Messages.err_spaces_in_name); 
     272                                setPageComplete(false); 
     273                                return; 
     274                        } 
     275                         
     276                        if (sysNameChars[i] == '/' || sysNameChars[i] == '\\') 
     277                        { 
     278                                updateStatus(Messages.err_slash_in_name); 
     279                                setPageComplete(false); 
     280                                return; 
     281                        }        
     282                         
     283                         
     284                } 
     285                 
     286                 
     287                //Check reference policy information ----------------------------------- 
     288                 
     289                //Checking that there is input 
     290                if (refPolName.length () == 0) 
     291                { 
     292                        setErrorMessage (Messages.err_specify_refpolicy); 
     293                        return; 
     294                } 
     295 
     296                // Check that it is a directory 
     297                File policyDir = new File (refPolName); 
     298                if (!policyDir.isDirectory ()) 
     299                { 
     300                        setErrorMessage (Messages.err_selection_not_directory); 
     301                        return; 
     302                } 
     303 
     304                //Check if 'Makefile' present, 'policy' directory exists, and if 'global_tunables' exist 
     305                if (!PolicyProjectNature.isValidRefPolicyDir (refPolName)) 
     306                { 
     307                        setErrorMessage (Messages.err_not_refpol_directory); 
     308                        return; 
     309                } 
    179310                 
    180311                updateStatus(null); 
     
    188319        } 
    189320         
    190         /*Get the SystemName*/ 
     321        /** 
     322         * Get the SystemName 
     323         * @return String - the name of the system  
     324         */ 
    191325        public String getSystemName()  
    192326        { 
     
    195329         
    196330        /** 
    197          * get the selected project 
    198          * @return project that has been selected 
     331         * Check that the name for the system does not already exists for the Project 
     332         * by verifying that the file <project name>/src/selinux-policy-<i_systemName> does not 
     333         * already exist  
     334         * @return boolean - true if system name already exists for project 
     335         */ 
     336        public boolean systemNameExists(String i_systemName) 
     337        { 
     338                //Get the system folder for the project with the i_systemName 
     339                IFolder project_systemFolder = selected_project.getFolder("/src/selinux-policy-" + i_systemName); 
     340                 
     341                //if the system folder exists for project, return true 
     342                if (project_systemFolder.exists() ) 
     343                        return true; 
     344                 
     345                //return false if the system folder does not already exist 
     346                else 
     347                        return false; 
     348        } 
     349         
     350        /** 
     351         * Return the name of the file that contains reference policy 
     352         * @return String - name of reference policy directory 
     353         */ 
     354        public String getRefPolFileName() 
     355        { 
     356                return refPolFileName.getText ().trim ();        
     357        } 
     358         
     359        /** 
     360         * Get the selected project 
     361         * @return IProject - project that has been selected 
    199362         */ 
    200363        public IProject getProject ()  
  • trunk/framework-plugin/src/com/tresys/framework/plugin/wizards/messages.properties

    r1517 r1574  
    3636 
    3737err_specify_project = You must select a project 
    38 err_speicfy_system = You must specify a system name 
     38err_specify_system = You must specify a system name 
    3939 
    4040## new project wizard 
     
    4848reference_policy_label = Reference Policy Directory: 
    4949 
     50err_spaces_in_name = The name cannot include spaces 
     51err_slash_in_name = The name cannot include any backword or forward slashes 
     52err_decimal_in_name = The name cannot start with a decimal 
    5053err_specify_dictionary = Dictionary location must be specified 
    5154err_dict_not_file = The dictionary entry is not a file 
     
    6063cds_file=CDS Framework File 
    6164create_file_description=This wizard creates a new CDSFramework File 
     65 
     66## new system wizard 
     67system_exists = The system name given already exists.  Enter a unique system name for the project. 
    6268 
    6369## preferences