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;
 }
Beispiel #2
0
 private Set<String> getResourcesToBuild(
     final int kind, @SuppressWarnings("rawtypes") final Map args, final IProject project)
     throws CoreException {
   Set<BuildResource> result = Sets.newHashSet();
   final IProgressMonitor submon = new NullProgressMonitor();
   // new SubProgressMonitor(monitor, 10);
   submon.beginTask("retrieving resources to build", IProgressMonitor.UNKNOWN);
   if (kind == FULL_BUILD) {
     result = helper.getAffectedResources(args, project, submon);
   } else {
     final IResourceDelta delta = getDelta(project);
     final Path path = new Path(".settings/org.erlide.core.prefs");
     if (delta.findMember(path) != null) {
       ErlLogger.info("project configuration changed: doing full rebuild");
       result = helper.getAffectedResources(args, project, submon);
     } else {
       result = helper.getAffectedResources(args, delta, submon);
     }
   }
   if (BuilderHelper.isDebugging()) {
     ErlLogger.debug(
         "Will compile %d resource(s): %s", Integer.valueOf(result.size()), result.toString());
   }
   submon.done();
   final Set<String> paths = new HashSet<String>();
   for (final BuildResource res : result) {
     paths.add(res.getResource().getLocation().toPortableString());
   }
   return paths;
 }
 @Override
 public void resourceChanged(IResourceChangeEvent event) {
   IResourceDelta delta = event.getDelta();
   if (delta == null) {
     return;
   }
   IEditorInput input = getEditorInput();
   IPath localPath = null;
   if (input instanceof IPathEditorInput) {
     localPath = ((IPathEditorInput) input).getPath();
   }
   if (localPath == null) {
     return;
   }
   localPath = ContentUtils.convertPathToWorkspacePath(localPath);
   delta = delta.findMember(localPath);
   if (delta == null) {
     return;
   }
   if (delta.getKind() == IResourceDelta.CHANGED) {
     // Refresh editor
     DBeaverUI.asyncExec(
         new Runnable() {
           @Override
           public void run() {
             loadImage();
           }
         });
   }
 }
 private IResourceDelta getDelta(File file) {
   IPath relpath = getRelativePath(file);
   if (relpath == null) {
     return null;
   }
   return delta.findMember(relpath);
 }
Beispiel #5
0
 @Override
 public void resourceChanged(IResourceChangeEvent event) {
   IResourceDelta delta = event.getDelta();
   if (delta != null) {
     final IPath serverPropertiesFullPath =
         serverProject.getFullPath().append(SERVER_PROPERTIES);
     if (delta.findMember(serverPropertiesFullPath) != null) {
       serverChanged();
     }
   }
 }
