Пример #1
0
 /**
  * Deletes any output files that are stale.
  *
  * @param context
  * @param monitor
  * @throws CoreException
  */
 private void clean(LocationContext context, IProgressMonitor monitor) throws CoreException {
   // simple implementation for now: just wipe the whole thing
   // ideally we would build a graph of dependencies by reading all sources
   // and
   // delete any output files that are old and any depending output files
   // (recursively).
   IFileStore[] outputPaths = context.getOutputPaths();
   monitor.beginTask("Cleaning output folders", outputPaths.length);
   try {
     for (int i = 0; i < outputPaths.length; i++) {
       clean(outputPaths[i], false, monitor);
       monitor.worked(1);
     }
   } finally {
     monitor.done();
   }
 }
Пример #2
0
 public synchronized IProblem[] compile(
     IFileStore[] toCompile,
     IRepository repository,
     final LocationContext context,
     final int mode,
     IProgressMonitor monitor)
     throws CoreException {
   boolean created = false;
   if (monitor == null) monitor = new NullProgressMonitor();
   if (toCompile == null) toCompile = context.getSourcePaths();
   monitor.beginTask("Compiling source files", IProgressMonitor.UNKNOWN);
   // empty all output locations before we start
   clean(context, new SubProgressMonitor(monitor, toCompile.length));
   if (mode == CLEAN || toCompile.length == 0) {
     // nothing else to do
     return new IProblem[0];
   }
   if (repository == null) {
     repository =
         MDDCore.createRepository(MDDUtil.fromJavaToEMF(context.getDefaultOutputPath().toURI()));
     for (IFileStore relatedRootPath : context.getRelatedPaths())
       for (IFileStore relatedEntry : relatedRootPath.childStores(EFS.NONE, null))
         if (isUMLFile(relatedEntry))
           repository.loadPackage(MDDUtil.fromJavaToEMF(relatedEntry.toURI()));
     created = true;
   }
   final BasicProblemTracker problemTracker = new BasicProblemTracker();
   final ReferenceTracker refTracker = new ReferenceTracker();
   final IFileStore[] tmpToCompile = toCompile;
   try {
     final IRepository[] tmpRepo = {repository};
     final IProgressMonitor[] tmpMonitor = {monitor};
     final CoreException[] tmpException = {null};
     repository.runInRepository(
         new Runnable() {
           public void run() {
             try {
               for (int i = 0; i < tmpToCompile.length; i++) {
                 IFileStore baseOutputPath = context.getOutputPath(tmpToCompile[i]);
                 if (baseOutputPath == null) baseOutputPath = context.getDefaultOutputPath();
                 int unitsInTree =
                     compileTree(
                         tmpRepo[0],
                         tmpToCompile[i],
                         baseOutputPath,
                         mode,
                         new SubProgressMonitor(tmpMonitor[0], IProgressMonitor.UNKNOWN),
                         refTracker,
                         problemTracker);
                 if (unitsInTree == 0)
                   problemTracker.add(
                       new UnclassifiedProblem(IProblem.Severity.INFO, "Nothing to compile"));
               }
               refTracker.resolve(tmpRepo[0], problemTracker);
             } catch (CoreException e) {
               tmpException[0] = e;
             }
           }
         });
     if (tmpException[0] != null) throw tmpException[0];
     repository.save(monitor);
   } catch (OperationCanceledException e) {
     // ignore
   } catch (Exception e) {
     problemTracker.add(new InternalProblem(e));
     LogUtils.logError(MDDCore.PLUGIN_ID, "Unexpected exception while compiling", e);
   } finally {
     monitor.done();
     if (created) repository.dispose();
   }
   IProblem[] allProblems = problemTracker.getAllProblems();
   Arrays.sort(allProblems);
   return allProblems;
 }