Пример #1
0
  /**
   * called from within a job
   *
   * @param monitor
   */
  public void evaluateChecks(
      Collection<ITypingCheck> checks, IProject project, IProgressMonitor monitor) {
    SubProgressMonitor monitor2 = new SubProgressMonitor(monitor, 1);
    monitor2.beginTask("Evaluating type checks...", checks.size() + 10);

    // called from within a job!
    IEvaluationStrategy strategy = null;

    try {
      strategy = EvaluationStrategyManager.getInstance().getEvaluationStrategy(project);
      // cannot check anything without a strategy
      if (strategy == null) return;
    } catch (FeatureModelNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    monitor2.worked(10);

    int i = 0;
    for (ITypingCheck check : checks) {
      i++;
      if (i % 25 == 0) {
        monitor2.subTask("Evaluating type check " + i + "/" + checks.size());
        monitor2.worked(25);
      }

      boolean isWelltyped = check.evaluate(strategy);

      if (!isWelltyped) markIlltyped(check);
      else markWelltyped(check);
    }

    monitor2.done();
  }
  /**
   * Tests SubProgressMonitor nesting when using the default constructor. (Tests parents in floating
   * point mode)
   *
   * @deprecated to suppress deprecation warnings
   */
  public void testConstructorNestingFP() {
    TestProgressMonitor top = new TestProgressMonitor();
    top.beginTask("", 2000);

    // Create an SPM, put it in floating-point mode, and consume half its work
    SubProgressMonitor fpMonitor = new SubProgressMonitor(top, 1000);
    fpMonitor.beginTask("", 100);
    fpMonitor.internalWorked(50.0);
    fpMonitor.internalWorked(-10.0); // should have no effect

    Assert.assertEquals(500.0, top.getTotalWork(), 0.01d);

    // Create a child monitor, and ensure that it grabs the correct amount of work
    // from the parent.
    SubProgressMonitor childMonitor = new SubProgressMonitor(fpMonitor, 20);
    childMonitor.beginTask("", 100);
    childMonitor.worked(100);
    childMonitor.done();

    Assert.assertEquals(700.0, top.getTotalWork(), 0.01d);

    // Create a child monitor, and ensure that it grabs the correct amount of work
    // from the parent.
    SubProgressMonitor childMonitor2 = new SubProgressMonitor(fpMonitor, 30);
    childMonitor2.beginTask("", 100);
    childMonitor2.worked(100);
    childMonitor2.done();

    Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d);

    // Ensure that creating another child will have no effect
    SubProgressMonitor childMonitor3 = new SubProgressMonitor(fpMonitor, 10);
    childMonitor3.beginTask("", 100);
    childMonitor3.worked(100);
    childMonitor3.done();

    Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d);
    fpMonitor.worked(100);
    Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d);
    fpMonitor.done();
    Assert.assertEquals(1000.0, top.getTotalWork(), 0.01d);
  }
