Author: olga Date: Fri Feb 29 15:23:53 2008 New Revision: 632493 URL: http://svn.apache.org/viewvc?rev=632493&view=rev Log: PIG-13: added version support
Modified: incubator/pig/trunk/CHANGES.txt incubator/pig/trunk/build.xml incubator/pig/trunk/src/org/apache/pig/Main.java Modified: incubator/pig/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=632493&r1=632492&r2=632493&view=diff ============================================================================== --- incubator/pig/trunk/CHANGES.txt (original) +++ incubator/pig/trunk/CHANGES.txt Fri Feb 29 15:23:53 2008 @@ -145,3 +145,5 @@ PIG-125: Improve exception handling in cases when an attempt is made to access a field as a tuple, and it turns out not to be a tuple (oae via gates). + + PIG-13: adding version to the system (joa23 via olgan) Modified: incubator/pig/trunk/build.xml URL: http://svn.apache.org/viewvc/incubator/pig/trunk/build.xml?rev=632493&r1=632492&r2=632493&view=diff ============================================================================== --- incubator/pig/trunk/build.xml (original) +++ incubator/pig/trunk/build.xml Fri Feb 29 15:23:53 2008 @@ -29,9 +29,9 @@ <property name="javac.deprecation" value="off" /> <property name="javac.version" value="1.5" /> <property name="javac.args" value="" /> - <!-- TODO we should use warning... <property name="javac.args.warnings" value="-Xlint:unchecked" /> --> + <!-- TODO we should use warning... <property name="javac.args.warnings" value="-Xlint:unchecked" /> --> <property name="javac.args.warnings" value="" /> - + <!-- build properties --> <property name="build.dir" value="${basedir}/build" /> <property name="build.classes" value="${build.dir}/classes" /> @@ -74,22 +74,48 @@ <fileset file="${lib.dir}/jsch-0.1.33.jar" /> <fileset file="${lib.dir}/junit-4.1.jar" /> </path> - + <path id="test.classpath"> - <pathelement location="${build.classes}"/> - <pathelement location="${test.src.dir}"/> - <path refid="classpath"/> + <pathelement location="${build.classes}"/> + <pathelement location="${test.src.dir}"/> + <path refid="classpath"/> </path> - + <target name="init"> <mkdir dir="${src.gen.query.parser.dir}" /> <mkdir dir="${src.gen.script.parser.dir}" /> <mkdir dir="${dist.dir}" /> <mkdir dir="${build.classes}" /> <mkdir dir="${test.build.classes}" /> + <tstamp> + <format property="timestamp" pattern="MMM dd yyyy, HH:mm:ss" /> + </tstamp> + <svnversion outputproperty="svn.revision"/> </target> + + <macrodef name="svnversion"> + <!-- the path needs to be small content otherwise it will take AGES ! --> + <attribute name="wcpath" default="${basedir}" /> + <attribute name="outputproperty" /> + <sequential> + <exec executable="svnversion" outputproperty="@{outputproperty}" failonerror="true" failifexecutionfails="false"> + <arg value="@{wcpath}" /> + <redirector> + <outputfilterchain> + <tokenfilter> + <!-- version can be xxxx, xxxx:yyyy, xxxxM, xxxxS or xxxx:yyyyMS , ... just get the working copy one --> + <replaceregex pattern="((\d+).*)" replace="\2" /> + </tokenfilter> + </outputfilterchain> + </redirector> + </exec> + <fail unless="@{outputproperty}" message="Failed to retrieve svn revision. You need 'svnversion' in your path and connectivity to the repository" /> + </sequential> + </macrodef> + + <!-- ================================================================== --> <!-- Clean. Delete the build files, and their directories --> <!-- ================================================================== --> @@ -167,20 +193,24 @@ <manifest> <attribute name="Main-Class" value="org.apache.pig.Main" /> <section name="org/apache/pig"> + <attribute name="Implementation-Vendor" value="Apache" /> <attribute name="Implementation-Title" value="Pig" /> <attribute name="Implementation-Version" value="${version}" /> - <attribute name="Implementation-Vendor" value="Apache" /> + <attribute name="Build-TimeStamp" value="${timestamp}" /> + <attribute name="Svn-Revision" value="${svn.revision}" /> </section> </manifest> </jar> - <!-- @depricated --> + <!-- @depricated --> <jar jarfile="${output.jarfile}" basedir="${build.classes}"> <manifest> <attribute name="Main-Class" value="org.apache.pig.Main" /> <section name="org/apache/pig"> + <attribute name="Implementation-Vendor" value="Apache" /> <attribute name="Implementation-Title" value="Pig" /> <attribute name="Implementation-Version" value="${version}" /> - <attribute name="Implementation-Vendor" value="Apache" /> + <attribute name="Build-TimeStamp" value="${timestamp}" /> + <attribute name="Svn-Revision" value="${svn.revision}" /> </section> </manifest> <zipfileset src="${lib.dir}/junit-4.1.jar" /> Modified: incubator/pig/trunk/src/org/apache/pig/Main.java URL: http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/Main.java?rev=632493&r1=632492&r2=632493&view=diff ============================================================================== --- incubator/pig/trunk/src/org/apache/pig/Main.java (original) +++ incubator/pig/trunk/src/org/apache/pig/Main.java Fri Feb 29 15:23:53 2008 @@ -35,6 +35,7 @@ import org.apache.pig.PigServer.ExecType; import org.apache.pig.impl.PigContext; import org.apache.pig.impl.logicalLayer.LogicalPlanBuilder; +import org.apache.pig.impl.util.JarManager; import org.apache.pig.tools.cmdline.CmdLineParser; import org.apache.pig.tools.grunt.Grunt; import org.apache.pig.tools.timer.PerformanceTimerFactory; @@ -86,6 +87,7 @@ opts.registerOpt('j', "jar", CmdLineParser.ValueExpected.REQUIRED); opts.registerOpt('v', "verbose", CmdLineParser.ValueExpected.NOT_ACCEPTED); opts.registerOpt('x', "exectype", CmdLineParser.ValueExpected.REQUIRED); + opts.registerOpt('i', "version", CmdLineParser.ValueExpected.OPTIONAL); char opt; while ((opt = opts.getNextOpt()) != CmdLineParser.EndOfOpts) { @@ -160,7 +162,9 @@ } pigContext.setExecType(exectype); break; - + case 'i': + System.out.println(getVersionString()); + return; default: { Character cc = new Character(opt); throw new AssertionError("Unhandled option " + cc.toString()); @@ -277,8 +281,29 @@ } } +private static String getVersionString() { + String findContainingJar = JarManager.findContainingJar(Main.class); + try { + StringBuffer buffer = new StringBuffer(); + JarFile jar = new JarFile(findContainingJar); + final Manifest manifest = jar.getManifest(); + final Map <String,Attributes> attrs = manifest.getEntries(); + Attributes attr = attrs.get("org/apache/pig"); + String version = (String) attr.getValue("Implementation-Version"); + String svnRevision = (String) attr.getValue("Svn-Revision"); + String buildTime = (String) attr.getValue("Build-TimeStamp"); + // we use a version string similar to svn + //svn, version 1.4.4 (r25188) + // compiled Sep 23 2007, 22:32:34 + return "Apache Pig version " + version + " (r" + svnRevision + ") \ncompiled "+buildTime; + } catch (Exception e) { + throw new RuntimeException("unable to read pigs manifest file", e); + } +} + public static void usage() { + System.out.println("\n"+getVersionString()+"\n"); System.out.println("USAGE: Pig [options] [-] : Run interactively in grunt shell."); System.out.println(" Pig [options] -e[xecute] cmd [cmd ...] : Run cmd(s)."); System.out.println(" Pig [options] [-f[ile]] file : Run cmds found in file."); @@ -292,5 +317,6 @@ System.out.println(" -o, -hod read hod server from system property ssh.gateway"); System.out.println(" -v, -verbose print all log messages to screen (default to print only INFO and above to screen)"); System.out.println(" -x, -exectype local|mapreduce, mapreduce is default"); + System.out.println(" -i, -version display version information"); } }