Package org.eclipse.core.resources

Examples of org.eclipse.core.resources.IWorkspaceRoot


   */
  public static void validateCycles(Map preferredClasspaths) throws JavaModelException {

    //long start = System.currentTimeMillis();

    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IProject[] rscProjects = workspaceRoot.getProjects();
    int length = rscProjects.length;
    JavaProject[] projects = new JavaProject[length];
       
    HashSet cycleParticipants = new HashSet();
    HashSet traversed = new HashSet();
View Full Code Here


    }
    rootIDs.add(projectRootId);

    IClasspathEntry[] resolvedClasspath = getResolvedClasspath();
     
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    boolean isInitialProject = referringEntry == null;
    for (int i = 0, length = resolvedClasspath.length; i < length; i++){
      ClasspathEntry entry = (ClasspathEntry) resolvedClasspath[i];
      if (isInitialProject || entry.isExported()){
        String rootID = entry.rootID();
        if (rootIDs.contains(rootID)) {
          continue;
        }
        // combine restrictions along the project chain
        ClasspathEntry combinedEntry = entry.combineWith(referringEntry);
        accumulatedEntries.add(combinedEntry);
       
        // recurse in project to get all its indirect exports (only consider exported entries from there on)       
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
          IResource member = workspaceRoot.findMember(entry.getPath());
          if (member != null && member.getType() == IResource.PROJECT){ // double check if bound to project (23977)
            IProject projRsc = (IProject) member;
            if (JavaProject.hasJavaNature(projRsc)) {
              JavaProject javaProject = (JavaProject) JavaCore.create(projRsc);
              javaProject.computeExpandedClasspath(
View Full Code Here

    String rootID = ((ClasspathEntry)resolvedEntry).rootID();
    if (rootIDs.contains(rootID)) return;

    IPath projectPath = this.project.getFullPath();
    IPath entryPath = resolvedEntry.getPath();
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPackageFragmentRoot root = null;
   
    switch(resolvedEntry.getEntryKind()){
     
      // source folder
      case IClasspathEntry.CPE_SOURCE :

        if (projectPath.isPrefixOf(entryPath)){
          if (checkExistency) {
            Object target = JavaModel.getTarget(workspaceRoot, entryPath, checkExistency);
            if (target == null) return;
 
            if (target instanceof IFolder || target instanceof IProject){
              root = getPackageFragmentRoot((IResource)target);
            }
          } else {
            root = getFolderPackageFragmentRoot(entryPath);
          }
        }
        break;

      // internal/external JAR or folder
      case IClasspathEntry.CPE_LIBRARY :
     
        if (referringEntry != null  && !resolvedEntry.isExported()) return;
       
        if (checkExistency) {
          Object target = JavaModel.getTarget(workspaceRoot, entryPath, checkExistency);
          if (target == null) return;
 
          if (target instanceof IResource){
            // internal target
            root = getPackageFragmentRoot((IResource) target);
          } else {
            // external target - only JARs allowed
            if (JavaModel.isFile(target) && (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))) {
              root = new JarPackageFragmentRoot(entryPath, this);
            }
          }
        } else {
          root = getPackageFragmentRoot(entryPath);
        }
        break;

      // recurse into required project
      case IClasspathEntry.CPE_PROJECT :

        if (!retrieveExportedRoots) return;
        if (referringEntry != null && !resolvedEntry.isExported()) return;

        IResource member = workspaceRoot.findMember(entryPath);
        if (member != null && member.getType() == IResource.PROJECT){// double check if bound to project (23977)
          IProject requiredProjectRsc = (IProject) member;
          if (JavaProject.hasJavaNature(requiredProjectRsc)){ // special builder binary output
            rootIDs.add(rootID);
            JavaProject requiredProject = (JavaProject)JavaCore.create(requiredProjectRsc);
View Full Code Here

   * @param document the document to index
   * @param indexLocation the location on the file system of the index
   */
  public final void scheduleDocumentIndexing(SearchDocument document, IPath indexLocation) {
    IPath documentPath = new Path(document.getPath());
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    Object file = JavaModel.getTarget(root, documentPath, true);
    IPath containerPath = documentPath;
    if (file instanceof IResource) {
      containerPath = ((IResource)file).getProject().getFullPath();
    } else if (file == null) {
View Full Code Here

   * @param recurseInContainers flag indicating whether validation should be applied to container entries recursively
   * @return a java model status describing the problem related to this classpath entry if any, a status object with code <code>IStatus.OK</code> if the entry is fine
   */
  public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean recurseInContainers){

    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPath path = entry.getPath();

    // Build some common strings for status message
    String projectName = project.getElementName();
    boolean pathStartsWithProject = projectName.equals(path.segment(0));
    String entryPathMsg = pathStartsWithProject ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();

    switch(entry.getEntryKind()){

      // container entry check
      case IClasspathEntry.CPE_CONTAINER :
        if (path.segmentCount() >= 1){
          try {
            IClasspathContainer container = JavaModelManager.getJavaModelManager().getClasspathContainer(path, project);
            // container retrieval is performing validation check on container entry kinds.
            if (container == null){
              return new JavaModelStatus(IJavaModelStatusConstants.CP_CONTAINER_PATH_UNBOUND, project, path);
            } else if (container == JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS) {
              // Validate extra attributes
              IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
              if (extraAttributes != null) {
                int length = extraAttributes.length;
                HashSet set = new HashSet(length);
                for (int i=0; i<length; i++) {
                  String attName = extraAttributes[i].getName();
                  if (!set.add(attName)) {
                    return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryExtraAttribute, new String[] {attName, entryPathMsg, projectName}));
                  }
                }
              }
              // don't create a marker if initialization is in progress (case of cp initialization batching)
              return JavaModelStatus.VERIFIED_OK;
            }
            IClasspathEntry[] containerEntries = container.getClasspathEntries();
            if (containerEntries != null){
              for (int i = 0, length = containerEntries.length; i < length; i++){
                IClasspathEntry containerEntry = containerEntries[i];
                int kind = containerEntry == null ? 0 : containerEntry.getEntryKind();
                if (containerEntry == null
                  || kind == IClasspathEntry.CPE_SOURCE
                  || kind == IClasspathEntry.CPE_VARIABLE
                  || kind == IClasspathEntry.CPE_CONTAINER){
                    String description = container.getDescription();
                    if (description == null) description = path.makeRelative().toString();
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CP_CONTAINER_ENTRY, project, path);
                }
                if (recurseInContainers) {
                  IJavaModelStatus containerEntryStatus = validateClasspathEntry(project, containerEntry, checkSourceAttachment, recurseInContainers);
                  if (!containerEntryStatus.isOK()){
                    return containerEntryStatus;
                  }
                }
              }
            }
          } catch(JavaModelException e){
            return new JavaModelStatus(e);
          }
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalContainerPath, new String[] {entryPathMsg, projectName}));
        }
        break;

      // variable entry check
      case IClasspathEntry.CPE_VARIABLE :
        if (path.segmentCount() >= 1){
          try {
            entry = JavaCore.getResolvedClasspathEntry(entry);
          } catch (AssertionFailedException e) {
            // Catch the assertion failure and throw java model exception instead
            // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
          }
          if (entry == null){
            return new JavaModelStatus(IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND, project, path);
          }

          // get validation status
          IJavaModelStatus status = validateClasspathEntry(project, entry, checkSourceAttachment, recurseInContainers);
          if (!status.isOK()) return status;

          // return deprecation status if any
          String variableName = path.segment(0);
          String deprecatedMessage = JavaCore.getClasspathVariableDeprecationMessage(variableName);
          if (deprecatedMessage != null) {
            return new JavaModelStatus(IStatus.WARNING, IJavaModelStatusConstants.DEPRECATED_VARIABLE, project, path, deprecatedMessage);
          }
          return status;
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalVariablePath, new String[] {entryPathMsg, projectName}));
        }

      // library entry check
      case IClasspathEntry.CPE_LIBRARY :
        if (path.isAbsolute() && !path.isEmpty()) {
          IPath sourceAttachment = entry.getSourceAttachmentPath();
          Object target = JavaModel.getTarget(workspaceRoot, path, true);
          if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
            long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
            long libraryJDK = Util.getJdkLevel(target);
            if (libraryJDK != 0 && libraryJDK > projectTargetJDK) {
              return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, CompilerOptions.versionFromJdkLevel(libraryJDK));
            }
          }
          if (target instanceof IResource){
            IResource resolvedResource = (IResource) target;
            switch(resolvedResource.getType()){
              case IResource.FILE :
                if (org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(resolvedResource.getName())) {
                  if (checkSourceAttachment
                    && sourceAttachment != null
                    && !sourceAttachment.isEmpty()
                    && JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
                  }
                } else {
                  return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryArchive, new String[] {entryPathMsg, projectName}));
                }
                break;
              case IResource.FOLDER :  // internal binary folder
                if (checkSourceAttachment
                  && sourceAttachment != null
                  && !sourceAttachment.isEmpty()
                  && JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
                  return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toString(), projectName}));
                }
            }
          } else if (target instanceof File){
            File file = JavaModel.getFile(target);
              if (file == null) {
              return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] {path.toOSString(), projectName}));
              } else if (!org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(file.getName())) {
              return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryArchive, (new String[] {path.toOSString(), projectName})));
              } else if (checkSourceAttachment
                && sourceAttachment != null
                && !sourceAttachment.isEmpty()
                && JavaModel.getTarget(workspaceRoot, sourceAttachment, true) == null){
                return  new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String [] {sourceAttachment.toString(), path.toOSString(), projectName}));
              }
          } else {
            boolean isExternal = path.getDevice() != null || !workspaceRoot.getProject(path.segment(0)).exists();
            if (isExternal) {
              return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), projectName}));
            } else {
              return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {entryPathMsg, projectName}));
            }
          }
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPath, new String[] {entryPathMsg, projectName}));
        }
        break;

      // project entry check
      case IClasspathEntry.CPE_PROJECT :
        if (path.isAbsolute() && path.segmentCount() == 1) {
          IProject prereqProjectRsc = workspaceRoot.getProject(path.segment(0));
          IJavaProject prereqProject = JavaCore.create(prereqProjectRsc);
          try {
            if (!prereqProjectRsc.exists() || !prereqProjectRsc.hasNature(JavaCore.NATURE_ID)){
              return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundProject, new String[] {path.segment(0), projectName}));
            }
