Java Code Examples for org.eclipse.core.runtime.IPath#equals()

The following examples show how to use org.eclipse.core.runtime.IPath#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixedFatJarExportPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
	try {
		IClasspathEntry cpe= root.getRawClasspathEntry();
		if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath outputLocation= cpe.getOutputLocation();
			if (outputLocation == null)
				outputLocation= root.getJavaProject().getOutputLocation();

			IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
			if (entry.equals(location))
				return true;
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}

	IResource resource= root.getResource();
	if (resource != null && entry.equals(resource.getLocation()))
		return true;

	IPath path= root.getPath();
	if (path != null && entry.equals(path))
		return true;

	return false;
}
 
Example 2
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean updateClasspath(IPath newPath, IProgressMonitor monitor) throws JavaModelException {
	boolean updated= false;
	
	IClasspathEntry[] classpath= fProject.getRawClasspath();
	IPath jreContainerPath= new Path(JavaRuntime.JRE_CONTAINER);
	for (int i= 0; i < classpath.length; i++) {
		IClasspathEntry curr= classpath[i];
		if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER && curr.getPath().matchingFirstSegments(jreContainerPath) > 0) {
			if (! newPath.equals(curr.getPath())) {
				updated= true;
				classpath[i]= JavaCore.newContainerEntry(newPath, curr.getAccessRules(), curr.getExtraAttributes(), curr.isExported());
			}
		}
	}
	if (updated) {
		fProject.setRawClasspath(classpath, monitor);
	}
	return updated;
}
 
Example 3
Source File: FatJarPackageWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isRootAt(IPackageFragmentRoot root, IPath entry) {
	try {
		IClasspathEntry cpe= root.getRawClasspathEntry();
		if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath outputLocation= cpe.getOutputLocation();
			if (outputLocation == null)
				outputLocation= root.getJavaProject().getOutputLocation();

			IPath location= ResourcesPlugin.getWorkspace().getRoot().findMember(outputLocation).getLocation();
			if (entry.equals(location))
				return true;
		}
	} catch (JavaModelException e) {
		JavaPlugin.log(e);
	}

	IResource resource= root.getResource();
	if (resource != null && entry.equals(resource.getLocation()))
		return true;

	IPath path= root.getPath();
	if (path != null && entry.equals(path))
		return true;

	return false;
}
 
Example 4
Source File: BuildPathBasePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void addExclusionPatterns(CPListElement newEntry, CPListElement[] existing, Set<CPListElement> modifiedEntries) {
	IPath entryPath= newEntry.getPath();
	for (int i= 0; i < existing.length; i++) {
		CPListElement curr= existing[i];
		if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath currPath= curr.getPath();
			if (!currPath.equals(entryPath)) {
				if (currPath.isPrefixOf(entryPath)) {
					if (addToExclusions(entryPath, curr)) {
						modifiedEntries.add(curr);
					}
				} else if (entryPath.isPrefixOf(currPath) && newEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
					if (addToExclusions(currPath, newEntry)) {
						modifiedEntries.add(curr);
					}
				}
			}
		}
	}
}
 
Example 5
Source File: RefactoringScopeFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException {
	IClasspathEntry result = null;
	IPath path = referencedProject.getProject().getFullPath();
	IClasspathEntry[] classpath = referencingProject.getResolvedClasspath(true);
	for (int i = 0; i < classpath.length; i++) {
		IClasspathEntry entry = classpath[i];
		if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) {
			if (entry.isExported()) {
				return entry;
			}
			// Consider it as a candidate. May be there is another entry that is
			// exported.
			result = entry;
		}
	}
	return result;
}
 
Example 6
Source File: MovePackageFragmentRootOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void removeEntryFromClasspath(IPath rootPath, IJavaProject project) throws JavaModelException {

		IClasspathEntry[] classpath = project.getRawClasspath();
		IClasspathEntry[] newClasspath = null;
		int cpLength = classpath.length;
		int newCPIndex = -1;

		for (int i = 0; i < cpLength; i++) {
			IClasspathEntry entry = classpath[i];
			if (rootPath.equals(entry.getPath())) {
				if (newClasspath == null) {
					newClasspath = new IClasspathEntry[cpLength];
					System.arraycopy(classpath, 0, newClasspath, 0, i);
					newCPIndex = i;
				}
			} else if (newClasspath != null) {
				newClasspath[newCPIndex++] = entry;
			}
		}

		if (newClasspath != null) {
			if (newCPIndex < newClasspath.length) {
				System.arraycopy(newClasspath, 0, newClasspath = new IClasspathEntry[newCPIndex], 0, newCPIndex);
			}
			project.setRawClasspath(newClasspath, this.progressMonitor);
		}
	}
 
