Author: rfscholte
Date: Sat May  4 11:54:32 2013
New Revision: 1479084

URL: http://svn.apache.org/r1479084
Log:
Add getMavenVersion()

Added:
    
maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/
    
maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java

Added: 
maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
URL: 
http://svn.apache.org/viewvc/maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java?rev=1479084&view=auto
==============================================================================
--- 
maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
 (added)
+++ 
maven/shared/trunk/maven-project-utils/src/main/java/org/apache/maven/shared/project/runtime/MavenUtils.java
 Sat May  4 11:54:32 2013
@@ -0,0 +1,60 @@
+package org.apache.maven.shared.project.runtime;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public final class MavenUtils
+{
+    
+    private MavenUtils()
+    {
+    }
+
+    public static String getMavenVersion()
+    {
+        // This relies on the fact that MavenProject is the in core classloader
+        // and that the core classloader is for the maven-core artifact
+        // and that should have a pom.properties file
+        // if this ever changes, we will have to revisit this code.
+        final Properties properties = new Properties();
+        final InputStream in =
+            MavenProject.class.getClassLoader().getResourceAsStream( 
"META-INF/maven/org.apache.maven/maven-core/pom.properties" );
+        try
+        {
+            properties.load( in );
+        }
+        catch ( IOException ioe )
+        {
+            return "";
+        }
+        finally
+        {
+            IOUtil.close( in );
+        }
+
+        return properties.getProperty( "version" ).trim();
+    }
+}


Reply via email to