Skip to content

Commit

Permalink
Some clean-up;
Browse files Browse the repository at this point in the history
* Removing method for adding reads without read kind
* Making sure Component instances aren't affected by subsequent builder calls
  • Loading branch information
gunnarmorling committed Feb 3, 2019
1 parent ae0dec0 commit 27ddd01
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public PackageReferenceCollector(JavaFileManager jfm, Log log, List<PackagePatte
builder = PackageDependencies.builder();

for (Component component : declaredComponents) {
builder.addComponent(component.getName(), component.getContained(), Collections.emptyList());
for (PackagePattern contained : component.getContained()) {
builder.addContains(component.getName(), contained);
}
}
}

Expand Down Expand Up @@ -202,6 +204,7 @@ public void onCompletingCompilation() {

if (createDotFile) {
builder.updateFromCycles(cycles);
packageDependencies = builder.build();

serializer = new DotSerializer();
packageDependencies.serialize(serializer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ public Builder(String name) {
this.reads = new HashMap<>();
}

public Builder addReads(Iterable<String> reads) {
for (String read : reads) {
addRead(read, ReadKind.ALLOWED);
}
return this;
}

public Builder addRead(String read, ReadKind readKind) {
if (!read.isEmpty() && !read.equals(name) && !read.equals("java.lang")) {
reads.put(read, readKind);
Expand Down Expand Up @@ -89,8 +82,8 @@ public String getName() {

public Component(String name, Set<PackagePattern> contained, Map<String, ReadKind> reads) {
super(name);
this.contained = Collections.unmodifiableSet(contained);
this.reads = Collections.unmodifiableMap(reads);
this.contained = Collections.unmodifiableSet(new HashSet<>(contained));
this.reads = Collections.unmodifiableMap(new HashMap<>(reads));
}

public static Builder builder(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ private void parseComponent(JsonNode component, Builder builder) {
List<PackagePattern> contains = parseContains((ArrayNode) (component.get("contains")));
List<String> reads = parseReads((ArrayNode) (component.get("reads")));

builder.addComponent(name, contains, reads);
for (String read : reads) {
builder.addRead(name, read, ReadKind.ALLOWED);
}

for (PackagePattern pattern : contains) {
builder.addContains(name, pattern);
}
}

private List<String> parseReads(ArrayNode arrayNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.moditect.deptective.internal.model;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -43,17 +42,6 @@ public PackageDependencies build() {
return new PackageDependencies(new Components(components), whitelisted);
}

public void addComponent(String name, Collection<PackagePattern> contains, Collection<String> reads) {
if (componentsByName.containsKey(name)) {
throw new IllegalArgumentException("Component " + name + " may not be configured more than once.");
}

componentsByName.put(
name,
Component.builder(name).addReads(reads).addContains(contains)
);
}

public void addContains(String componentName, PackagePattern contained) {
Component.Builder builder = componentsByName.computeIfAbsent(componentName, n -> Component.builder(n));
builder.addContains(contained);
Expand Down

0 comments on commit 27ddd01

Please sign in to comment.