Example 7
Source File: ResourceModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the resource will exist in the future based on
 * the recorded resource modifications.
 *
 * @param resource the resource to check
 * @return whether the resource will exist or not
 */
public boolean willExist(IResource resource) {
	if (fDeltaDescriptions == null)
		return false;
	IPath fullPath= resource.getFullPath();
	for (Iterator<DeltaDescription> iter= fDeltaDescriptions.iterator(); iter.hasNext();) {
		DeltaDescription delta= iter.next();
		if (fullPath.equals(delta.getDestinationPath()))
			return true;
	}
	return false;
}
 
Example 8
Source File: ClasspathChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ArrayList determineAffectedPackageFragments(IPath location) throws JavaModelException {
	ArrayList fragments = new ArrayList();

	// see if this will cause any package fragments to be affected
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IResource resource = null;
	if (location != null) {
		resource = workspace.getRoot().findMember(location);
	}
	if (resource != null && resource.getType() == IResource.FOLDER) {
		IFolder folder = (IFolder) resource;
		// only changes if it actually existed
		IClasspathEntry[] classpath = this.project.getExpandedClasspath();
		for (int i = 0; i < classpath.length; i++) {
			IClasspathEntry entry = classpath[i];
			IPath path = classpath[i].getPath();
			if (entry.getEntryKind() != IClasspathEntry.CPE_PROJECT && path.isPrefixOf(location) && !path.equals(location)) {
				IPackageFragmentRoot[] roots = this.project.computePackageFragmentRoots(classpath[i]);
				PackageFragmentRoot root = (PackageFragmentRoot) roots[0];
				// now the output location becomes a package fragment - along with any subfolders
				ArrayList folders = new ArrayList();
				folders.add(folder);
				collectAllSubfolders(folder, folders);
				Iterator elements = folders.iterator();
				int segments = path.segmentCount();
				while (elements.hasNext()) {
					IFolder f = (IFolder) elements.next();
					IPath relativePath = f.getFullPath().removeFirstSegments(segments);
					String[] pkgName = relativePath.segments();
					IPackageFragment pkg = root.getPackageFragment(pkgName);
					if (!Util.isExcluded(pkg))
						fragments.add(pkg);
				}
			}
		}
	}
	return fragments;
}
 
Example 9
Source File: WebAppUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the project's default output directory to the WAR output directory's
 * WEB-INF/classes folder. If the WAR output directory does not have a WEB-INF
 * directory, this method returns without doing anything.
 *
 * @throws CoreException if there's a problem setting the output directory
 */
public static void setOutputLocationToWebInfClasses(IJavaProject javaProject,
    IProgressMonitor monitor) throws CoreException {
  IProject project = javaProject.getProject();

  IFolder webInfOut = getWebInfOut(project);
  if (!webInfOut.exists()) {
    // If the project has no output <WAR>/WEB-INF directory, don't touch the
    // output location
    return;
  }

  IPath oldOutputPath = javaProject.getOutputLocation();
  IPath outputPath = webInfOut.getFullPath().append("classes");

  if (!outputPath.equals(oldOutputPath)) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    // Remove old output location and contents
    IFolder oldOutputFolder = workspaceRoot.getFolder(oldOutputPath);
    if (oldOutputFolder.exists()) {
      try {
        removeOldClassfiles(oldOutputFolder);
      } catch (Exception e) {
        CorePluginLog.logError(e);
      }
    }

    // Create the new output location if necessary
    IFolder outputFolder = workspaceRoot.getFolder(outputPath);
    if (!outputFolder.exists()) {
      // TODO: Could move recreate this in a utilities class
      CoreUtility.createDerivedFolder(outputFolder, true, true, null);
    }

    javaProject.setOutputLocation(outputPath, monitor);
  }
}
 
