Skip to content

Commit

Permalink
2.2.0 release
Browse files Browse the repository at this point in the history
- fix goals being put not added
- made plugin api nicer to work with
  • Loading branch information
Osiris-Team committed Jul 28, 2024
1 parent 1a68572 commit 18bcf3e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ AUTO-GENERATED FILE, CHANGES SHOULD BE DONE IN ./JPM.java or ./src/main/java/JPM
<id>resource-bundles</id>
<phase>package</phase>
<goals>
<goal>resource-bundle</goal>
<goal>test-resource-bundle</goal>
</goals>
<configuration>
Expand Down
95 changes: 56 additions & 39 deletions src/main/java/JPM.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,25 @@ public ThisProject(List<String> 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<String> 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<Plugin> plugins = new ArrayList<>();
Expand Down Expand Up @@ -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<Project, XML> code){
Expand All @@ -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);

Expand Down Expand Up @@ -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() {
Expand All @@ -473,9 +493,10 @@ public XML toXML() {

// Add <goals> element if goals list is not empty
if (!goals.isEmpty()) {
xml.put("goals", ""); // Placeholder for <goals> element
for (String goal : goals) {
xml.put("goals goal", goal);
XML goalXml = new XML("goal");
goalXml.put("", goal);
xml.add("goals", goalXml);
}
}

Expand Down Expand Up @@ -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);
}
}
});
Expand All @@ -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", ""));
});
}
}
Expand All @@ -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");
});
}
}
Expand All @@ -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");
});
}
}
Expand All @@ -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");
});
}
}
Expand All @@ -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", "");
});
}
}
Expand Down

0 comments on commit 18bcf3e

Please sign in to comment.