Skip to content

Commit

Permalink
Add debug logs to RuleToDependency (#50)
Browse files Browse the repository at this point in the history
Add debug logs to RuleToDependency
  • Loading branch information
menny authored Oct 23, 2019
2 parents d22b489 + 60568ab commit 4c5ee7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public Dependency resolve(String mavenCoordinate, final Collection<String> repos
rule.setPackaging(packaging);
}

return RuleToDependency.from(rule);
return new RuleToDependency(debugLogs).from(rule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@

public class RuleToDependency {

public static Dependency from(Rule rule) {
private final boolean debugLogs;

public RuleToDependency(boolean debugLogs) {
this.debugLogs = debugLogs;
}

public Dependency from(Rule rule) {
return from(rule, new HashMap<>());
}

public static Dependency from(Rule rule, HashMap<String, Dependency> cache) {
if (cache.containsKey(rule.mavenCoordinates())) return cache.get(rule.mavenCoordinates());
public Dependency from(Rule rule, HashMap<String, Dependency> cache) {
if (debugLogs) {
System.out.println("Resolving dependencies for " + rule.mavenCoordinates());
}
if (cache.containsKey(rule.mavenCoordinates())) {
if (debugLogs) {
System.out.println("Dependencies taken from cache for " + rule.mavenCoordinates());
}
return cache.get(rule.mavenCoordinates());
}

Dependency mapped = new Dependency(rule.groupId(), rule.artifactId(), rule.version(), rule.packaging(),
rule.getDeps().stream().map(dep -> from(dep, cache)).collect(Collectors.toList()),
Expand All @@ -30,6 +44,9 @@ public static Dependency from(Rule rule, HashMap<String, Dependency> cache) {
.filter(Objects::nonNull)
.collect(Collectors.toList()));

if (debugLogs) {
System.out.println("Caching dependencies for " + rule.mavenCoordinates());
}
cache.put(rule.mavenCoordinates(), mapped);
return mapped;
}
Expand Down

0 comments on commit 4c5ee7f

Please sign in to comment.