Пример #3
0
  private void buildMetaInf(IPath outputLocation, IProgressMonitor monitor)
      throws CoreException, JavaModelException {
    IProject project = getProject();
    IFolder metaInf = project.getFolder(META_INF);

    if (!metaInf.exists()) {
      error("META-INF folder not found for project: " + getProject().getName()); // $NON-NLS-1$
      return;
    }

    IFolder binFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation);
    if (!binFolder.exists()) {
      binFolder.create(true, true, null);
    } else {
      binFolder.refreshLocal(IResource.DEPTH_ONE, null);
    }
    IFolder binaryMetaInf = binFolder.getFolder(META_INF);
    if (!binaryMetaInf.exists()) {
      binaryMetaInf.create(true, true, null);
    } else {
      binaryMetaInf.refreshLocal(IResource.DEPTH_ONE, null);
    }

    SubProgressMonitor sub = new SubProgressMonitor(monitor, 1);

    IResource[] children = metaInf.members();
    sub.beginTask(Messages.Builder_CopyMetaInfContent, children.length);
    for (IResource iResource : children) {
      if (!iResource.isTeamPrivateMember() && !iResource.isDerived()) {
        IPath target = binaryMetaInf.getFullPath().append(iResource.getName());
        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(target);
        if (res != null && res.exists()) {
          if (DEBUG) {
            debug(res.getFullPath().toString() + " exists, deleting"); // $NON-NLS-1$
          }
          res.refreshLocal(IResource.DEPTH_INFINITE, null);
          res.delete(true, null);
          if (DEBUG) {
            debug(res.getFullPath().toString() + " deleted"); // $NON-NLS-1$
          }
        }
        iResource.copy(target, true, null);
        if (DEBUG) {
          debug(
              "Copied "
                  + iResource.getFullPath().toString()
                  + " to "
                  + target.toString()); // $NON-NLS-1$ //$NON-NLS-2$
        }
      }
      sub.worked(1);
    }
    monitor.done();
  }
  /** Test SubProgressMonitor's created with negative a work value. */
  public void testNegativeWorkValues() {
    TestProgressMonitor top = new TestProgressMonitor();
    top.beginTask("", 10);

    SubProgressMonitor childMonitor = new SubProgressMonitor(top, IProgressMonitor.UNKNOWN); // -1
    childMonitor.beginTask("", 10);
    childMonitor.worked(5);
    Assert.assertEquals(0.0, top.getTotalWork(), 0.01d);
    childMonitor.done();
    Assert.assertEquals(0.0, top.getTotalWork(), 0.01d);

    top.done();
  }
Пример #5
0
  public IStatus build(
      org.emftext.language.sql.resource.sql.mopp.SqlResource resource, IProgressMonitor monitor) {
    // Set option 'overrideBuilder' to 'false' and then perform build here.

    // We use one tick from the parent monitor because the BuilderAdapter reserves one
    // tick for the Builder.
    SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
    subMonitor.beginTask("Building " + resource.getURI().lastSegment(), 10);
    // The actual work of the builder can be performed here.
    subMonitor.worked(10);
    subMonitor.done();
    return Status.OK_STATUS;
  }
  /**
   * Tests the automatic cleanup when progress monitors are created via their constructor
   *
   * @deprecated to suppress deprecation warnings
   */
  public void testParallelChildren() {
    TestProgressMonitor top = new TestProgressMonitor();
    top.beginTask("", 1000);
    SubProgressMonitor mon = new SubProgressMonitor(top, 1000);
    mon.beginTask("", 1000);

    SubProgressMonitor monitor1 = new SubProgressMonitor(mon, 200);
    SubProgressMonitor monitor2 = new SubProgressMonitor(mon, 200);

    Assert.assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d);
    monitor1.beginTask("", 1000);
    Assert.assertEquals("Ensure no work has been reported yet", 0.0, top.getTotalWork(), 0.01d);
    monitor2.beginTask("", 1000);
    Assert.assertEquals("Should not have cleaned up monitor 1", 0.0, top.getTotalWork(), 0.01d);
    monitor1.done();

    Assert.assertEquals("Should have cleaned up monitor 1", 200.0, top.getTotalWork(), 0.01d);
    monitor1.worked(1000);
    Assert.assertEquals(
        "Monitor1 shouldn't report work once it's complete", 200.0, top.getTotalWork(), 0.01d);
    monitor2.worked(500);
    Assert.assertEquals(300.0, top.getTotalWork(), 0.01d);

    // Create a monitor that will leak - monitors won't be auto-completed until their done methods
    // are
    // called
    SubProgressMonitor monitor3 = new SubProgressMonitor(mon, 300);
    Assert.assertEquals(
        "Monitor2 should not have been cleaned up yet", 300.0, top.getTotalWork(), 0.01d);
    SubProgressMonitor monitor4 = new SubProgressMonitor(mon, 300);
    monitor4.beginTask("", 100);
    mon.done();
    Assert.assertNotNull(monitor3);

    Assert.assertEquals(
        "All leaked work should have been collected", 1000.0, top.getTotalWork(), 0.01d);
  }