Example 10
Source File: JavaProjectElementInfo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isClasspathEntryOrOutputLocation(IPath path, IPath location, IClasspathEntry[] resolvedClasspath, IPath projectOutput) {
	if (projectOutput.equals(path)) return true;
	for (int i = 0, length = resolvedClasspath.length; i < length; i++) {
		IClasspathEntry entry = resolvedClasspath[i];
		IPath entryPath;
		if ((entryPath = entry.getPath()).equals(path) || entryPath.equals(location)) {
			return true;
		}
		IPath output;
		if ((output = entry.getOutputLocation()) != null && output.equals(path)) {
			return true;
		}
	}
	return false;
}
 
Example 11
Source File: JavadocTreeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath[] getClassPath(IJavaProject[] javaProjects) {
	HashSet<IPath> res= new HashSet<IPath>();

	IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
	for (int j= 0; j < javaProjects.length; j++) {
		IJavaProject curr= javaProjects[j];
		try {
			IPath outputLocation= null;

			// Not really clear yet what to do here for EFS. See bug
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=113233.

			// However if the output location is not local it is currently
			// not part of JavaRuntime.computeDefaultRuntimeClassPath either
			// so it will be simply not added to the result which would be
			// correct.
			IResource outputPathFolder= root.findMember(curr.getOutputLocation());
			if (outputPathFolder != null)
				outputLocation= outputPathFolder.getLocation();

			String[] classPath= JavaRuntime.computeDefaultRuntimeClassPath(curr);
			for (int i= 0; i < classPath.length; i++) {
				IPath path= Path.fromOSString(classPath[i]);
				if (!path.equals(outputLocation)) {
					res.add(path);
				}
			}
		} catch (CoreException e) {
			JavaPlugin.log(e);
		}
	}
	return res.toArray(new IPath[res.size()]);
}
 
Example 12
Source File: SarlClassPathDetector.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Replies the folder path.
 *
 * @param packPath the path to path.
 * @param relpath the relative path.
 * @return the folder path or {@code null} if it cannot be computed.
 */
protected static IPath getFolderPath(IPath packPath, IPath relpath) {
	final int remainingSegments = packPath.segmentCount() - relpath.segmentCount();
	if (remainingSegments >= 0) {
		final IPath common = packPath.removeFirstSegments(remainingSegments);
		if (common.equals(relpath)) {
			return packPath.uptoSegment(remainingSegments);
		}
	}
	return null;
}
 
Example 13
Source File: EclipseProjectImporter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void importDir(java.nio.file.Path dir, IProgressMonitor m) {
	SubMonitor monitor = SubMonitor.convert(m, 4);
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IPath dotProjectPath = new Path(dir.resolve(DESCRIPTION_FILE_NAME).toAbsolutePath().toString());
	IProjectDescription descriptor;
	try {
		descriptor = workspace.loadProjectDescription(dotProjectPath);
		String name = descriptor.getName();
		if (!descriptor.hasNature(JavaCore.NATURE_ID)) {
			return;
		}
		IProject project = workspace.getRoot().getProject(name);
		if (project.exists()) {
			IPath existingProjectPath = project.getLocation();
			existingProjectPath = fixDevice(existingProjectPath);
			dotProjectPath = fixDevice(dotProjectPath);
			if (existingProjectPath.equals(dotProjectPath.removeLastSegments(1))) {
				project.open(IResource.NONE, monitor.newChild(1));
				project.refreshLocal(IResource.DEPTH_INFINITE, monitor.newChild(1));
				return;
			} else {
				project = findUniqueProject(workspace, name);
				descriptor.setName(project.getName());
			}
		}
		project.create(descriptor, monitor.newChild(1));
		project.open(IResource.NONE, monitor.newChild(1));
	} catch (CoreException e) {
		JavaLanguageServerPlugin.log(e.getStatus());
		throw new RuntimeException(e);
	} finally {
		monitor.done();
	}
}
 
Example 14
Source File: ManifestBasedSREInstall.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static String makeRelativePath(IPath pathToConvert, IPath jarPath, IPath rootPath) {
	if (pathToConvert == null) {
		return null;
	}
	if (!jarPath.equals(pathToConvert) && rootPath.isPrefixOf(pathToConvert)) {
		return pathToConvert.makeRelativeTo(rootPath).toPortableString();
	}
	return pathToConvert.toPortableString();
}
 