Beispiel #6
0
 public void resourceChanged(IResourceChangeEvent e) {
   IResourceDelta delta = e.getDelta();
   IResource resource = getResource();
   if (delta != null && resource != null) {
     IResourceDelta child = delta.findMember(resource.getFullPath());
     if (child != null) {
       IMarkerDelta[] deltas = child.getMarkerDeltas();
       if (deltas.length > 0) {
         forceReconciling(false);
       }
     }
   }
 }
  /**
   * @see
   *     org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
   */
  @Override
  public void resourceChanged(IResourceChangeEvent event) {
    final IResourceDelta rootDelta = event.getDelta();
    if (rootDelta == null) return;

    final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject project : projects) {
      final IPath roughnessPath = project.getFullPath().append(ROUGHNESS_DATABASE_PATH);
      final IResourceDelta fileDelta = rootDelta.findMember(roughnessPath);
      if (fileDelta != null) {
        if ((fileDelta.getFlags() & IResourceDelta.CONTENT) != 0)
          startStyleUpdateJob((IFile) fileDelta.getResource());
      }
    }
  }
    /**
     * Goes through all the resource-dependent preferences associated with currentProject & key and
     * updates the preference keys if needed based on projectDelta
     *
     * @param currentProject current project of the preferences to be looked at
     * @param key current key/subcategory of the preferences to be looked at
     * @param projectDelta the changes to process the preference keys against
     * @param projectsToSave the projects that need to be updated/saved
     * @return true if currentProject's preferences were modified
     */
    private boolean processPreferences(
        IProject currentProject, String key, IResourceDelta projectDelta, Set projectsToSave) {
      boolean resourceChanges = false;

      // get the project-key preference node
      Preferences projectPrefs = CSSContentProperties.getPreferences(currentProject, key, false);
      if (projectPrefs == null)
        // no preferences for this project-key, just bail
        return false;
      String[] affectedResources;
      try {
        affectedResources = projectPrefs.keys();
      } catch (BackingStoreException e) {
        // problems with the project scope... we gonna miss the
        // changes (but will log)
        Logger.log(
            Logger.WARNING_DEBUG, "Problem retreiving JSP Fragment preferences", e); // $NON-NLS-1$
        return false;
      }

      // go through each preference key (which is really a file name)
      for (int i = 0; i < affectedResources.length; i++) {
        // see if preference key/file name was file that was changed
        IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i]));
        // no changes for the given resource
        if (memberDelta == null) continue;
        if (memberDelta.getKind() == IResourceDelta.REMOVED) {
          resourceChanges = true;
          // remove the setting for the original location
          String currentValue = projectPrefs.get(affectedResources[i], null);
          projectPrefs.remove(affectedResources[i]);
          if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
            // if moving, copy the setting for the new location
            IProject targetProject =
                ResourcesPlugin.getWorkspace()
                    .getRoot()
                    .getProject(memberDelta.getMovedToPath().segment(0));
            Preferences targetPrefs = CSSContentProperties.getPreferences(targetProject, key, true);
            targetPrefs.put(
                CSSContentProperties.getKeyFor(memberDelta.getMovedToPath()), currentValue);
            if (targetProject != currentProject) projectsToSave.add(targetProject);
          }
        }
      }
      return resourceChanges;
    }
 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;
 }
Beispiel #10
0
  protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor)
      throws CoreException, IOException, ParseException {
    final Architecture architecture = ArchitectureUtils.getOrInitializeArchitecture(getProject());
    final boolean updateDC = (delta.findMember(new Path(DCLUtil.DC_FILENAME)) != null);
    if (updateDC) {
      architecture.updateDependencyConstraints(this.getProject());
    }
    monitor.beginTask(
        "Checking architecture",
        delta.getAffectedChildren(
                IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED,
                IResource.FILE)
            .length);
    delta.accept(new IncrementalDeltaVisitor(architecture, monitor));

    /* For now, any change in the DCL File requires full build */
    if (updateDC) {
      getProject().accept(new FullBuildVisitor(architecture, monitor, false));
    }
  }
Beispiel #11
0
  private void incrementalBuild(
      IPath outputLocation, final IResourceDelta delta, IProgressMonitor monitor)
      throws CoreException {
    monitor.beginTask(Messages.Builder_IncrementalBuildMessage, 2);

    if (delta.findMember(new Path(META_INF)) != null) {
      buildMetaInf(outputLocation, new SubProgressMonitor(monitor, 1));
    } else {
      monitor.worked(1);
    }

    buildLibraries(
        new Predicate<String>() {
          @Override
          public boolean accept(String t) {
            return delta.findMember(new Path(t)) != null;
          }
        },
        outputLocation,
        new SubProgressMonitor(monitor, 1));
    monitor.done();
  }
