From 5787b70567acfc4a7eb08220cc074b6ceb439c54 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Tue, 2 Jun 2009 22:54:18 +0000 Subject: [PATCH] o adding RuntimeInformation component to the compat package. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@781203 13f79535-47bb-0310-9956-ffa450edef68 --- .../execution/ApplicationInformation.java | 25 ++++ .../execution/DefaultRuntimeInformation.java | 109 ++++++++++++++++++ .../maven/execution/RuntimeInformation.java | 38 ++++++ 3 files changed, 172 insertions(+) create mode 100644 maven-compat/src/main/java/org/apache/maven/execution/ApplicationInformation.java create mode 100644 maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java create mode 100644 maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java diff --git a/maven-compat/src/main/java/org/apache/maven/execution/ApplicationInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/ApplicationInformation.java new file mode 100644 index 0000000000..cdde895028 --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/execution/ApplicationInformation.java @@ -0,0 +1,25 @@ +package org.apache.maven.execution; + +import org.apache.maven.artifact.versioning.ArtifactVersion; + +public class ApplicationInformation +{ + private ArtifactVersion version; + private String builtOn; + + public ApplicationInformation( ArtifactVersion version, String builtOn ) + { + this.version = version; + this.builtOn = builtOn; + } + + public ArtifactVersion getVersion() + { + return version; + } + + public String getBuiltOn() + { + return builtOn; + } +} diff --git a/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java new file mode 100644 index 0000000000..c1c11ca2df --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/execution/DefaultRuntimeInformation.java @@ -0,0 +1,109 @@ +package org.apache.maven.execution; + +/* + * 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. + */ + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.codehaus.plexus.util.IOUtil; + +/** + * Describes runtime information about the application. + * + * @author Jason van Zyl + * @author Brett Porter + * @version $Id$ + */ +@Component(role = RuntimeInformation.class) +public class DefaultRuntimeInformation + implements RuntimeInformation, Initializable +{ + private ApplicationInformation applicationInformation; + + public ApplicationInformation getApplicationInformation() + { + return applicationInformation; + } + + /** @deprecated Use getApplicationInformation() */ + public ArtifactVersion getApplicationVersion() + { + return applicationInformation.getVersion(); + } + + public void initialize() + throws InitializationException + { + applicationInformation = getVersion( getClass().getClassLoader(), "org.apache.maven", "maven-core" ); + } + + public static ApplicationInformation getVersion( ClassLoader loader, String groupId, String artifactId ) + { + String MAVEN_PROPERTIES = "META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties"; + + String version = "unknown"; + String builtOn = "unknown"; + + InputStream resourceAsStream = null; + try + { + Properties properties = new Properties(); + resourceAsStream = loader.getResourceAsStream( MAVEN_PROPERTIES ); + + if ( resourceAsStream == null ) + { + return new ApplicationInformation( new DefaultArtifactVersion( "3.0" ), builtOn ); + } + + properties.load( resourceAsStream ); + + String property = properties.getProperty( "version" ); + + if ( property != null ) + { + version = property; + } + + property = properties.getProperty( "builtOn" ); + + if ( property != null ) + { + builtOn = property; + } + + return new ApplicationInformation( new DefaultArtifactVersion( version ), builtOn ); + + } + catch ( IOException e ) + { + return new ApplicationInformation( new DefaultArtifactVersion( version ), builtOn ); + } + finally + { + IOUtil.close( resourceAsStream ); + } + } +} diff --git a/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java b/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java new file mode 100644 index 0000000000..c1a1bb9404 --- /dev/null +++ b/maven-compat/src/main/java/org/apache/maven/execution/RuntimeInformation.java @@ -0,0 +1,38 @@ +package org.apache.maven.execution; + +import org.apache.maven.artifact.versioning.ArtifactVersion; + +/* + * 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. + */ + +/** + * Describes runtime information about the application. + * + * @author Brett Porter + * @version $Id$ + */ +public interface RuntimeInformation +{ + ApplicationInformation getApplicationInformation(); + + /** @deprecated Use getApplicationInformation() */ + //!!BC Used by the Eclipse Plugin + ArtifactVersion getApplicationVersion(); + +}