Example 15
Source File: SetMainFileAction.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
    * 
 */
public void run(IAction action) {
    
    IResource file = ((FileEditorInput)editor.getEditorInput()).getFile();
    IProject project = file.getProject();
    
       //load settings, if changed on disk
       if (TexlipseProperties.isProjectPropertiesFileChanged(project)) {
           TexlipseProperties.loadProjectProperties(project);
       }
       
       // check that there is an output format property
       String format = TexlipseProperties.getProjectProperty(project, TexlipseProperties.OUTPUT_FORMAT);
       if (format == null || format.length() == 0) {
           TexlipseProperties.setProjectProperty(project, TexlipseProperties.OUTPUT_FORMAT, TexlipsePlugin.getPreference(TexlipseProperties.OUTPUT_FORMAT));
       }
       
       // check that there is a builder number
       String builderNum = TexlipseProperties.getProjectProperty(project, TexlipseProperties.BUILDER_NUMBER);
       if (builderNum == null || builderNum.length() == 0) {
           TexlipseProperties.setProjectProperty(project, TexlipseProperties.BUILDER_NUMBER, TexlipsePlugin.getPreference(TexlipseProperties.BUILDER_NUMBER));
       }
       
    String name = file.getName();
       IPath path = file.getFullPath();
       
       IResource currentMainFile = TexlipseProperties.getProjectSourceFile(project);
       // check if this is already the main file
       if (currentMainFile != null && path.equals(currentMainFile.getFullPath())) {
           return;
       }
       
       // set main file
    TexlipseProperties.setProjectProperty(project, TexlipseProperties.MAINFILE_PROPERTY, name);
    
       // set output files
    String output = name.substring(0, name.lastIndexOf('.')+1) + format;
    TexlipseProperties.setProjectProperty(project, TexlipseProperties.OUTPUTFILE_PROPERTY, output);

       // set source directory
    String dir = path.removeFirstSegments(1).removeLastSegments(1).toString();
       TexlipseProperties.setProjectProperty(project, TexlipseProperties.SOURCE_DIR_PROPERTY, dir);
       
       // make sure there is output directory setting
       String oldOut = TexlipseProperties.getProjectProperty(project, TexlipseProperties.OUTPUT_DIR_PROPERTY);
       if (oldOut == null) {
           TexlipseProperties.setProjectProperty(project, TexlipseProperties.OUTPUT_DIR_PROPERTY, dir);
       }
       
       // make sure there is temp directory setting
       String oldTmp = TexlipseProperties.getProjectProperty(project, TexlipseProperties.TEMP_DIR_PROPERTY);
       if (oldTmp == null) {
           TexlipseProperties.setProjectProperty(project, TexlipseProperties.TEMP_DIR_PROPERTY, dir);
       }

       //save settings to file
       TexlipseProperties.saveProjectProperties(project);
}
 
Example 16
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Validate the new entry in the context of the existing entries. Furthermore,
 * check if exclusion filters need to be applied and do so if necessary.
 *
 * If validation was successful, add the new entry to the list of existing entries.
 *
 * @param entry the entry to be validated and added to the list of existing entries.
 * @param existingEntries a list of existing entries representing the build path
 * @param project the Java project
 * @throws CoreException in case that validation fails
 */
