From 4a243e773d08bcb690ac2b9b1036645c5a47971e Mon Sep 17 00:00:00 2001 From: jycr Date: Sat, 5 Aug 2023 15:42:16 +0200 Subject: [PATCH 1/4] refactor: Use `String.format` for log --- .../github/johnpoth/jshell/JShellMojo.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/github/johnpoth/jshell/JShellMojo.java b/src/main/java/com/github/johnpoth/jshell/JShellMojo.java index 16cdedd..f25adb8 100644 --- a/src/main/java/com/github/johnpoth/jshell/JShellMojo.java +++ b/src/main/java/com/github/johnpoth/jshell/JShellMojo.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,6 +16,14 @@ */ package com.github.johnpoth.jshell; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; + import javax.tools.Tool; import java.io.File; import java.nio.file.Files; @@ -26,18 +34,10 @@ import java.util.Optional; import java.util.ServiceLoader; import java.util.stream.Collectors; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -@Mojo( name = "run", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST, requiresDependencyCollection = ResolutionScope.TEST ) -public class JShellMojo extends AbstractMojo -{ +@Mojo(name = "run", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST, requiresDependencyCollection = ResolutionScope.TEST) +public class JShellMojo extends AbstractMojo { @Parameter(defaultValue = "${project.runtimeClasspathElements}", property = "rcp", required = true) private List runtimeClasspathElements; @@ -121,12 +121,15 @@ private List filterClasspath(List cp) { return cp.stream() .filter(s -> { Path path = Paths.get(s); - if (Files.notExists(path)){ - getLog().warn("Removing: " + s +" from the classpath." + System.lineSeparator() + - "If this is unexpected, please make sure you correctly build the project beforehand by invoking the correct Maven build phase (usually `install`, `test-compile` or `compile`). For example:" + System.lineSeparator() + - "mvn test-compile com.github.johnpoth:jshell-maven-plugin:1.3:run" + System.lineSeparator() + - "For more information visit https://github.com/johnpoth/jshell-maven-plugin" - ); + if (Files.notExists(path)) { + getLog().warn(String.format( + "Removing: %s from the classpath.%n" + + "If this is unexpected, please make sure you correctly build the project beforehand by invoking the correct Maven build phase (usually `install`, `test-compile` or `compile`). For example:%n" + + "mvn test-compile com.github.johnpoth:jshell-maven-plugin:%s:run%n" + + "For more information visit https://github.com/johnpoth/jshell-maven-plugin", + s, + "1.3" + )); return false; } if (Files.isDirectory(path)) { @@ -135,7 +138,7 @@ private List filterClasspath(List cp) { if (s.endsWith(".jar")) { return true; } - getLog().debug("Removing: " + s +" from the classpath because it is unsupported in JShell."); + getLog().debug("Removing: " + s + " from the classpath because it is unsupported in JShell."); return false; }).collect(Collectors.toList()); } @@ -145,19 +148,19 @@ private String[] addArguments(String cp) { if (useProjectClasspath) { args.add("--class-path"); args.add(cp); - } else if (classpath != null ){ + } else if (classpath != null) { args.add("--class-path"); args.add(classpath); } - if (modulepath != null){ + if (modulepath != null) { args.add("--module-path"); args.add(modulepath); } - if (addModules!= null){ + if (addModules != null) { args.add("--add-modules"); args.add(addModules); } - if (addExports!= null){ + if (addExports != null) { args.add("--add-exports"); args.add(addExports); } From f8dfb9a9c4aa96262495967b70a97232fb0ce543 Mon Sep 17 00:00:00 2001 From: jycr Date: Sat, 5 Aug 2023 15:43:23 +0200 Subject: [PATCH 2/4] feat: Adds JAR Metadata (Specification-Title, Specification-Version, etc.) --- .gitignore | 3 ++- .mvn/extensions.xml | 7 ++++++ .mvn/maven-git-versioning-extension.xml | 22 +++++++++++++++++ pom.xml | 24 +++++++++++++++++++ .../github/johnpoth/jshell/JShellMojo.java | 4 +++- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 .mvn/extensions.xml create mode 100644 .mvn/maven-git-versioning-extension.xml diff --git a/.gitignore b/.gitignore index b57c544..49745f4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ target .idea .classpath .project -.settings \ No newline at end of file +.settings +/.git-versioned-pom.xml diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml new file mode 100644 index 0000000..0140c38 --- /dev/null +++ b/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + me.qoomon + maven-git-versioning-extension + 9.6.5 + + diff --git a/.mvn/maven-git-versioning-extension.xml b/.mvn/maven-git-versioning-extension.xml new file mode 100644 index 0000000..4559a39 --- /dev/null +++ b/.mvn/maven-git-versioning-extension.xml @@ -0,0 +1,22 @@ + + + + .+ + + ${version} + + + + \d+\.\d+\.\d+.*)$]]> + ${ref.version} + + + + + + ${commit} + + diff --git a/pom.xml b/pom.xml index f49fafb..2f1c486 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,30 @@ + + org.apache.maven.plugins + maven-jar-plugin + 3.3.0 + + + + true + true + true + + + + ${git.commit} + + ${git.commit.timestamp.datetime} + + ${project.version}-${git.commit} + ${java.version} + ${java.vendor} + + + + diff --git a/src/main/java/com/github/johnpoth/jshell/JShellMojo.java b/src/main/java/com/github/johnpoth/jshell/JShellMojo.java index f25adb8..bfc9d7c 100644 --- a/src/main/java/com/github/johnpoth/jshell/JShellMojo.java +++ b/src/main/java/com/github/johnpoth/jshell/JShellMojo.java @@ -35,6 +35,8 @@ import java.util.ServiceLoader; import java.util.stream.Collectors; +import static java.util.Optional.ofNullable; + @Mojo(name = "run", defaultPhase = LifecyclePhase.INSTALL, requiresDependencyResolution = ResolutionScope.TEST, requiresDependencyCollection = ResolutionScope.TEST) public class JShellMojo extends AbstractMojo { @@ -128,7 +130,7 @@ private List filterClasspath(List cp) { "mvn test-compile com.github.johnpoth:jshell-maven-plugin:%s:run%n" + "For more information visit https://github.com/johnpoth/jshell-maven-plugin", s, - "1.3" + ofNullable(this.getClass().getPackage().getImplementationVersion()).orElse("RELEASE") )); return false; } From 27266ae4bf49e4146a6967fd84ce39d55d2ad046 Mon Sep 17 00:00:00 2001 From: jycr Date: Fri, 4 Aug 2023 02:34:48 +0200 Subject: [PATCH 3/4] feat: Configuring for Reproducible Builds Additional Information: * [Maven Guide - Configuring for Reproducible Builds](https://maven.apache.org/guides/mini/guide-reproducible-builds.html) --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 2f1c486..a0bfb83 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,10 @@ + + + ${git.commit.timestamp.datetime} + UTF-8 UTF-8 From 51653e6c262df57f0510e00dc144222ee2d6c800 Mon Sep 17 00:00:00 2001 From: jycr Date: Sat, 5 Aug 2023 16:22:06 +0200 Subject: [PATCH 4/4] chore: Reduce logging level when removing from classpath a file that does not exist --- src/main/java/com/github/johnpoth/jshell/JShellMojo.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/johnpoth/jshell/JShellMojo.java b/src/main/java/com/github/johnpoth/jshell/JShellMojo.java index bfc9d7c..73c146f 100644 --- a/src/main/java/com/github/johnpoth/jshell/JShellMojo.java +++ b/src/main/java/com/github/johnpoth/jshell/JShellMojo.java @@ -124,7 +124,7 @@ private List filterClasspath(List cp) { .filter(s -> { Path path = Paths.get(s); if (Files.notExists(path)) { - getLog().warn(String.format( + getLog().info(String.format( "Removing: %s from the classpath.%n" + "If this is unexpected, please make sure you correctly build the project beforehand by invoking the correct Maven build phase (usually `install`, `test-compile` or `compile`). For example:%n" + "mvn test-compile com.github.johnpoth:jshell-maven-plugin:%s:run%n" + @@ -140,7 +140,9 @@ private List filterClasspath(List cp) { if (s.endsWith(".jar")) { return true; } - getLog().debug("Removing: " + s + " from the classpath because it is unsupported in JShell."); + if (getLog().isDebugEnabled()) { + getLog().debug("Removing: " + s + " from the classpath because it is unsupported in JShell."); + } return false; }).collect(Collectors.toList()); }