Example #1
0
  /**
   * Collects the scope elements and reference ids in one pass
   *
   * @param baseline the baseline to check the components for
   * @param ids the live set of reference ids
   * @param scope the live set of elements for the scope
   * @throws CoreException
   */
  private void getContext(IApiBaseline baseline, Set<String> ids, Set<IApiComponent> scope)
      throws CoreException {
    excludedElements =
        CommonUtilsTask.initializeFilteredElements(this.excludeListLocation, baseline, this.debug);
    if (this.debug) {
      System.out.println(
          "===================================================================================="); //$NON-NLS-1$
      System.out.println("Excluded elements list:"); // $NON-NLS-1$
      System.out.println(excludedElements);
    }

    includedElements =
        CommonUtilsTask.initializeFilteredElements(this.includeListLocation, baseline, this.debug);
    if (this.debug) {
      System.out.println(
          "===================================================================================="); //$NON-NLS-1$
      System.out.println("Included elements list:"); // $NON-NLS-1$
      System.out.println(includedElements);
    }

    IApiComponent[] components = baseline.getApiComponents();
    this.notsearched = new TreeSet<>(Util.componentsorter);
    Pattern refPattern = null, scopePattern = null;
    if (this.referencepattern != null) {
      refPattern = Pattern.compile(this.referencepattern);
    }
    if (this.scopepattern != null) {
      scopePattern = Pattern.compile(this.scopepattern);
    }
    for (IApiComponent component : components) {
      String symbolicName = component.getSymbolicName();
      boolean skip = false;
      if (!includedElements.isEmpty()
          && !(includedElements.containsExactMatch(symbolicName)
              || includedElements.containsPartialMatch(symbolicName))) {
        skip = true;
      }
      if (!skip
          && (excludedElements.containsExactMatch(symbolicName)
              || excludedElements.containsPartialMatch(symbolicName))) {
        skip = true;
      }
      if (!skip) {
        if (acceptComponent(component, refPattern, true)) {
          ids.add(symbolicName);
        }
        if (acceptComponent(component, scopePattern, false)) {
          scope.add(component);
        }
      } else {
        this.notsearched.add(
            new SkippedComponent(symbolicName, component.getVersion(), component.getErrors()));
      }
    }
  }
  /* (non-Javadoc)
   * @see org.apache.tools.ant.Task#execute()
   */
  public void execute() throws BuildException {
    assertParameters();
    writeDebugHeader();
    cleanReportLocation();

    IApiBaseline baseline = getBaseline(CURRENT_BASELINE_NAME, this.currentBaselineLocation);
    try {
      String xmlLocation = scanLocation;
      File file = new File(xmlLocation);
      File nested = new File(file, "xml"); // $NON-NLS-1$
      if (nested.exists() && nested.isDirectory()) {
        file = nested;
      }
      ReferenceLookupVisitor lookup = new ReferenceLookupVisitor(baseline, this.reportLocation);
      lookup.setAnalysisScope(scopepattern);
      lookup.setTargetScope(referencepattern);

      FilteredElements excludedElements =
          CommonUtilsTask.initializeFilteredElements(
              this.excludeListLocation, baseline, this.debug);
      if (this.debug) {
        System.out.println(
            "===================================================================================="); //$NON-NLS-1$
        System.out.println("Excluded elements list:"); // $NON-NLS-1$
        System.out.println(excludedElements);
      }
      lookup.setExcludedElements(excludedElements);

      FilteredElements includedElements =
          CommonUtilsTask.initializeFilteredElements(
              this.includeListLocation, baseline, this.debug);
      if (this.debug) {
        System.out.println(
            "===================================================================================="); //$NON-NLS-1$
        System.out.println("Included elements list:"); // $NON-NLS-1$
        System.out.println(includedElements);
      }
      lookup.setIncludedElements(includedElements);

      UseScanParser parser = new UseScanParser();
      parser.parse(file.getAbsolutePath(), new NullProgressMonitor(), lookup);
    } catch (CoreException ce) {
      throw new BuildException(ce.getStatus().getMessage(), ce);
    } catch (Exception e) {
      throw new BuildException(e.getMessage(), e);
    } finally {
      if (baseline != null) {
        baseline.dispose();
        deleteBaseline(this.currentBaselineLocation, this.baselinedir);
      }
    }
  }