Пример #1
0
  @Override
  protected final IProject[] build(
      int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
      throws CoreException {
    if (!validateProject()) {
      // Project who invoked the builder is not supported
      return new IProject[0];
    }

    getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);

    if (kind == IncrementalProjectBuilder.FULL_BUILD) {
      initialize();
      clean(monitor);
      build(monitor);
    } else {
      IResourceDelta delta = getDelta(getProject());
      // if (delta == null)
      DeltaFileVisitor visitor = new DeltaFileVisitor();
      delta.accept(visitor, IResourceDelta.ADDED | IResourceDelta.CHANGED);
      // {
      if (visitor.isSourceFound()) {
        initialize();
        build(monitor);
      }
      // } else
      // {
      // incrementalBuild(delta, monitor);
      // }
    }

    endBuild(monitor);
    return new IProject[] {getProject()};
  }
  protected IResourceDelta createSaveDelta() throws CoreException {
    IResourceDelta javaResource = mock(IResourceDelta.class);
    when(javaResource.getFullPath()).thenReturn(new Path("a.java"));
    javaResource.accept((IResourceDeltaVisitor) anyObject());

    return createResourceDelta(project, new IResourceDelta[] {javaResource});
  }
Пример #3
0
  @Override
  protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor)
      throws CoreException {

    IProject project = getProject();
    if (project == null) return null;

    if ((kind == INCREMENTAL_BUILD) || (kind == AUTO_BUILD)) {
      IResourceDelta delta = getDelta(project);
      if (delta == null) {
        project.accept(new PDDLVisitor());
      } else {
        delta.accept(new PDDLVisitor());
      }
    } else if (kind == FULL_BUILD) {
      project.accept(new PDDLVisitor());
    } else if (kind == CLEAN_BUILD) {
      IPDDLNature nature = PDDLNature.getPDDLNature(project);
      if (nature != null) {
        IPDDLProjectIndex index = nature.getPDDLProjectIndex();
        if (index != null) index.clear();
      }
    }

    return null;
  }
