/** * Checks if there is a rule which allows the given edge. * <p> * Checks for dependencies on implementation; logs all dependencies on implementation, including the relevant * base relations. * * @param edge the edge * @return true if there is at least one rule which allows the given edge. */ private boolean hasMatchingRule(Dependency edge) { Boolean dependsOnImpl = edge.getProperty(DependencyMapper.DEPENDS_ON_IMPL, false); if (dependsOnImpl) { implementationDependencies.add(edge); LOGGER.warn("Dependency on implementation instead of API: {}:", edge); edge.getBaseDependencies().stream() .filter(baseDep -> baseDep.getTarget().getProperty(implPropertyKey, false)) .forEach(baseDep -> LOGGER.warn(" * {}", baseDep)); } return isInSameScope(edge) || hasAllowedParentEdge(edge); }
@SuppressWarnings("unchecked") private Boolean isExplicitlyAllowed(Node source, Node target) { List<String> uses = (List<String>) source.getProperty(Constants.USES); Boolean result = uses != null && uses.contains(target.getName()); if (result) { source.addListProperty(Constants.USED_RULES, target.getName()); } Dependency edge = dependencyGraph.getEdge(source, target); if (edge != null) { List<String> referencedApis = (List<String>) edge.getProperty(Constants.TARGET_API); if (uses != null && referencedApis != null && uses.containsAll(referencedApis)) { referencedApis.forEach(targetName -> source.addListProperty(Constants.USED_RULES, targetName)); result = true; } } return result; }
private void mapReference(Dependency dependency) { ReferencesRelation referencesRelation = new ReferencesRelation(); referencesRelation.setReferenceType(dependency.getDependencyType().name()); referencesRelation.setFrom(nodeMap.get(dependency.getSource().getName())); referencesRelation.setTo(nodeMap.get(dependency.getTarget().getName())); referencesRelation.setLineNo(dependency.getProperty("lineNo", new ArrayList<>())); mapProperties(referencesRelation.getProperties(), dependency.getProperties()); referencesRelation.getProperties().remove("lineNo"); referencesRelation.getFrom().getReferencesRelations().add(referencesRelation); referencesRelations.add(referencesRelation); }
private StringTemplate createEdgeST(Dependency dependency) { noEdges++; StringTemplate edgeST = templates.getInstanceOf(EDGE_ST); edgeST.setAttribute("from", GraphExportStyles.getId(dependency.getSource().getName())); edgeST.setAttribute("to", GraphExportStyles.getId(dependency.getTarget().getName())); edgeST.setAttribute("style", DotExportStyles.getEdgeStyle(dependency)); if (createEdgeLabels) { if (dependency.hasProperty(Constants.BASE_REL_COUNT)) { edgeST.setAttribute(LABEL_ATT, dependency.getProperty(Constants.BASE_REL_COUNT)); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_TARGETS)) { edgeST.setAttribute(HEAD_LABEL_ATT, dependency.getProperty(Constants.BASE_REL_COUNT_TARGETS)); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_SOURCES)) { edgeST.setAttribute(TAIL_LABEL_ATT, dependency.getProperty(Constants.BASE_REL_COUNT_SOURCES)); } } return edgeST; }
private StringTemplate createEdgeST(Dependency dependency) { noEdges++; StringTemplate edgeST = templates.getInstanceOf(EDGE_ST); edgeST.setAttribute("from", GraphExportStyles.getId(dependency.getSource().getName())); edgeST.setAttribute("to", GraphExportStyles.getId(dependency.getTarget().getName())); edgeST.setAttribute("style", getEdgeStyle(dependency)); if (createEdgeLabels) { if (dependency.hasProperty(Constants.BASE_REL_COUNT)) { edgeST.setAttribute(LABEL_ATT, dependency.getProperty(Constants.BASE_REL_COUNT)); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_TARGETS)) { edgeST.setAttribute(HEAD_LABEL_ATT, dependency.getProperty(Constants.BASE_REL_COUNT_TARGETS)); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_SOURCES)) { edgeST.setAttribute(TAIL_LABEL_ATT, dependency.getProperty(Constants.BASE_REL_COUNT_SOURCES)); } } return edgeST; }
private StringTemplate createEdgeST(Dependency dependency) { noEdges++; StringTemplate edgeST = templates.getInstanceOf(EDGE_ST); edgeST.setAttribute("from", GraphExportStyles.getId(dependency.getSource().getName())); edgeST.setAttribute("to", GraphExportStyles.getId(dependency.getTarget().getName())); LineStyle style = GraphExportStyles.getEdgeStyle(dependency); edgeST.setAttribute("color", style.getColor()); edgeST.setAttribute("style", style.getLineStyle()); edgeST.setAttribute("width", style.getWidth()); if (createEdgeLabels) { if (dependency.hasProperty(Constants.BASE_REL_COUNT)) { edgeST.setAttribute(EDGE_LABEL_ATT, createEdgeLabelST(dependency.getProperty(Constants.BASE_REL_COUNT, 0), Position.MIDDLE, style.getColor())); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_TARGETS)) { edgeST.setAttribute(EDGE_LABEL_ATT, createEdgeLabelST(dependency.getProperty(Constants.BASE_REL_COUNT_TARGETS, 0), Position.HEAD, style.getColor())); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_SOURCES)) { edgeST.setAttribute(EDGE_LABEL_ATT, createEdgeLabelST(dependency.getProperty(Constants.BASE_REL_COUNT_SOURCES, 0), Position.TAIL, style.getColor())); } } return edgeST; }
private StringTemplate createEdgeST(Dependency dependency) { noEdges++; StringTemplate edgeST = templates.getInstanceOf(EDGE_ST); edgeST.setAttribute("from", GraphExportStyles.getId(dependency.getSource().getName())); edgeST.setAttribute("to", GraphExportStyles.getId(dependency.getTarget().getName())); LineStyle style = GraphExportStyles.getEdgeStyle(dependency); edgeST.setAttribute("color", style.getColor()); edgeST.setAttribute("style", style.getLineStyle()); edgeST.setAttribute("width", style.getWidth()); if (createEdgeLabels) { if (dependency.hasProperty(Constants.BASE_REL_COUNT)) { edgeST.setAttribute(EDGE_LABEL_ATT, createEdgeLabelST(dependency.getProperty(Constants.BASE_REL_COUNT, 0), Position.MIDDLE, style.getColor())); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_TARGETS)) { edgeST.setAttribute(EDGE_LABEL_ATT, createEdgeLabelST(dependency.getProperty(Constants.BASE_REL_COUNT_TARGETS, 0), Position.HEAD, style.getColor())); } if (dependency.hasProperty(Constants.BASE_REL_COUNT_SOURCES)) { edgeST.setAttribute(EDGE_LABEL_ATT, createEdgeLabelST(dependency.getProperty(Constants.BASE_REL_COUNT_SOURCES, 0), Position.TAIL, style.getColor())); } } return edgeST; }
private static void createArchitectureDependency(DependencyGraph dependencyGraph, String tag, Dependency dep) { Node baseFrom = dep.getSource(); Node baseTo = dep.getTarget(); // if the tag is not set on either of these two, the Node will be null, too, and no dependency will be mapped: Node parentFrom = dependencyGraph.getNode((String) baseFrom.getProperty(tag + Constants.PARENT_SUFFIX)); Node parentTo = dependencyGraph.getNode((String) baseTo.getProperty(tag + Constants.PARENT_SUFFIX)); if (parentFrom != null && parentTo != null && !parentFrom.equals(parentTo)) { Dependency architectureDependency = dependencyGraph.addDependency(parentFrom, parentTo, dep.getDependencyType()); architectureDependency.addBaseDependency(dep); // if there is at least one base dependency which depends on an Impl class, it's marked as DEPENDS_ON_IMPL boolean isImpl = architectureDependency.getProperty(DEPENDS_ON_IMPL, false) || baseTo.getProperty(tag + Constants.IMPL_SUFFIX, false); architectureDependency.setProperty(DEPENDS_ON_IMPL, isImpl); architectureDependency.addListProperty(Constants.TARGET_API, baseTo.getProperty(tag + Constants.PARENT_API_SUFFIX)); } } }