Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.IPath


 
  /*
   * @see IJavaProject
   */
  public boolean isOnClasspath(IResource resource) {
    IPath exactPath = resource.getFullPath();
    IPath path = exactPath;
   
    // ensure that folders are only excluded if all of their children are excluded
    int resourceType = resource.getType();
    boolean isFolderPath = resourceType == IResource.FOLDER || resourceType == IResource.PROJECT;
   
    IClasspathEntry[] classpath;
    try {
      classpath = this.getResolvedClasspath();
    } catch(JavaModelException e){
      return false; // not a Java project
    }
    for (int i = 0; i < classpath.length; i++) {
      IClasspathEntry entry = classpath[i];
      IPath entryPath = entry.getPath();
      if (entryPath.equals(exactPath)) { // package fragment roots must match exactly entry pathes (no exclusion there)
        return true;
      }
      if (entryPath.isPrefixOf(path)
          && !Util.isExcluded(path, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars(), isFolderPath)) {
        return true;
      }
    }
    return false;
View Full Code Here


    }
    return false;
  }

  private boolean isOnClasspathEntry(IPath elementPath, boolean isFolderPath, boolean isPackageFragmentRoot, IClasspathEntry entry) {
    IPath entryPath = entry.getPath();
    if (isPackageFragmentRoot) {
      // package fragment roots must match exactly entry pathes (no exclusion there)
      if (entryPath.equals(elementPath))
        return true;
    } else {
      if (entryPath.isPrefixOf(elementPath)
          && !Util.isExcluded(elementPath, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars(), isFolderPath))
        return true;
    }
    return false;
  }
