protected boolean findSourceFiles(IResourceDelta delta) throws CoreException {
   ArrayList visited =
       this.makeOutputFolderConsistent ? new ArrayList(this.sourceLocations.length) : null;
   for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
     ClasspathMultiDirectory md = this.sourceLocations[i];
     if (this.makeOutputFolderConsistent
         && md.hasIndependentOutputFolder
         && !visited.contains(md.binaryFolder)) {
       // even a project which acts as its own source folder can have an independent/nested output
       // folder
       visited.add(md.binaryFolder);
       IResourceDelta binaryDelta = delta.findMember(md.binaryFolder.getProjectRelativePath());
       if (binaryDelta != null) {
         int segmentCount = binaryDelta.getFullPath().segmentCount();
         IResourceDelta[] children = binaryDelta.getAffectedChildren();
         for (int j = 0, m = children.length; j < m; j++)
           if (!checkForClassFileChanges(children[j], md, segmentCount)) return false;
       }
     }
     if (md.sourceFolder.equals(this.javaBuilder.currentProject)) {
       // skip nested source & output folders when the project is a source folder
       int segmentCount = delta.getFullPath().segmentCount();
       IResourceDelta[] children = delta.getAffectedChildren();
       for (int j = 0, m = children.length; j < m; j++)
         if (!isExcludedFromProject(children[j].getFullPath()))
           if (!findSourceFiles(children[j], md, segmentCount)) return false;
     } else {
       IResourceDelta sourceDelta = delta.findMember(md.sourceFolder.getProjectRelativePath());
       if (sourceDelta != null) {
         if (sourceDelta.getKind() == IResourceDelta.REMOVED) {
           if (JavaBuilder.DEBUG)
             System.out.println(
                 "ABORTING incremental build... found removed source folder"); //$NON-NLS-1$
           return false; // removed source folder should not make it here, but handle anyways
           // (ADDED is supported)
         }
         int segmentCount = sourceDelta.getFullPath().segmentCount();
         IResourceDelta[] children = sourceDelta.getAffectedChildren();
         try {
           for (int j = 0, m = children.length; j < m; j++)
             if (!findSourceFiles(children[j], md, segmentCount)) return false;
         } catch (CoreException e) {
           // catch the case that a package has been renamed and collides on disk with an
           // as-yet-to-be-deleted package
           if (e.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found renamed package"); //$NON-NLS-1$
             return false;
           }
           throw e; // rethrow
         }
       }
     }
     this.notifier.checkCancel();
   }
   return true;
 }
 protected boolean findAffectedSourceFiles(
     IResourceDelta delta, ClasspathLocation[] classFoldersAndJars, IProject prereqProject) {
   for (int i = 0, l = classFoldersAndJars.length; i < l; i++) {
     ClasspathLocation bLocation = classFoldersAndJars[i];
     // either a .class file folder or a zip/jar file
     if (bLocation != null) { // skip unchanged output folder
       IPath p = bLocation.getProjectRelativePath();
       if (p != null) {
         IResourceDelta binaryDelta = delta.findMember(p);
         if (binaryDelta != null) {
           if (bLocation instanceof ClasspathJar) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found delta to jar/zip file"); //$NON-NLS-1$
             return false; // do full build since jar file was changed (added/removed were caught
             // as classpath change)
           }
           if (binaryDelta.getKind() == IResourceDelta.ADDED
               || binaryDelta.getKind() == IResourceDelta.REMOVED) {
             if (JavaBuilder.DEBUG)
               System.out.println(
                   "ABORTING incremental build... found added/removed binary folder"); //$NON-NLS-1$
             return false; // added/removed binary folder should not make it here (classpath
             // change), but handle anyways
           }
           int segmentCount = binaryDelta.getFullPath().segmentCount();
           IResourceDelta[] children =
               binaryDelta.getAffectedChildren(); // .class files from class folder
           StringSet structurallyChangedTypes = null;
           if (bLocation.isOutputFolder())
             structurallyChangedTypes =
                 this.newState.getStructurallyChangedTypes(
                     this.javaBuilder.getLastState(prereqProject));
           for (int j = 0, m = children.length; j < m; j++)
             findAffectedSourceFiles(children[j], segmentCount, structurallyChangedTypes);
           this.notifier.checkCancel();
         }
       }
     }
   }
   return true;
 }
Ejemplo n.º 3
0
 private boolean hasStructuralDelta() {
   // handle case when currentProject has only .class file folders and/or jar files... no
   // source/output folders
   IResourceDelta delta = getDelta(this.currentProject);
   if (delta != null && delta.getKind() != IResourceDelta.NO_CHANGE) {
     ClasspathLocation[] classFoldersAndJars =
         (ClasspathLocation[]) this.binaryLocationsPerProject.get(this.currentProject);
     if (classFoldersAndJars != null) {
       for (int i = 0, l = classFoldersAndJars.length; i < l; i++) {
         ClasspathLocation classFolderOrJar =
             classFoldersAndJars[i]; // either a .class file folder or a zip/jar file
         if (classFolderOrJar != null) {
           IPath p = classFolderOrJar.getProjectRelativePath();
           if (p != null) {
             IResourceDelta binaryDelta = delta.findMember(p);
             if (binaryDelta != null && binaryDelta.getKind() != IResourceDelta.NO_CHANGE)
               return true;
           }
         }
       }
     }
   }
   return false;
 }
