Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdchristo committed Mar 7, 2017
1 parent 2aa9f01 commit 7097d34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
15 changes: 0 additions & 15 deletions src/main/java/com/github/chrisdchristo/capsule/CapsuleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,6 @@ public class CapsuleMojo extends SuperMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

// System.out.println("PLUGIN-LIST:");
// for (final Dependency dep : this.plugin.getDependencies()) {
// System.out.println(coords(dep) + dep.getScope());
// }
//
// System.out.println("PLUGIN-DIRECT-DEPENDENCIES:");
// for (final Dependency dep : pluginDirectDependencies()) {
// System.out.println(coords(dep) + dep.getScope());
// }
//
// System.out.println("PLUGIN-DEPENDENCIES:");
// for (final Dependency dep : pluginDependencies()) {
// System.out.println(coords(dep) + "(" + dep.getScope() + ")");
// }

// check for type (this overrides custom behaviour)
if (type == Type.empty) {
includeApp = false;
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/com/github/chrisdchristo/capsule/SuperMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ public abstract class SuperMojo extends AbstractMojo {
// DEPENDENCIES

protected Set<Dependency> appDependencies() { return set(project.getTestDependencies()); }
protected Set<Dependency> pluginDependencies() { return getDependenciesOf(set(plugin().getDependencies()), true); }

protected Set<Dependency> appDirectDependencies() { return set(project.getDependencies()); }
protected Set<Dependency> pluginDirectDependencies() { return set(plugin().getDependencies()); }

protected Set<Artifact> appDependencyArtifacts() { return project.getArtifacts(); }
protected Set<Artifact> pluginDependencyArtifacts() { return getDependencyArtifactsOf(set(plugin().getDependencies()), true); }

protected Set<Artifact> appDirectDependencyArtifacts() { return project.getDependencyArtifacts(); }

protected Set<Dependency> pluginDependencies() { return getDependenciesOf(set(plugin().getDependencies()), true); }
protected Set<Dependency> pluginDirectDependencies() { return set(plugin().getDependencies()); }
protected Set<Artifact> pluginDependencyArtifacts() { return getDependencyArtifactsOf(set(plugin().getDependencies()), true); }
protected Set<Artifact> pluginDirectDependencyArtifacts() { return toArtifacts(set(plugin().getDependencies())); }


Expand Down Expand Up @@ -117,6 +115,7 @@ private Artifact toArtifact(final ArtifactResult ar) {
artifact.setScope(ar.getRequest().getDependencyNode().getDependency().getScope());
artifact.setOptional(ar.getRequest().getDependencyNode().getDependency().isOptional());
}
if (artifact.getScope() == null || artifact.getScope().isEmpty()) artifact.setScope("compile");
artifact.setFile(ar.getArtifact().getFile());
return artifact;
}
Expand All @@ -125,6 +124,7 @@ private Artifact toArtifact(final Dependency dependency) {
if (dependency == null) return null;
final Artifact artifact = toArtifact(resolve(dependency));
artifact.setScope(dependency.getScope());
if (artifact.getScope() == null || artifact.getScope().isEmpty()) artifact.setScope("compile");
return artifact;
}

Expand All @@ -137,6 +137,7 @@ private Dependency toDependency(final Artifact artifact) {
dependency.setScope(artifact.getScope());
dependency.setClassifier(artifact.getClassifier());
dependency.setOptional(artifact.isOptional());
if (dependency.getScope() == null || dependency.getScope().isEmpty()) dependency.setScope("compile");
return dependency;
}

Expand All @@ -145,18 +146,16 @@ private Dependency toDependency(final ArtifactResult ar) {
}

private Set<Artifact> getDependencyArtifactsOf(final Dependency dependency, final boolean includeRoot) {
info("TEST Getting dependencies of [" + coords(dependency) + "]");
final Set<Artifact> artifacts = new HashSet<>();
if (includeRoot) artifacts.add(toArtifact(dependency));
for (final ArtifactResult ar : resolveDependencies(dependency)) {
final Artifact artifact = toArtifact(ar);
info("TEST \t found: [" + coords(artifact) + "]");

// if null set to default compile
if (artifact.getScope() == null || artifact.getScope().isEmpty()) artifact.setScope("compile");

// skip any deps that aren't compile or runtime
if (!artifact.getScope().equals("compile") || !artifact.getScope().equals("runtime")) continue;
if (!artifact.getScope().equals("compile") && !artifact.getScope().equals("runtime")) continue;

// set direct-scope on transitive deps
if (dependency.getScope().equals("provided")) artifact.setScope("provided");
Expand Down Expand Up @@ -234,7 +233,7 @@ protected String coords(final Artifact artifact) {
return coords(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getVersion());
}

private String coords(final Dependency dependency) {
protected String coords(final Dependency dependency) {
return coords(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getVersion());
}

Expand All @@ -260,13 +259,14 @@ protected String coordsWithExclusions(final Dependency dependency) {
private Set<Dependency> cleanDependencies(final Set<Dependency> dependencies) {
final Set<Dependency> dependenciesClean = new HashSet<>();
for (final Dependency dependencyA : dependencies) {
boolean found = false;
for (final Dependency dependencyB : dependenciesClean) {
if (dependencyA.getGroupId().equals(dependencyB.getGroupId()) &&
dependencyA.getArtifactId().equals(dependencyB.getArtifactId()) &&
dependencyA.getVersion().equals(dependencyB.getVersion()))
continue;
if (coords(dependencyA).equals(coords(dependencyB))) {
found = true;
break;
}
}
dependenciesClean.add(dependencyA);
if (!found) dependenciesClean.add(dependencyA);
}
return dependenciesClean;
}
Expand All @@ -275,13 +275,14 @@ private Set<Dependency> cleanDependencies(final Set<Dependency> dependencies) {
private Set<Artifact> cleanArtifacts(final Set<Artifact> artifacts) {
final Set<Artifact> artifactsClean = new HashSet<>();
for (final Artifact artifactA : artifacts) {
boolean found = false;
for (final Artifact artifactB : artifactsClean) {
if (artifactA.getGroupId().equals(artifactB.getGroupId()) &&
artifactA.getArtifactId().equals(artifactB.getArtifactId()) &&
artifactA.getVersion().equals(artifactB.getVersion()))
continue;
if (coords(artifactA).equals(coords(artifactB))){
found = true;
break;
}
}
artifactsClean.add(artifactA);
if (!found) artifactsClean.add(artifactA);
}
return artifactsClean;
}
Expand Down

0 comments on commit 7097d34

Please sign in to comment.