-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
44 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/MPPluginMojoSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <groupId>:<artifactId>} to display tree for. If plugin is from "known" | ||
* groupId (as configured in settings.xml) it may be in format of {@code :<artifactId>} 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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginClasspathMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/PluginListRepositoriesMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters