Skip to content

Commit

Permalink
[MNG-6960] Use RuntimeInformation instead of reading properties
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-o committed Feb 27, 2022
1 parent 05e96da commit f0caf9c
Showing 1 changed file with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -93,6 +94,9 @@ public class DefaultRepositorySystemSessionFactory
@Inject
MavenRepositorySystem mavenRepositorySystem;

@Inject
private RuntimeInformation runtimeInformation;

public DefaultRepositorySystemSession newRepositorySession( MavenExecutionRequest request )
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
Expand Down Expand Up @@ -244,28 +248,10 @@ else if ( request.isUpdateSnapshots() )

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" );
}

}

0 comments on commit f0caf9c

Please sign in to comment.