示例#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();
  }
  /** @deprecated to suppress deprecation warnings */
  public void testCancellation() {
    TestProgressMonitor root = new TestProgressMonitor();
    root.beginTask("", 1000);

    SubProgressMonitor spm = new SubProgressMonitor(root, 1000);

    // Test that changes at the root propogate to the child
    root.setCanceled(true);
    Assert.assertTrue(spm.isCanceled());
    root.setCanceled(false);
    Assert.assertFalse(spm.isCanceled());

    // Test that changes to the child propogate to the root
    spm.setCanceled(true);
    Assert.assertTrue(root.isCanceled());
    spm.setCanceled(false);
    Assert.assertFalse(root.isCanceled());

    // Test a chain of depth 2
    spm.beginTask("", 1000);
    SubProgressMonitor spm2 = new SubProgressMonitor(spm, 1000);

    // Test that changes at the root propogate to the child
    root.setCanceled(true);
    Assert.assertTrue(spm2.isCanceled());
    root.setCanceled(false);
    Assert.assertFalse(spm2.isCanceled());

    // Test that changes to the child propogate to the root
    spm2.setCanceled(true);
    Assert.assertTrue(root.isCanceled());
    spm2.setCanceled(false);
    Assert.assertFalse(root.isCanceled());
  }
 @Override
 public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
   pm.beginTask("", 2); // $NON-NLS-1$
   RefactoringStatus result;
   try {
     result = new RefactoringStatus();
     IJavaElement element = (IJavaElement) getModifiedElement();
     // don't check for read-only since we don't go through
     // validate edit.
     result.merge(super.isValid(new SubProgressMonitor(pm, 1)));
     if (result.hasFatalError()) return result;
     if (element != null && element.exists() && element instanceof IPackageFragment) {
       IPackageFragment pack = (IPackageFragment) element;
       if (fRenameSubpackages) {
         IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
         SubProgressMonitor subPm = new SubProgressMonitor(pm, 1);
         subPm.beginTask("", allPackages.length); // $NON-NLS-1$
         for (int i = 0; i < allPackages.length; i++) {
           // don't check for read-only since we don't go through
           // validate edit.
           checkIfModifiable(result, allPackages[i].getResource(), VALIDATE_NOT_DIRTY);
           if (result.hasFatalError()) return result;
           isValid(result, allPackages[i], new SubProgressMonitor(subPm, 1));
         }
       } else {
         isValid(result, pack, new SubProgressMonitor(pm, 1));
       }
     }
   } finally {
     pm.done();
   }
   return result;
 }
  /**
   * Creates and destroys the given number of child progress monitors under the given parent.
   *
   * @param monitor monitor to create children under. The caller must call done on this monitor if
   *     necessary.
   * @param progressSize total number of children to create.
   * @deprecated to suppress deprecation warnings
   */
  private static void createChildrenUnderParent(IProgressMonitor monitor, int progressSize) {
    monitor.beginTask("", progressSize);

    for (int count = 0; count < progressSize; count++) {
      SubProgressMonitor mon = new SubProgressMonitor(monitor, 1);
      mon.beginTask("", 100);
      mon.done();
    }
  }
  /**
   * Allows a given set or subset of runtime detectors the ability to search through a folder
   *
   * @param directory
   * @param runtimeCollector
   * @param depth
   * @param runtimeDetectors
   * @param monitor
   */
  public void searchDirectory(
      File directory,
      List<RuntimeDefinition> runtimeCollector,
      int depth,
      Set<IRuntimeDetector> runtimeDetectors,
      IProgressMonitor monitor) {

    if (depth == 0 || monitor.isCanceled() || directory == null || !directory.isDirectory()) {
      return;
    }

    int workSize = (1000 + (10 * runtimeDetectors.size()));
    monitor.beginTask(
        Messages.JBossRuntimeLocator_Searching + directory.getAbsolutePath(), workSize);
    monitor.setTaskName(Messages.JBossRuntimeLocator_Searching + directory.getAbsolutePath());

    for (IRuntimeDetector detector : runtimeDetectors) {
      if (monitor.isCanceled()) {
        return;
      }
      if (!detector.isEnabled()) {
        monitor.worked(10);
        continue;
      }
      RuntimeDefinition runtimeDefinition =
          detector.getRuntimeDefinition(directory, new SubProgressMonitor(monitor, 10));
      if (runtimeDefinition != null) {
        runtimeCollector.add(runtimeDefinition);
        monitor.done();
        return;
      }
    }

    File[] files =
        directory.listFiles(
            new FileFilter() {
              public boolean accept(File file) {
                return file.isDirectory();
              }
            });

    SubProgressMonitor childrenMonitor = new SubProgressMonitor(monitor, 1000);
    childrenMonitor.beginTask("", 100 * files.length);
    if (files != null) {
      int size = files.length;
      for (int i = 0; i < size; i++) {
        if (monitor.isCanceled()) return;
        searchDirectory(
            files[i],
            runtimeCollector,
            depth - 1,
            runtimeDetectors,
            new SubProgressMonitor(childrenMonitor, 100));
      }
    }
    childrenMonitor.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);
  }
