@Override
 public boolean isAffected(Delta delta, IResourceDescription candidate)
     throws IllegalArgumentException {
   if (!hasChanges(delta, candidate)) return false;
   Set<QualifiedName> names = Sets.newHashSet();
   addExportedNames(names, delta.getOld());
   addExportedNames(names, delta.getNew());
   return !Collections.disjoint(names, getImportedNames(candidate));
 }
예제 #2
0
  /** @since 2.7 */
  protected IFileCallback getPostProcessor(
      Delta delta, final IBuildContext context, final Set<IFile> derivedResources) {
    final String uri = delta.getUri().toString();
    return new EclipseResourceFileSystemAccess2.IFileCallback() {

      @Override
      public boolean beforeFileDeletion(IFile file) {
        derivedResources.remove(file);
        context.needRebuild();
        return true;
      }

      @Override
      public void afterFileUpdate(IFile file) {
        handleFileAccess(file);
      }

      @Override
      public void afterFileCreation(IFile file) {
        handleFileAccess(file);
      }

      protected void handleFileAccess(IFile file) {
        try {
          derivedResources.remove(file);
          derivedResourceMarkers.installMarker(file, uri);
          context.needRebuild();
        } catch (CoreException e) {
          throw new RuntimeException(e);
        }
      }
    };
  }
  @Override
  public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
    if (!context.getBuiltProject().hasNature(KarelNature.NATURE_ID)) return;

    for (Delta delta : context.getDeltas()) {
      IResourceDescription newRes = delta.getNew();
      if (newRes == null) continue;

      try {
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        URI uri = CommonPlugin.resolve(newRes.getURI());
        if (!uri.isFile()) continue;
        IPath path = new Path(uri.toFileString());
        IFile file = workspaceRoot.getFileForLocation(path);
        if (file == null) continue;
        generate(context.getBuiltProject(), file, monitor);
      } catch (Exception e) {
        IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
        Activator.getDefault().getLog().log(status);
      }
    }

    context.getResourceSet();
  }
예제 #4
0
 protected void handleChangedContents(
     Delta delta, IBuildContext context, EclipseResourceFileSystemAccess2 fileSystemAccess)
     throws CoreException {
   // TODO: we will run out of memory here if the number of deltas is large enough
   Resource resource = context.getResourceSet().getResource(delta.getUri(), true);
   if (shouldGenerate(resource, context)) {
     try {
       generator.doGenerate(resource, fileSystemAccess);
     } catch (RuntimeException e) {
       if (e.getCause() instanceof CoreException) {
         throw (CoreException) e.getCause();
       }
       throw e;
     }
   }
 }
예제 #5
0
 /** @since 2.7 */
 protected String getCurrentSourceFolder(IBuildContext context, Delta delta) {
   Iterable<org.eclipse.xtext.util.Pair<IStorage, IProject>> storages =
       storage2UriMapper.getStorages(delta.getUri());
   for (org.eclipse.xtext.util.Pair<IStorage, IProject> pair : storages) {
     final IResource resource = (IResource) pair.getFirst();
     IProject project = pair.getSecond();
     for (OutputConfiguration output : getOutputConfigurations(context).values()) {
       for (SourceMapping sourceMapping : output.getSourceMappings()) {
         IContainer folder = ResourceUtil.getContainer(project, sourceMapping.getSourceFolder());
         if (folder.contains(resource)) {
           return sourceMapping.getSourceFolder();
         }
       }
     }
   }
   return null;
 }
예제 #6
0
 /** @since 2.7 */
 protected Set<IFile> getDerivedResources(
     Delta delta,
     final Map<String, OutputConfiguration> outputConfigurations,
     Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers) {
   String uri = delta.getUri().toString();
   Set<IFile> derivedResources = newLinkedHashSet();
   for (OutputConfiguration config : outputConfigurations.values()) {
     if (config.isCleanUpDerivedResources()) {
       Iterable<IMarker> markers = generatorMarkers.get(config);
       for (IMarker marker : markers) {
         String source = derivedResourceMarkers.getSource(marker);
         if (source != null && source.equals(uri))
           derivedResources.add((IFile) marker.getResource());
       }
     }
   }
   return derivedResources;
 }
예제 #7
0
 /** @since 2.7 */
 protected void cleanDerivedResources(
     Delta delta,
     Set<IFile> derivedResources,
     IBuildContext context,
     EclipseResourceFileSystemAccess2 access,
     IProgressMonitor deleteMonitor)
     throws CoreException {
   String uri = delta.getUri().toString();
   for (IFile iFile : newLinkedHashSet(derivedResources)) {
     if (deleteMonitor.isCanceled()) {
       throw new OperationCanceledException();
     }
     IMarker marker = derivedResourceMarkers.findDerivedResourceMarker(iFile, uri);
     if (marker != null) marker.delete();
     if (derivedResourceMarkers.findDerivedResourceMarkers(iFile).length == 0) {
       access.deleteFile(iFile, deleteMonitor);
       context.needRebuild();
     }
   }
 }