Пример #4
0
  protected void incrementalBuild(IResourceDelta delta, final IProgressMonitor monitor) {
    int deltaKind = delta.getKind();

    if (deltaKind == IResourceDelta.REMOVED) {
      return;
    }

    // final boolean[] buildCSS = new boolean[1];

    try {
      delta.accept(
          new IResourceDeltaVisitor() {
            public boolean visit(IResourceDelta delta) {
              final IResource resource = delta.getResource();
              IPath fullResourcePath = resource.getFullPath();

              for (String segment : fullResourcePath.segments()) {
                if ("_diffs".equals(segment)) // $NON-NLS-1$
                {
                  // IDE-110 IDE-648
                  final IWebProject webproject =
                      LiferayCore.create(IWebProject.class, getProject());

                  if (webproject != null && webproject.getDefaultDocrootFolder() != null) {
                    IFolder webappRoot = webproject.getDefaultDocrootFolder();

                    if (webappRoot != null) {
                      IFolder diffs = webappRoot.getFolder(new Path("_diffs")); // $NON-NLS-1$

                      if (diffs != null
                          && diffs.exists()
                          && diffs.getFullPath().isPrefixOf(fullResourcePath)) {
                        applyDiffsDeltaToDocroot(delta, diffs.getParent(), monitor);

                        return false;
                      }
                    }
                  }
                } else if ("build.xml".equals(segment)) // IDE-828 //$NON-NLS-1$
                {
                  IPath relPath = resource.getProjectRelativePath();

                  if (relPath != null && relPath.segmentCount() == 1) {
                    try {
                      compileTheme(resource.getProject());
                    } catch (CoreException e) {
                      ThemeCore.logError("Error compiling theme.", e); // $NON-NLS-1$
                    }
                  }
                }
              }

              return true; // visit children too
            }
          });
    } catch (CoreException e) {
      ThemeCore.logError(e);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
   */
  public void resourceChanged(IResourceChangeEvent event) {

    IResourceDelta delta = event.getDelta();
    try {
      delta.accept(this);
    } catch (CoreException e) {
      e.printStackTrace();
    }
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org
  * .eclipse.core.resources.IResourceChangeEvent)
  */
 public void resourceChanged(final IResourceChangeEvent event) {
   final IResourceDelta delta = event.getDelta();
   try {
     if (delta != null) {
       // ErlLogger.debug("change " + event.toString());
       delta.accept(this);
     }
   } catch (final CoreException e) {
     ErlLogger.warn(e);
   }
 }
Пример #7
0
 public Set<BuildResource> getAffectedResources(
     @SuppressWarnings("rawtypes") final Map args,
     final IResourceDelta delta,
     final IProgressMonitor monitor)
     throws CoreException {
   final Set<BuildResource> result = Sets.newHashSet();
   if (delta != null) {
     delta.accept(new BuilderVisitor(result, monitor, this));
   }
   return result;
 }
Пример #8
0
 @Override
 public void resourceChanged(IResourceChangeEvent e) {
   IResourceDelta delta = e.getDelta();
   try {
     if (delta != null && isInstalled) {
       delta.accept(this);
     }
   } catch (CoreException x) {
     log.warn("Error handling resourceChanged", x);
   }
 }
    /**
     * Provides manipulation of IResourceChangeEvent instance due to implement <code>
     * IResourceChangeListener</code>. This method must not be called by client because it is called
     * by platform when resources are changed.
     *
     * @param event A resource change event to describe changes to resources.
     */
    public void resourceChanged(IResourceChangeEvent event) {
      if (((event.getType() & IResourceChangeEvent.POST_CHANGE) != 0)) {
        //          ||
        //          ((event.getType() & IResourceChangeEvent.POST_AUTO_BUILD) != 0)) {
        try {
          IResourceDelta rootDelta = event.getDelta();

          // Accepts the class instance to let the instance be able to visit resource delta.
          rootDelta.accept(this);
        } catch (CoreException e) {
          e.printStackTrace();
        }
      }
    }
Пример #10
0
  protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {
    int deltaKind = delta.getKind();

    if (deltaKind == IResourceDelta.REMOVED || deltaKind == IResourceDelta.REMOVED_PHANTOM) {
      return;
    }

    final boolean[] buildCSS = new boolean[1];

    try {
      delta.accept(
          new IResourceDeltaVisitor() {

            private IFolder docroot = null;

            public boolean visit(IResourceDelta delta) {
              IPath fullResourcePath = delta.getResource().getFullPath();

              for (String segment : fullResourcePath.segments()) {
                if ("_diffs".equals(segment)) {
                  if (docroot == null) {
                    docroot = CoreUtil.getDocroot(getProject());
                  }

                  IFolder diffs = docroot.getFolder("_diffs");

                  if (diffs.exists() && diffs.getFullPath().isPrefixOf(fullResourcePath)) {
                    buildCSS[0] = true;

                    return false;
                  }
                }
              }

              return true; // visit children too
            }
          });
    } catch (CoreException e) {
      e.printStackTrace();
    }

    if (buildCSS[0]) {
      try {
        cssBuild(getProject());
      } catch (CoreException e) {
        ThemeCore.logError("Error in Theme CSS Builder", e);
      }
    }
  }
Пример #11
0
  /*
   * @see IResourceChangeListener#resourceChanged
   */
  @Override
  public void resourceChanged(IResourceChangeEvent event) {
    HashSet<IResource> changedElements = new HashSet<IResource>();

    try {
      IResourceDelta delta = event.getDelta();
      if (delta != null) delta.accept(new ProjectErrorVisitor(changedElements));
    } catch (CoreException e) {
      CUIPlugin.log(e.getStatus());
    }

    if (!changedElements.isEmpty()) {
      IResource[] changes = changedElements.toArray(new IResource[changedElements.size()]);
      fireChanges(changes, true);
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.core.resources.mapping.ModelProvider#validateChange(org.eclipse.core.resources.IResourceDelta, org.eclipse.core.runtime.IProgressMonitor)
  */
 public IStatus validateChange(IResourceDelta rootDelta, IProgressMonitor monitor) {
   if (!enabled)
     return new ModelStatus(
         IStatus.OK, ResourcesPlugin.PI_RESOURCES, ID, Status.OK_STATUS.getMessage());
   final ChangeDescription description = new ChangeDescription();
   try {
     rootDelta.accept(
         new IResourceDeltaVisitor() {
           public boolean visit(IResourceDelta delta) {
             return description.recordChange(delta);
           }
         });
   } catch (CoreException e) {
     description.addError(e);
   }
   return description.asStatus();
 }
Пример #13
0
  private void incrementalBuild(
      List<IBuildParticipant> participants, IResourceDelta delta, IProgressMonitor monitor) {
    try {
      SubMonitor sub = SubMonitor.convert(monitor, 100);
      ResourceCollector collector = new ResourceCollector();
      delta.accept(collector);

      indexProjectBuildPaths(sub.newChild(25));

      // Notify of the removed files
      removeFiles(participants, collector.removedFiles, sub.newChild(5));

      // Now build the new/updated files
      buildFiles(participants, collector.updatedFiles, sub.newChild(70));
    } catch (CoreException e) {
      IdeLog.logError(BuildPathCorePlugin.getDefault(), e);
    }
  }
Пример #14
0
    public void resourceChanged(IResourceChangeEvent event) {
      IResourceDelta delta = event.getDelta();
      try {
        class ResourceDeltaVisitor implements IResourceDeltaVisitor {
          protected ResourceSet resourceSet = getResourceSet();

          public boolean visit(IResourceDelta delta) {
            if (delta.getResource().getType() != IResource.FILE) {
              return true;
            }
            int deltaKind = delta.getKind();
            if (deltaKind == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) {
              URI platformURI = URI.createPlatformResourceURI(delta.getFullPath().toString(), true);
              Resource changedResource = resourceSet.getResource(platformURI, false);
              if (changedResource != null) {
                changedResource.unload();
                com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
                    currentResource = getResource();
                if (changedResource.equals(currentResource)) {
                  // reload the resource displayed in the editor
                  resourceSet.getResource(currentResource.getURI(), true);
                }
                if (currentResource != null && currentResource.getErrors().isEmpty()) {
                  EcoreUtil.resolveAll(currentResource);
                }
                // reset the selected element in outline and properties by text position
                if (highlighting != null) {
                  highlighting.updateEObjectSelection();
                }
              }
            }

            return true;
          }
        }

        ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
        delta.accept(visitor);
      } catch (CoreException exception) {
        com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptUIPlugin.logError(
            "Unexpected Error: ", exception);
      }
    }
Пример #15
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));
    }
  }
