コード例 #1
0
  private void doBuildFiles(
      List<IBuildParticipant> participants, Collection<IFile> files, IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(files)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, 15 * files.size());
    for (IFile file : files) {
      BuildContext context = new BuildContext(file);
      sub.worked(1);

      IBuildParticipantManager manager = getBuildParticipantManager();
      if (manager == null) {
        return;
      }
      List<IBuildParticipant> filteredParticipants =
          manager.filterParticipants(participants, context.getContentType());
      sub.worked(2);

      buildFile(context, filteredParticipants, sub.newChild(12));

      // stop building if canceled
      if (sub.isCanceled()) {
        break;
      }
    }
    sub.done();
  }
コード例 #2
0
  protected void perfValidate(String filename, int iterations) throws Exception {
    // read in the file
    InputStream in =
        FileLocator.openStream(
            Platform.getBundle(JSCorePlugin.PLUGIN_ID),
            Path.fromPortableString("performance/" + filename),
            false);
    IFile file = project.createFile(filename, IOUtil.read(in));
    RebuildIndexJob job = new RebuildIndexJob(project.getURI());
    job.run(null);

    // Ok now actually validate the thing, the real work
    for (int i = 0; i < iterations; i++) {
      EditorTestHelper.joinBackgroundActivities();

      BuildContext context = new BuildContext(file);
      // Don't measure reading in string...
      context.getContents();

      startMeasuring();
      validator.buildFile(context, null);
      stopMeasuring();
    }
    commitMeasurements();
    assertPerformance();
  }
コード例 #3
0
  private void buildFile(
      BuildContext context, List<IBuildParticipant> participants, IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(participants)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, 2 * participants.size());
    for (IBuildParticipant participant : participants) {
      long startTime = System.nanoTime();
      participant.buildFile(context, sub.newChild(1));
      if (traceParticipantsEnabled) {
        double endTime = ((double) System.nanoTime() - startTime) / 1000000;
        IdeLog.logTrace(
            BuildPathCorePlugin.getDefault(),
            MessageFormat.format(
                "Executed build participant ''{0}'' on ''{1}'' in {2} ms.",
                participant.getName(), context.getURI(), endTime),
            IDebugScopes.BUILDER_PARTICIPANTS); // $NON-NLS-1$
      }

      // stop building if it has been canceled
      if (sub.isCanceled()) {
        break;
      }
    }
    updateMarkers(context, sub.newChild(participants.size()));
    sub.done();
  }
コード例 #4
0
  public void deleteFile(BuildContext context, IProgressMonitor monitor) {
    if (context == null) {
      return;
    }

    context.removeProblems(ICSSConstants.W3C_PROBLEM);
  }
コード例 #5
0
  public void buildFile(BuildContext context, IProgressMonitor monitor) {
    if (context == null) {
      return;
    }

    List<IProblem> problems = new ArrayList<IProblem>();

    String source = context.getContents();
    URI uri = context.getURI();
    String path = uri.toString();

    String report = getReport(source, uri);
    List<String> filters = getFilters();
    processErrorsInReport(report, path, problems, filters);
    processWarningsInReport(report, path, problems, filters);

    context.putProblems(ICSSConstants.W3C_PROBLEM, problems);
  }
コード例 #6
0
  public void buildFile(BuildContext context, IProgressMonitor monitor) {
    String contents = null;
    String uri = context.getName();
    try {
      contents = context.getContents();

      RubyParseState parseState = new RubyParseState(contents, uri, 1, version);
      uri = context.getURI().toString();
      context.getAST(parseState);
    } catch (CoreException e) {
      // ignore, just forcing a parse
    }

    Collection<IProblem> problems = new ArrayList<IProblem>();
    for (IParseError parseError : context.getParseErrors()) {
      int severity = parseError.getSeverity().intValue();
      int line = -1;
      if (contents != null) {
        line = getLineNumber(parseError.getOffset(), contents);
      }
      problems.add(
          new Problem(
              severity,
              parseError.getMessage(),
              parseError.getOffset(),
              parseError.getLength(),
              line,
              uri));
    }
    context.putProblems(IMarker.PROBLEM, problems);
  }
コード例 #7
0
  private void updateMarkers(BuildContext context, IProgressMonitor monitor) {
    final IFile file = context.getFile();
    final Map<String, Collection<IProblem>> itemsByType = context.getProblems();
    if (CollectionsUtil.isEmpty(itemsByType)) {
      return;
    }
    // Performance fix: schedules the error handling as a single workspace update so that we don't
    // trigger a
    // bunch of resource updated events while problem markers are being added to the file.
    IWorkspaceRunnable runnable =
        new IWorkspaceRunnable() {
          public void run(IProgressMonitor monitor) {
            updateMarkers(file, itemsByType, monitor);
          }
        };

    try {
      ResourcesPlugin.getWorkspace()
          .run(runnable, getMarkerRule(file), IWorkspace.AVOID_UPDATE, monitor);
    } catch (CoreException e) {
      IdeLog.logError(BuildPathCorePlugin.getDefault(), "Error updating markers", e); // $NON-NLS-1$
    }
  }
コード例 #8
0
  protected void perfValidate(String filename, int iterations) throws Exception {
    // read in the file
    URL url =
        FileLocator.find(
            Platform.getBundle(JSCorePlugin.PLUGIN_ID),
            Path.fromPortableString("performance/" + filename),
            null);
    File file = ResourceUtil.resourcePathToFile(url);
    IFileStore fileStore = EFS.getStore(file.toURI());

    // Ok now actually validate the thing, the real work
    for (int i = 0; i < iterations; i++) {
      EditorTestHelper.joinBackgroundActivities();

      // Force a re-parse every time so we're comparing apples to apples for JSLint
      BuildContext context =
          new FileStoreBuildContext(fileStore) {
            @Override
            protected ParseResult parse(
                String contentType, IParseState parseState, WorkingParseResult working)
                throws Exception {
              if (reparseEveryTime()) {
                return new JSParser().parse(parseState);
              }
              return super.parse(contentType, parseState, working);
            }
          };
      // Don't measure reading in string...
      context.getContents();

      startMeasuring();
      validator.buildFile(context, null);
      stopMeasuring();
    }
    commitMeasurements();
    assertPerformance();
  }
コード例 #9
0
  private void removeFiles(
      List<IBuildParticipant> participants,
      Set<IFile> filesToRemoveFromIndex,
      IProgressMonitor monitor)
      throws CoreException {
    if (CollectionsUtil.isEmpty(filesToRemoveFromIndex)) {
      return;
    }

    SubMonitor sub = SubMonitor.convert(monitor, 16 * filesToRemoveFromIndex.size());
    for (IFile file : filesToRemoveFromIndex) {
      BuildContext context = new BuildContext(file);
      sub.worked(1);
      IBuildParticipantManager manager = getBuildParticipantManager();
      if (manager == null) {
        return;
      }
      List<IBuildParticipant> filteredParticipants =
          manager.filterParticipants(participants, context.getContentType());
      sub.worked(5);
      deleteFile(context, filteredParticipants, sub.newChild(10));
    }
    sub.done();
  }
コード例 #10
0
 public void deleteFile(BuildContext context, IProgressMonitor monitor) {
   context.removeProblems(IMarker.PROBLEM);
 }