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.component.annotations.Component;
25 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
26 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
27 import org.codehaus.plexus.util.IOUtil;
28
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.util.Properties;
32
33
34
35
36
37
38
39 @Deprecated
40 @Component( role = RuntimeInformation.class )
41 public class DefaultRuntimeInformation
42 implements RuntimeInformation, Initializable
43 {
44 private static final String MAVEN_GROUPID = "org.apache.maven";
45
46 private static final String MAVEN_PROPERTIES = "META-INF/maven/" + MAVEN_GROUPID + "/maven-core/pom.properties";
47
48 private ArtifactVersion applicationVersion;
49
50 public ArtifactVersion getApplicationVersion()
51 {
52 return applicationVersion;
53 }
54
55 public void initialize()
56 throws InitializationException
57 {
58 InputStream resourceAsStream = null;
59 try
60 {
61 Properties properties = new Properties();
62 resourceAsStream = getClass().getClassLoader().getResourceAsStream( MAVEN_PROPERTIES );
63
64 if ( resourceAsStream == null )
65 {
66 throw new IllegalStateException( "Unable to find Maven properties in classpath: " + MAVEN_PROPERTIES );
67 }
68 properties.load( resourceAsStream );
69
70 String property = properties.getProperty( "version" );
71 if ( property == null )
72 {
73 throw new InitializationException( "maven-core properties did not include the version" );
74 }
75
76 applicationVersion = new DefaultArtifactVersion( property );
77 }
78 catch ( IOException e )
79 {
80 throw new InitializationException( "Unable to read properties file from maven-core", e );
81 }
82 finally
83 {
84 IOUtil.close( resourceAsStream );
85 }
86 }
87 }