Пример #16
0
  @Override
  protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    Buildlet[] buildlets = createBuildlets();
    Worker worker = new Worker(buildlets, false);
    IProject project = getProject();

    if (kind == FULL_BUILD) {
      project.accept(worker);
    } else {
      IResourceDelta delta = getDelta(getProject());
      if (delta == null) {
        project.accept(worker);
      } else {
        delta.accept(worker);
        if (worker.getRebuild()) project.accept(worker);
      }
    }

    worker.run(monitor);
    return null;
  }
Пример #17
0
  /**
   * @param monitor the progress monitor to use for reporting progress to the user. It is the
   *     caller's responsibility to call done() on the given monitor. Accepts null, indicating that
   *     no progress should be reported and that the operation cannot be cancelled.
   */
  protected void incrementalBuild(IResourceDelta delta, final IProgressMonitor monitor)
      throws CoreException {
    final SubMonitor progress =
        SubMonitor.convert(monitor, Messages.XtextBuilder_CollectingResources, 10);
    progress.subTask(Messages.XtextBuilder_CollectingResources);

    if (queuedBuildData.needRebuild(getProject())) {
      needRebuild();
    }

    final ToBeBuilt toBeBuilt = new ToBeBuilt();
    IResourceDeltaVisitor visitor =
        new IResourceDeltaVisitor() {
          @Override
          public boolean visit(IResourceDelta delta) throws CoreException {
            if (progress.isCanceled()) throw new OperationCanceledException();
            if (delta.getResource() instanceof IProject) {
              return delta.getResource() == getProject();
            }
            if (delta.getResource() instanceof IStorage) {
              if (delta.getKind() == IResourceDelta.REMOVED) {
                return toBeBuiltComputer.removeStorage(
                    null, toBeBuilt, (IStorage) delta.getResource());
              } else if (delta.getKind() == IResourceDelta.ADDED
                  || delta.getKind() == IResourceDelta.CHANGED) {
                return toBeBuiltComputer.updateStorage(
                    null, toBeBuilt, (IStorage) delta.getResource());
              }
            }
            return true;
          }
        };
    delta.accept(visitor);
    if (progress.isCanceled()) throw new OperationCanceledException();
    progress.worked(2);
    doBuild(toBeBuilt, progress.newChild(8), BuildType.INCREMENTAL);
  }
