You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/02/27 18:32:10 UTC

[maven] branch MNG-6960-3.8.x created (now f0caf9c)

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

michaelo pushed a change to branch MNG-6960-3.8.x
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at f0caf9c  [MNG-6960] Use RuntimeInformation instead of reading properties

This branch includes the following new commits:

     new f0caf9c  [MNG-6960] Use RuntimeInformation instead of reading properties

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] 01/01: [MNG-6960] Use RuntimeInformation instead of reading properties

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

michaelo pushed a commit to branch MNG-6960-3.8.x
in repository https://gitbox.apache.org/repos/asf/maven.git

commit f0caf9c9b31e31abb91ca986fe8168867cd0ded2
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Feb 27 19:27:25 2022 +0100

    [MNG-6960] Use RuntimeInformation instead of reading properties
---
 .../DefaultRepositorySystemSessionFactory.java     | 28 ++++++----------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
index 9c4cede..3bb622c 100644
--- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
+++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java
@@ -25,6 +25,7 @@ import org.apache.maven.bridge.MavenRepositorySystem;
 import org.apache.maven.eventspy.internal.EventSpyDispatcher;
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.apache.maven.rtinfo.RuntimeInformation;
 import org.apache.maven.settings.Mirror;
 import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Server;
@@ -93,6 +94,9 @@ public class DefaultRepositorySystemSessionFactory
     @Inject
     MavenRepositorySystem mavenRepositorySystem;
 
+    @Inject
+    private RuntimeInformation runtimeInformation;
+
     public DefaultRepositorySystemSession newRepositorySession( MavenExecutionRequest request )
     {
         DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
@@ -244,28 +248,10 @@ public class DefaultRepositorySystemSessionFactory
 
     private String getUserAgent()
     {
-        return "Apache-Maven/" + getMavenVersion() + " (Java " + System.getProperty( "java.version" ) + "; "
+        String version = runtimeInformation.getMavenVersion();
+        version = version.isEmpty() ? version : "/" + version;
+        return "Apache-Maven" + version + " (Java " + System.getProperty( "java.version" ) + "; "
             + System.getProperty( "os.name" ) + " " + System.getProperty( "os.version" ) + ")";
     }
 
-    private String getMavenVersion()
-    {
-        Properties props = new Properties();
-
-        try ( InputStream is = getClass().getResourceAsStream(
-            "/META-INF/maven/org.apache.maven/maven-core/pom.properties" ) )
-        {
-            if ( is != null )
-            {
-                props.load( is );
-            }
-        }
-        catch ( IOException e )
-        {
-            logger.debug( "Failed to read Maven version", e );
-        }
-
-        return props.getProperty( "version", "unknown-version" );
-    }
-
 }