private static void validateAndAddEntry(CPListElement entry, List<CPListElement> existingEntries, IJavaProject project) throws CoreException {
	IPath path= entry.getPath();
	IPath projPath= project.getProject().getFullPath();
	IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
	IStatus validate= workspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER);
	StatusInfo rootStatus= new StatusInfo();
	rootStatus.setOK();
	boolean isExternal= isExternalArchiveOrLibrary(entry);
	if (!isExternal && validate.matches(IStatus.ERROR) && !project.getPath().equals(path)) {
		rootStatus.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage()));
		throw new CoreException(rootStatus);
	} else {
		if (!isExternal && !project.getPath().equals(path)) {
			IResource res= workspaceRoot.findMember(path);
			if (res != null) {
				if (res.getType() != IResource.FOLDER && res.getType() != IResource.FILE) {
					rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_NotAFolder);
					throw new CoreException(rootStatus);
				}
			} else {
				URI projLocation= project.getProject().getLocationURI();
				if (projLocation != null) {
					IFileStore store= EFS.getStore(projLocation).getFileStore(path);
					if (store.fetchInfo().exists()) {
						rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExistingDifferentCase);
						throw new CoreException(rootStatus);
					}
				}
			}
		}

		for (int i= 0; i < existingEntries.size(); i++) {
			CPListElement curr= existingEntries.get(i);
			if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
				if (path.equals(curr.getPath()) && !project.getPath().equals(path)) {
					rootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting);
					throw new CoreException(rootStatus);
				}
			}
		}

		if (!isExternal && !entry.getPath().equals(project.getPath()))
			exclude(entry.getPath(), existingEntries, new ArrayList<CPListElement>(), project, null);

		IPath outputLocation= project.getOutputLocation();
		insertAtEndOfCategory(entry, existingEntries);

		IClasspathEntry[] entries= convert(existingEntries);

		IJavaModelStatus status= JavaConventions.validateClasspath(project, entries, outputLocation);
		if (!status.isOK()) {
			if (outputLocation.equals(projPath)) {
				IStatus status2= JavaConventions.validateClasspath(project, entries, outputLocation);
				if (status2.isOK()) {
					if (project.isOnClasspath(project)) {
						rootStatus.setInfo(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSFandOL, BasicElementLabels.getPathLabel(outputLocation, false)));
					} else {
						rootStatus.setInfo(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceOL, BasicElementLabels.getPathLabel(outputLocation, false)));
					}
					return;
				}
			}
			rootStatus.setError(status.getMessage());
			throw new CoreException(rootStatus);
		}

		if (isSourceFolder(project) || project.getPath().equals(path)) {
			rootStatus.setWarning(NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSF);
			return;
		}

		rootStatus.setOK();
		return;
	}
}
 
Example 17
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * A hook method that gets called when the package field has changed. The method
 * validates the package name and returns the status of the validation. The validation
 * also updates the package fragment model.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus packageChanged() {
	StatusInfo status= new StatusInfo();
	IPackageFragmentRoot root= getPackageFragmentRoot();
	fPackageDialogField.enableButton(root != null);

	IJavaProject project= root != null ? root.getJavaProject() : null;

	String packName= getPackageText();
	if (packName.length() > 0) {
		IStatus val= validatePackageName(packName, project);
		if (val.getSeverity() == IStatus.ERROR) {
			status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage()));
			return status;
		} else if (val.getSeverity() == IStatus.WARNING) {
			status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
			// continue
		}
	} else {
		status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
	}

	if (project != null) {
		if (project.exists() && packName.length() > 0) {
			try {
				IPath rootPath= root.getPath();
				IPath outputPath= project.getOutputLocation();
				if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
					// if the bin folder is inside of our root, don't allow to name a package
					// like the bin folder
					IPath packagePath= rootPath.append(packName.replace('.', '/'));
					if (outputPath.isPrefixOf(packagePath)) {
						status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
						return status;
					}
				}
			} catch (JavaModelException e) {
				JavaPlugin.log(e);
				// let pass
			}
		}

		fCurrPackage= root.getPackageFragment(packName);
		IResource resource= fCurrPackage.getResource();
		if (resource != null){
			if (resource.isVirtual()){
				status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual);
				return status;
			}
			if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered);
				return status;
			}
		}
	} else {
		status.setError(""); //$NON-NLS-1$
	}
	return status;
}
 
