View Javadoc

1   package org.apache.maven.execution;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Describes runtime information about the application.
35   *
36   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
37   * @version $Id: DefaultRuntimeInformation.java 958295 2010-06-26 23:16:18Z hboutemy $
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  }