KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > execution > DefaultRuntimeInformation


1 package org.apache.maven.execution;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.artifact.versioning.ArtifactVersion;
20 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
21 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
22 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
23 import org.codehaus.plexus.util.IOUtil;
24
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 /**
30  * Describes runtime information about the application.
31  *
32  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
33  * @version $Id: DefaultRuntimeInformation.java 320675 2005-10-13 06:50:22Z brett $
34  */

35 public class DefaultRuntimeInformation
36     implements RuntimeInformation, Initializable
37 {
38     private ArtifactVersion applicationVersion;
39
40     public ArtifactVersion getApplicationVersion()
41     {
42         return applicationVersion;
43     }
44
45     public void initialize()
46         throws InitializationException
47     {
48         InputStream JavaDoc resourceAsStream = null;
49         try
50         {
51             Properties JavaDoc properties = new Properties JavaDoc();
52             resourceAsStream = getClass().getClassLoader().getResourceAsStream(
53                 "META-INF/maven/org.apache.maven/maven-core/pom.properties" );
54             properties.load( resourceAsStream );
55
56             String JavaDoc property = properties.getProperty( "version" );
57             if ( property == null )
58             {
59                 throw new InitializationException( "maven-core properties did not include the version" );
60             }
61
62             applicationVersion = new DefaultArtifactVersion( property );
63         }
64         catch ( IOException JavaDoc e )
65         {
66             throw new InitializationException( "Unable to read properties file from maven-core", e );
67         }
68         finally
69         {
70             IOUtil.close( resourceAsStream );
71         }
72     }
73 }
74
Popular Tags