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/05/03 11:23:03 UTC

[maven-shared-jar] branch MSHARED-408 created (now b214082)

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

slachiewicz pushed a change to branch MSHARED-408
in repository https://gitbox.apache.org/repos/asf/maven-shared-jar.git.


      at b214082  [MSHARED-408] Not ignore parent model group and version values

This branch includes the following new commits:

     new b214082  [MSHARED-408] Not ignore parent model group and version values

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.



[maven-shared-jar] 01/01: [MSHARED-408] Not ignore parent model group and version values

Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MSHARED-408
in repository https://gitbox.apache.org/repos/asf/maven-shared-jar.git

commit b214082330ef0ddfd91e17c74c7bc6d063b24987
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Sat Oct 19 23:04:41 2019 +0200

    [MSHARED-408] Not ignore parent model group and version values
    
    In EmbeddedMavenModelExposer  use parent pom group and version if current project skip omits it
---
 .../exposers/EmbeddedMavenModelExposer.java        |  24 +++++++++++++--------
 .../exposers/EmbeddedMavenModelExposerTest.java    |  20 +++++++++++++++++
 src/test/resources/jars/test1.jar                  | Bin 0 -> 1071 bytes
 3 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java
index 2018994..1ef3ebf 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java
@@ -27,7 +27,6 @@ import org.apache.maven.shared.jar.identification.JarIdentification;
 import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.apache.maven.shared.utils.io.IOUtil;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.IOException;
@@ -60,13 +59,24 @@ public class EmbeddedMavenModelExposer
 
         JarEntry pom = entries.get( 0 );
         MavenXpp3Reader pomreader = new MavenXpp3Reader();
-        InputStream is = null;
-        try
+        try ( InputStream is = jarAnalyzer.getEntryInputStream( pom );
+              InputStreamReader isreader = new InputStreamReader( is ) )
         {
-            is = jarAnalyzer.getEntryInputStream( pom );
-            InputStreamReader isreader = new InputStreamReader( is );
             Model model = pomreader.read( isreader );
 
+            if ( model.getParent() != null )
+            {
+                // use parent values only if project values not exists
+                if ( model.getGroupId() == null )
+                {
+                    identification.addAndSetGroupId( model.getParent().getGroupId() );
+                }
+                if ( model.getVersion() == null )
+                {
+                    identification.addAndSetVersion( model.getParent().getVersion() );
+                }
+            }
+
             identification.addAndSetGroupId( model.getGroupId() );
             identification.addAndSetArtifactId( model.getArtifactId() );
             identification.addAndSetVersion( model.getVersion() );
@@ -92,9 +102,5 @@ public class EmbeddedMavenModelExposer
         {
             getLogger().error( "Unable to parse model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e );
         }
-        finally
-        {
-            IOUtil.close( is );
-        }
     }
 }
diff --git a/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java b/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
index 7cd39d1..f90e148 100644
--- a/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
@@ -32,6 +32,26 @@ import java.io.File;
 public class EmbeddedMavenModelExposerTest
     extends AbstractJarAnalyzerTestCase
 {
+    public void testExposerWithParent()
+            throws Exception
+    {
+        File file = getSampleJar( "test1.jar" );
+
+        JarIdentification identification = new JarIdentification();
+
+        EmbeddedMavenModelExposer exposer = new EmbeddedMavenModelExposer();
+        exposer.expose( identification, new JarAnalyzer( file ) );
+
+        assertEquals( 1, identification.getPotentialGroupIds().size() );
+        assertEquals(  "test", identification.getPotentialGroupIds().get( 0 ) );
+
+        assertEquals( 1, identification.getPotentialArtifactIds().size() );
+        assertEquals(  "test1", identification.getPotentialArtifactIds().get( 0 ) );
+
+        assertEquals( 1, identification.getPotentialVersions().size() );
+        assertEquals(  "1.1-SNAPSHOT", identification.getPotentialVersions().get( 0 ) );
+    }
+
     public void testExposerWithJXR()
         throws Exception
     {
diff --git a/src/test/resources/jars/test1.jar b/src/test/resources/jars/test1.jar
new file mode 100644
index 0000000..0f441c5
Binary files /dev/null and b/src/test/resources/jars/test1.jar differ