Example 18
Source File: NewModuleWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private IStatus packageChanged() {

    String packName = modulePackageField.getText();
    IStatus validatePackageStatus = Util.validatePackageName(packName);

    if (validatePackageStatus.getSeverity() == IStatus.ERROR) {
      return validatePackageStatus;
    }

    if (packName.length() == 0) {
      modulePackageField.setStatus(NewWizardMessages.NewTypeWizardPage_default);
    } else {
      modulePackageField.setStatus("");
    }

    IJavaProject project = getJavaProject();
    IPackageFragmentRoot root = getPackageFragmentRoot();

    if (project != null && root != null) {
      if (project.exists() && packName.length() > 0) {
        try {
          IPath rootPath = root.getPath();
          IPath outputPath = project.getOutputLocation();
          if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
            // if the bin folder is inside of our root, don't allow to name a
            // package like the bin folder
            IPath packagePath = rootPath.append(packName.replace('.', '/'));
            if (outputPath.isPrefixOf(packagePath)) {
              return Util.newErrorStatus(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
            }
          }
        } catch (JavaModelException e) {
          // Not a critical exception at this juncture; we'll just log it
          // and move on.
          GWTPluginLog.logError(e);
        }
      }
    }

    return validatePackageStatus;
  }
 
Example 19
Source File: ClasspathChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int classpathContains(IClasspathEntry[] list, IClasspathEntry entry) {
	IPath[] exclusionPatterns = entry.getExclusionPatterns();
	IPath[] inclusionPatterns = entry.getInclusionPatterns();
	int listLen = list == null ? 0 : list.length;
	nextEntry: for (int i = 0; i < listLen; i++) {
		IClasspathEntry other = list[i];
		if (other.getContentKind() == entry.getContentKind()
			&& other.getEntryKind() == entry.getEntryKind()
			&& other.isExported() == entry.isExported()
			&& other.getPath().equals(entry.getPath())) {
				// check custom outputs
				IPath entryOutput = entry.getOutputLocation();
				IPath otherOutput = other.getOutputLocation();
				if (entryOutput == null) {
					if (otherOutput != null)
						continue;
				} else {
					if (!entryOutput.equals(otherOutput))
						continue;
				}

				// check inclusion patterns
				IPath[] otherIncludes = other.getInclusionPatterns();
				if (inclusionPatterns != otherIncludes) {
				    if (inclusionPatterns == null) continue;
					int includeLength = inclusionPatterns.length;
					if (otherIncludes == null || otherIncludes.length != includeLength)
						continue;
					for (int j = 0; j < includeLength; j++) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						if (!inclusionPatterns[j].toString().equals(otherIncludes[j].toString()))
							continue nextEntry;
					}
				}
				// check exclusion patterns
				IPath[] otherExcludes = other.getExclusionPatterns();
				if (exclusionPatterns != otherExcludes) {
				    if (exclusionPatterns == null) continue;
					int excludeLength = exclusionPatterns.length;
					if (otherExcludes == null || otherExcludes.length != excludeLength)
						continue;
					for (int j = 0; j < excludeLength; j++) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						if (!exclusionPatterns[j].toString().equals(otherExcludes[j].toString()))
							continue nextEntry;
					}
				}
				return i;
		}
	}
	return -1;
}
 
Example 20
Source File: ProjectContentsLocationArea.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Check if the entry in the widget location is valid. If it is valid return null. Otherwise return a string that
 * indicates the problem.
 * 
 * @return String
 */
public String checkValidLocation()
{

	String locationFieldContents = locationPathField.getText();
	if (locationFieldContents.length() == 0)
	{
		return IDEWorkbenchMessages.WizardNewProjectCreationPage_projectLocationEmpty;
	}

	URI newPath = getProjectLocationURI();
	if (newPath == null)
	{
		return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationError;
	}

	if (existingProject != null)
	{
		URI projectPath = existingProject.getLocationURI();
		if (projectPath != null && URIUtil.equals(projectPath, newPath))
		{
			return IDEWorkbenchMessages.ProjectLocationSelectionDialog_locationIsSelf;
		}
	}

	if (!isDefault())
	{
		File newLocation = new File(locationFieldContents);
		if (newLocation.exists())
		{
			if (!ArrayUtil.isEmpty(newLocation.list()))
			{
				return MessageFormat.format(EplMessages.ProjectContentsLocationArea_NonEmptyDirectory, newLocation);
			}
		}

		// If default location is not selected, then the project can not be created under any child folder of
		// workspace.
		IPath parentLocation = Path.fromOSString(locationFieldContents).removeLastSegments(1);
		IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
		if (parentLocation.equals(workspaceLocation))
		{
			return MessageFormat.format(EplMessages.ProjectContentsLocationArea_OverlapError, newLocation,
					existingProject.getName());
		}

	}

	return null;
}