diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/MPPluginMojoSupport.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/MPPluginMojoSupport.java new file mode 100644 index 00000000..b1be287e --- /dev/null +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/MPPluginMojoSupport.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023-2024 Maveniverse Org. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + */ +package eu.maveniverse.maven.toolbox.plugin; + +import eu.maveniverse.maven.toolbox.shared.ResolutionRoot; +import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Support class for "project aware" Mojos. + */ +public abstract class MPPluginMojoSupport extends MPMojoSupport { + /** + * The plugin key in the format {@code :} to display tree for. If plugin is from "known" + * groupId (as configured in settings.xml) it may be in format of {@code :} and this mojo will find it. + * Finally, if plugin key is plain string like {@code "clean"}, this mojo will apply some heuristics to find it. + */ + @Parameter(property = "pluginKey", required = true) + private String pluginKey; + + protected ResolutionRoot pluginAsResolutionRoot(ToolboxCommando toolboxCommando) throws Exception { + Plugin plugin = null; + if (pluginKey == null || pluginKey.trim().isEmpty()) { + throw new IllegalArgumentException("pluginKey must not be empty string"); + } + if (pluginKey.startsWith(":")) { + for (String pluginGroup : settings.getPluginGroups()) { + plugin = mavenProject.getPlugin(pluginGroup + pluginKey); + if (plugin != null) { + break; + } + } + } else { + plugin = mavenProject.getPlugin(pluginKey); + if (plugin == null) { + for (Plugin p : mavenProject.getBuildPlugins()) { + if (p.getKey().contains(pluginKey)) { + plugin = p; + break; + } + } + } + } + if (plugin == null) { + throw new IllegalArgumentException("Plugin not found"); + } + ResolutionRoot root = + toolboxCommando.loadGav(plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion()); + if (!plugin.getDependencies().isEmpty()) { + root.getDependencies().addAll(toDependencies(plugin.getDependencies())); + } + return root; + } +} diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginClasspathMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginClasspathMojo.java new file mode 100644 index 00000000..58d0ba1b --- /dev/null +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginClasspathMojo.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023-2024 Maveniverse Org. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + */ +package eu.maveniverse.maven.toolbox.plugin.mp; + +import eu.maveniverse.maven.toolbox.plugin.MPPluginMojoSupport; +import eu.maveniverse.maven.toolbox.shared.ResolutionScope; +import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +@Mojo(name = "plugin-classpath", threadSafe = true) +public class PluginClasspathMojo extends MPPluginMojoSupport { + /** + * The resolution scope to display, accepted values are "runtime", "compile", "test", etc. + */ + @Parameter(property = "scope", defaultValue = "runtime", required = true) + private String scope; + + @Override + protected void doExecute(ToolboxCommando toolboxCommando) throws Exception { + toolboxCommando.classpath(ResolutionScope.parse(scope), pluginAsResolutionRoot(toolboxCommando), output); + } +} diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginListRepositoriesMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginListRepositoriesMojo.java new file mode 100644 index 00000000..ff6c544e --- /dev/null +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginListRepositoriesMojo.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023-2024 Maveniverse Org. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + */ +package eu.maveniverse.maven.toolbox.plugin.mp; + +import eu.maveniverse.maven.toolbox.plugin.MPPluginMojoSupport; +import eu.maveniverse.maven.toolbox.shared.ResolutionScope; +import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Resolves transitively a given GAV and outputs used repositories. + */ +@Mojo(name = "plugin-list-repositories", threadSafe = true) +public final class PluginListRepositoriesMojo extends MPPluginMojoSupport { + /** + * The resolution scope to display, accepted values are "runtime", "compile", "test", etc. + */ + @Parameter(property = "scope", defaultValue = "runtime", required = true) + private String scope; + + @Override + protected void doExecute(ToolboxCommando toolboxCommando) throws Exception { + toolboxCommando.listRepositories(ResolutionScope.parse(scope), pluginAsResolutionRoot(toolboxCommando), output); + } +} diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginTreeMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginTreeMojo.java index 09fc938d..55f5639f 100644 --- a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginTreeMojo.java +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginTreeMojo.java @@ -7,24 +7,14 @@ */ package eu.maveniverse.maven.toolbox.plugin.mp; -import eu.maveniverse.maven.toolbox.plugin.MPMojoSupport; -import eu.maveniverse.maven.toolbox.shared.ResolutionRoot; +import eu.maveniverse.maven.toolbox.plugin.MPPluginMojoSupport; import eu.maveniverse.maven.toolbox.shared.ResolutionScope; import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; -import org.apache.maven.model.Plugin; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @Mojo(name = "plugin-tree", threadSafe = true) -public class PluginTreeMojo extends MPMojoSupport { - /** - * The plugin key in the format {@code :} to display tree for. If plugin is from "known" - * groupId (as configured in settings.xml) it may be in format of {@code :} and this mojo will find it. - * Finally, if plugin key is plain string like {@code "clean"}, this mojo will apply some heuristics to find it. - */ - @Parameter(property = "pluginKey", required = true) - private String pluginKey; - +public class PluginTreeMojo extends MPPluginMojoSupport { /** * The resolution scope to display, accepted values are "runtime", "compile", "test", etc. */ @@ -39,36 +29,7 @@ public class PluginTreeMojo extends MPMojoSupport { @Override protected void doExecute(ToolboxCommando toolboxCommando) throws Exception { - Plugin plugin = null; - if (pluginKey == null || pluginKey.trim().isEmpty()) { - throw new IllegalArgumentException("pluginKey must not be empty string"); - } - if (pluginKey.startsWith(":")) { - for (String pluginGroup : settings.getPluginGroups()) { - plugin = mavenProject.getPlugin(pluginGroup + pluginKey); - if (plugin != null) { - break; - } - } - } else { - plugin = mavenProject.getPlugin(pluginKey); - if (plugin == null) { - for (Plugin p : mavenProject.getBuildPlugins()) { - if (p.getKey().contains(pluginKey)) { - plugin = p; - break; - } - } - } - } - if (plugin == null) { - throw new IllegalArgumentException("Plugin not found"); - } - ResolutionRoot root = - toolboxCommando.loadGav(plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion()); - if (!plugin.getDependencies().isEmpty()) { - root.getDependencies().addAll(toDependencies(plugin.getDependencies())); - } - toolboxCommando.tree(ResolutionScope.parse(scope), root, verboseTree, output); + toolboxCommando.tree( + ResolutionScope.parse(scope), pluginAsResolutionRoot(toolboxCommando), verboseTree, output); } } diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java index fddf4eea..faf5e550 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxCommandoImpl.java @@ -292,7 +292,7 @@ public boolean visitLeave(DependencyNode node) { })); repositories.forEach((k, v) -> { output.normal(k.toString()); - output.verbose(" First introduced on {}", v == sentinel ? "root" : v); + output.normal(" First introduced on {}", v == sentinel ? "root" : v); }); return !repositories.isEmpty(); }