View Full Code Here

        for (int i = 0; i < max; i++)
          indexedFileNames.put(paths[i], DELETED);
      }
      final long indexLastModified = max == 0 ? 0L : index.getIndexFile().lastModified();

      IWorkspaceRoot root = this.project.getWorkspace().getRoot();
      for (int i = 0; i < sourceEntriesNumber; i++) {
        if (this.isCancelled) return false;

        IClasspathEntry entry = sourceEntries[i];
        IResource sourceFolder = root.findMember(entry.getPath());
        if (sourceFolder != null) {
         
          // collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041)
          final HashSet outputs = new HashSet();
          if (sourceFolder.getType() == IResource.PROJECT) {
View Full Code Here

      char[] pkgName = CharOperation.subarray(fileName, jarSeparator+1, pkgEnd);
      CharOperation.replace(pkgName, '/', '.');
      return root.getPackageFragment(new String(pkgName));
    } else {
      Path path = new Path(new String(fileName, 0, pkgEnd));
      IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
      IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
      IJavaElement element = JavaCore.create(folder);
      if (element == null) return null;
      switch (element.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT:
          return (IPackageFragment) element;
View Full Code Here

      }
    }
   
    // perform refresh
    Iterator projectNames = this.state.getOldJavaProjecNames().iterator();
    IWorkspaceRoot wksRoot = ResourcesPlugin.getWorkspace().getRoot();
    while (projectNames.hasNext()) {
     
      if (monitor != null && monitor.isCanceled()) break;
     
      String projectName = (String) projectNames.next();
      IProject project = wksRoot.getProject(projectName);
      if (!JavaProject.hasJavaNature(project)) {
        // project is not accessible or has lost its Java nature
        continue;
      }
      JavaProject javaProject = (JavaProject) JavaCore.create(project);
View Full Code Here

    boolean needCycleValidation = false;
 
    // validate classpaths of affected projects (dependent projects
    // or projects that reference a library in one of the projects that have changed)
    if (!affectedProjects.isEmpty()) {
      IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
      IProject[] projects = workspaceRoot.getProjects();
      int length = projects.length;
      for (int i = 0; i < length; i++){
        IProject project = projects[i];
        JavaProject javaProject = (JavaProject)JavaCore.create(project);
        try {
View Full Code Here

        else
            workspaceInitCallbackQueue.add(callback);
    }

    private static File getWorkspaceDirectory() throws CoreException {
        IWorkspaceRoot eclipseWorkspace = ResourcesPlugin.getWorkspace().getRoot();

        IProject cnfProject = eclipseWorkspace.getProject("bnd");
        if (!cnfProject.exists())
            cnfProject = eclipseWorkspace.getProject("cnf");

        if (cnfProject.exists()) {
            if (!cnfProject.isOpen())
                cnfProject.open(null);
            return cnfProject.getLocation().toFile().getParentFile();
        }

        // Have to assume that the eclipse workspace == the bnd workspace,
        // and cnf hasn't been imported yet.
        return eclipseWorkspace.getLocation().toFile();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.core.resources.IWorkspaceRoot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.