Load Maven version and display

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163824 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-07 03:06:18 +00:00
parent 664a916c17
commit 27b9286a40
1 changed files with 23 additions and 1 deletions

View File

@ -33,7 +33,9 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.model.Model;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.monitor.event.DefaultEventDispatcher; import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.event.DefaultEventMonitor; import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventDispatcher; import org.apache.maven.monitor.event.EventDispatcher;
@ -51,7 +53,10 @@ import org.codehaus.plexus.util.FileUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -107,7 +112,24 @@ public class MavenCli
} }
if ( commandLine.hasOption( CLIManager.VERSION ) ) if ( commandLine.hasOption( CLIManager.VERSION ) )
{ {
System.out.println( "Maven version: " ); // TODO: is there a beter way? Maybe read the manifest?
String version = "unknown";
for ( Enumeration e = MavenCli.class.getClassLoader().getResources( "/META-INF/maven/pom.xml" );
e.hasMoreElements(); )
{
URL resource = (URL) e.nextElement();
if ( resource.getPath().indexOf( "maven-core" ) >= 0 )
{
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read( new InputStreamReader( resource.openStream() ) );
version = model.getVersion();
break;
}
}
System.out.println( "Maven version: " + version );
return 0; return 0;
} }