@Override
  public List<Violation> check(
      ConfigurationServiceImpl configuration, RuleDTO rootRule, RuleDTO currentRule) {
    violations.clear();
    fromMappings = getAllClasspathsOfModule(currentRule.moduleFrom, currentRule.violationTypeKeys);
    toMappings = getAllClasspathsOfModule(currentRule.moduleTo, currentRule.violationTypeKeys);

    // Create HashMap with all allowed to-classes (including the from-classes)
    HashMap<String, Mapping> fromMap = new HashMap<String, Mapping>();
    for (Mapping from : fromMappings) {
      fromMap.put(from.getPhysicalPath(), from);
    }
    for (Mapping to : toMappings) {
      fromMap.put(to.getPhysicalPath(), to);
    }

    // Create a HashMap with all allowed from-to combinations, based on the exception rules.
    HashSet<String> allExceptionFromTos = getAllExceptionFromTos(currentRule);

    for (Mapping classPathTo : toMappings) {
      // Get all dependencies with matching dependency.classPathTo
      DependencyDTO[] dependenciesTo =
          analyseService.getDependenciesFromTo("", classPathTo.getPhysicalPath());
      for (DependencyDTO dependency : dependenciesTo) {
        String fromToCombi = dependency.from + "|" + classPathTo.getPhysicalPath();
        if (fromMap.containsKey(dependency.from) || allExceptionFromTos.contains(fromToCombi)) {
          // Do nothing
        } else {
          Mapping classPathFrom = new Mapping(dependency.from, classPathTo.getViolationTypes());
          Violation violation =
              createViolation(rootRule, classPathFrom, classPathTo, dependency, configuration);

          // Get logicalModuleFrom based on dependency.from and add it to the violation
          ModuleDTO moduleFrom =
              ServiceProvider.getInstance()
                  .getDefineService()
                  .getModule_BasedOnSoftwareUnitName(dependency.from);
          if (moduleFrom != null) {
            // Add moduleFrom to violation.logicalModules, so that graphics can include these
            // violations in architecture diagrams
            LogicalModules logicalModulesOld = violation.getLogicalModules();
            LogicalModule logicalModuleTo = logicalModulesOld.getLogicalModuleTo();
            LogicalModule logicalModuleFrom =
                new LogicalModule(moduleFrom.logicalPath, moduleFrom.type);
            LogicalModules logicalModules = new LogicalModules(logicalModuleFrom, logicalModuleTo);
            violation.setLogicalModules(logicalModules);
          }

          violations.add(violation);
        }
      }
    }
    return violations;
  }
Пример #2
0
 public String toString() {
   String representation = "";
   representation += "\nfromClasspath: " + classPathFrom;
   representation += "\ntoClasspath: " + classPathTo;
   representation +=
       "\nlogicalModuleFrom: " + logicalModules.getLogicalModuleFrom().getLogicalModulePath();
   representation +=
       "\nlogicalModuleTo: " + logicalModules.getLogicalModuleTo().getLogicalModulePath();
   representation += "\nruleType: " + ruletypeKey;
   representation += ", line: " + linenumber;
   representation += ", violationType: " + violationTypeKey;
   representation += ", indirect: " + inDirect;
   representation += "\n";
   return representation;
 }