Ejemplo n.º 1
0
    private boolean moveSettingsIfDerivedChanged(
        IResourceDelta parent,
        IProject currentProject,
        Preferences projectPrefs,
        String[] affectedResources) {
      boolean resourceChanges = false;

      if ((parent.getFlags() & IResourceDelta.DERIVED_CHANGED) != 0) {
        // if derived changed, move encoding to correct preferences
        IPath parentPath = parent.getResource().getProjectRelativePath();
        for (int i = 0; i < affectedResources.length; i++) {
          IPath affectedPath = new Path(affectedResources[i]);
          // if parentPath is an ancestor of affectedPath
          if (parentPath.isPrefixOf(affectedPath)) {
            IResource member = currentProject.findMember(affectedPath);
            if (member != null) {
              Preferences targetPrefs =
                  getPreferences(currentProject, true, member.isDerived(IResource.CHECK_ANCESTORS));
              // if new preferences are different than current
              if (!projectPrefs.absolutePath().equals(targetPrefs.absolutePath())) {
                // remove encoding from old preferences and save in correct preferences
                String currentValue = projectPrefs.get(affectedResources[i], null);
                projectPrefs.remove(affectedResources[i]);
                targetPrefs.put(affectedResources[i], currentValue);
                resourceChanges = true;
              }
            }
          }
        }
      }

      IResourceDelta[] children = parent.getAffectedChildren();
      for (int i = 0; i < children.length; i++) {
        resourceChanges =
            moveSettingsIfDerivedChanged(
                    children[i], currentProject, projectPrefs, affectedResources)
                || resourceChanges;
      }
      return resourceChanges;
    }
Ejemplo n.º 2
0
 protected void splitEncodingPreferences(IProject project) {
   Preferences projectRegularPrefs = getPreferences(project, false, false, false);
   Preferences projectDerivedPrefs = null;
   if (projectRegularPrefs == null) return;
   try {
     boolean prefsChanged = false;
     String[] affectedResources;
     affectedResources = projectRegularPrefs.keys();
     for (int i = 0; i < affectedResources.length; i++) {
       String path = affectedResources[i];
       IResource resource = project.findMember(path);
       if (resource != null) {
         if (resource.isDerived(IResource.CHECK_ANCESTORS)) {
           String value = projectRegularPrefs.get(path, null);
           projectRegularPrefs.remove(path);
           // lazy creation of derived preferences
           if (projectDerivedPrefs == null)
             projectDerivedPrefs = getPreferences(project, true, true, true);
           projectDerivedPrefs.put(path, value);
           prefsChanged = true;
         }
       }
     }
     if (prefsChanged) {
       Map<IProject, Boolean> projectsToSave = new HashMap<>();
       // this is internal change so do not notify charset delta job
       projectsToSave.put(project, Boolean.TRUE);
       job.addChanges(projectsToSave);
     }
   } 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, project.getFullPath(), message, e));
   }
 }
Ejemplo n.º 3
0
 public void setCharsetFor(IPath resourcePath, String newCharset) throws CoreException {
   // for the workspace root we just set a preference in the instance scope
   if (resourcePath.segmentCount() == 0) {
     IEclipsePreferences resourcesPreferences =
         InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES);
     if (newCharset != null) resourcesPreferences.put(ResourcesPlugin.PREF_ENCODING, newCharset);
     else resourcesPreferences.remove(ResourcesPlugin.PREF_ENCODING);
     try {
       resourcesPreferences.flush();
     } catch (BackingStoreException e) {
       IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
       String message = Messages.resources_savingEncoding;
       throw new ResourceException(
           IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e);
     }
     return;
   }
   // for all other cases, we set a property in the corresponding project
   IResource resource = workspace.getRoot().findMember(resourcePath);
   if (resource != null) {
     try {
       // disable the listener so we don't react to changes made by ourselves
       Preferences encodingSettings =
           getPreferences(
               resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS));
       if (newCharset == null || newCharset.trim().length() == 0)
         encodingSettings.remove(getKeyFor(resourcePath));
       else encodingSettings.put(getKeyFor(resourcePath), newCharset);
       flushPreferences(encodingSettings, true);
     } catch (BackingStoreException e) {
       IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
       String message = Messages.resources_savingEncoding;
       throw new ResourceException(
           IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e);
     }
   }
 }