示例#7
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();
  }
示例#9
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);
  }
 static ICompilationUnit[] createNewWorkingCopies(
     ICompilationUnit[] compilationUnitsToModify,
     TextChangeManager manager,
     WorkingCopyOwner owner,
     SubProgressMonitor pm)
     throws CoreException {
   pm.beginTask("", compilationUnitsToModify.length); // $NON-NLS-1$
   ICompilationUnit[] newWorkingCopies = new ICompilationUnit[compilationUnitsToModify.length];
   for (int i = 0; i < compilationUnitsToModify.length; i++) {
     ICompilationUnit cu = compilationUnitsToModify[i];
     newWorkingCopies[i] = createNewWorkingCopy(cu, manager, owner, new SubProgressMonitor(pm, 1));
   }
   pm.done();
   return newWorkingCopies;
 }
示例#12
0
 // FIXME deal with interfaces/implementations
 public final void addFrom(final IJavaElement scope, final SubProgressMonitor progressMonitor)
     throws CoreException {
   progressMonitor.beginTask("Adding resources and resourceMethods", 1);
   HTTPMethods httpMethods = metamodel.getHttpMethods();
   List<IType> javaTypes =
       JAXRSAnnotationsScanner.findResources(scope, httpMethods.getTypeNames(), progressMonitor);
   for (IType javaType : javaTypes) {
     try {
       resources.put(
           javaType.getFullyQualifiedName(), new Resource(javaType, metamodel, progressMonitor));
     } catch (InvalidModelElementException e) {
       Logger.warn(
           "Type '"
               + javaType.getFullyQualifiedName()
               + "' is not a valid JAX-RS Resource: "
               + e.getMessage());
     }
   }
 }