Ejemplo n.º 4
0
    @Override
    public boolean visit(IResourceDelta delta) throws CoreException {
      if (delta == null) {
        return false;
      }

      IFile file = getFile();
      if (file == null) {
        return false;
      }

      delta = delta.findMember(file.getFullPath());

      if (delta == null) {
        return false;
      }

      Runnable runnable = null;

      switch (delta.getKind()) {
        case IResourceDelta.CHANGED:
          FileInfo info = (FileInfo) getElementInfo(fileEditorInput);
          if (info == null || !canRefreshFromFile(info)) {
            break;
          }

          boolean isSynchronized = computeModificationStamp(file) == info.modificationStamp;
          if ((IResourceDelta.ENCODING & delta.getFlags()) != 0 && isSynchronized) {
            runnable =
                new SafeChange(fileEditorInput) {
                  @Override
                  protected void execute(IEditorInput input) throws Exception {
                    handleElementContentChanged(input);
                  }
                };
          }

          if (runnable == null
              && (IResourceDelta.CONTENT & delta.getFlags()) != 0
              && !isSynchronized) {
            runnable =
                new SafeChange(fileEditorInput) {
                  @Override
                  protected void execute(IEditorInput input) throws Exception {
                    handleElementContentChanged(input);
                  }
                };
          }
          break;

        case IResourceDelta.REMOVED:
          if ((IResourceDelta.MOVED_TO & delta.getFlags()) != 0) {
            final IPath path = delta.getMovedToPath();
            runnable =
                new SafeChange(fileEditorInput) {
                  @Override
                  protected void execute(IEditorInput input) throws Exception {
                    handleElementMoved(input, path);
                  }
                };
          } else {
            info = (FileInfo) getElementInfo(fileEditorInput);
            if (info != null && canRefreshFromFile(info)) {
              runnable =
                  new SafeChange(fileEditorInput) {
                    @Override
                    protected void execute(IEditorInput input) throws Exception {
                      handleElementDeleted(input);
                    }
                  };
            }
          }
          break;
      }

      if (runnable != null) {
        update(runnable);
      }

      return false;
    }
Ejemplo n.º 5
0
 private void processEntryChanges(
     IResourceDelta projectDelta, Map<IProject, Boolean> projectsToSave) {
   // check each resource with user-set encoding to see if it has
   // been moved/deleted or if derived state has been changed
   IProject currentProject = (IProject) projectDelta.getResource();
   Preferences projectRegularPrefs = getPreferences(currentProject, false, false, true);
   Preferences projectDerivedPrefs = getPreferences(currentProject, false, true, true);
   Map<Boolean, String[]> affectedResourcesMap = new HashMap<>();
   try {
     // no regular preferences for this project
     if (projectRegularPrefs == null) affectedResourcesMap.put(Boolean.FALSE, new String[0]);
     else affectedResourcesMap.put(Boolean.FALSE, projectRegularPrefs.keys());
     // no derived preferences for this project
     if (projectDerivedPrefs == null) affectedResourcesMap.put(Boolean.TRUE, new String[0]);
     else affectedResourcesMap.put(Boolean.TRUE, projectDerivedPrefs.keys());
   } catch (BackingStoreException e) {
     // problems with the project scope... we will miss the changes (but will log)
     String message = Messages.resources_readingEncoding;
     Policy.log(
         new ResourceStatus(
             IResourceStatus.FAILED_GETTING_CHARSET, currentProject.getFullPath(), message, e));
     return;
   }
   for (Iterator<Boolean> it = affectedResourcesMap.keySet().iterator(); it.hasNext(); ) {
     Boolean isDerived = it.next();
     String[] affectedResources = affectedResourcesMap.get(isDerived);
     Preferences projectPrefs =
         isDerived.booleanValue() ? projectDerivedPrefs : projectRegularPrefs;
     for (int i = 0; i < affectedResources.length; i++) {
       IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i]));
       // no changes for the given resource
       if (memberDelta == null) continue;
       if (memberDelta.getKind() == IResourceDelta.REMOVED) {
         boolean shouldDisableCharsetDeltaJobForCurrentProject = false;
         // remove the setting for the original location - save its value though
         String currentValue = projectPrefs.get(affectedResources[i], null);
         projectPrefs.remove(affectedResources[i]);
         if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
           IPath movedToPath = memberDelta.getMovedToPath();
           IResource resource = workspace.getRoot().findMember(movedToPath);
           if (resource != null) {
             Preferences encodingSettings =
                 getPreferences(
                     resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS));
             if (currentValue == null || currentValue.trim().length() == 0)
               encodingSettings.remove(getKeyFor(movedToPath));
             else encodingSettings.put(getKeyFor(movedToPath), currentValue);
             IProject targetProject = workspace.getRoot().getProject(movedToPath.segment(0));
             if (targetProject.equals(currentProject))
               // if the file was moved inside the same project disable charset listener
               shouldDisableCharsetDeltaJobForCurrentProject = true;
             else projectsToSave.put(targetProject, Boolean.FALSE);
           }
         }
         projectsToSave.put(
             currentProject, Boolean.valueOf(shouldDisableCharsetDeltaJobForCurrentProject));
       }
     }
     if (moveSettingsIfDerivedChanged(
         projectDelta, currentProject, projectPrefs, affectedResources)) {
       // if settings were moved between preferences files disable charset listener so we don't
       // react to changes made by ourselves
       projectsToSave.put(currentProject, Boolean.TRUE);
     }
   }
 }