Example #1
0
 protected int getLineNumber(DroolsFile resource, VerifierMessageBase base) {
   for (RuleDescr ruleDescr : resource.getPackageDescr().getRules()) {
     if (base.getFaulty() instanceof RuleComponent)
       if (((RuleComponent) base.getFaulty()).getRuleName().equals(ruleDescr.getName())) {
         return ruleDescr.getLine();
       }
   }
   return 1;
 }
Example #2
0
  public void analyse(Project project, SensorContext context) {
    DroolsPlugin.configureSourceDir(project);
    Language drools = new Drools(project);
    ProjectFileSystem fileSystem = project.getFileSystem();
    Map<String, DroolsPackage> packageMap = new HashMap<String, DroolsPackage>();
    VerifierBuilder verifierBuilder = VerifierBuilderFactory.newVerifierBuilder();
    for (File file : fileSystem.getSourceFiles(drools)) {
      Verifier verifier = verifierBuilder.newVerifier();
      try {
        DroolsFile resource = DroolsFile.fromIOFile(file, false);
        Source source = analyseSourceCode(file);
        if (source != null) {
          context.saveMeasure(
              resource, CoreMetrics.LINES, (double) source.getMeasure(Metric.LINES));
          context.saveMeasure(
              resource, CoreMetrics.NCLOC, (double) source.getMeasure(Metric.LINES_OF_CODE));
          context.saveMeasure(
              resource,
              CoreMetrics.COMMENT_LINES,
              (double) source.getMeasure(Metric.COMMENT_LINES));
        }
        context.saveMeasure(resource, CoreMetrics.FILES, 1.0);
        context.saveMeasure(
            resource,
            CoreMetrics.CLASSES,
            (double)
                (resource.getPackageDescr().getRules().size()
                    + resource.getPackageDescr().getFunctions().size()));
        packageMap.put(resource.getParent().getKey(), resource.getParent());

        verifier.addResourcesToVerify(new FileSystemResource(file), ResourceType.DRL);
        verifier.fireAnalysis();
        saveViolations(resource, context, verifier.getResult());
      } catch (Throwable e) {
        DroolsPlugin.LOG.error(
            "error while verifier analyzing '" + file.getAbsolutePath() + "'", e);
      } finally {
        verifier.dispose();
      }
    }

    for (DroolsPackage droolsPackage : packageMap.values()) {
      context.saveMeasure(droolsPackage, CoreMetrics.PACKAGES, 1.0);
    }
  }