Skip to content

Commit a5aea01

Browse files
committed
WIP
1 parent 84e5684 commit a5aea01

File tree

8 files changed

+153
-27
lines changed

8 files changed

+153
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2023-2024 Maveniverse Org.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*/
8+
package eu.maveniverse.maven.toolbox.plugin;
9+
10+
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
11+
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
12+
import org.apache.maven.plugin.MojoExecutionException;
13+
import org.apache.maven.plugin.MojoFailureException;
14+
import org.apache.maven.plugins.annotations.Mojo;
15+
import org.apache.maven.plugins.annotations.Parameter;
16+
17+
@Mojo(name = "classpath", threadSafe = true)
18+
public class ClasspathMojo extends ProjectMojoSupport {
19+
/**
20+
* The resolution scope to display, accepted values are "runtime", "compile", "test", etc.
21+
*/
22+
@Parameter(property = "scope", defaultValue = "runtime", required = true)
23+
private String scope;
24+
25+
@Override
26+
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
27+
toolboxCommando.classpath(ResolutionScope.parse(scope), projectAsResolutionRoot(), output);
28+
}
29+
}

maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/DumpMojo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
public class DumpMojo extends ProjectMojoSupport {
1515
@Override
1616
protected void doExecute(ToolboxCommando toolboxCommando) {
17-
toolboxCommando.dump(verbose, output);
17+
toolboxCommando.dump(logger.isDebugEnabled(), output);
1818
}
1919
}

maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/ProjectMojoSupport.java

-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.maven.plugin.MojoExecutionException;
2424
import org.apache.maven.plugin.MojoFailureException;
2525
import org.apache.maven.plugins.annotations.Component;
26-
import org.apache.maven.plugins.annotations.Parameter;
2726
import org.apache.maven.project.MavenProject;
2827
import org.eclipse.aether.artifact.ArtifactTypeRegistry;
2928
import org.eclipse.aether.artifact.DefaultArtifact;
@@ -35,12 +34,8 @@
3534
*/
3635
public abstract class ProjectMojoSupport extends AbstractMojo {
3736
protected final Logger logger = LoggerFactory.getLogger(getClass());
38-
3937
protected final Output output = new Slf4jOutput(logger);
4038

41-
@Parameter(property = "verbose", defaultValue = "false", required = true)
42-
protected boolean verbose;
43-
4439
@Component
4540
private MavenProject mavenProject;
4641

maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/TreeMojo.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ public class TreeMojo extends ProjectMojoSupport {
2222
@Parameter(property = "scope", defaultValue = "runtime", required = true)
2323
private String scope;
2424

25+
/**
26+
* Set it {@code true} for verbose tree.
27+
*/
28+
@Parameter(property = "verboseTree", defaultValue = "false", required = true)
29+
private boolean verboseTree;
30+
2531
@Override
2632
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
27-
toolboxCommando.tree(ResolutionScope.parse(scope), projectAsResolutionRoot(), verbose, output);
33+
toolboxCommando.tree(ResolutionScope.parse(scope), projectAsResolutionRoot(), verboseTree, output);
2834
}
2935
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2023-2024 Maveniverse Org.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*/
8+
package eu.maveniverse.maven.toolbox.plugin.gav;
9+
10+
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
11+
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
12+
import org.apache.maven.plugin.MojoExecutionException;
13+
import org.apache.maven.plugin.MojoFailureException;
14+
import org.apache.maven.plugins.annotations.Mojo;
15+
import org.apache.maven.plugins.annotations.Parameter;
16+
import org.eclipse.aether.resolution.ArtifactDescriptorException;
17+
18+
@Mojo(name = "gav-classpath", requiresProject = false, threadSafe = true)
19+
public class GavClasspathMojo extends GavMojoSupport {
20+
/**
21+
* The artifact coordinates in the format {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}
22+
* to display tree for.
23+
*/
24+
@Parameter(property = "gav", required = true)
25+
private String gav;
26+
27+
/**
28+
* The resolution scope to display, accepted values are "runtime", "compile", "test", etc.
29+
*/
30+
@Parameter(property = "scope", defaultValue = "runtime", required = true)
31+
private String scope;
32+
33+
/**
34+
* Apply BOMs, if needed.
35+
*/
36+
@Parameter(property = "boms", defaultValue = "")
37+
private java.util.List<String> boms;
38+
39+
@Override
40+
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
41+
try {
42+
toolboxCommando.classpath(ResolutionScope.parse(scope), toolboxCommando.loadGav(gav, boms), output);
43+
} catch (RuntimeException e) {
44+
throw new MojoExecutionException(e);
45+
} catch (ArtifactDescriptorException e) {
46+
throw new MojoFailureException(e);
47+
}
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2023-2024 Maveniverse Org.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*/
8+
package eu.maveniverse.maven.toolbox.plugin.gav;
9+
10+
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
11+
import org.apache.maven.plugins.annotations.Mojo;
12+
13+
@Mojo(name = "gav-dump", requiresProject = false, threadSafe = true)
14+
public class GavDumpMojo extends GavMojoSupport {
15+
@Override
16+
protected void doExecute(ToolboxCommando toolboxCommando) {
17+
toolboxCommando.dump(logger.isDebugEnabled(), output);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2023-2024 Maveniverse Org.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*/
8+
package eu.maveniverse.maven.toolbox.plugin.gav;
9+
10+
import eu.maveniverse.maven.mima.context.Context;
11+
import eu.maveniverse.maven.mima.context.ContextOverrides;
12+
import eu.maveniverse.maven.mima.context.Runtime;
13+
import eu.maveniverse.maven.mima.context.Runtimes;
14+
import eu.maveniverse.maven.toolbox.shared.Output;
15+
import eu.maveniverse.maven.toolbox.shared.Slf4jOutput;
16+
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
17+
import org.apache.maven.plugin.AbstractMojo;
18+
import org.apache.maven.plugin.MojoExecutionException;
19+
import org.apache.maven.plugin.MojoFailureException;
20+
import org.apache.maven.plugins.annotations.Parameter;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
public abstract class GavMojoSupport extends AbstractMojo {
25+
protected final Logger logger = LoggerFactory.getLogger(getClass());
26+
protected final Output output = new Slf4jOutput(logger);
27+
28+
@Parameter(property = "verbose", defaultValue = "false", required = true)
29+
protected boolean verbose;
30+
31+
@Override
32+
public final void execute() throws MojoExecutionException, MojoFailureException {
33+
Runtime runtime = Runtimes.INSTANCE.getRuntime();
34+
try (Context context = runtime.create(ContextOverrides.create().build())) {
35+
doExecute(ToolboxCommando.create(runtime, context));
36+
}
37+
}
38+
39+
protected abstract void doExecute(ToolboxCommando toolboxCommando)
40+
throws MojoExecutionException, MojoFailureException;
41+
}

maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/GavTreeMojo.java maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/gav/GavTreeMojo.java

+7-20
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,18 @@
55
* which accompanies this distribution, and is available at
66
* https://www.eclipse.org/legal/epl-v20.html
77
*/
8-
package eu.maveniverse.maven.toolbox.plugin;
8+
package eu.maveniverse.maven.toolbox.plugin.gav;
99

10-
import eu.maveniverse.maven.mima.context.Context;
11-
import eu.maveniverse.maven.mima.context.ContextOverrides;
12-
import eu.maveniverse.maven.mima.context.Runtime;
13-
import eu.maveniverse.maven.mima.context.Runtimes;
1410
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
15-
import eu.maveniverse.maven.toolbox.shared.Slf4jOutput;
1611
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
17-
import org.apache.maven.plugin.AbstractMojo;
1812
import org.apache.maven.plugin.MojoExecutionException;
1913
import org.apache.maven.plugin.MojoFailureException;
2014
import org.apache.maven.plugins.annotations.Mojo;
2115
import org.apache.maven.plugins.annotations.Parameter;
2216
import org.eclipse.aether.resolution.ArtifactDescriptorException;
23-
import org.slf4j.Logger;
24-
import org.slf4j.LoggerFactory;
2517

2618
@Mojo(name = "gav-tree", requiresProject = false, threadSafe = true)
27-
public class GavTreeMojo extends AbstractMojo {
28-
private final Logger logger = LoggerFactory.getLogger(getClass());
29-
19+
public class GavTreeMojo extends GavMojoSupport {
3020
/**
3121
* The artifact coordinates in the format {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}
3222
* to display tree for.
@@ -43,8 +33,8 @@ public class GavTreeMojo extends AbstractMojo {
4333
/**
4434
* Set it {@code true} for verbose tree.
4535
*/
46-
@Parameter(property = "verbose", defaultValue = "false", required = true)
47-
private boolean verbose;
36+
@Parameter(property = "verboseTree", defaultValue = "false", required = true)
37+
private boolean verboseTree;
4838

4939
/**
5040
* Apply BOMs, if needed.
@@ -53,12 +43,9 @@ public class GavTreeMojo extends AbstractMojo {
5343
private java.util.List<String> boms;
5444

5545
@Override
56-
public void execute() throws MojoExecutionException, MojoFailureException {
57-
Runtime runtime = Runtimes.INSTANCE.getRuntime();
58-
try (Context context = runtime.create(ContextOverrides.create().build())) {
59-
ToolboxCommando toolboxCommando = ToolboxCommando.create(runtime, context);
60-
toolboxCommando.tree(
61-
ResolutionScope.parse(scope), toolboxCommando.loadGav(gav, boms), verbose, new Slf4jOutput(logger));
46+
protected void doExecute(ToolboxCommando toolboxCommando) throws MojoExecutionException, MojoFailureException {
47+
try {
48+
toolboxCommando.tree(ResolutionScope.parse(scope), toolboxCommando.loadGav(gav, boms), verboseTree, output);
6249
} catch (RuntimeException e) {
6350
throw new MojoExecutionException(e);
6451
} catch (ArtifactDescriptorException e) {

0 commit comments

Comments
 (0)