public boolean performOk() {
    boolean doctype = performDoctypeOk();
    boolean cssprofile = performCSSProfileOk();
    if (doctype || cssprofile) {
      // touch to mark for build-driven revalidation
      IResource resource = getResource();
      if (resource != null) {
        try {
          resource.accept(
              new IResourceVisitor() {

                public boolean visit(IResource resource) throws CoreException {
                  try {
                    resource.touch(null);
                  } catch (CoreException e) {
                    return false;
                  }
                  return true;
                }
              },
              IResource.DEPTH_INFINITE,
              false);
        } catch (CoreException e) {
          Logger.logException(e);
        }
      }
    }

    return super.performOk();
  }
Exemple #2
0
 public static IScope getSubTree(IResource r) {
   ResourceVisitor visitor = new ResourceVisitor();
   ZigguratInject.inject(visitor);
   try {
     r.accept(visitor);
   } catch (CoreException e) {
     e.printStackTrace();
   }
   return visitor.getResult();
 }
 /**
  * Performs the tpe checking on the selected resources.
  *
  * @param monitor progress monitor, can be null
  * @return true iff no type problems were found
  * @throws CoreException
  */
 public boolean doCheck(IProgressMonitor monitor) throws CoreException {
   if (monitor == null) {
     monitor = new NullProgressMonitor();
   }
   monitor.beginTask("Static type analysis", resources.size());
   for (IResource resource : resources) {
     if (monitor.isCanceled()) {
       throw new OperationCanceledException();
     }
     CheckerVisitor visitor = new CheckerVisitor(monitor);
     resource.accept(visitor);
     monitor.worked(1);
   }
   return handler.finish(null);
 }
  private static void deletePersistentProperties(IResource resource) throws CoreException {
    resource.accept(
        new IResourceProxyVisitor() {

          @Override
          public boolean visit(IResourceProxy proxy) throws CoreException {
            if (proxy.getType() == IResource.FILE) {
              IResource resource = proxy.requestResource();
              resource.setPersistentProperty(MODIFICATION_STAMP_PERSISTENT_PROP_KEY, null);
              resource.setPersistentProperty(LAST_ANALYSIS_DATE_PERSISTENT_PROP_KEY, null);
              return false;
            }
            return true;
          }
        },
        IResource.NONE);
  }
 private void checkDirtyResources(final RefactoringStatus result) throws CoreException {
   for (int i = 0; i < fResources.length; i++) {
     IResource resource = fResources[i];
     if (resource instanceof IProject && !((IProject) resource).isOpen()) continue;
     resource.accept(
         new IResourceVisitor() {
           public boolean visit(IResource visitedResource) throws CoreException {
             if (visitedResource instanceof IFile) {
               checkDirtyFile(result, (IFile) visitedResource);
             }
             return true;
           }
         },
         IResource.DEPTH_INFINITE,
         false);
   }
 }
