You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/12/14 23:31:29 UTC
[maven-jlink-plugin] 01/01: small code cleanup
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch code-cleanup1
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git
commit 5ad883b63e7cf1ca188477cc481228eb0f36ccd1
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Dec 15 00:31:10 2020 +0100
small code cleanup
---
.../maven/plugins/jlink/AbstractJLinkMojo.java | 32 ++--------------------
.../org/apache/maven/plugins/jlink/JLinkMojo.java | 13 ++-------
.../maven/plugins/jlink/AbstractJLinkMojoTest.java | 10 +++----
3 files changed, 11 insertions(+), 44 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
index 16542a0..1ed65a0 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/AbstractJLinkMojo.java
@@ -91,15 +91,7 @@ public abstract class AbstractJLinkMojo
tc = tcs.get( 0 );
}
}
- catch ( ReflectiveOperationException e )
- {
- // ignore
- }
- catch ( SecurityException e )
- {
- // ignore
- }
- catch ( IllegalArgumentException e )
+ catch ( ReflectiveOperationException | SecurityException | IllegalArgumentException e )
{
// ignore
}
@@ -213,16 +205,7 @@ public abstract class AbstractJLinkMojo
*/
protected String getPlatformDependSeparateList( Collection<String> modulePaths )
{
- StringBuilder sb = new StringBuilder();
- for ( String module : modulePaths )
- {
- if ( sb.length() > 0 )
- {
- sb.append( File.pathSeparatorChar );
- }
- sb.append( module );
- }
- return sb.toString();
+ return String.join( Character.toString( File.pathSeparatorChar ), modulePaths );
}
/**
@@ -232,16 +215,7 @@ public abstract class AbstractJLinkMojo
*/
protected String getCommaSeparatedList( Collection<String> modules )
{
- StringBuilder sb = new StringBuilder();
- for ( String module : modules )
- {
- if ( sb.length() > 0 )
- {
- sb.append( ',' );
- }
- sb.append( module );
- }
- return sb.toString();
+ return String.join( ",", modules );
}
}
diff --git a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
index f8ff013..7fb3ac2 100644
--- a/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
@@ -59,9 +59,7 @@ import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
*
* @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
*/
-// CHECKSTYLE_OFF: LineLength
-@Mojo( name = "jlink", requiresDependencyResolution = ResolutionScope.RUNTIME, defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true )
-// CHECKSTYLE_ON: LineLength
+@Mojo( name = "jlink", requiresDependencyResolution = ResolutionScope.RUNTIME, defaultPhase = LifecyclePhase.PACKAGE )
public class JLinkMojo
extends AbstractJLinkMojo
{
@@ -359,7 +357,7 @@ public class JLinkMojo
private List<File> getCompileClasspathElements( MavenProject project )
{
- List<File> list = new ArrayList<File>( project.getArtifacts().size() + 1 );
+ List<File> list = new ArrayList<>( project.getArtifacts().size() + 1 );
for ( Artifact a : project.getArtifacts() )
{
@@ -493,12 +491,7 @@ public class JLinkMojo
{
zipArchiver.createArchive();
}
- catch ( ArchiverException e )
- {
- getLog().error( e.getMessage(), e );
- throw new MojoExecutionException( e.getMessage(), e );
- }
- catch ( IOException e )
+ catch ( ArchiverException | IOException e )
{
getLog().error( e.getMessage(), e );
throw new MojoExecutionException( e.getMessage(), e );
diff --git a/src/test/java/org/apache/maven/plugins/jlink/AbstractJLinkMojoTest.java b/src/test/java/org/apache/maven/plugins/jlink/AbstractJLinkMojoTest.java
index 55bd52e..1aef05a 100644
--- a/src/test/java/org/apache/maven/plugins/jlink/AbstractJLinkMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/jlink/AbstractJLinkMojoTest.java
@@ -52,7 +52,7 @@ public class AbstractJLinkMojoTest
public void convertShouldReturnSingleCharacter()
{
StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x" );
- assertThat( result.toString() ).isNotEmpty().isEqualTo( "x" );
+ assertThat( result ).isNotEmpty().hasToString( "x" );
}
@Test
@@ -60,7 +60,7 @@ public class AbstractJLinkMojoTest
public void convertShouldReturnTwoCharactersSeparatedByPathSeparator()
{
StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x;a" );
- assertThat( result.toString() ).isEqualTo( "x" + File.pathSeparatorChar + "a" );
+ assertThat( result ).hasToString( "x" + File.pathSeparatorChar + "a" );
}
@Test
@@ -68,7 +68,7 @@ public class AbstractJLinkMojoTest
public void convertUsingDifferentDelimiterShouldReturnTwoCharactersSeparatedByPathSeparator()
{
StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x:a" );
- assertThat( result.toString() ).isEqualTo( "x" + File.pathSeparatorChar + "a" );
+ assertThat( result ).hasToString( "x" + File.pathSeparatorChar + "a" );
}
@Test
@@ -77,7 +77,7 @@ public class AbstractJLinkMojoTest
public void convertUsingMultipleDelimitersShouldReturnTwoCharactersSeparatedByPathSeparator()
{
StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath( "x:a::" );
- assertThat( result.toString() ).isEqualTo( "x" + File.pathSeparatorChar + "a" );
+ assertThat( result ).hasToString( "x" + File.pathSeparatorChar + "a" );
}
@Test
@@ -108,7 +108,7 @@ public class AbstractJLinkMojoTest
@DisplayName( "getCommaSeparatedList() should return a single character" )
public void getCommaSeparatedListShouldReturnASingleCharacter()
{
- String result = mojoMock.getCommaSeparatedList( Arrays.asList( "A" ) );
+ String result = mojoMock.getCommaSeparatedList( Collections.singletonList( "A" ) );
assertThat( result ).isEqualTo( "A" );
}