Ejemplo n.º 4
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);
     }
   }
 }
Ejemplo n.º 5
0
  protected void cleanOutputFolders(boolean copyBack) throws CoreException {
    boolean deleteAll =
        JavaCore.CLEAN.equals(
            this.javaBuilder.javaProject.getOption(
                JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
    if (deleteAll) {
      if (this.javaBuilder.participants != null)
        for (int i = 0, l = this.javaBuilder.participants.length; i < l; i++)
          this.javaBuilder.participants[i].cleanStarting(this.javaBuilder.javaProject);

      ArrayList visited = new ArrayList(this.sourceLocations.length);
      for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        this.notifier.subTask(
            Messages.bind(
                Messages.build_cleaningOutput, this.javaBuilder.currentProject.getName()));
        ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        if (sourceLocation.hasIndependentOutputFolder) {
          IContainer outputFolder = sourceLocation.binaryFolder;
          if (!visited.contains(outputFolder)) {
            visited.add(outputFolder);
            IResource[] members = outputFolder.members();
            for (int j = 0, m = members.length; j < m; j++) {
              IResource member = members[j];
              if (!member.isDerived()) {
                member.accept(
                    new IResourceVisitor() {
                      public boolean visit(IResource resource) throws CoreException {
                        resource.setDerived(true, null);
                        return resource.getType() != IResource.FILE;
                      }
                    });
              }
              member.delete(IResource.FORCE, null);
            }
          }
          this.notifier.checkCancel();
          if (copyBack) copyExtraResourcesBack(sourceLocation, true);
        } else {
          boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
          final char[][] exclusionPatterns =
              isOutputFolder
                  ? sourceLocation.exclusionPatterns
                  : null; // ignore exclusionPatterns if output folder == another source folder...
                          // not this one
          final char[][] inclusionPatterns =
              isOutputFolder
                  ? sourceLocation.inclusionPatterns
                  : null; // ignore inclusionPatterns if output folder == another source folder...
                          // not this one
          sourceLocation.binaryFolder.accept(
              new IResourceProxyVisitor() {
                public boolean visit(IResourceProxy proxy) throws CoreException {
                  if (proxy.getType() == IResource.FILE) {
                    if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(
                        proxy.getName())) {
                      IResource resource = proxy.requestResource();
                      if (exclusionPatterns != null || inclusionPatterns != null)
                        if (Util.isExcluded(
                            resource.getFullPath(), inclusionPatterns, exclusionPatterns, false))
                          return false;
                      if (!resource.isDerived()) resource.setDerived(true, null);
                      resource.delete(IResource.FORCE, null);
                    }
                    return false;
                  }
                  if (exclusionPatterns != null
                      && inclusionPatterns
                          == null) // must walk children if inclusionPatterns != null
                  if (Util.isExcluded(proxy.requestFullPath(), null, exclusionPatterns, true))
                      return false;
                  BatchImageBuilder.this.notifier.checkCancel();
                  return true;
                }
              },
              IResource.NONE);
          this.notifier.checkCancel();
        }
        this.notifier.checkCancel();
      }
    } else if (copyBack) {
      for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
        ClasspathMultiDirectory sourceLocation = this.sourceLocations[i];
        if (sourceLocation.hasIndependentOutputFolder)
          copyExtraResourcesBack(sourceLocation, false);
        this.notifier.checkCancel();
      }
    }
    // GROOVY start
    LanguageSupportFactory.getEventHandler()
        .handle(this.javaBuilder.javaProject, "cleanOutputFolders");
    // GROOVY end
  }