Skip to content

Commit

Permalink
Simplify, and add selector to all
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Feb 27, 2025
1 parent 9e4abc8 commit afb9647
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ protected boolean isReactorDependency(Dependency dependency) {
p.getVersion(), dependency.getArtifact().getVersion()));
}

protected ReactorLocator getReactorLocator() {
return new MavenReactorLocator(mavenSession);
}

protected ReactorLocator getReactorLocatorWithSelector(String selector) {
if (selector == null || selector.trim().isEmpty()) {
return getReactorLocator();
} else {
return new MavenReactorLocator(mavenSession, selector);
}
protected ReactorLocator getReactorLocator(String selector) {
return new MavenReactorLocator(mavenSession, selector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public class MavenReactorLocator implements ReactorLocator {
private final Project current;
private final List<Project> allProjects;

public MavenReactorLocator(MavenSession session) {
this(session, null);
}

public MavenReactorLocator(MavenSession session, String selector) {
requireNonNull(session, "session");
this.allProjects = session.getAllProjects().stream()
Expand All @@ -59,11 +55,11 @@ public MavenReactorLocator(MavenSession session, String selector) {
throw new IllegalArgumentException("Could not find 1 matching project: " + matches);
}
this.current = locateProject(
RepositoryUtils.toArtifact(candidates.get(0).getArtifact()))
RepositoryUtils.toArtifact(candidates.get(0).getArtifact()))
.orElseThrow();
} else {
this.current = locateProject(
RepositoryUtils.toArtifact(session.getCurrentProject().getArtifact()))
this.current = locateProject(RepositoryUtils.toArtifact(
session.getCurrentProject().getArtifact()))
.orElseThrow();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@
import eu.maveniverse.maven.toolbox.plugin.MPMojoSupport;
import eu.maveniverse.maven.toolbox.shared.Result;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.aether.collection.CollectResult;

/**
* Displays project inheritance of Maven Projects.
*/
@Mojo(name = "parent-child-tree", aggregator = true, threadSafe = true)
public class ParentChildTreeMojo extends MPMojoSupport {
/**
* Set the project selector, like {@code -rf} Maven command uses it, can be {@code :A}, {@code G:A}. The selector
* string must match ONE project within reactor, otherwise (matches 0 or more than 1) it will fail.
*/
@Parameter(property = "selector")
private String selector;

@Override
protected Result<CollectResult> doExecute() throws Exception {
return getToolboxCommando().parentChildTree(getReactorLocator());
return getToolboxCommando().parentChildTree(getReactorLocator(selector));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public class ProjectDependencyTreeMojo extends MPMojoSupport {

@Override
protected Result<CollectResult> doExecute() throws Exception {
return getToolboxCommando().projectDependencyTree(getReactorLocatorWithSelector(selector), showExternal);
return getToolboxCommando().projectDependencyTree(getReactorLocator(selector), showExternal);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@
import eu.maveniverse.maven.toolbox.plugin.MPMojoSupport;
import eu.maveniverse.maven.toolbox.shared.Result;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.eclipse.aether.collection.CollectResult;

/**
* Displays subproject collection of Maven Projects.
*/
@Mojo(name = "subproject-tree", aggregator = true, threadSafe = true)
public class SubprojectTreeMojo extends MPMojoSupport {
/**
* Set the project selector, like {@code -rf} Maven command uses it, can be {@code :A} or {@code G:A}. The selector
* string must match ONE project within reactor, otherwise (matches 0 or more than 1) it will fail.
*/
@Parameter(property = "selector")
private String selector;

@Override
protected Result<CollectResult> doExecute() throws Exception {
return getToolboxCommando().subprojectTree(getReactorLocator());
return getToolboxCommando().subprojectTree(getReactorLocator(selector));
}
}

0 comments on commit afb9647

Please sign in to comment.