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 2020/04/20 12:39:50 UTC

[maven] 01/01: First try

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

michaelo pushed a commit to branch MRESOLVER-94
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 45841d95679ff320b8303dc01c90c57d83b26565
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Mon Apr 20 14:39:40 2020 +0200

    First try
---
 .../DefaultRepositorySystemSessionFactory.java     | 35 +++++++---------------
 .../internal/DefaultLifecyclePluginAnalyzer.java   | 18 ++++++-----
 2 files changed, 21 insertions(+), 32 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 248a3b6..9641378 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;
@@ -53,11 +54,8 @@ import org.eclipse.sisu.Nullable;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import java.io.IOException;
-import java.io.InputStream;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.Properties;
 
 /**
  * @since 3.3.0
@@ -69,6 +67,9 @@ public class DefaultRepositorySystemSessionFactory
     private Logger logger;
 
     @Inject
+    private RuntimeInformation runtimeInformation;
+
+    @Inject
     private ArtifactHandlerManager artifactHandlerManager;
 
     @Inject
@@ -243,28 +244,12 @@ public class DefaultRepositorySystemSessionFactory
 
     private String getUserAgent()
     {
-        return "Apache-Maven/" + getMavenVersion() + " (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" );
+        String mavenVersion = runtimeInformation.getMavenVersion();
+        return String.format( "Apache-Maven%s (Java %s; %s %s)",
+                ( !mavenVersion.isEmpty() ? "/" + mavenVersion : "" ),
+                System.getProperty( "java.version" ),
+                System.getProperty( "os.name" ),
+                System.getProperty( "os.version" ) );
     }
 
 }
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
index 1201742..c778e80 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
@@ -37,6 +37,7 @@ import org.apache.maven.model.InputLocation;
 import org.apache.maven.model.InputSource;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginExecution;
+import org.apache.maven.rtinfo.RuntimeInformation;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.Logger;
@@ -45,7 +46,7 @@ import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  * <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
- * 
+ *
  * @since 3.0
  * @author Benjamin Bentmann
  * @author Jason van Zyl
@@ -66,6 +67,9 @@ public class DefaultLifecyclePluginAnalyzer
     @Requirement
     private Logger logger;
 
+    @Requirement
+    private RuntimeInformation runtimeInformation;
+
     public DefaultLifecyclePluginAnalyzer()
     {
     }
@@ -143,7 +147,7 @@ public class DefaultLifecyclePluginAnalyzer
 
     private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, String phase, LifecyclePhase goals )
     {
-        String modelId = "org.apache.maven:maven-core:" + this.getClass().getPackage().getImplementationVersion()
+        String modelId = "org.apache.maven:maven-core:" + runtimeInformation.getMavenVersion()
             + ":default-lifecycle-bindings";
         InputSource inputSource = new InputSource();
         inputSource.setModelId( modelId );
@@ -153,13 +157,13 @@ public class DefaultLifecyclePluginAnalyzer
         List<LifecycleMojo> mojos = goals.getMojos();
         if ( mojos != null )
         {
-            
+
             for ( int i = 0; i < mojos.size(); i++ )
             {
                 LifecycleMojo mojo = mojos.get( i );
-                
+
                 GoalSpec gs = parseGoalSpec( mojo.getGoal() );
-    
+
                 if ( gs == null )
                 {
                     logger.warn( "Ignored invalid goal specification '" + mojo.getGoal()
@@ -176,7 +180,7 @@ public class DefaultLifecyclePluginAnalyzer
                 plugin.setLocation( "groupId", location );
                 plugin.setLocation( "artifactId", location );
                 plugin.setLocation( "version", location );
-    
+
                 Plugin existing = plugins.get( plugin );
                 if ( existing != null )
                 {
@@ -191,7 +195,7 @@ public class DefaultLifecyclePluginAnalyzer
                 {
                     plugins.put( plugin, plugin );
                 }
-    
+
                 PluginExecution execution = new PluginExecution();
                 execution.setId( getExecutionId( plugin, gs.goal ) );
                 execution.setPhase( phase );