Coverage Report - org.apache.maven.execution.DefaultRuntimeInformation
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultRuntimeInformation
0 %
0/17
0 %
0/4
4
 
 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.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  
  * Describes runtime information about the application.
 34  
  *
 35  
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
 36  
  * @version $Id: DefaultRuntimeInformation.java 640549 2008-03-24 20:05:11Z bentmann $
 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  
 }