/** * Replies if the project name is valid. * * <p>Copied from JDT. * * @return the validity state. */ protected boolean isValidProjectName() { final String name = this.fProjText.getText(); if (Strings.isNullOrEmpty(name)) { setErrorMessage(Messages.MainLaunchConfigurationTab_3); return false; } final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (status.isOK()) { final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (!project.exists()) { setErrorMessage(MessageFormat.format(Messages.MainLaunchConfigurationTab_4, name)); return false; } if (!project.isOpen()) { setErrorMessage(MessageFormat.format(Messages.MainLaunchConfigurationTab_5, name)); return false; } } else { setErrorMessage( MessageFormat.format(Messages.MainLaunchConfigurationTab_6, status.getMessage())); return false; } return true; }
/** * @see org.teiid.designer.core.workspace.ModelWorkspace#createModelProject(java.lang.String, * java.lang.String, org.eclipse.core.runtime.IProgressMonitor) * @since 4.0 */ @Override public ModelProject createModelProject( final String name, final IPath path, final IProgressMonitor monitor) throws CoreException { CoreArgCheck.isNotNull(name); // Check if project already exists if (findModelProject(name) != null) { throw new ModelWorkspaceException( ModelerCore.Util.getString( "ModelWorkspaceImpl.cannotCreateModelProject", name)); // $NON-NLS-1$ } // Validate name final IWorkspace workspace = ModelerCore.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (!status.isOK()) { throw new ModelWorkspaceException( new ModelStatusImpl(status.getSeverity(), status.getCode(), status.getMessage())); } // Create new model project final IProject project = workspace.getRoot().getProject(name); final IProjectDescription desc = workspace.newProjectDescription(project.getName()); desc.setLocation(path); desc.setNatureIds(MODEL_NATURES); final IWorkspaceRunnable op = new IWorkspaceRunnable() { @Override public void run(final IProgressMonitor monitor) throws CoreException { project.create(desc, monitor); project.open(monitor); } }; workspace.run(op, monitor); return new ModelProjectImpl(project, this); }
/** * Handles modify event of project name text box. * * @param event */ protected void handleModifyText(ModifyEvent event) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); final int resourceProj = 4; String projName = ((Text) event.widget).getText(); IStatus projNameStatus = workspace.validateName(projName, resourceProj); IPath projLocation = root.getLocation().append(projName); if (projName.isEmpty()) { setDescription(Messages.wizPageDesc); setPageComplete(false); } else if (!projNameStatus.isOK()) { setErrorMessage(projNameStatus.getMessage()); setPageComplete(false); } else if (root.getProject(projName).exists()) { setErrorMessage(Messages.wizPageErrMsg1); setPageComplete(false); } else if (projLocation.toFile().exists()) { try { String path = projLocation.toFile().getCanonicalPath(); projLocation = new Path(path); } catch (IOException e) { Activator.getDefault().log(Messages.wizPageErrPath, e); setErrorMessage(Messages.wizPageErrPath); setPageComplete(false); } String nameInWorkspace = projLocation.lastSegment(); if (nameInWorkspace.equalsIgnoreCase(projName)) { String msg = String.format(Messages.wizPageNameMustBe, nameInWorkspace); setErrorMessage(msg); setPageComplete(false); } } else { setErrorMessage(null); setDescription(Messages.wizPageDesc); setPageComplete(true); } }
public IValidationStatus validateLocationGeneric(IWorkspace workspace) { IStatus folderLocationValidation = workspace.validatePath(getTargetLocation(), IResource.FOLDER); IStatus projectLocationValidation = workspace.validatePath(getTargetLocation(), IResource.PROJECT); if (!folderLocationValidation.isOK() && !projectLocationValidation.isOK()) { return ValidationStatus.createError(PATH_IS_NOT_VALID_FOR_A_RESOURCE_OF_THE_GIVEN_TYPE_S); } if (getTargetLocation().contains(ICommonConstants.ARTIFACT_TYPE.SCRIPTING_SERVICES)) { if (isValidScriptingServiceFileName(getFileName())) { IWorkspaceRoot root = workspace.getRoot(); if (isResourceExist(root)) { IResource res = extractResource(root); return ValidationStatus.createError( String.format( RESOURCE_ALREADY_EXISTS_IN_THE_WORKSPACE, res.getFullPath().toString())); } return ValidationStatus.createOk(); } return ValidationStatus.createError(NAME_IS_NOT_VALID_FOR_A_RESOURCE_OF_THE_GIVEN_TYPE_S); } IStatus nameValidation = workspace.validateName(getFileName(), IResource.FILE); if (!nameValidation.isOK()) { return ValidationStatus.createError(NAME_IS_NOT_VALID_FOR_A_RESOURCE_OF_THE_GIVEN_TYPE_S); } IWorkspaceRoot root = workspace.getRoot(); if (isResourceExist(root)) { IPath location = new Path(getTargetLocation()).append(getFileName()); return ValidationStatus.createError( String.format(RESOURCE_ALREADY_EXISTS_IN_THE_WORKSPACE, location.toString())); } return ValidationStatus.createOk(); }
private void validateNewExperimentName() { String name = fExperimentName.getText(); IWorkspace workspace = fExperimentFolder.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { // $NON-NLS-1$ updateStatus( new Status( IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IPath path = new Path(name); if (fExperimentFolder.getFolder(path).exists() || fExperimentFolder.getFile(path).exists()) { updateStatus( new Status( IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); // $NON-NLS-1$ }
public static boolean validation(ILaunchConfiguration config) { try { String projectName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); IProject project = null; if (projectName.length() > 0) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IStatus status = workspace.validateName(projectName, IResource.PROJECT); if (status.isOK()) { project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (!project.exists()) { return false; } if (!project.isOpen()) { return false; } } else { return false; } } else { return false; } String directory = config.getAttribute(Plugin.ATTR_WEBAPPDIR, ""); if (!"".equals(directory.trim())) { if ("/".equals(directory)) { // root as webapp folder IFolder file = project.getFolder(new Path("/WEB-INF")); if (!file.exists()) { return false; } } else { IFolder folder = project.getFolder(directory); if (!folder.exists()) { return false; } IFolder file = project.getFolder(new Path(directory + "/WEB-INF")); if (!file.exists()) { return false; } } } else { return false; } String port = config.getAttribute(Plugin.ATTR_PORT, ""); String sslPort = config.getAttribute(Plugin.ATTR_SSL_PORT, ""); if (port.length() == 0 && sslPort.length() == 0) { return false; } if (isInvalidPort(port)) return false; if (isInvalidPort(sslPort)) return false; if (config.getAttribute(Plugin.ATTR_ENABLE_SCANNER, false)) { String scan = config.getAttribute(Plugin.ATTR_SCANINTERVALSECONDS, "5"); if (scan.length() == 0) { return false; } if (isInvalidScan(scan)) return false; } if (config.getAttribute(Plugin.ATTR_ENABLE_SSL, false)) { // Validate that we have the necessary key store info. String keystore = config.getAttribute(Plugin.ATTR_KEYSTORE, "").trim(); String keyPwd = config.getAttribute(Plugin.ATTR_KEY_PWD, "").trim(); String password = config.getAttribute(Plugin.ATTR_PWD, "").trim(); if (keystore.length() == 0) { return false; } else if (!new File(keystore).isFile()) { return false; } if (keyPwd.length() == 0) { return false; } if (password.length() == 0) { return false; } } return true; } catch (CoreException ex) { return false; } }
public void update(Observable o, Object arg) { final IWorkspace workspace = DLTKUIPlugin.getWorkspace(); final String name = fNameGroup.getName(); // check whether the project name field is empty if (name.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_enterProjectName); setPageComplete(false); return; } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // check whether project already exists final IProject handle = getProjectHandle(); if (!isInLocalServer()) { if (handle.exists()) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_projectAlreadyExists); setPageComplete(false); return; } } IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); String newProjectNameLowerCase = name.toLowerCase(); for (IProject currentProject : projects) { String existingProjectName = currentProject.getName(); if (existingProjectName.toLowerCase().equals(newProjectNameLowerCase)) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_projectAlreadyExists); setPageComplete(false); return; } } final String location = fPHPLocationGroup.getLocation().toOSString(); // check whether location is empty if (location.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_enterLocation); setPageComplete(false); return; } // check whether the location is a syntactically correct path if (!Path.EMPTY.isValidPath(location)) { setErrorMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_invalidDirectory); setPageComplete(false); return; } // check whether the location has the workspace as prefix IPath projectPath = Path.fromOSString(location); if (!fPHPLocationGroup.isInWorkspace() && Platform.getLocation().isPrefixOf(projectPath)) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_cannotCreateInWorkspace); setPageComplete(false); return; } // If we do not place the contents in the workspace validate the // location. if (!fPHPLocationGroup.isInWorkspace()) { IEnvironment environment = getEnvironment(); if (EnvironmentManager.isLocal(environment)) { final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath); File file = projectPath.toFile(); if (!locationStatus.isOK()) { setErrorMessage(locationStatus.getMessage()); setPageComplete(false); return; } if (!canCreate(projectPath.toFile())) { setErrorMessage( NewWizardMessages.ScriptProjectWizardFirstPage_Message_invalidDirectory); setPageComplete(false); return; } } } if (fragment != null) { fragment.getWizardModel().putObject("ProjectName", fNameGroup.getName()); if (!fragment.isComplete()) { setErrorMessage((String) fragment.getWizardModel().getObject(ERROR_MESSAGE)); setPageComplete(false); return; } } setPageComplete(true); setErrorMessage(null); setMessage(null); }
/** * Validate the given package name for the given source and compliance levels. * * <p>The syntax of a package name corresponds to PackageName as defined by PackageDeclaration * (JLS2 7.4). For example, <code>"java.lang"</code>. * * <p>Note that the given name must be a non-empty package name (that is, attempting to validate * the default package will return an error status.) Also it must not contain any characters or * substrings that are not valid on the file system on which workspace root is located. * * @param name the name of a package * @param sourceLevel the source level * @param complianceLevel the compliance level * @return a status object with code <code>IStatus.OK</code> if the given name is valid as a * package name, otherwise a status object indicating what is wrong with the name * @since 3.3 */ public static IStatus validatePackageName( String name, String sourceLevel, String complianceLevel) { if (name == null) { return new Status( IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_nullName, null); } int length; if ((length = name.length()) == 0) { return new Status( IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_emptyName, null); } if (name.charAt(0) == DOT || name.charAt(length - 1) == DOT) { return new Status( IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_dotName, null); } if (CharOperation.isWhitespace(name.charAt(0)) || CharOperation.isWhitespace(name.charAt(name.length() - 1))) { return new Status( IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_nameWithBlanks, null); } int dot = 0; while (dot != -1 && dot < length - 1) { if ((dot = name.indexOf(DOT, dot + 1)) != -1 && dot < length - 1 && name.charAt(dot + 1) == DOT) { return new Status( IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.convention_package_consecutiveDotsName, null); } } IWorkspace workspace = ResourcesPlugin.getWorkspace(); StringTokenizer st = new StringTokenizer(name, "."); // $NON-NLS-1$ boolean firstToken = true; IStatus warningStatus = null; while (st.hasMoreTokens()) { String typeName = st.nextToken(); typeName = typeName.trim(); // grammar allows spaces char[] scannedID = scannedIdentifier(typeName, sourceLevel, complianceLevel); if (scannedID == null) { return new Status( IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.bind(Messages.convention_illegalIdentifier, typeName), null); } IStatus status = workspace.validateName(new String(scannedID), IResource.FOLDER); if (!status.isOK()) { return status; } if (firstToken && scannedID.length > 0 && ScannerHelper.isUpperCase(scannedID[0])) { if (warningStatus == null) { warningStatus = new Status( IStatus.WARNING, JavaCore.PLUGIN_ID, -1, Messages.convention_package_uppercaseName, null); } } firstToken = false; } if (warningStatus != null) { return warningStatus; } return JavaModelStatus.VERIFIED_OK; }
public void update(Observable o, Object arg) { final IWorkspace workspace = JavaPlugin.getWorkspace(); final String name = fNameGroup.getName(); // check whether the project name field is empty if (name.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName); setPageComplete(false); return; } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // check whether project already exists final IProject handle = workspace.getRoot().getProject(name); if (handle.exists()) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists); setPageComplete(false); return; } // check whether package name is valid final String packageName = fNameGroup.getPackageName(); if (packageName.length() == 0) { setErrorMessage(null); setMessage("Enter a top level package name."); setPageComplete(false); return; } if (JavaConventions.validatePackageName( packageName, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3) .getSeverity() == IStatus.ERROR) { setErrorMessage(null); setMessage("The entered top level package name is not valid."); setPageComplete(false); return; } IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name); if (projectLocation.toFile().exists()) { try { // correct casing String canonicalPath = projectLocation.toFile().getCanonicalPath(); projectLocation = new Path(canonicalPath); } catch (IOException e) { JavaPlugin.log(e); } String existingName = projectLocation.lastSegment(); if (!existingName.equals(fNameGroup.getName())) { setErrorMessage( Messages.format( NewWizardMessages .NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot, BasicElementLabels.getResourceName(existingName))); setPageComplete(false); return; } setErrorMessage("A project at specified location already exists."); setPageComplete(false); return; } final String location = fLocationGroup.getLocation().toOSString(); // check whether location is empty if (location.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation); setPageComplete(false); return; } // check whether the location is a syntactically correct path if (!Path.EMPTY.isValidPath(location)) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory); setPageComplete(false); return; } IPath projectPath = Path.fromOSString(location); if (fLocationGroup.isWorkspaceRadioSelected()) projectPath = projectPath.append(fNameGroup.getName()); if (projectPath.toFile().exists()) { // create from existing source if (Platform.getLocation().isPrefixOf(projectPath)) { // create // from // existing // source // in // workspace if (!Platform.getLocation().equals(projectPath.removeLastSegments(1))) { setErrorMessage( NewRooWizardMessages.NewRooProjectWizardPageOne_Message_notOnWorkspaceRoot); setPageComplete(false); return; } if (!projectPath.toFile().exists()) { setErrorMessage( NewRooWizardMessages.NewRooProjectWizardPageOne_notExisingProjectOnWorkspaceRoot); setPageComplete(false); return; } } } else if (!fLocationGroup.isWorkspaceRadioSelected()) { // create at // non // existing // external // location if (!canCreate(projectPath.toFile())) { setErrorMessage( NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation); setPageComplete(false); return; } // If we do not place the contents in the workspace validate the // location. final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath); if (!locationStatus.isOK()) { setErrorMessage(locationStatus.getMessage()); setPageComplete(false); return; } } if (firstValidation) { firstValidation = false; if (RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall() == null) { setErrorMessage("No Roo installation configured in workspace preferences."); setPageComplete(false); return; } } else { IRooInstall install = null; if (useDefaultRooInstall()) { install = RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall(); } else { String installName = getRooInstallName(); if (installName != null) { install = RooCoreActivator.getDefault().getInstallManager().getRooInstall(installName); } } if (install == null) { setErrorMessage("No Roo installation configured in workspace preferences."); setPageComplete(false); return; } else { installError = install.validate(); if (installError != null && !installError.isOK()) { setErrorMessage(installError.getMessage()); setPageComplete(false); return; } } } setPageComplete(true); setErrorMessage(null); setMessage(null); }
/** * Return the project being created, or <code>null</code> if the name is not a valid project name. * * @return the project being created */ private static IProject getProject(IWorkspace workspace, String name) { if (!workspace.validateName(name, IResource.PROJECT).isOK()) { return null; } return workspace.getRoot().getProject(name); }
public void update(Observable o, Object arg) { final IWorkspace workspace = JavaPlugin.getWorkspace(); final String name = fNameGroup.getName(); // check whether the project name field is empty if (name.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName); setPageComplete(false); return; } // check whether the project name is valid IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (nameStatus.isOK()) { // there are further restrictions on Grails project names nameStatus = validateProjectName(name); } if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // check whether project already exists final IProject handle = workspace.getRoot().getProject(name); if (handle.exists()) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists); setPageComplete(false); return; } IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name); if (projectLocation.toFile().exists()) { try { // correct casing String canonicalPath = projectLocation.toFile().getCanonicalPath(); projectLocation = new Path(canonicalPath); } catch (IOException e) { JavaPlugin.log(e); } String existingName = projectLocation.lastSegment(); if (!existingName.equals(fNameGroup.getName())) { setErrorMessage( Messages.format( NewWizardMessages .NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot, BasicElementLabels.getResourceName(existingName))); setPageComplete(false); return; } } final String location = fLocationGroup.getLocation().toOSString(); // check whether location is empty if (location.length() == 0) { setErrorMessage(null); setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation); setPageComplete(false); return; } // check whether the location is a syntactically correct path if (!Path.EMPTY.isValidPath(location)) { setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory); setPageComplete(false); return; } IPath projectPath = Path.fromOSString(location); if (fLocationGroup.isWorkspaceRadioSelected()) projectPath = projectPath.append(fNameGroup.getName()); boolean importing = false; if (projectPath.toFile().exists()) { // create from existing source if (Platform.getLocation() .isPrefixOf(projectPath)) { // create from existing source in workspace if (!projectPath.toFile().exists()) { setErrorMessage( org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_notExisingProjectOnWorkspaceRoot); setPageComplete(false); return; } } importing = true; } else if (!fLocationGroup .isWorkspaceRadioSelected()) { // create at non existing external location if (!canCreate(projectPath.toFile())) { setErrorMessage( NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation); setPageComplete(false); return; } // If we do not place the contents in the workspace validate the // location. final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath); if (!locationStatus.isOK()) { setErrorMessage(locationStatus.getMessage()); setPageComplete(false); return; } } // Let other checks perform before this one. // If a location was specified, the project name must match the last segment of the location if (!projectPath.isEmpty()) { String expectedProjectName = projectPath.lastSegment(); if ((name == null) || !name.equals(expectedProjectName)) { setErrorMessage( NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_invalidProjectNameForExternalLocation); setPageComplete(false); return; } } if (GrailsCoreActivator.getDefault().getInstallManager().getDefaultGrailsInstall() == null) { setErrorMessage( org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_noGrailsInstallationInWorkspacePreferences); setPageComplete(false); return; } setPageComplete(true); setErrorMessage(null); if (importing) { // Project exists, but is not in workspace therefore import it. setMessage( Messages.format( org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages .NewGrailsProjectWizardPageOne_importingExistingProject, BasicElementLabels.getResourceName(projectPath.lastSegment()))); } else { setMessage(null); } }