Based on Alexander's agreement that he would do the work to port the 
saveVersion script to Windows I am reverting my -1 on this patch.

Ralph


On Jun 29, 2012, at 4:55 AM, Ralph Goers wrote:

> As I stated in the Review - please revert this fix until it supports Windows 
> or FLUME-1174 is closed as won't-fix.
> 
> Ral[ph
> 
> On Jun 29, 2012, at 1:10 AM, [email protected] wrote:
> 
>> Author: hshreedharan
>> Date: Fri Jun 29 08:10:02 2012
>> New Revision: 1355259
>> 
>> URL: http://svn.apache.org/viewvc?rev=1355259&view=rev
>> Log:
>> FLUME-1240. Add version info to Flume NG.
>> 
>> (Leslin (Hong Xiang Lin) via Hari Shreedharan)
>> 
>> 
>> Added:
>>   incubator/flume/trunk/flume-ng-core/scripts/
>>   incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh   (with props)
>>   
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/VersionAnnotation.java
>>    (with props)
>>   
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/tools/VersionInfo.java
>>    (with props)
>>   
>> incubator/flume/trunk/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
>>    (with props)
>> Modified:
>>   incubator/flume/trunk/bin/flume-ng
>>   incubator/flume/trunk/flume-ng-core/pom.xml
>> 
>> Modified: incubator/flume/trunk/bin/flume-ng
>> URL: 
>> http://svn.apache.org/viewvc/incubator/flume/trunk/bin/flume-ng?rev=1355259&r1=1355258&r2=1355259&view=diff
>> ==============================================================================
>> --- incubator/flume/trunk/bin/flume-ng (original)
>> +++ incubator/flume/trunk/bin/flume-ng Fri Jun 29 08:10:02 2012
>> @@ -25,21 +25,25 @@
>> 
>> FLUME_AGENT_CLASS="org.apache.flume.node.Application"
>> FLUME_AVRO_CLIENT_CLASS="org.apache.flume.client.avro.AvroCLIClient"
>> +FLUME_VERSION_CLASS="org.apache.flume.tools.VersionInfo"
>> 
>> +CLEAN_FLAG=1
>> ################################
>> # functions
>> ################################
>> 
>> info() {
>> -  local msg=$1
>> -
>> -  echo "Info: $msg" >&2
>> +  if [ ${CLEAN_FLAG} -ne 0 ]; then
>> +    local msg=$1
>> +    echo "Info: $msg" >&2
>> +  fi
>> }
>> 
>> warn() {
>> -  local msg=$1
>> -
>> -  echo "Warning: $msg" >&2
>> +  if [ ${CLEAN_FLAG} -ne 0 ]; then
>> +    local msg=$1
>> +    echo "Warning: $msg" >&2
>> +  fi
>> }
>> 
>> error() {
>> @@ -164,6 +168,7 @@ commands:
>>  help                  display this help text
>>  agent                 run a Flume agent
>>  avro-client           run an avro Flume client
>> +  version               show Flume version info
>> 
>> global options:
>>  --conf,-c <conf>      use configs in <conf> directory
>> @@ -199,7 +204,9 @@ run_flume() {
>>    error "Must specify flume application class" 1
>>  fi
>> 
>> -  set -x
>> +  if [ ${CLEAN_FLAG} -ne 0 ]; then
>> +    set -x
>> +  fi
>>  $EXEC $JAVA_HOME/bin/java $JAVA_OPTS -cp "$FLUME_CLASSPATH" \
>>      -Djava.library.path=$FLUME_JAVA_LIBRARY_PATH "$FLUME_APPLICATION_CLASS" 
>> $*
>> }
>> @@ -236,6 +243,10 @@ case "$mode" in
>>  avro-client)
>>    opt_avro_client=1
>>    ;;
>> +  version)
>> +   opt_version=1
>> +   CLEAN_FLAG=0
>> +   ;;
>>  *)
>>    error "Unknown or unspecified command '$mode'"
>>    echo
>> @@ -348,6 +359,8 @@ if [ -n "$opt_agent" ] ; then
>>  run_flume $FLUME_AGENT_CLASS $args
>> elif [ -n "$opt_avro_client" ] ; then
>>  run_flume $FLUME_AVRO_CLIENT_CLASS $args
>> +elif [ -n "${opt_version}" ] ; then
>> +  run_flume $FLUME_VERSION_CLASS $args
>> else
>>  error "This message should never appear" 1
>> fi
>> 
>> Modified: incubator/flume/trunk/flume-ng-core/pom.xml
>> URL: 
>> http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-core/pom.xml?rev=1355259&r1=1355258&r2=1355259&view=diff
>> ==============================================================================
>> --- incubator/flume/trunk/flume-ng-core/pom.xml (original)
>> +++ incubator/flume/trunk/flume-ng-core/pom.xml Fri Jun 29 08:10:02 2012
>> @@ -37,6 +37,48 @@ limitations under the License.
>>        <artifactId>apache-rat-plugin</artifactId>
>>      </plugin>
>> 
>> +      <plugin>
>> +        <groupId>org.codehaus.mojo</groupId>
>> +        <artifactId>exec-maven-plugin</artifactId>
>> +        <version>1.2.1</version>
>> +        <executions>
>> +          <execution>
>> +            <id>generate-version</id>
>> +            <phase>generate-sources</phase>
>> +            <configuration>
>> +              <executable>scripts/saveVersion.sh</executable>
>> +              <arguments>
>> +                <argument>${project.version}</argument>
>> +                <argument>${project.build.directory}</argument>
>> +              </arguments>
>> +            </configuration>
>> +            <goals>
>> +              <goal>exec</goal>
>> +            </goals>
>> +          </execution>
>> +        </executions>
>> +      </plugin>
>> +
>> +      <plugin>
>> +        <groupId>org.codehaus.mojo</groupId>
>> +        <artifactId>build-helper-maven-plugin</artifactId>
>> +        <version>1.7</version>
>> +        <executions>
>> +          <execution>
>> +            <id>add-source</id>
>> +            <phase>generate-sources</phase>
>> +            <goals>
>> +              <goal>add-source</goal>
>> +            </goals>
>> +            <configuration>
>> +              <sources>
>> +                <source>target/generated-sources/java</source>
>> +              </sources>
>> +            </configuration>
>> +          </execution>
>> +        </executions>
>> +      </plugin>
>> +
>>    </plugins>
>>  </build>
>> 
>> 
>> Added: incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh
>> URL: 
>> http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh?rev=1355259&view=auto
>> ==============================================================================
>> --- incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh (added)
>> +++ incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh Fri Jun 29 
>> 08:10:02 2012
>> @@ -0,0 +1,69 @@
>> +#!/bin/sh
>> +
>> +# 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.
>> +
>> +# This script is used to generate the annotation of package info that
>> +# records the version, revision, branch, url, user and timestamp.
>> +
>> +unset LANG
>> +unset LC_CTYPE
>> +unset LC_TIME
>> +version=$1
>> +buildDirectory=$2
>> +user=`whoami`
>> +date=`date`
>> +dir=`pwd`
>> +cwd=`dirname $dir`
>> +if [ -d ../.svn ]; then
>> +  revision=`svn info ../ | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
>> +  url=`svn info  ../ | sed -n -e 's/URL: \(.*\)/\1/p'`
>> +  branch=`echo $url | sed -n -e 's,.*\(branches/.*\)$,\1,p' \
>> +                             -e 's,.*\(tags/.*\)$,\1,p' \
>> +                             -e 's,.*trunk$,trunk,p'`
>> +elif git rev-parse HEAD 2>/dev/null > /dev/null ; then
>> +  revision=`git log -1 --pretty=format:"%H"`
>> +  hostname=`hostname`
>> +  branch=`git branch | sed -n -e 's/^* //p'`
>> +  url="git://${hostname}${cwd}"
>> +else
>> +  revision="Unknown"
>> +  branch="Unknown"
>> +  url="file://$cwd"
>> +fi
>> +
>> +if [ -n "$(which md5sum)" ]; then
>> +  srcChecksum=`find ../ -name '*.java' | grep -v generated-sources | 
>> LC_ALL=C sort | \
>> +      xargs md5sum | md5sum | cut -d ' ' -f 1`
>> +else
>> +  srcChecksum=`find ../ -name '*.java' | grep -v generated-sources | 
>> LC_ALL=C sort | \
>> +      xargs md5 | md5 | cut -d ' ' -f 1`
>> +fi
>> +
>> +mkdir -p $buildDirectory/generated-sources/java/org/apache/flume/
>> +cat << EOF | \
>> +  sed -e "s/VERSION/$version/" -e "s/USER/$user/" -e "s/DATE/$date/" \
>> +      -e "s|URL|$url|" -e "s/REV/$revision/" \
>> +      -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
>> +      > 
>> $buildDirectory/generated-sources/java/org/apache/flume/package-info.java
>> +/*
>> + * Generated by scripts/saveVersion.sh
>> + */
>> +@VersionAnnotation(version="VERSION", revision="REV", branch="BRANCH",
>> +                         user="USER", date="DATE", url="URL",
>> +                         srcChecksum="SRCCHECKSUM")
>> +package org.apache.flume;
>> +EOF
>> \ No newline at end of file
>> 
>> Propchange: incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh
>> ------------------------------------------------------------------------------
>>   svn:eol-style = native
>> 
>> Propchange: incubator/flume/trunk/flume-ng-core/scripts/saveVersion.sh
>> ------------------------------------------------------------------------------
>>   svn:executable = *
>> 
>> Added: 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/VersionAnnotation.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/VersionAnnotation.java?rev=1355259&view=auto
>> ==============================================================================
>> --- 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/VersionAnnotation.java
>>  (added)
>> +++ 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/VersionAnnotation.java
>>  Fri Jun 29 08:10:02 2012
>> @@ -0,0 +1,76 @@
>> +/**
>> + * 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.
>> + */
>> +package org.apache.flume;
>> +
>> +import java.lang.annotation.ElementType;
>> +import java.lang.annotation.Retention;
>> +import java.lang.annotation.RetentionPolicy;
>> +import java.lang.annotation.Target;
>> +
>> +
>> +/**
>> + * This class is about package attribute that captures
>> + * version info of Flume that was compiled.
>> + */
>> +
>> +@Retention(RetentionPolicy.RUNTIME)
>> +@Target(ElementType.PACKAGE)
>> +public @interface VersionAnnotation {
>> +
>> +  /**
>> +   * Get the Flume version
>> +   * @return the version string "1.1"
>> +   */
>> +  String version();
>> +
>> +  /**
>> +   * Get the subversion revision.
>> +   * @return the revision number as a string (eg. "100755")
>> +   */
>> +  String revision();
>> +
>> +  /**
>> +   * Get the branch from which this was compiled.
>> +   * @return The branch name, e.g. "trunk"
>> +   */
>> +  String branch();
>> +
>> +  /**
>> +   * Get the username that compiled Flume.
>> +   */
>> +  String user();
>> +
>> +  /**
>> +   * Get the date when Flume was compiled.
>> +   * @return the date in unix 'date' format
>> +   */
>> +  String date();
>> +
>> +  /**
>> +   * Get the url for the subversion repository.
>> +   */
>> +  String url();
>> +
>> +  /**
>> +   * Get a checksum of the source files from which
>> +   * Flume was compiled.
>> +   * @return a string that uniquely identifies the source
>> +   **/
>> +  String srcChecksum();
>> +
>> +}
>> 
>> Propchange: 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/VersionAnnotation.java
>> ------------------------------------------------------------------------------
>>   svn:eol-style = native
>> 
>> Added: 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/tools/VersionInfo.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/tools/VersionInfo.java?rev=1355259&view=auto
>> ==============================================================================
>> --- 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/tools/VersionInfo.java
>>  (added)
>> +++ 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/tools/VersionInfo.java
>>  Fri Jun 29 08:10:02 2012
>> @@ -0,0 +1,122 @@
>> +/**
>> + * 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.
>> + */
>> +package org.apache.flume.tools;
>> +
>> +import org.apache.flume.VersionAnnotation;
>> +import org.slf4j.Logger;
>> +import org.slf4j.LoggerFactory;
>> +
>> +/*
>> + * This class provides version info of Flume NG
>> + */
>> +
>> +public class VersionInfo {
>> +  private static final Logger LOG = 
>> LoggerFactory.getLogger(VersionInfo.class);
>> +
>> +  private static Package myPackage;
>> +  private static VersionAnnotation version;
>> +
>> +  static {
>> +    myPackage = VersionAnnotation.class.getPackage();
>> +    version = myPackage.getAnnotation(VersionAnnotation.class);
>> +  }
>> +
>> +  /**
>> +   * Get the meta-data for the Flume package.
>> +   * @return
>> +   */
>> +  static Package getPackage() {
>> +    return myPackage;
>> +  }
>> +
>> +  /**
>> +   * Get the Flume version.
>> +   * @return the Flume version string, eg. "1.1"
>> +   */
>> +  public static String getVersion() {
>> +    return version != null ? version.version() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * Get the subversion revision number for the root directory
>> +   * @return the revision number, eg. "100755"
>> +   */
>> +  public static String getRevision() {
>> +    return version != null ? version.revision() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * Get the branch on which this originated.
>> +   * @return The branch name, e.g. "trunk" or "branches/branch-1.1"
>> +   */
>> +  public static String getBranch() {
>> +    return version != null ? version.branch() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * The date that Flume was compiled.
>> +   * @return the compilation date in unix date format
>> +   */
>> +  public static String getDate() {
>> +    return version != null ? version.date() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * The user that compiled Flume.
>> +   * @return the username of the user
>> +   */
>> +  public static String getUser() {
>> +    return version != null ? version.user() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * Get the subversion URL for the root Flume directory.
>> +   */
>> +  public static String getUrl() {
>> +    return version != null ? version.url() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * Get the checksum of the source files from which Flume was
>> +   * built.
>> +   **/
>> +  public static String getSrcChecksum() {
>> +    return version != null ? version.srcChecksum() : "Unknown";
>> +  }
>> +
>> +  /**
>> +   * Returns the build version info which includes version,
>> +   * revision, user, date and source checksum
>> +   */
>> +  public static String getBuildVersion(){
>> +    return VersionInfo.getVersion() +
>> +    " from " + VersionInfo.getRevision() +
>> +    " by " + VersionInfo.getUser() +
>> +    " on " + VersionInfo.getDate() +
>> +    " source checksum " + VersionInfo.getSrcChecksum();
>> +  }
>> +
>> +  public static void main(String[] args) {
>> +    LOG.debug("version: "+ version);
>> +    System.out.println("Flume " + getVersion());
>> +    System.out.println("Subversion " + getUrl() + " -r " + getRevision());
>> +    System.out.println("Compiled by " + getUser() + " on " + getDate());
>> +    System.out.println("From source with checksum " + getSrcChecksum());
>> +  }
>> +
>> +}
>> 
>> Propchange: 
>> incubator/flume/trunk/flume-ng-core/src/main/java/org/apache/flume/tools/VersionInfo.java
>> ------------------------------------------------------------------------------
>>   svn:eol-style = native
>> 
>> Added: 
>> incubator/flume/trunk/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
>> URL: 
>> http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java?rev=1355259&view=auto
>> ==============================================================================
>> --- 
>> incubator/flume/trunk/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
>>  (added)
>> +++ 
>> incubator/flume/trunk/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
>>  Fri Jun 29 08:10:02 2012
>> @@ -0,0 +1,63 @@
>> +/**
>> + * 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.
>> + */
>> +
>> +package org.apache.flume.tools;
>> +
>> +import static org.junit.Assert.*;
>> +
>> +import org.junit.Test;
>> +import org.slf4j.Logger;
>> +import org.slf4j.LoggerFactory;
>> +
>> +public class TestVersionInfo {
>> +
>> +  private static final Logger logger = LoggerFactory
>> +      .getLogger(TestVersionInfo.class);
>> +
>> +  /**
>> +   *  Make sure that Unknown is expected when no version info
>> +   */
>> +  @Test
>> +  public void testVersionInfoUnknown() {
>> +
>> +    logger.debug("Flume " + VersionInfo.getVersion());
>> +    logger.debug("Subversion " + VersionInfo.getUrl() + " -r " + 
>> VersionInfo.getRevision());
>> +    logger.debug("Compiled by " + VersionInfo.getUser() + " on " + 
>> VersionInfo.getDate());
>> +    logger.debug("From source with checksum " + 
>> VersionInfo.getSrcChecksum());
>> +    logger.debug("Flume " + VersionInfo.getBuildVersion());
>> +
>> +    assertTrue("getVersion returned Unknown",
>> +        !VersionInfo.getVersion().equals("Unknown"));
>> +    assertTrue("getUser returned Unknown",
>> +        !VersionInfo.getUser().equals("Unknown"));
>> +    assertTrue("getUrl returned Unknown",
>> +        !VersionInfo.getUrl().equals("Unknown"));
>> +    assertTrue("getSrcChecksum returned Unknown",
>> +        !VersionInfo.getSrcChecksum().equals("Unknown"));
>> +
>> +    // check getBuildVersion() return format
>> +    assertTrue("getBuildVersion returned unexpected format",VersionInfo.
>> +        getBuildVersion().matches(".+from.+by.+on.+source checksum.+"));
>> +
>> +    //"Unknown" when build without svn or git
>> +    assertNotNull("getRevision returned null", VersionInfo.getRevision());
>> +    assertNotNull("getBranch returned null", VersionInfo.getBranch());
>> +
>> +  }
>> +
>> +}
>> 
>> Propchange: 
>> incubator/flume/trunk/flume-ng-core/src/test/java/org/apache/flume/tools/TestVersionInfo.java
>> ------------------------------------------------------------------------------
>>   svn:eol-style = native
>> 
>> 
> 

Reply via email to