From 18bcf3ebd3dde906e63a5018480e5fd61f8e63e2 Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Sun, 28 Jul 2024 16:02:22 +0200 Subject: [PATCH] 2.2.0 release - fix goals being put not added - made plugin api nicer to work with --- pom.xml | 1 + src/main/java/JPM.java | 95 +++++++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index a149e00..10aa242 100644 --- a/pom.xml +++ b/pom.xml @@ -105,6 +105,7 @@ AUTO-GENERATED FILE, CHANGES SHOULD BE DONE IN ./JPM.java or ./src/main/java/JPM resource-bundles package + resource-bundle test-resource-bundle diff --git a/src/main/java/JPM.java b/src/main/java/JPM.java index cc76e93..31d96ed 100644 --- a/src/main/java/JPM.java +++ b/src/main/java/JPM.java @@ -36,18 +36,25 @@ public ThisProject(List args) { addCompilerArg("-Xlint:deprecation"); } - public static void main(String[] args) throws Exception { - new ThisProject(Arrays.asList(args)).generatePom(); + public static void main(String[] _args) throws Exception { + List args = Arrays.asList(_args); + ThisProject project = new ThisProject(args); + project.generatePom(); JPM.executeMaven("clean", "package"); // or JPM.executeMaven(args); if you prefer the CLI, like "java JPM.java clean package" } } +class Plugins extends JPM.Plugins{ + // Add your Maven Plugins using the JPM.Plugin class here and + // take a look at "JPM.AssemblyPlugin" class further below to get started +} + class ThirdPartyPlugins extends JPM.Plugins{ // Add third party plugins below, find them here: https://github.com/topics/1jpm-plugin?o=desc&s=updated - // (If you want to develop a plugin take a look at "JPM.Clean" class further below to get started) + // (If you want to develop a plugin take a look at "JPM.AssemblyPlugin" class further below to get started) } -// 1JPM version 2.1.1-IN_WORK by Osiris-Team: https://github.com/Osiris-Team/1JPM +// 1JPM version 2.2.0 by Osiris-Team: https://github.com/Osiris-Team/1JPM // To upgrade JPM, replace the JPM class below with its newer version public class JPM { public static final List plugins = new ArrayList<>(); @@ -373,16 +380,25 @@ public Plugin(String groupId, String artifactId, String version) { this.version = version; } - public void addConfiguration(String key, String value) { + public Plugin putConfiguration(String key, String value) { configuration.put(key, value); + return this; + } + + public Execution addExecution(String id, String phase){ + Execution execution = new Execution(id, phase); + executions.add(execution); + return execution; } - public void addExecution(Execution execution) { + public Execution addExecution(Execution execution) { executions.add(execution); + return execution; } - public void addDependency(Dependency dependency) { + public Plugin addDependency(Dependency dependency) { dependencies.add(dependency); + return this; } public Plugin onBeforeToXML(BiConsumer code){ @@ -402,7 +418,9 @@ private void executeAfterToXML(Project project) { dependencies.clear(); } - + /** + * Usually you will override this. + */ public XML toXML(Project project, XML projectXML) { executeBeforeToXML(project, projectXML); @@ -451,12 +469,14 @@ public Execution(String id, String phase) { this.configuration = new HashMap<>(); } - public void addGoal(String goal) { + public Execution addGoal(String goal) { goals.add(goal); + return this; } - public void addConfiguration(String key, String value) { + public Execution putConfiguration(String key, String value) { configuration.put(key, value); + return this; } public XML toXML() { @@ -473,9 +493,10 @@ public XML toXML() { // Add element if goals list is not empty if (!goals.isEmpty()) { - xml.put("goals", ""); // Placeholder for element for (String goal : goals) { - xml.put("goals goal", goal); + XML goalXml = new XML("goal"); + goalXml.put("", goal); + xml.add("goals", goalXml); } } @@ -615,13 +636,13 @@ public static class CompilerPlugin extends Plugin { public CompilerPlugin() { super("org.apache.maven.plugins", "maven-compiler-plugin", "3.8.1"); onBeforeToXML((project, pom) -> { - addConfiguration("source", project.javaVersionSource); - addConfiguration("target", project.javaVersionTarget); + putConfiguration("source", project.javaVersionSource); + putConfiguration("target", project.javaVersionTarget); // Add compiler arguments from the project if (!project.compilerArgs.isEmpty()) { for (String arg : project.compilerArgs) { - addConfiguration("compilerArgs arg", arg); + putConfiguration("compilerArgs arg", arg); } } }); @@ -636,9 +657,9 @@ public static class JarPlugin extends Plugin { public JarPlugin() { super("org.apache.maven.plugins", "maven-jar-plugin", "3.2.0"); onBeforeToXML((project, pom) -> { - addConfiguration("archive manifest addClasspath", "true"); - addConfiguration("archive manifest mainClass", project.mainClass); - addConfiguration("finalName", project.jarName.replace(".jar", "")); + putConfiguration("archive manifest addClasspath", "true"); + putConfiguration("archive manifest mainClass", project.mainClass); + putConfiguration("finalName", project.jarName.replace(".jar", "")); }); } } @@ -651,14 +672,13 @@ public static class AssemblyPlugin extends Plugin { public AssemblyPlugin() { super("org.apache.maven.plugins", "maven-assembly-plugin", "3.3.0"); onBeforeToXML((project, pom) -> { - addConfiguration("descriptorRefs descriptorRef", "jar-with-dependencies"); - addConfiguration("archive manifest mainClass", project.mainClass); - addConfiguration("finalName", project.fatJarName.replace(".jar", "")); - addConfiguration("appendAssemblyId", "false"); - - Execution execution = new Execution("make-assembly", "package"); - execution.addGoal("single"); - addExecution(execution); + putConfiguration("descriptorRefs descriptorRef", "jar-with-dependencies"); + putConfiguration("archive manifest mainClass", project.mainClass); + putConfiguration("finalName", project.fatJarName.replace(".jar", "")); + putConfiguration("appendAssemblyId", "false"); + + addExecution("make-assembly", "package") + .addGoal("single"); }); } } @@ -671,9 +691,8 @@ public static class SourcePlugin extends Plugin { public SourcePlugin() { super("org.apache.maven.plugins", "maven-source-plugin", "3.2.1"); onBeforeToXML((project, pom) -> { - Execution execution = new Execution("attach-sources", null); - addExecution(execution); - execution.addGoal("jar"); + addExecution("attach-sources", null) + .addGoal("jar"); }); } } @@ -686,12 +705,11 @@ public static class JavadocPlugin extends Plugin { public JavadocPlugin() { super("org.apache.maven.plugins", "maven-javadoc-plugin", "3.0.0"); onBeforeToXML((project, pom) -> { - Execution execution = new Execution("resource-bundles", "package"); - addExecution(execution); - execution.addGoal("resource-bundle"); - execution.addGoal("test-resource-bundle"); - execution.addConfiguration("doclint", "none"); - execution.addConfiguration("detectOfflineLinks", "false"); + addExecution("resource-bundles", "package") + .addGoal("resource-bundle") + .addGoal("test-resource-bundle") + .putConfiguration("doclint", "none") + .putConfiguration("detectOfflineLinks", "false"); }); } } @@ -704,10 +722,9 @@ public static class EnforcerPlugin extends Plugin { public EnforcerPlugin() { super("org.apache.maven.plugins", "maven-enforcer-plugin", "3.3.0"); onBeforeToXML((project, pom) -> { - Execution execution = new Execution("enforce", null); - addExecution(execution); - execution.addGoal("enforce"); - execution.addConfiguration("rules dependencyConvergence", ""); + addExecution("enforce", null) + .addGoal("enforce") + .putConfiguration("rules dependencyConvergence", ""); }); } }