Пример #18
0
 public void resourceChanged(IResourceChangeEvent event) {
   if (!fgJSPIndexingIsEnabled || event == null) return;
   IResourceDelta d = event.getDelta();
   if (d == null) return;
   try {
     d.accept(
         new IResourceDeltaVisitor() {
           public boolean visit(IResourceDelta delta) {
             if (delta != null) {
               IResource r = delta.getResource();
               if (r instanceof IFile) {
                 IFile file = (IFile) r;
                 String type = file.getFileExtension();
                 if (JSP_TYPE.equalsIgnoreCase(type)) {
                   switch (delta.getKind()) {
                     case IResourceDelta.ADDED:
                       jspAdded(file);
                       break;
                     case IResourceDelta.REMOVED:
                       jspRemoved(file);
                       break;
                     case IResourceDelta.CHANGED:
                       // no need to index if the content has not changed
                       if ((delta.getFlags() & IResourceDelta.CONTENT) != 0) jspAdded(file);
                       break;
                   }
                 }
               }
             }
             return true;
           }
         });
   } catch (CoreException e) {
     log("processing resource delta", e); // $NON-NLS-1$
   }
 }
Пример #19
0
 public void resourceChanged(IResourceChangeEvent event) {
   if (event.getType() != IResourceChangeEvent.POST_CHANGE) return;
   IResourceDelta delta = event.getDelta().findMember(iFile.getFullPath());
   if (delta == null) return;
   final boolean modified[] = new boolean[1];
   modified[0] = false;
   IResourceDeltaVisitor visitor =
       new IResourceDeltaVisitor() {
         public boolean visit(IResourceDelta delta) {
           // only interested in changed resources (not added or removed)
           if (delta.getKind() != IResourceDelta.CHANGED) return true;
           // only interested in content changes
           if ((delta.getFlags() & IResourceDelta.CONTENT) == 0) return true;
           modified[0] = true;
           return true;
         }
       };
   try {
     delta.accept(visitor);
   } catch (CoreException e) {
     // open error dialog with syncExec or print to plugin log file
   }
   if (modified[0]) sendRequest("reload");
 }
 public org.eclipse.core.resources.IProject[] build(
     int kind,
     java.util.Map<?, ?> args,
     final org.eclipse.core.runtime.IProgressMonitor monitor,
     final west.twouse.language.sparqlas.resource.sparqlas.ISparqlasBuilder builder,
     org.eclipse.core.resources.IProject project)
     throws org.eclipse.core.runtime.CoreException {
   org.eclipse.core.resources.IResourceDelta delta = getDelta(project);
   if (delta == null) {
     return null;
   }
   delta.accept(
       new org.eclipse.core.resources.IResourceDeltaVisitor() {
         public boolean visit(org.eclipse.core.resources.IResourceDelta delta)
             throws org.eclipse.core.runtime.CoreException {
           org.eclipse.core.resources.IResource resource = delta.getResource();
           if (resource instanceof org.eclipse.core.resources.IFile
               && "sparqlas".equals(resource.getFileExtension())) {
             org.eclipse.emf.common.util.URI uri =
                 org.eclipse.emf.common.util.URI.createPlatformResourceURI(
                     resource.getFullPath().toString(), true);
             if (builder.isBuildingNeeded(uri)) {
               west.twouse.language.sparqlas.resource.sparqlas.mopp.SparqlasResource
                   customResource =
                       (west.twouse.language.sparqlas.resource.sparqlas.mopp.SparqlasResource)
                           new org.eclipse.emf.ecore.resource.impl.ResourceSetImpl()
                               .getResource(uri, true);
               builder.build(customResource, monitor);
             }
             return false;
           }
           return true;
         }
       });
   return null;
 }
Пример #21
0
    /**
     * This will process IResourceChangeEvent.POST_BUILD events so that we can react to builds of
     * our workspace loaded services.
     *
     * @param event The event that is to be processed. Assumes that <code>
     *     event.getType() == IResourceChangeEvent.POST_BUILD</code>.
     */
    private void processBuildEvent(IResourceChangeEvent event) {
      final IResourceDelta delta = event.getDelta();
      switch (event.getBuildKind()) {
        case IncrementalProjectBuilder.AUTO_BUILD:
          // Nothing built in such cases
          if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) {
            break;
          }
          // Fall through to the incremental build handling otherwise
          // $FALL-THROUGH$
        case IncrementalProjectBuilder.INCREMENTAL_BUILD:
          final AcceleoDeltaVisitor visitor = new AcceleoDeltaVisitor();
          try {
            delta.accept(visitor);
          } catch (CoreException e) {
            AcceleoCommonPlugin.log(e, false);
          }
          for (IProject changed : visitor.getChangedProjects()) {
            IPluginModelBase model = PluginRegistry.findModel(changed);
            if (model != null) {
              changedContributions.add(model);
            }
          }
          for (String changedClass : visitor.getChangedClasses()) {
            final WorkspaceClassInstance workspaceInstance =
                workspaceLoadedClasses.get(changedClass);
            if (workspaceInstance != null) {
              workspaceInstance.setStale(true);
            }
          }
          break;
        case IncrementalProjectBuilder.FULL_BUILD:
          for (Map.Entry<IPluginModelBase, Bundle> entry : workspaceInstalledBundles.entrySet()) {
            IPluginModelBase model = entry.getKey();
            if (model != null) {
              changedContributions.add(model);
            }
          }
          for (WorkspaceClassInstance workspaceInstance : workspaceLoadedClasses.values()) {
            workspaceInstance.setStale(true);
          }
          break;
        case IncrementalProjectBuilder.CLEAN_BUILD:
          // workspace has been cleaned. Unload every service until next they're built
          final Iterator<Map.Entry<IPluginModelBase, Bundle>> workspaceBundleIterator =
              workspaceInstalledBundles.entrySet().iterator();
          while (workspaceBundleIterator.hasNext()) {
            Map.Entry<IPluginModelBase, Bundle> entry = workspaceBundleIterator.next();
            final Bundle bundle = entry.getValue();

            try {
              uninstallBundle(bundle);
            } catch (BundleException e) {
              AcceleoCommonPlugin.log(
                  new Status(
                      IStatus.ERROR,
                      AcceleoCommonPlugin.PLUGIN_ID,
                      AcceleoCommonMessages.getString(
                          UNINSTALLATION_FAILURE_KEY, bundle.getSymbolicName()),
                      e));
            }

            workspaceBundleIterator.remove();
          }
          for (WorkspaceClassInstance workspaceInstance : workspaceLoadedClasses.values()) {
            workspaceInstance.setStale(true);
          }
          break;
        default:
          // no default action
      }
    }
Пример #22
0
 void doBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException {
   if (delta == null) return;
   ResourceVisitor visitor = new ResourceVisitor(testFinder);
   delta.accept(visitor);
   visitor.processResources(monitor, invoker);
 }
