Skip to content

Commit

Permalink
HADOOP-8924. Add maven plugin alternative to shell script to save pac…
Browse files Browse the repository at this point in the history
…kage-info.java. Contributed by Alejandro Abdelnur and Chris Nauroth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1435380 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Suresh Srinivas committed Jan 18, 2013
1 parent f8cca2d commit ae270e7
Show file tree
Hide file tree
Showing 15 changed files with 818 additions and 289 deletions.
67 changes: 0 additions & 67 deletions hadoop-common-project/hadoop-common/dev-support/saveVersion.sh

This file was deleted.

60 changes: 44 additions & 16 deletions hadoop-common-project/hadoop-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,51 @@
</dependencies>

<build>
<!--
Include all files in src/main/resources. By default, do not apply property
substitution (filtering=false), but do apply property substitution to
common-version-info.properties (filtering=true). This will substitute the
version information correctly, but prevent Maven from altering other files
like core-default.xml.
-->
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>common-version-info.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>common-version-info.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-maven-plugins</artifactId>
<executions>
<execution>
<id>version-info</id>
<goals>
<goal>version-info</goal>
</goals>
<configuration>
<source>
<directory>${basedir}/src/main</directory>
<includes>
<include>java/**/*.java</include>
<include>proto/**/*.proto</include>
</includes>
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -288,22 +332,6 @@
</target>
</configuration>
</execution>
<execution>
<id>save-version</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${project.build.directory}/generated-sources/java"/>
<exec executable="sh">
<arg
line="${basedir}/dev-support/saveVersion.sh ${project.version} ${project.build.directory}/generated-sources/java"/>
</exec>
</target>
</configuration>
</execution>
<execution>
<id>generate-test-sources</id>
<phase>generate-test-sources</phase>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,103 +20,137 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.HadoopVersionAnnotation;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* This class finds the package info for Hadoop and the HadoopVersionAnnotation
* information.
* This class returns build information about Hadoop components.
*/
@InterfaceAudience.Private
@InterfaceStability.Unstable
public class VersionInfo {
private static final Log LOG = LogFactory.getLog(VersionInfo.class);

private static Package myPackage;
private static HadoopVersionAnnotation version;

static {
myPackage = HadoopVersionAnnotation.class.getPackage();
version = myPackage.getAnnotation(HadoopVersionAnnotation.class);
private Properties info;

protected VersionInfo(String component) {
info = new Properties();
String versionInfoFile = component + "-version-info.properties";
try {
InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(versionInfoFile);
info.load(is);
} catch (IOException ex) {
LogFactory.getLog(getClass()).warn("Could not read '" +
versionInfoFile + "', " + ex.toString(), ex);
}
}

/**
* Get the meta-data for the Hadoop package.
* @return
*/
static Package getPackage() {
return myPackage;
protected String _getVersion() {
return info.getProperty("version", "Unknown");
}


protected String _getRevision() {
return info.getProperty("revision", "Unknown");
}

protected String _getBranch() {
return info.getProperty("branch", "Unknown");
}

protected String _getDate() {
return info.getProperty("date", "Unknown");
}

protected String _getUser() {
return info.getProperty("user", "Unknown");
}

protected String _getUrl() {
return info.getProperty("url", "Unknown");
}

protected String _getSrcChecksum() {
return info.getProperty("srcChecksum", "Unknown");
}

protected String _getBuildVersion(){
return getVersion() +
" from " + _getRevision() +
" by " + _getUser() +
" source checksum " + _getSrcChecksum();
}

private static VersionInfo COMMON_VERSION_INFO = new VersionInfo("common");
/**
* Get the Hadoop version.
* @return the Hadoop version string, eg. "0.6.3-dev"
*/
public static String getVersion() {
return version != null ? version.version() : "Unknown";
return COMMON_VERSION_INFO._getVersion();
}

/**
* Get the subversion revision number for the root directory
* @return the revision number, eg. "451451"
*/
public static String getRevision() {
return version != null ? version.revision() : "Unknown";
return COMMON_VERSION_INFO._getRevision();
}

/**
* Get the branch on which this originated.
* @return The branch name, e.g. "trunk" or "branches/branch-0.20"
*/
public static String getBranch() {
return version != null ? version.branch() : "Unknown";
return COMMON_VERSION_INFO._getBranch();
}

/**
* The date that Hadoop was compiled.
* @return the compilation date in unix date format
*/
public static String getDate() {
return version != null ? version.date() : "Unknown";
return COMMON_VERSION_INFO._getDate();
}

/**
* The user that compiled Hadoop.
* @return the username of the user
*/
public static String getUser() {
return version != null ? version.user() : "Unknown";
return COMMON_VERSION_INFO._getUser();
}

/**
* Get the subversion URL for the root Hadoop directory.
*/
public static String getUrl() {
return version != null ? version.url() : "Unknown";
return COMMON_VERSION_INFO._getUrl();
}

/**
* Get the checksum of the source files from which Hadoop was
* built.
**/
public static String getSrcChecksum() {
return version != null ? version.srcChecksum() : "Unknown";
return COMMON_VERSION_INFO._getSrcChecksum();
}

/**
* Returns the buildVersion which includes version,
* revision, user and date.
*/
public static String getBuildVersion(){
return VersionInfo.getVersion() +
" from " + VersionInfo.getRevision() +
" by " + VersionInfo.getUser() +
" source checksum " + VersionInfo.getSrcChecksum();
return COMMON_VERSION_INFO._getBuildVersion();
}

public static void main(String[] args) {
LOG.debug("version: "+ version);
LOG.debug("version: "+ getVersion());
System.out.println("Hadoop " + getVersion());
System.out.println("Subversion " + getUrl() + " -r " + getRevision());
System.out.println("Compiled by " + getUser() + " on " + getDate());
Expand Down
Loading

0 comments on commit ae270e7

Please sign in to comment.