This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jarsigner-plugin.git

commit a133df6468bfab7bfee79356f0e01ecc1eb98e07
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Nov 17 06:34:33 2026 +0000

    Simplify redundant code
---
 .../plugins/jarsigner/AbstractJarsignerMojo.java   |  6 ++---
 .../maven/plugins/jarsigner/TsaSelector.java       |  2 +-
 .../jarsigner/JarsignerSignMojoParallelTest.java   |  7 ++----
 .../jarsigner/JarsignerSignMojoRetryTest.java      | 21 +++++-----------
 .../plugins/jarsigner/JarsignerSignMojoTest.java   | 11 +++------
 .../jarsigner/JarsignerSignMojoTsaTest.java        |  3 +--
 .../plugins/jarsigner/JarsignerVerifyMojoTest.java | 11 +++------
 .../maven/plugins/jarsigner/MojoTestCreator.java   |  2 +-
 .../maven/plugins/jarsigner/RequestMatchers.java   | 28 +++++++++++-----------
 9 files changed, 34 insertions(+), 57 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java 
b/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java
index 1437b96..2332f84 100644
--- 
a/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java
+++ 
b/src/main/java/org/apache/maven/plugins/jarsigner/AbstractJarsignerMojo.java
@@ -535,9 +535,9 @@ public abstract class AbstractJarsignerMojo extends 
AbstractMojo {
         }
 
         request.setArguments(
-                !additionalArguments.isEmpty()
-                        ? additionalArguments.toArray(new 
String[additionalArguments.size()])
-                        : null);
+                additionalArguments.isEmpty()
+                        ? null
+                        : additionalArguments.toArray(new 
String[additionalArguments.size()]));
 
         // Special handling for passwords through the Maven Security Dispatcher
         request.setStorepass(decrypt(storepass));