View Full Code Here

   * load preferences from a shareable format (VCM-wise)
   */
   private Preferences loadPreferences() {
    
     Preferences preferences = new Preferences();
     IPath projectMetaLocation = getPluginWorkingLocation();
    if (projectMetaLocation != null) {
      File prefFile = projectMetaLocation.append(PREF_FILENAME).toFile();
      if (prefFile.exists()) { // load preferences from file
        InputStream in = null;
        try {
          in = new BufferedInputStream(new FileInputStream(prefFile));
          preferences.load(in);
View Full Code Here

    IClasspathEntry[] classpath = readFileEntries(null/*not interested in unknown elements*/);
    if (classpath == JavaProject.INVALID_CLASSPATH)
      return defaultOutputLocation();
   
    // extract the output location
    IPath outputLocation = null;
    if (classpath.length > 0) {
      IClasspathEntry entry = classpath[classpath.length - 1];
      if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
        outputLocation = entry.getPath();
      }
View Full Code Here

    try {
      manager.setClasspathBeingResolved(this, true);
     
      // get raw info inside a synchronized block to ensure that it is consistent
      IClasspathEntry[] rawClasspath;
      IPath outputLocation;
      IJavaModelStatus rawClasspathStatus;
      synchronized (perProjectInfo) {
        rawClasspath= perProjectInfo.rawClasspath;
        if (rawClasspath == null)
          rawClasspath = perProjectInfo.readAndCacheClasspath(this);
        outputLocation = perProjectInfo.outputLocation;
        rawClasspathStatus = perProjectInfo.rawClasspathStatus;
      }
            
      IJavaModelStatus unresolvedEntryStatus = JavaModelStatus.VERIFIED_OK;
      HashMap rawReverseMap = new HashMap();
      Map rootPathToResolvedEntries = new HashMap();
     
      ArrayList resolvedEntries = new ArrayList();
      int length = rawClasspath.length;
      for (int i = 0; i < length; i++) {
 
        IClasspathEntry rawEntry = rawClasspath[i];
        IPath resolvedPath;
       
        switch (rawEntry.getEntryKind()){
         
          case IClasspathEntry.CPE_VARIABLE :
            IClasspathEntry resolvedEntry = null;
View Full Code Here

      HashSet cycleParticipants,
      IWorkspaceRoot workspaceRoot,
      HashSet traversed,
      Map preferredClasspaths){

    IPath path = this.getPath();
    prereqChain.add(path);
    traversed.add(path);
    try {
      IClasspathEntry[] classpath = null;
      if (preferredClasspaths != null) classpath = (IClasspathEntry[])preferredClasspaths.get(this);
      if (classpath == null) classpath = getResolvedClasspath();
      for (int i = 0, length = classpath.length; i < length; i++) {
        IClasspathEntry entry = classpath[i];
       
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT){
          IPath prereqProjectPath = entry.getPath();
          int index = cycleParticipants.contains(prereqProjectPath) ? 0 : prereqChain.indexOf(prereqProjectPath);
          if (index >= 0) { // refer to cycle, or in cycle itself
            for (int size = prereqChain.size(); index < size; index++) {
              cycleParticipants.add(prereqChain.get(index));
            }
View Full Code Here

        return false;

      if (!this.path.equals(otherEntry.getPath()))
        return false;

      IPath otherPath = otherEntry.getSourceAttachmentPath();
      if (this.sourceAttachmentPath == null) {
        if (otherPath != null)
          return false;
      } else {
        if (!this.sourceAttachmentPath.equals(otherPath))
View Full Code Here

          new String[] {"{0}", "{1}", getPath().segment(0)}))//$NON-NLS-1$ //$NON-NLS-2$
      result[3] = manager.intern(Messages.bind(
          org.aspectj.org.eclipse.jdt.internal.core.util.Messages.restrictedAccess_field_project,
          new String[] {"{0}", "{1}", getPath().segment(0)}))//$NON-NLS-1$ //$NON-NLS-2$
    } else {
      IPath libPath = getPath();
      Object target = JavaModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), libPath, false);
      String pathString;
      if (target instanceof java.io.File)
        pathString = libPath.toOSString();
      else
        pathString = libPath.makeRelative().toString();
      result[0] = manager.intern(Messages.bind(
        org.aspectj.org.eclipse.jdt.internal.core.util.Messages.restrictedAccess_library,
        new String[] {"{0}", pathString})); //$NON-NLS-1$
      result[1] = manager.intern(Messages.bind(
          org.aspectj.org.eclipse.jdt.internal.core.util.Messages.restrictedAccess_constructor_library,
View Full Code Here

   *    object indicating what is wrong with the classpath or output location
   */
  public static IJavaModelStatus validateClasspath(IJavaProject javaProject, IClasspathEntry[] rawClasspath, IPath projectOutputLocation) {

    IProject project = javaProject.getProject();
    IPath projectPath= project.getFullPath();
    String projectName = javaProject.getElementName();

    /* validate output location */
    if (projectOutputLocation == null) {
      return new JavaModelStatus(IJavaModelStatusConstants.NULL_PATH);
    }
    if (projectOutputLocation.isAbsolute()) {
      if (!projectPath.isPrefixOf(projectOutputLocation)) {
        return new JavaModelStatus(IJavaModelStatusConstants.PATH_OUTSIDE_PROJECT, javaProject, projectOutputLocation.toString());
      }
    } else {
      return new JavaModelStatus(IJavaModelStatusConstants.RELATIVE_PATH, projectOutputLocation);
    }

    boolean hasSource = false;
    boolean hasLibFolder = false;


    // tolerate null path, it will be reset to default
    if (rawClasspath == null)
      return JavaModelStatus.VERIFIED_OK;

    // retrieve resolved classpath
    IClasspathEntry[] classpath;
    try {
      classpath = ((JavaProject)javaProject).resolveClasspath(rawClasspath);
    } catch(JavaModelException e){
      return e.getJavaModelStatus();
    }
    int length = classpath.length;

    int outputCount = 1;
    IPath[] outputLocations  = new IPath[length+1];
    boolean[] allowNestingInOutputLocations = new boolean[length+1];
    outputLocations[0] = projectOutputLocation;

    // retrieve and check output locations
    IPath potentialNestedOutput = null; // for error reporting purpose
    int sourceEntryCount = 0;
    boolean disableExclusionPatterns = JavaCore.DISABLED.equals(javaProject.getOption(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, true));
    boolean disableCustomOutputLocations = JavaCore.DISABLED.equals(javaProject.getOption(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, true));

    for (int i = 0 ; i < length; i++) {
      IClasspathEntry resolvedEntry = classpath[i];
      if (disableExclusionPatterns &&
              ((resolvedEntry.getInclusionPatterns() != null && resolvedEntry.getInclusionPatterns().length > 0)
              || (resolvedEntry.getExclusionPatterns() != null && resolvedEntry.getExclusionPatterns().length > 0))) {
        return new JavaModelStatus(IJavaModelStatusConstants.DISABLED_CP_EXCLUSION_PATTERNS, javaProject, resolvedEntry.getPath());
      }
      switch(resolvedEntry.getEntryKind()){
        case IClasspathEntry.CPE_SOURCE :
          sourceEntryCount++;

          IPath customOutput;
          if ((customOutput = resolvedEntry.getOutputLocation()) != null) {

            if (disableCustomOutputLocations) {
              return new JavaModelStatus(IJavaModelStatusConstants.DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS, javaProject, resolvedEntry.getPath());
            }
            // ensure custom output is in project
            if (customOutput.isAbsolute()) {
              if (!javaProject.getPath().isPrefixOf(customOutput)) {
                return new JavaModelStatus(IJavaModelStatusConstants.PATH_OUTSIDE_PROJECT, javaProject, customOutput.toString());
              }
            } else {
              return new JavaModelStatus(IJavaModelStatusConstants.RELATIVE_PATH, customOutput);
            }

            // ensure custom output doesn't conflict with other outputs
            // check exact match
            if (Util.indexOfMatchingPath(customOutput, outputLocations, outputCount) != -1) {
              continue; // already found
            }
            // accumulate all outputs, will check nesting once all available (to handle ordering issues)
            outputLocations[outputCount++] = customOutput;
          }
      }
    }
    // check nesting across output locations
    for (int i = 1 /*no check for default output*/ ; i < outputCount; i++) {
        IPath customOutput = outputLocations[i];
        int index;
      // check nesting
      if ((index = Util.indexOfEnclosingPath(customOutput, outputLocations, outputCount)) != -1 && index != i) {
        if (index == 0) {
          // custom output is nested in project's output: need to check if all source entries have a custom
          // output before complaining
          if (potentialNestedOutput == null) potentialNestedOutput = customOutput;
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestOutputInOutput, new String[] {customOutput.makeRelative().toString(), outputLocations[index].makeRelative().toString()}));
        }
      }
    }
    // allow custom output nesting in project's output if all source entries have a custom output
    if (sourceEntryCount <= outputCount-1) {
        allowNestingInOutputLocations[0] = true;
    } else if (potentialNestedOutput != null) {
      return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestOutputInOutput, new String[] {potentialNestedOutput.makeRelative().toString(), outputLocations[0].makeRelative().toString()}));
    }

    for (int i = 0 ; i < length; i++) {
      IClasspathEntry resolvedEntry = classpath[i];
      IPath path = resolvedEntry.getPath();
      int index;
      switch(resolvedEntry.getEntryKind()){

        case IClasspathEntry.CPE_SOURCE :
          hasSource = true;
          if ((index = Util.indexOfMatchingPath(path, outputLocations, outputCount)) != -1){
            allowNestingInOutputLocations[index] = true;
          }
          break;

        case IClasspathEntry.CPE_LIBRARY:
          hasLibFolder |= !org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(path.lastSegment());
          if ((index = Util.indexOfMatchingPath(path, outputLocations, outputCount)) != -1){
            allowNestingInOutputLocations[index] = true;
          }
          break;
      }
    }
    if (!hasSource && !hasLibFolder) { // if no source and no lib folder, then allowed
      for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true;
    }

    HashSet pathes = new HashSet(length);

    // check all entries
    for (int i = 0 ; i < length; i++) {
      IClasspathEntry entry = classpath[i];
      if (entry == null) continue;
      IPath entryPath = entry.getPath();
      int kind = entry.getEntryKind();

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

      // complain if duplicate path
      if (!pathes.add(entryPath)){
        return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName}));
      }
      // no further check if entry coincidates with project or output location
      if (entryPath.equals(projectPath)){
        // complain if self-referring project entry
        if (kind == IClasspathEntry.CPE_PROJECT){
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, Messages.bind(Messages.classpath_cannotReferToItself, entryPath.makeRelative().toString()));
        }
        // tolerate nesting output in src if src==prj
        continue;
      }

      // allow nesting source entries in each other as long as the outer entry excludes the inner one
      if (kind == IClasspathEntry.CPE_SOURCE
          || (kind == IClasspathEntry.CPE_LIBRARY && !org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(entryPath.lastSegment()))){
        for (int j = 0; j < classpath.length; j++){
          IClasspathEntry otherEntry = classpath[j];
          if (otherEntry == null) continue;
          int otherKind = otherEntry.getEntryKind();
          IPath otherPath = otherEntry.getPath();
          if (entry != otherEntry
            && (otherKind == IClasspathEntry.CPE_SOURCE
                || (otherKind == IClasspathEntry.CPE_LIBRARY
                    && !org.aspectj.org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(otherPath.lastSegment())))){
            char[][] inclusionPatterns, exclusionPatterns;
            if (otherPath.isPrefixOf(entryPath)
                && !otherPath.equals(entryPath)
                && !Util.isExcluded(entryPath.append("*"), inclusionPatterns = ((ClasspathEntry)otherEntry).fullInclusionPatternChars(), exclusionPatterns = ((ClasspathEntry)otherEntry).fullExclusionPatternChars(), false)) { //$NON-NLS-1$
              String exclusionPattern = entryPath.removeFirstSegments(otherPath.segmentCount()).segment(0);
              if (Util.isExcluded(entryPath, inclusionPatterns, exclusionPatterns, false)) {
                return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_mustEndWithSlash, new String[] {exclusionPattern, entryPath.makeRelative().toString()}));
              } else {
                if (otherKind == IClasspathEntry.CPE_SOURCE) {
                  exclusionPattern += '/';
                  if (!disableExclusionPatterns) {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInEntry, new String[] {entryPath.makeRelative().toString(), otherEntry.getPath().makeRelative().toString(), exclusionPattern}));
                  } else {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInEntryNoExclusion, new String[] {entryPath.makeRelative().toString(), otherEntry.getPath().makeRelative().toString(), exclusionPattern}));
                  }
                } else {
                  return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInLibrary, new String[] {entryPath.makeRelative().toString(), otherEntry.getPath().makeRelative().toString()}));
                }
              }
            }
          }
        }
      }

      // prevent nesting output location inside entry unless enclosing is a source entry which explicitly exclude the output location
        char[][] inclusionPatterns = ((ClasspathEntry)entry).fullInclusionPatternChars();
        char[][] exclusionPatterns = ((ClasspathEntry)entry).fullExclusionPatternChars();
        for (int j = 0; j < outputCount; j++){
            IPath currentOutput = outputLocations[j];
          if (entryPath.equals(currentOutput)) continue;
        if (entryPath.isPrefixOf(currentOutput)) {
            if (kind != IClasspathEntry.CPE_SOURCE || !Util.isExcluded(currentOutput, inclusionPatterns, exclusionPatterns, true)) {
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestOutputInEntry, new String[] {currentOutput.makeRelative().toString(), entryPath.makeRelative().toString()}));
            }
        }
        }

        // prevent nesting entry inside output location - when distinct from project or a source folder
        for (int j = 0; j < outputCount; j++){
            if (allowNestingInOutputLocations[j]) continue;
            IPath currentOutput = outputLocations[j];
        if (currentOutput.isPrefixOf(entryPath)) {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_cannotNestEntryInOutput, new String[] {entryPath.makeRelative().toString(), currentOutput.makeRelative().toString()}));
        }
        }
    }
    // ensure that no specific output is coincidating with another source folder (only allowed if matching current source folder)
    // 36465 - for 2.0 backward compatibility, only check specific output locations (the default can still coincidate)
    // perform one separate iteration so as to not take precedence over previously checked scenarii (in particular should
    // diagnose nesting source folder issue before this one, for example, [src]"Project/", [src]"Project/source/" and output="Project/" should
    // first complain about missing exclusion pattern
    for (int i = 0 ; i < length; i++) {
      IClasspathEntry entry = classpath[i];
      if (entry == null) continue;
      IPath entryPath = entry.getPath();
      int kind = entry.getEntryKind();

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

      if (kind == IClasspathEntry.CPE_SOURCE) {
        IPath output = entry.getOutputLocation();
        if (output == null) continue; // 36465 - for 2.0 backward compatibility, only check specific output locations (the default can still coincidate)
        // if (output == null) output = projectOutputLocation; // if no specific output, still need to check using default output (this line would check default output)
        for (int j = 0; j < length; j++) {
          IClasspathEntry otherEntry = classpath[j];
          if (otherEntry == entry) continue;
View Full Code Here

   * @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}));
            }
            if (!prereqProjectRsc.isOpen()){
              return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_closedProject, new String[] {path.segment(0)}));
            }
            if (!JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
              long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
              long prereqProjectTargetJDK = CompilerOptions.versionToJdkLevel(prereqProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
              if (prereqProjectTargetJDK > projectTargetJDK) {
                return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, CompilerOptions.versionFromJdkLevel(prereqProjectTargetJDK));
              }
            }
          } catch (CoreException e){
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundProject, new String[] {path.segment(0), projectName}));
          }
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalProjectPath, new String[] {path.toString(), projectName}));
        }
        break;

      // project source folder
      case IClasspathEntry.CPE_SOURCE :
        if (((entry.getInclusionPatterns() != null && entry.getInclusionPatterns().length > 0)
                  || (entry.getExclusionPatterns() != null && entry.getExclusionPatterns().length > 0))
            && JavaCore.DISABLED.equals(project.getOption(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS, true))) {
          return new JavaModelStatus(IJavaModelStatusConstants.DISABLED_CP_EXCLUSION_PATTERNS, project, path);
        }
        if (entry.getOutputLocation() != null && JavaCore.DISABLED.equals(project.getOption(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS, true))) {
          return new JavaModelStatus(IJavaModelStatusConstants.DISABLED_CP_MULTIPLE_OUTPUT_LOCATIONS, project, path);
        }
        if (path.isAbsolute() && !path.isEmpty()) {
          IPath projectPath= project.getProject().getFullPath();
          if (!projectPath.isPrefixOf(path) || JavaModel.getTarget(workspaceRoot, path, true) == null){
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceFolder, new String[] {entryPathMsg, projectName}));
          }
        } else {
          return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalSourceFolderPath, new String[] {entryPathMsg, projectName}));
        }
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.IPath

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.