Пример #23
0
        @Override
        public void resourceChanged(IResourceChangeEvent event) {
          IResourceDelta delta = event.getDelta();
          try {
            class ResourceDeltaVisitor implements IResourceDeltaVisitor {
              protected ResourceSet resourceSet = editingDomain.getResourceSet();
              protected Collection<Resource> changedResources = new ArrayList<Resource>();
              protected Collection<Resource> removedResources = new ArrayList<Resource>();

              public Collection<Resource> getChangedResources() {
                return changedResources;
              }

              public Collection<Resource> getRemovedResources() {
                return removedResources;
              }

              @Override
              public boolean visit(IResourceDelta delta) {
                if (delta.getResource().getType() == IResource.FILE) {
                  if (delta.getKind() == IResourceDelta.REMOVED
                      || delta.getKind() == IResourceDelta.CHANGED
                          && delta.getFlags() != IResourceDelta.MARKERS) {
                    Resource resource =
                        resourceSet.getResource(
                            URI.createPlatformResourceURI(delta.getFullPath().toString(), true),
                            false);
                    if (resource != null) {
                      if (delta.getKind() == IResourceDelta.REMOVED) {
                        removedResources.add(resource);
                      } else if (!savedResources.remove(resource)) {
                        changedResources.add(resource);
                      }
                    }
                  }
                }

                return true;
              }
            }

            final ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
            delta.accept(visitor);

            if (!visitor.getRemovedResources().isEmpty()) {
              getSite()
                  .getShell()
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          removedResources.addAll(visitor.getRemovedResources());
                          if (!isDirty()) {
                            getSite().getPage().closeEditor(RmapEditor.this, false);
                          }
                        }
                      });
            }

            if (!visitor.getChangedResources().isEmpty()) {
              getSite()
                  .getShell()
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          changedResources.addAll(visitor.getChangedResources());
                          if (getSite().getPage().getActiveEditor() == RmapEditor.this) {
                            handleActivate();
                          }
                        }
                      });
            }
          } catch (CoreException exception) {
            RmapEditorPlugin.INSTANCE.log(exception);
          }
        }
Пример #24
0
        public void resourceChanged(IResourceChangeEvent event) {
          // Only listening to these.
          // if (event.getType() == IResourceDelta.POST_CHANGE)
          {
            IResourceDelta delta = event.getDelta();
            try {
              class ResourceDeltaVisitor implements IResourceDeltaVisitor {
                protected ResourceSet resourceSet = editingDomain.getResourceSet();

                protected Collection changedResources = new ArrayList();

                protected Collection removedResources = new ArrayList();

                public boolean visit(IResourceDelta delta) {
                  if (delta.getFlags() != IResourceDelta.MARKERS
                      && delta.getResource().getType() == IResource.FILE) {
                    if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED))
                        != 0) {
                      Resource resource =
                          resourceSet.getResource(
                              URI.createURI(delta.getFullPath().toString()), false);
                      if (resource != null) {
                        if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
                          removedResources.add(resource);
                        } else {
                          changedResources.add(resource);
                        }
                      }
                    }
                  }

                  return true;
                }

                public Collection getChangedResources() {
                  return changedResources;
                }

                public Collection getRemovedResources() {
                  return removedResources;
                }
              }

              ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
              delta.accept(visitor);

              if (!visitor.getRemovedResources().isEmpty()) {
                removedResources.addAll(visitor.getRemovedResources());
                if (!isDirty()) {
                  getSite()
                      .getShell()
                      .getDisplay()
                      .asyncExec(
                          new Runnable() {
                            public void run() {
                              getSite().getPage().closeEditor(GenfwEditor.this, false);
                              GenfwEditor.this.dispose();
                            }
                          });
                }
              }

              if (!visitor.getChangedResources().isEmpty()) {
                changedResources.addAll(visitor.getChangedResources());
              }
            } catch (CoreException exception) {
              GenfwEditorPlugin.INSTANCE.log(exception);
            }
          }
        }
