| 1 | |
package org.apache.maven.execution; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.artifact.versioning.ArtifactVersion; |
| 23 | |
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; |
| 24 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; |
| 25 | |
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; |
| 26 | |
import org.codehaus.plexus.util.IOUtil; |
| 27 | |
|
| 28 | |
import java.io.IOException; |
| 29 | |
import java.io.InputStream; |
| 30 | |
import java.util.Properties; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | public class DefaultRuntimeInformation |
| 39 | |
implements RuntimeInformation, Initializable |
| 40 | |
{ |
| 41 | |
private static final String MAVEN_GROUPID = "org.apache.maven"; |
| 42 | |
|
| 43 | |
private static final String MAVEN_PROPERTIES = "META-INF/maven/" + MAVEN_GROUPID + "/maven-core/pom.properties"; |
| 44 | |
|
| 45 | |
private ArtifactVersion applicationVersion; |
| 46 | |
|
| 47 | |
public ArtifactVersion getApplicationVersion() |
| 48 | |
{ |
| 49 | 0 | return applicationVersion; |
| 50 | |
} |
| 51 | |
|
| 52 | |
public void initialize() |
| 53 | |
throws InitializationException |
| 54 | |
{ |
| 55 | 0 | InputStream resourceAsStream = null; |
| 56 | |
try |
| 57 | |
{ |
| 58 | 0 | Properties properties = new Properties(); |
| 59 | 0 | resourceAsStream = getClass().getClassLoader().getResourceAsStream( MAVEN_PROPERTIES ); |
| 60 | |
|
| 61 | 0 | if ( resourceAsStream == null ) |
| 62 | |
{ |
| 63 | 0 | throw new IllegalStateException( "Unable to find Maven properties in classpath: " + MAVEN_PROPERTIES ); |
| 64 | |
} |
| 65 | 0 | properties.load( resourceAsStream ); |
| 66 | |
|
| 67 | 0 | String property = properties.getProperty( "version" ); |
| 68 | 0 | if ( property == null ) |
| 69 | |
{ |
| 70 | 0 | throw new InitializationException( "maven-core properties did not include the version" ); |
| 71 | |
} |
| 72 | |
|
| 73 | 0 | applicationVersion = new DefaultArtifactVersion( property ); |
| 74 | |
} |
| 75 | 0 | catch ( IOException e ) |
| 76 | |
{ |
| 77 | 0 | throw new InitializationException( "Unable to read properties file from maven-core", e ); |
| 78 | |
} |
| 79 | |
finally |
| 80 | |
{ |
| 81 | 0 | IOUtil.close( resourceAsStream ); |
| 82 | 0 | } |
| 83 | 0 | } |
| 84 | |
} |