diff --git a/src/main/java/org/apache/maven/plugins/jarsigner/TsaSelector.java 
b/src/main/java/org/apache/maven/plugins/jarsigner/TsaSelector.java
index aa9e779..16ef8cd 100644
--- a/src/main/java/org/apache/maven/plugins/jarsigner/TsaSelector.java
+++ b/src/main/java/org/apache/maven/plugins/jarsigner/TsaSelector.java
@@ -105,7 +105,7 @@ class TsaSelector {
     }
 
     /** Representation of a single TSA server and the parameters to use for it 
*/
-    static class TsaServer {
+    static final class TsaServer {
         private static final TsaServer EMPTY = new TsaServer(null, null, null, 
null);
 
         private final AtomicInteger failureCount = new AtomicInteger(0);
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoParallelTest.java
 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoParallelTest.java
index 3ca475d..65024eb 100644
--- 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoParallelTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoParallelTest.java
@@ -73,8 +73,7 @@ public class JarsignerSignMojoParallelTest {
         projectDir = new File(folder, "dummy-project");
         projectDir.mkdir();
         configuration.put("processMainArtifact", "false");
-        mojoTestCreator =
-                new 
MojoTestCreator<JarsignerSignMojo>(JarsignerSignMojo.class, project, 
projectDir, jarSigner);
+        mojoTestCreator = new MojoTestCreator<>(JarsignerSignMojo.class, 
project, projectDir, jarSigner);
         log = mock(Log.class);
         mojoTestCreator.setLog(log);
         executor =
@@ -198,9 +197,7 @@ public class JarsignerSignMojoParallelTest {
                 .thenReturn(RESULT_OK);
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
 
-        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, mojo::execute);
 
         assertTrue(mojoException.getMessage().contains("Failed executing 
'jarsigner "));
         Locale.setDefault(orginalLocale);
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoRetryTest.java
 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoRetryTest.java
index 68eb3a9..c4f72b1 100644
--- 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoRetryTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoRetryTest.java
@@ -73,8 +73,7 @@ public class JarsignerSignMojoRetryTest {
         Locale.setDefault(Locale.ENGLISH); // For English ResourceBundle to 
test log messages
         projectDir = new File(folder, "dummy-project");
         projectDir.mkdir();
-        mojoTestCreator =
-                new 
MojoTestCreator<JarsignerSignMojo>(JarsignerSignMojo.class, project, 
projectDir, jarSigner);
+        mojoTestCreator = new MojoTestCreator<>(JarsignerSignMojo.class, 
project, projectDir, jarSigner);
         log = mock(Log.class);
         mojoTestCreator.setLog(log);
         Artifact mainArtifact = TestArtifacts.createJarArtifact(projectDir, 
"my-project.jar");
@@ -106,9 +105,7 @@ public class JarsignerSignMojoRetryTest {
         configuration.put("maxTries", "1");
         mojoTestCreator.setWaitStrategy(waitStrategy);
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
-        assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        assertThrows(MojoExecutionException.class, mojo::execute);
         verify(jarSigner).execute(any());
         verify(waitStrategy, never()).waitAfterFailure(0, 
Duration.ofSeconds(0));
     }
@@ -136,9 +133,7 @@ public class JarsignerSignMojoRetryTest {
         configuration.put("maxTries", "2");
         mojoTestCreator.setWaitStrategy(waitStrategy);
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
-        assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        assertThrows(MojoExecutionException.class, mojo::execute);
         verify(jarSigner, times(2)).execute(any());
         verify(waitStrategy).waitAfterFailure(0, Duration.ofSeconds(0));
     }
@@ -152,9 +147,7 @@ public class JarsignerSignMojoRetryTest {
 
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
 
-        assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        assertThrows(MojoExecutionException.class, mojo::execute);
 
         verify(jarSigner).execute(any()); // Should have tried exactly one 
time, regardless of invalid value
         verify(log).warn(contains("Invalid maxTries"));
@@ -221,7 +214,7 @@ public class JarsignerSignMojoRetryTest {
         long noSleepValue = 42_001;
         // Storage of the most recent sleep value
         AtomicLong sleepValue = new AtomicLong(noSleepValue);
-        Sleeper sleeper = value -> sleepValue.set(value);
+        Sleeper sleeper = sleepValue::set;
 
         mojo.waitAfterFailure(0, Duration.ofSeconds(0), sleeper);
         assertEquals(noSleepValue, sleepValue.get());
@@ -284,9 +277,7 @@ public class JarsignerSignMojoRetryTest {
         configuration.put("maxTries", "5");
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
 
-        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, mojo::execute);
 
         // Make sure that the last error exit code is present
         assertTrue(mojoException.getMessage().contains(String.valueOf(42)));
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTest.java 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTest.java
index 057caae..999d0da 100644
--- 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTest.java
@@ -78,8 +78,7 @@ public class JarsignerSignMojoTest {
         Locale.setDefault(Locale.ENGLISH); // For English ResourceBundle to 
test log messages
         projectDir = new File(folder, "dummy-project");
         projectDir.mkdir();
-        mojoTestCreator =
-                new 
MojoTestCreator<JarsignerSignMojo>(JarsignerSignMojo.class, project, 
projectDir, jarSigner);
+        mojoTestCreator = new MojoTestCreator<>(JarsignerSignMojo.class, 
project, projectDir, jarSigner);
         log = mock(Log.class);
         mojoTestCreator.setLog(log);
     }
@@ -133,9 +132,7 @@ public class JarsignerSignMojoTest {
         
when(jarSigner.execute(any(JarSignerSignRequest.class))).thenReturn(RESULT_ERROR);
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
 
-        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, mojo::execute);
         
assertTrue(mojoException.getMessage().contains(String.valueOf(RESULT_ERROR.getExitCode())));
         assertTrue(mojoException
                 .getMessage()
@@ -150,9 +147,7 @@ public class JarsignerSignMojoTest {
         when(jarSigner.execute(any(JarSignerSignRequest.class))).thenThrow(new 
JavaToolException("test failure"));
         JarsignerSignMojo mojo = mojoTestCreator.configure(configuration);
 
-        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, mojo::execute);
         assertTrue(mojoException.getMessage().contains("test failure"));
     }
 
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTsaTest.java
 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTsaTest.java
index aed7843..1d01103 100644
--- 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTsaTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerSignMojoTsaTest.java
@@ -67,8 +67,7 @@ public class JarsignerSignMojoTsaTest {
         Locale.setDefault(Locale.ENGLISH); // For English ResourceBundle to 
test log messages
         projectDir = new File(folder, "dummy-project");
         projectDir.mkdir();
-        mojoTestCreator =
-                new 
MojoTestCreator<JarsignerSignMojo>(JarsignerSignMojo.class, project, 
projectDir, jarSigner);
+        mojoTestCreator = new MojoTestCreator<>(JarsignerSignMojo.class, 
project, projectDir, jarSigner);
         log = mock(Log.class);
         mojoTestCreator.setLog(log);
         Artifact mainArtifact = TestArtifacts.createJarArtifact(projectDir, 
"my-project.jar");
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerVerifyMojoTest.java 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerVerifyMojoTest.java
index 9485add..8dd7c62 100644
--- 
a/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerVerifyMojoTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/jarsigner/JarsignerVerifyMojoTest.java
@@ -63,8 +63,7 @@ public class JarsignerVerifyMojoTest {
     public void setUp() throws Exception {
         dummyMavenProjectDir = new File(folder, "dummy-project");
         dummyMavenProjectDir.mkdir();
-        mojoTestCreator = new MojoTestCreator<JarsignerVerifyMojo>(
-                JarsignerVerifyMojo.class, project, dummyMavenProjectDir, 
jarSigner);
+        mojoTestCreator = new MojoTestCreator<>(JarsignerVerifyMojo.class, 
project, dummyMavenProjectDir, jarSigner);
         log = mock(Log.class);
         mojoTestCreator.setLog(log);
     }
@@ -122,9 +121,7 @@ public class JarsignerVerifyMojoTest {
         
when(jarSigner.execute(any(JarSignerVerifyRequest.class))).thenReturn(RESULT_ERROR);
         JarsignerVerifyMojo mojo = mojoTestCreator.configure(configuration);
 
-        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, mojo::execute);
         
assertTrue(mojoException.getMessage().contains(String.valueOf(RESULT_ERROR.getExitCode())));
         assertTrue(mojoException
                 .getMessage()
@@ -157,9 +154,7 @@ public class JarsignerVerifyMojoTest {
 
         JarsignerVerifyMojo mojo = mojoTestCreator.configure(configuration);
 
-        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, () -> {
-            mojo.execute();
-        });
+        MojoExecutionException mojoException = 
assertThrows(MojoExecutionException.class, mojo::execute);
         
assertTrue(mojoException.getMessage().contains(mainArtifact.getFile().getPath()));
     }
 
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/MojoTestCreator.java 
b/src/test/java/org/apache/maven/plugins/jarsigner/MojoTestCreator.java
index 8c144ab..b78efc0 100644
--- a/src/test/java/org/apache/maven/plugins/jarsigner/MojoTestCreator.java
+++ b/src/test/java/org/apache/maven/plugins/jarsigner/MojoTestCreator.java
@@ -175,7 +175,7 @@ public class MojoTestCreator<T extends 
AbstractJarsignerMojo> {
             String defaultValue = defaultConfiguration.get(parameterName);
             defaultValue = substituteParameterValueVariables(defaultValue);
             Field field = getField(mojo, parameterName);
-            setFieldByStringValue(mojo, field, defaultValue.toString());
+            setFieldByStringValue(mojo, field, defaultValue);
         }
     }
 
diff --git 
a/src/test/java/org/apache/maven/plugins/jarsigner/RequestMatchers.java 
b/src/test/java/org/apache/maven/plugins/jarsigner/RequestMatchers.java
index 6334f9a..dd93798 100644
--- a/src/test/java/org/apache/maven/plugins/jarsigner/RequestMatchers.java
+++ b/src/test/java/org/apache/maven/plugins/jarsigner/RequestMatchers.java
@@ -32,7 +32,7 @@ import org.mockito.ArgumentMatcher;
 class RequestMatchers {
 
     /** Matcher for parameters common for JarSignerRequest instances */
-    private static class AbstractJarSignerRequestMatcher<T extends 
AbstractJarSignerRequest>
+    private static final class AbstractJarSignerRequestMatcher<T extends 
AbstractJarSignerRequest>
             implements ArgumentMatcher<T> {
         private final String predicateDescription;
         private final Object value;
@@ -57,7 +57,7 @@ class RequestMatchers {
     }
 
     /** Matcher for parameters specific to JarSignerSignRequest instances */
-    private static class JarSignerSignRequestMatcher implements 
ArgumentMatcher<JarSignerSignRequest> {
+    private static final class JarSignerSignRequestMatcher implements 
ArgumentMatcher<JarSignerSignRequest> {
         private final String predicateDescription;
         private final Object value;
         private final Predicate<JarSignerSignRequest> predicate;
@@ -82,19 +82,19 @@ class RequestMatchers {
 
     /** Create a matcher that matches when the request is using a specific 
file name for the archive */
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasFileName(String expectedFileName) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has archive file name ",
                 expectedFileName,
                 request -> 
request.getArchive().getPath().endsWith(expectedFileName));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasAlias(String alias) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has alias ", alias, request -> 
request.getAlias().equals(alias));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasArguments(String[] arguments) {
-        return new AbstractJarSignerRequestMatcher<T>("has arguments ", 
arguments, request -> {
+        return new AbstractJarSignerRequestMatcher<>("has arguments ", 
arguments, request -> {
             List<String> haystack = Arrays.asList(request.getArguments());
             for (String argumentNeedle : arguments) {
                 if (!haystack.contains(argumentNeedle)) {
@@ -106,56 +106,56 @@ class RequestMatchers {
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasKeystore(String keystore) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has keystore ", keystore, request -> 
request.getKeystore().equals(keystore));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasMaxMemory(String maxMemory) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has maxMemory ", maxMemory, request -> 
request.getMaxMemory().equals(maxMemory));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasProtectedAuthenticationPath(
             boolean protectedAuthenticationPath) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has protectedAuthenticationPath ",
                 protectedAuthenticationPath,
                 request -> request.isProtectedAuthenticationPath() == 
protectedAuthenticationPath);
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasProviderArg(String providerArg) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has providerArg ",
                 providerArg,
                 request -> request.getProviderArg().equals(providerArg));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasProviderClass(String providerClass) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has providerClass ",
                 providerClass,
                 request -> request.getProviderClass().equals(providerClass));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasProviderName(String providerName) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has providerName ",
                 providerName,
                 request -> request.getProviderName().equals(providerName));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasStorepass(String storepass) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has storepass ", storepass, request -> 
request.getStorepass().equals(storepass));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasStoretype(String storetype) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has storetype ", storetype, request -> 
request.getStoretype().equals(storetype));
     }
 
     static <T extends AbstractJarSignerRequest> ArgumentMatcher<T> 
hasVerbose(boolean verbose) {
-        return new AbstractJarSignerRequestMatcher<T>(
+        return new AbstractJarSignerRequestMatcher<>(
                 "has verbose ", verbose, request -> request.isVerbose() == 
verbose);
     }
 

Reply via email to