Beispiel #12
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;
 }
    @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;
    }
  public void resourceChanged(IResourceChangeEvent event) {
    // we are only interested in POST_CHANGE events
    if (event.getType() != IResourceChangeEvent.POST_CHANGE) return;

    final Set<IProject> projectsWithModifiedWTPModel = new HashSet<IProject>();
    final Set<IProject> projectsWithModifiedPDEModel = new HashSet<IProject>();

    IResourceDelta rootDelta = event.getDelta();
    IResourceDelta[] projectDeltas = rootDelta.getAffectedChildren();
    for (IResourceDelta projectDelta : projectDeltas) {
      IProject project = (IProject) projectDelta.getResource();

      // first check if the modified project is a web application bundle
      if (!isWAB(project)) continue;

      // get the delta, if any, for the org.eclipse.wst.common.component file
      IResourceDelta componentDelta = projectDelta.findMember(VIRTUAL_COMPONENT_PATH);
      if (isContentChanged(componentDelta)) {
        // add the project to the list of affected projects
        projectsWithModifiedWTPModel.add(project);
      }

      // get the delta, if any, for the MANIFEST.MF file
      IResourceDelta manifestDelta = projectDelta.findMember(getManifestPath(project));
      if (isContentChanged(manifestDelta)) {
        // add the project to the list of modified projects
        projectsWithModifiedPDEModel.add(project);
      }
    }

    if (projectsWithModifiedWTPModel.size() > 0 || projectsWithModifiedPDEModel.size() > 0) {
      // process in a separate job that all projects are identified for possible change in the
      // context root.
      // reading and writing to models involves expensive I/O operation that should be executed
      // outside the
      // resource change listener.
      new Job(Messages.WebContextRootSynchonizer_JobName) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
          // process all projects that are identified for possible change in the context root
          for (IProject project : projectsWithModifiedWTPModel) {
            try {
              // trigger a build to give opportunity to the models to refresh
              project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
              // get the new context root from the WTP model
              String newContextRoot = getContextRootFromWTPModel(project);
              // get the old context root from the PDE model
              String oldContextRoot = getContextRootFromPDEModel(project);
              // check the context roots and decide if updating the one in the PDE model is needed
              if (!areEqual(newContextRoot, oldContextRoot)) {
                setContextRootInPDEModel(project, newContextRoot, monitor);
              }
            } catch (CoreException e) {
              LibraFacetPlugin.logError(
                  NLS.bind(
                      Messages.WebContextRootSynchonizer_UpdatingPDEModelFailed, project.getName()),
                  e);
            }
          }

          for (IProject project : projectsWithModifiedPDEModel) {
            try {
              // trigger a build to give opportunity to the models to refresh
              project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
              // get the new context root from the PDE model
              String newContextRoot = getContextRootFromPDEModel(project);
              // get the old context root from the WTP model
              String oldContextRoot = getContextRootFromWTPModel(project);
              // check the context roots and decide if updating the one in the WTP model is needed
              if (!areEqual(newContextRoot, oldContextRoot)) {
                setContextRootInWTPModel(project, newContextRoot);
              }
            } catch (CoreException e) {
              LibraFacetPlugin.logError(
                  NLS.bind(
                      Messages.WebContextRootSynchonizer_UpdatingWTPModelFailed, project.getName()),
                  e);
            }
          }
          return Status.OK_STATUS;
        }

        private boolean areEqual(String value1, String value2) {
          if (value1 == null) return value2 == null;
          return value1.equals(value2);
        }
      }.schedule();
    }
  }
 protected boolean hasDelta(IPath path) {
   return delta == null || path == null || delta.findMember(path) != null;
 }
Beispiel #16
0
  public void resourceChanged(IResourceChangeEvent event) {
    IResource myResource = ResourceUtil.getResource(getEditorInput());

    IResourceDelta delta = event.getDelta();
    if (delta == null) return;
    IPath fullPath = myResource.getFullPath();
    delta = delta.findMember(fullPath);
    if (delta == null) return;

    // Delegate to any interested pages
    for (Object page : pages) {
      if (page instanceof IResourceChangeListener) {
        ((IResourceChangeListener) page).resourceChanged(event);
      }
    }

    // Close editor if file removed or switch to new location if file moved
    if (delta.getKind() == IResourceDelta.REMOVED) {
      if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(delta.getMovedToPath());
        final FileEditorInput newInput = new FileEditorInput(file);

        setInput(newInput);
        Display display = getEditorSite().getShell().getDisplay();
        if (display != null) {
          SWTConcurrencyUtil.execForDisplay(
              display,
              true,
              new Runnable() {
                public void run() {
                  setPartNameForInput(newInput);
                  sourcePage.setInput(newInput);
                }
              });
        }
      } else {
        close(false);
      }

    }
    // File content updated externally => reload all pages
    else if ((delta.getKind() & IResourceDelta.CHANGED) > 0
        && (delta.getFlags() & IResourceDelta.CONTENT) > 0) {
      if (!saving.get()) {
        final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
        final IDocument document = docProvider.getDocument(getEditorInput());
        SWTConcurrencyUtil.execForControl(
            getEditorSite().getShell(),
            true,
            new Runnable() {
              public void run() {
                try {
                  model.loadFrom(new IDocumentWrapper(document));
                  updatePages();
                } catch (IOException e) {
                  logger.logError("Failed to reload document", e);
                }
              }
            });
      }
    }
  }
 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);
     }
   }
 }