Skip to content

Commit

Permalink
moditect#27 Unifying update of components after cycle detection
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarmorling committed Jan 29, 2019
1 parent c73af1b commit 6cbeae5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,7 @@ public void onCompletingCompilation() {
}

if (createDotFile) {
if (!cycles.isEmpty()) {
for (Component.Builder component : builder.getComponents()) {
for (Cycle<IdentifiableComponent> cycle : cycles) {
if (contains(cycle, component.getName())) {
for (IdentifiableComponent nodeInCycle : cycle.getNodes()) {
if (component.getReads().containsKey(nodeInCycle.getName())) {
component.addRead(nodeInCycle.getName(), ReadKind.CYCLE);
}
}
}
}
}
}
builder.updateFromCycles(cycles);

serializer = new DotSerializer();
packageDependencies.serialize(serializer);
Expand All @@ -231,16 +219,6 @@ public void onCompletingCompilation() {
}
}

private boolean contains(Cycle<IdentifiableComponent> cycle, String name) {
for (IdentifiableComponent component : cycle.getNodes()) {
if (component.getName().equals(name)) {
return true;
}
}

return false;
}

private boolean isWhitelistAllExternal() {
return whitelistPatterns.contains(PackagePattern.ALL_EXTERNAL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,7 @@ public void onCompletingCompilation() {
return;
}

if (!cycles.isEmpty()) {
for (Component.Builder component : actualPackageDependencies.getComponents()) {
for (Cycle<IdentifiableComponent> cycle : cycles) {
if (contains(cycle, component.getName())) {
for (IdentifiableComponent nodeInCycle : cycle.getNodes()) {
if (component.getReads().containsKey(nodeInCycle.getName())) {
component.addRead(nodeInCycle.getName(), ReadKind.CYCLE);
}
}
}
}
}
}
actualPackageDependencies.updateFromCycles(cycles);

DotSerializer serializer = new DotSerializer();
actualPackageDependencies.build().serialize(serializer);
Expand All @@ -219,16 +207,6 @@ public void onCompletingCompilation() {
}
}

private boolean contains(Cycle<IdentifiableComponent> cycle, String name) {
for (IdentifiableComponent component : cycle.getNodes()) {
if (component.getName().equals(name)) {
return true;
}
}

return false;
}

private boolean isIgnoredDependency(String referencedPackageName) {
return "java.lang".equals(referencedPackageName) ||
allowedPackageDependencies.isWhitelisted(referencedPackageName) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.moditect.deptective.internal.export.ModelSerializer;
import org.moditect.deptective.internal.graph.Cycle;

public class PackageDependencies {

Expand Down Expand Up @@ -79,6 +81,24 @@ public void addWhitelistedPackage(PackagePattern pattern) {
public Iterable<Component.Builder> getComponents() {
return componentsByName.values();
}

public void updateFromCycles(List<Cycle<IdentifiableComponent>> cycles) {
for (Cycle<IdentifiableComponent> cycle : cycles) {
for (IdentifiableComponent nodeInCycle : cycle.getNodes()) {
Component.Builder builder = componentsByName.get(nodeInCycle.name);

if (builder == null) {
continue;
}

for (IdentifiableComponent otherNodeInCycle : cycle.getNodes()) {
if (builder.getReads().containsKey(otherNodeInCycle.getName())) {
builder.addRead(otherNodeInCycle.getName(), ReadKind.CYCLE);
}
}
}
}
}
}

private final Components components;
Expand Down

0 comments on commit 6cbeae5

Please sign in to comment.