Exemple #6
0
  private void scanResource() throws CoreException {
    resource.accept(
        new IResourceVisitor() {

          public boolean visit(IResource resource) {
            String relpath = getRelativePath(resource);
            if (isIncluded(relpath) && !isExcluded(relpath)) {
              if (resource instanceof IContainer) {
                includedDirectories.add(relpath);
              } else {
                includedFiles.add(relpath);
              }
              return true;
            } else if (resource instanceof IFolder) {
              return couldHoldIncluded(relpath);
            }

            return false;
          }
        });
  }
  public boolean execute(IProgressMonitor progressMonitor) {

    if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true;
    if (!project.isAccessible()) return true; // nothing to do
    IResource folder = this.project.getParent().findMember(this.folderPath);
    if (folder == null || folder.getType() == IResource.FILE)
      return true; // nothing to do, source folder was removed

    /* ensure no concurrent write access to index */
    Index index =
        this.manager.getIndex(
            this.containerPath, true, /*reuse index file*/ true /*create if none*/);
    if (index == null) return true;
    ReadWriteMonitor monitor = index.monitor;
    if (monitor == null) return true; // index got deleted since acquired

    try {
      monitor.enterRead(); // ask permission to read

      final IPath container = this.containerPath;
      final IndexManager indexManager = this.manager;
      final SourceElementParser parser =
          indexManager.getSourceElementParser(
              JavaCore.create(this.project), null /*requestor will be set by indexer*/);
      if (this.exclusionPatterns == null && this.inclusionPatterns == null) {
        folder.accept(
            new IResourceProxyVisitor() {
              public boolean visit(IResourceProxy proxy) /* throws CoreException */ {
                if (proxy.getType() == IResource.FILE) {
                  if (descent.internal.core.util.Util.isJavaLikeFileName(proxy.getName()))
                    indexManager.addSource((IFile) proxy.requestResource(), container, parser);
                  return false;
                }
                return true;
              }
            },
            IResource.NONE);
      } else {
        folder.accept(
            new IResourceProxyVisitor() {
              public boolean visit(IResourceProxy proxy) /* throws CoreException */ {
                switch (proxy.getType()) {
                  case IResource.FILE:
                    if (descent.internal.core.util.Util.isJavaLikeFileName(proxy.getName())) {
                      IResource resource = proxy.requestResource();
                      if (!Util.isExcluded(resource, inclusionPatterns, exclusionPatterns))
                        indexManager.addSource((IFile) resource, container, parser);
                    }
                    return false;
                  case IResource.FOLDER:
                    if (exclusionPatterns != null && inclusionPatterns == null) {
                      // if there are inclusion patterns then we must walk the children
                      if (Util.isExcluded(
                          proxy.requestFullPath(), inclusionPatterns, exclusionPatterns, true))
                        return false;
                    }
                }
                return true;
              }
            },
            IResource.NONE);
      }
    } catch (CoreException e) {
      if (JobManager.VERBOSE) {
        Util.verbose(
            "-> failed to add " + this.folderPath + " to index because of the following exception:",
            System.err); // $NON-NLS-1$ //$NON-NLS-2$
        e.printStackTrace();
      }
      return false;
    } finally {
      monitor.exitRead(); // free read lock
    }
    return true;
  }
  protected void moveResource(
      IPackageFragmentRoot root, IEGLPathEntry rootEntry, final IWorkspaceRoot workspaceRoot)
      throws EGLModelException {

    final char[][] exclusionPatterns = ((EGLPathEntry) rootEntry).fullExclusionPatternChars();
    IResource rootResource = root.getResource();
    if (rootEntry.getEntryKind() != IEGLPathEntry.CPE_SOURCE || exclusionPatterns == null) {
      try {
        IResource destRes;
        if ((this.updateModelFlags & IPackageFragmentRoot.REPLACE) != 0
            && (destRes = workspaceRoot.findMember(this.destination)) != null) {
          destRes.delete(this.updateResourceFlags, fMonitor);
        }
        rootResource.move(this.destination, this.updateResourceFlags, fMonitor);
      } catch (CoreException e) {
        throw new EGLModelException(e);
      }
    } else {
      final int sourceSegmentCount = rootEntry.getPath().segmentCount();
      final IFolder destFolder = workspaceRoot.getFolder(this.destination);
      final IPath[] nestedFolders = getNestedFolders(root);
      IResourceProxyVisitor visitor =
          new IResourceProxyVisitor() {
            public boolean visit(IResourceProxy proxy) throws CoreException {
              if (proxy.getType() == IResource.FOLDER) {
                IPath path = proxy.requestFullPath();
                if (prefixesOneOf(path, nestedFolders)) {
                  if (equalsOneOf(path, nestedFolders)) {
                    // nested source folder
                    return false;
                  } else {
                    // folder containing nested source folder
                    IFolder folder =
                        destFolder.getFolder(path.removeFirstSegments(sourceSegmentCount));
                    if ((updateModelFlags & IPackageFragmentRoot.REPLACE) != 0 && folder.exists()) {
                      return true;
                    }
                    folder.create(updateResourceFlags, true, fMonitor);
                    return true;
                  }
                } else {
                  // subtree doesn't contain any nested source folders
                  IPath destPath = destination.append(path.removeFirstSegments(sourceSegmentCount));
                  IResource destRes;
                  if ((updateModelFlags & IPackageFragmentRoot.REPLACE) != 0
                      && (destRes = workspaceRoot.findMember(destPath)) != null) {
                    destRes.delete(updateResourceFlags, fMonitor);
                  }
                  proxy.requestResource().move(destPath, updateResourceFlags, fMonitor);
                  return false;
                }
              } else {
                IPath path = proxy.requestFullPath();
                IPath destPath = destination.append(path.removeFirstSegments(sourceSegmentCount));
                IResource destRes;
                if ((updateModelFlags & IPackageFragmentRoot.REPLACE) != 0
                    && (destRes = workspaceRoot.findMember(destPath)) != null) {
                  destRes.delete(updateResourceFlags, fMonitor);
                }
                proxy.requestResource().move(destPath, updateResourceFlags, fMonitor);
                return false;
              }
            }
          };
      try {
        rootResource.accept(visitor, IResource.NONE);
      } catch (CoreException e) {
        throw new EGLModelException(e);
      }
    }
    this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
  }
  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
  }