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:47:31 UTC

[maven-jlink-plugin] branch code-cleanup1 updated (5ad883b -> b0eb4e8)

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

slachiewicz pushed a change to branch code-cleanup1
in repository https://gitbox.apache.org/repos/asf/maven-jlink-plugin.git.


 discard 5ad883b  small code cleanup
     new b0eb4e8  small code cleanup

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5ad883b)
            \
             N -- N -- N   refs/heads/code-cleanup1 (b0eb4e8)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 23 +++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)


[maven-jlink-plugin] 01/01: small code cleanup

Posted by sl...@apache.org.
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 b0eb4e8532263eb79e059d478cc84fcba5a93cb0
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Dec 15 00:45:20 2020 +0100

    small code cleanup
---
 .../maven/plugins/jlink/AbstractJLinkMojo.java     | 32 ++-----------------
 .../org/apache/maven/plugins/jlink/JLinkMojo.java  | 36 +++++++++-------------
 .../maven/plugins/jlink/AbstractJLinkMojoTest.java | 10 +++---
 3 files changed, 23 insertions(+), 55 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..69fab8e 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() )
         {
@@ -396,7 +394,8 @@ public class JLinkMojo
 
             for ( Map.Entry<File, JavaModuleDescriptor> entry : resolvePathsResult.getPathElements().entrySet() )
             {
-                if ( entry.getValue() == null )
+                JavaModuleDescriptor descriptor = entry.getValue();
+                if ( descriptor == null )
                 {
                     String message = "The given dependency " + entry.getKey()
                         + " does not have a module-info.java file. So it can't be linked.";
@@ -405,13 +404,12 @@ public class JLinkMojo
                 }
 
                 // Don't warn for automatic modules, let the jlink tool do that
-                getLog().debug( " module: " + entry.getValue().name() + " automatic: "
-                    + entry.getValue().isAutomatic() );
-                if ( modulepathElements.containsKey( entry.getValue().name() ) )
+                getLog().debug( " module: " + descriptor.name() + " automatic: " + descriptor.isAutomatic() );
+                if ( modulepathElements.containsKey( descriptor.name() ) )
                 {
-                    getLog().warn( "The module name " + entry.getValue().name() + " does already exists." );
+                    getLog().warn( "The module name " + descriptor.name() + " does already exists." );
                 }
-                modulepathElements.put( entry.getValue().name(), entry.getKey() );
+                modulepathElements.put( descriptor.name(), entry.getKey() );
             }
 
             // This part is for the module in target/classes ? (Hacky..)
@@ -425,22 +423,23 @@ public class JLinkMojo
                 ResolvePathsResult<File> resolvePaths = locationManager.resolvePaths( singleModuls );
                 for ( Entry<File, JavaModuleDescriptor> entry : resolvePaths.getPathElements().entrySet() )
                 {
-                    if ( entry.getValue() == null )
+                    JavaModuleDescriptor descriptor = entry.getValue();
+                    if ( descriptor == null )
                     {
                         String message = "The given project " + entry.getKey()
                             + " does not contain a module-info.java file. So it can't be linked.";
                         getLog().error( message );
                         throw new MojoFailureException( message );
                     }
-                    if ( modulepathElements.containsKey( entry.getValue().name() ) )
+                    if ( modulepathElements.containsKey( descriptor.name() ) )
                     {
-                        getLog().warn( "The module name " + entry.getValue().name() + " does already exists." );
+                        getLog().warn( "The module name " + descriptor.name() + " does already exists." );
                     }
-                    modulepathElements.put( entry.getValue().name(), entry.getKey() );
+                    modulepathElements.put( descriptor.name(), entry.getKey() );
                 }
             }
 
-        }   
+        }
         catch ( IOException e )
         {
             getLog().error( e.getMessage() );
@@ -493,12 +492,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" );
     }