Пример #25
0
  /**
   * Visits all IResouces in delta (IResourceDelta) and saves the corresponding file if it is
   * relevant.<br>
   * A file is relevant if: - it's a class file - it's location is in a project with the lyrebird
   * natur
   *
   * @param delta
   * @throws FileNotFoundException // TODO when and why?
   */
  public void writeResourceDeltas(IResourceDelta delta) throws FileNotFoundException {

    configOutput();

    date = new Date().getTime();
    IResourceDeltaVisitor visitor =
        new IResourceDeltaVisitor() {

          @Override
          public boolean visit(IResourceDelta delta) throws CoreException {

            IResource resource = delta.getResource();

            if (resource != null
                && resource.getProject() != null
                && resource.getProject().isNatureEnabled(LyrebirdNature.NATURE_ID)
                && resource.getType() == IResource.FILE
                && "class".equalsIgnoreCase(resource.getFileExtension())) {
              try {

                if (saveGlobal) {
                  // check that we dont get a change in Lyrebirds outputfolder
                  if (resource.getRawLocation().matchingFirstSegments(new Path(globalPath))
                      == new Path(globalPath).segmentCount()) return false;

                  File outputfoler =
                      new File(globalPath, resource.getFullPath().toFile().getParent());
                  if (!outputfoler.exists()) outputfoler.mkdirs();

                  File des =
                      new File(
                          outputfoler,
                          Path.SEPARATOR
                              + date
                              + "_"
                              + getKind(delta.getKind())
                              + "_"
                              + resource.getName());
                  if (!getSourceFile(resource).exists()) {
                    des.createNewFile();
                  } else {
                    copyFile(getSourceFile(resource), des);
                  }
                } else {
                  // check that we dont get a change in Lyrebirds outputfolder
                  if (resource.getProjectRelativePath().segment(0).equals(projectPath))
                    return false;

                  File projecFile =
                      new File(workspaceLocation, resource.getProject().getFullPath().toOSString());
                  File projectOutPutFile = new File(projecFile, projectPath);
                  if (!projectOutPutFile.exists()) projectOutPutFile.mkdirs();
                  File outputFoler =
                      new File(
                          projectOutPutFile,
                          resource.getProjectRelativePath().toFile().getParent());

                  if (!outputFoler.exists()) outputFoler.mkdirs();

                  File des =
                      new File(
                          outputFoler,
                          Path.SEPARATOR
                              + date
                              + "_"
                              + getKind(delta.getKind())
                              + "_"
                              + resource.getName());
                  if (!getSourceFile(resource).exists()) {
                    des.createNewFile();
                  } else {
                    copyFile(getSourceFile(resource), des);
                  }
                }

              } catch (IOException e) {
                IStatus is = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "IOException", e);
                StatusManager.getManager().handle(is, StatusManager.LOG);
                StatusManager.getManager().handle(is, StatusManager.SHOW);
                return false;
              }
            }
            return true;
          }
        };
    try {
      delta.accept(visitor);
    } catch (CoreException e) {
      IStatus is = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "CoreException", e);
      StatusManager.getManager().handle(is, StatusManager.LOG);
    }
  }
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.eclipse.core.resources.mapping.ModelProvider#validateChange(org.eclipse.core.resources.IResourceDelta,
  *     org.eclipse.core.runtime.IProgressMonitor)
  */
 @Override
 public IStatus validateChange(IResourceDelta delta, IProgressMonitor monitor) {
   IStatus result = null;
   if (delta != null) {
     try {
       ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
       delta.accept(visitor);
       if (visitor.getProjectContainingSessionToSaveToDelete().size() == 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "This modeling project contains unsaved data. This data will be lost.");
       } else if (visitor.getProjectContainingSessionToSaveToDelete().size() > 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Some modeling projects ("
                     + getProjectsName(visitor.getProjectContainingSessionToSaveToDelete())
                     + ") contain unsaved data. This data will be lost.");
       } else if (visitor.getMainRepresentationsFilesToDelete().size() == 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Deletion of the main representations file of \""
                     + visitor.getMainRepresentationsFilesToDelete().get(0).getProject().getName()
                     + "\" will invalidate it.");
       } else if (visitor.getMainRepresentationsFilesToDelete().size() > 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Deletion of the main representations files of some modeling projects ("
                     + getFilesProjectName(visitor.getMainRepresentationsFilesToDelete())
                     + ") will invalidate them.");
       } else if (visitor.getRepresentationsFileToAddOnValidModelingProject().size() == 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Add another representations file to \""
                     + visitor
                         .getRepresentationsFileToAddOnValidModelingProject()
                         .get(0)
                         .getProject()
                         .getName()
                     + "\" may invalidate it.");
       } else if (visitor.getRepresentationsFileToAddOnValidModelingProject().size() > 1) {
         result =
             new ModelStatus(
                 IStatus.ERROR,
                 SiriusPlugin.ID,
                 ModelingModelProvider.MODELING_MODEL_PROVIDER_ID,
                 "Add another representations file to "
                     + getFilesProjectName(
                         visitor.getRepresentationsFileToAddOnValidModelingProject())
                     + " may invalidate them.");
       }
     } catch (CoreException e) {
       /* do nothing */
     }
   }
   if (result == null) {
     result = super.validateChange(delta, monitor);
   }
   return result;
 }