示例#13
0
  /**
   * Generates a new key pair given the parameters in fheparams, stores the key locally and in the
   * keypair parameter
   *
   * @param fheparams the scheme parameters
   * @param keyPair holds the keypair
   */
  public GHKeyGen(FHEParams fheparams, GHKeyPair keyPair, IProgressMonitor monitor, int work) {
    t = fheparams.t;
    n = 1 << fheparams.logn;

    SubProgressMonitor sm = new SubProgressMonitor(monitor, work / 3);
    sm.beginTask("", work / 3);
    do { // try until HNF has the desired form, i.e. determinant is odd and lattice contains the
         // vector (-r,1,0,...,0)
      // generate random polynomial with coefficients uniformly random in [-2^t,2^t]
      v = Polynomial.randomPolynomial(n - 1, t);

      // verify whether the coefficient sum is odd, otherwise add 1
      int parity = 0;
      for (int i = 0; i < n; i++) {
        parity ^= (v.coeffs[i].testBit(0) ? 1 : 0);
      }
      if (parity == 0) v.coeffs[0].add(new BigInteger("1"));
      if (sm.isCanceled()) return;

    } while (!invModFx(v, fheparams.logn));
    sm.done();
    sm.beginTask("", work / 3);
    BigInteger sum = new BigInteger("0");
    BigInteger factor;
    // the public key blocks that squash the decryption scheme
    pkBlocksX = new BigInteger[fheparams.s];
    // the correct power such that \sum_pkBlocksX[i]*R^pkBlocksIdX[i] = w mod d
    int[] pkBlocksIdX = new int[fheparams.s];
    // make sure the sum is correct
    boolean sumtest = false;

    while (!sumtest) {
      sum = new BigInteger("0");
      // generate the first s-1 randomly
      for (int i = 0; i < fheparams.s - 1; i++) {
        byte[] temp = new byte[det.bitLength() / 8];
        r.nextBytes(temp);
        pkBlocksX[i] = (new BigInteger(temp)).abs().mod(det);
        pkBlocksIdX[i] = r.nextInt(fheparams.S);
        factor =
            (new BigInteger("2"))
                .modPow(
                    (new BigInteger(Integer.toString(pkBlocksIdX[i])))
                        .multiply(new BigInteger(Integer.toString(fheparams.logR))),
                    det);
        factor = (factor.multiply(pkBlocksX[i])).mod(det);
        sum = (sum.add(factor)).mod(det);
      }
      sum = w.subtract(sum).mod(det);
      // calculate the last x_i from the first s-1, try until the sum is invertible
      while (pkBlocksX[fheparams.s - 1] == null) {
        try {
          pkBlocksIdX[fheparams.s - 1] = r.nextInt(fheparams.S);
          factor =
              new BigInteger("2")
                  .modPow(
                      (new BigInteger(Integer.toString(pkBlocksIdX[fheparams.s - 1])))
                          .multiply(new BigInteger(Integer.toString(fheparams.logR))),
                      det);
          factor = factor.modInverse(det);
          pkBlocksX[fheparams.s - 1] = sum.multiply(factor).mod(det);
        } catch (ArithmeticException e) {

        }
        if (sm.isCanceled()) return;
      }
      // check whether \sum_pkBlocksX[i]*R^pkBlocksIdX[i] = w mod d
      sum = new BigInteger("0");
      for (int i = 0; i < fheparams.s; i++) {
        factor =
            new BigInteger("2")
                .modPow(
                    new BigInteger(Integer.toString(pkBlocksIdX[i]))
                        .multiply(new BigInteger(Integer.toString(fheparams.logR))),
                    det);
        factor = factor.multiply(pkBlocksX[i]).mod(det);
        sum = sum.add(factor).mod(det);
      }
      if (sum.compareTo(w) == 0) {
        sumtest = true;
      }
      if (sm.isCanceled()) return;
    }
    sm.done();
    // Compute the number of ciphertext for each progression,
    // i.e., an integer N such that N(N-1)/2 > S
    sm.beginTask("", work / 3);
    int nCtxts = (int) Math.ceil(2 * Math.sqrt(fheparams.S));
    int[] bits = new int[nCtxts * fheparams.s];
    for (int i = 0; i < fheparams.s; i++) {
      // let j1,j2 be the idx'th pair in {nCtxts choose 2}
      int j1, j2;
      int[] temp = encodeIndex(pkBlocksIdX[i], nCtxts);
      j1 = temp[0];
      j2 = temp[1];
      bits[i * nCtxts + j1] = bits[i * nCtxts + j2] = 1; // set these two bits to one
      if (sm.isCanceled()) return;
    }
    sm.done();
    ctxts = GHEncrypt.encrypt(fheparams, this, bits);
    keyPair.setKeyPair(det, root, w, ctxts, pkBlocksX);
  }