Nice :) FYI, a postgoal on java:jar-resources is more appropriate than on java:compile.
- Brett Quoting "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>: > polx 2005/01/23 16:34:06 > > Modified: jelly/src/java/org/apache/commons/jelly Jelly.java > jelly/src/java/org/apache/commons/jelly/util > CommandLineParser.java > jelly/xdocs changes.xml > jelly maven.xml > Log: > Adding jelly -h and -v. (help and current-version). > paul > > Revision Changes Path > 1.35 +29 -1 > jakarta-commons/jelly/src/java/org/apache/commons/jelly/Jelly.java > > Index: Jelly.java > =================================================================== > RCS file: > /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/Jelly.java,v > retrieving revision 1.34 > retrieving revision 1.35 > diff -u -r1.34 -r1.35 > --- Jelly.java 9 Sep 2004 15:10:03 -0000 1.34 > +++ Jelly.java 24 Jan 2005 00:34:06 -0000 1.35 > @@ -101,6 +101,34 @@ > } > } > } > + > + > + public static String getJellyVersion() { > + return readBuildTimestampResource("jelly-version.txt"); > + } > + > + public static String getJellyBuildDate() { > + return readBuildTimestampResource("jelly-build-date.txt"); > + } > + > + private static String readBuildTimestampResource(String name) { > + java.io.Reader in = null; > + try { > + java.io.StringWriter w = new java.io.StringWriter(); > + in = new > java.io.InputStreamReader(Jelly.class.getResourceAsStream(name),"utf-8"); > + int r; > + while ( (r=in.read()) >= 0 ) { > + w.write((char) r); > + } > + return w.toString(); > + } catch(Exception ex) { > + ex.printStackTrace(); > + try { in.close(); } catch(Exception e) {} > + throw new IllegalStateException("Resource \"" + name + "\" not > found."); > + } > + } > + > + > > /** > * Compiles the script > > > > 1.10 +50 -13 > jakarta-commons/jelly/src/java/org/apache/commons/jelly/util/CommandLineParser.java > > Index: CommandLineParser.java > =================================================================== > RCS file: > /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/util/CommandLineParser.java,v > retrieving revision 1.9 > retrieving revision 1.10 > diff -u -r1.9 -r1.10 > --- CommandLineParser.java 10 Jan 2005 05:35:17 -0000 1.9 > +++ CommandLineParser.java 24 Jan 2005 00:34:06 -0000 1.10 > @@ -19,7 +19,9 @@ > import java.io.File; > import java.io.FileWriter; > import java.net.URL; > +import java.util.Arrays; > import java.util.ArrayList; > +import java.util.List; > import java.util.Properties; > > import org.apache.commons.cli.CommandLine; > @@ -27,6 +29,7 @@ > import org.apache.commons.cli.Options; > import org.apache.commons.cli.ParseException; > import org.apache.commons.cli.Parser; > +import org.apache.commons.cli.HelpFormatter; > import org.apache.commons.jelly.Jelly; > import org.apache.commons.jelly.JellyContext; > import org.apache.commons.jelly.JellyException; > @@ -46,6 +49,8 @@ > public class CommandLineParser { > > protected static CommandLineParser _instance = new > CommandLineParser(); > + > + private Options cmdLineOptions = null; > > public static CommandLineParser getInstance() { > return _instance; > @@ -66,6 +71,19 @@ > } catch (ParseException e) { > throw new JellyException(e); > } > + > + // check for -h or -v > + if (cmdLine.hasOption("h")) { > + new HelpFormatter().printHelp("jelly [scriptFile] [-script > scriptFile] [-o outputFile] [-Dsysprop=syspropval] [-awt]", > + cmdLineOptions); > + System.exit(1); > + } > + if (cmdLine.hasOption("v")) { > + System.err.println("Jelly " + Jelly.getJellyVersion()); > + System.err.println(" compiled: " + > Jelly.getJellyBuildDate()); > + System.err.println(""); > + System.exit(1); > + } > > // get the -script option. If there isn't one then use args[0] > String scriptFile = null; > @@ -74,6 +92,9 @@ > } else { > scriptFile = args[0]; > } > + > + // check the -awt option. > + boolean runInSwingThread = cmdLine.hasOption("awt") || > cmdLine.hasOption("swing"); > > // > // Use classloader to find file > @@ -93,13 +114,22 @@ > Jelly jelly = new Jelly(); > jelly.setScript(scriptFile); > > - Script script = jelly.compileScript(); > + final Script script = jelly.compileScript(); > > // add the system properties and the command line arguments > - JellyContext context = jelly.getJellyContext(); > + final JellyContext context = jelly.getJellyContext(); > context.setVariable("args", args); > context.setVariable("commandLine", cmdLine); > - script.run(context, output); > + if (runInSwingThread) { > + javax.swing.SwingUtilities.invokeAndWait(new Runnable() { > public void run() { > + try { > + script.run(context, output); > + } catch (Exception ex) { > + ex.printStackTrace(); > + } > + } } ); } else { > + script.run(context, output); > + } > > // now lets wait for all threads to close > Runtime.getRuntime().addShutdownHook(new Thread() { > @@ -126,10 +156,17 @@ > */ > public CommandLine parseCommandLineOptions(String[] args) throws > ParseException { > // create the expected options > - Options cmdLineOptions = new Options(); > + cmdLineOptions = new Options(); > cmdLineOptions.addOption("o", true, "Output file"); > cmdLineOptions.addOption("script", true, "Jelly script to run"); > - > + cmdLineOptions.addOption("h","help", false, "Give this help > message"); > + cmdLineOptions.addOption("v","version", false, "prints Jelly's > version and exits"); > + cmdLineOptions.addOption("script", true, "Jelly script to run"); > + cmdLineOptions.addOption("awt", false, "Wether to run in the AWT > thread."); > + cmdLineOptions.addOption("swing", false, "Synonym of \"-awt\"."); > + List builtinOptionNames = Arrays.asList(new String[]{ > + > "-o","-script","-h","--help","-v","--version","-awt","-swing"}); > + > // -D options will be added to the system properties > Properties sysProps = System.getProperties(); > > @@ -144,18 +181,18 @@ > // -D args will not be copied into the filteredArgList. > if (arg.startsWith("-D") && (arg.length() > 2)) { > arg = arg.substring(2); > - int ePos = arg.indexOf("="); > - if(ePos==-1 || ePos==0 || ePos==arg.length()-1) > - System.err.println("Invalid system > property: \"" + arg + "\"."); > - sysProps.setProperty(arg.substring(0,ePos), > arg.substring(ePos+1)); > + int ePos = arg.indexOf("="); > + if(ePos==-1 || ePos==0 || ePos==arg.length()-1) > + System.err.println("Invalid system property: \"" + arg > + "\"."); > + sysProps.setProperty(arg.substring(0,ePos), > arg.substring(ePos+1)); > } else { > // add this to the filtered list of arguments > filteredArgList.add(arg); > > // add additional "-?" options to the options object. if > this is not done > - // the only options allowed would be "-o" and "-script". > + // the only options allowed would be the builtin-ones. > if (arg.startsWith("-") && arg.length() > 1) { > - if (!(arg.equals("-o") && arg.equals("-script"))) { > + if (!(builtinOptionNames.contains(arg))) { > cmdLineOptions.addOption(arg.substring(1, > arg.length()), true, "dynamic option"); > } > } > @@ -167,7 +204,7 @@ > filteredArgList.toArray(filterArgs); > > // parse the command line > - Parser parser = new GnuParser(); > + Parser parser = new org.apache.commons.cli.GnuParser(); > return parser.parse(cmdLineOptions, filterArgs); > } > > > > > 1.24 +4 -0 jakarta-commons/jelly/xdocs/changes.xml > > Index: changes.xml > =================================================================== > RCS file: /home/cvs/jakarta-commons/jelly/xdocs/changes.xml,v > retrieving revision 1.23 > retrieving revision 1.24 > diff -u -r1.23 -r1.24 > --- changes.xml 22 Nov 2004 03:05:07 -0000 1.23 > +++ changes.xml 24 Jan 2005 00:34:06 -0000 1.24 > @@ -24,6 +24,10 @@ > <author email="[EMAIL PROTECTED]">dIon Gillard</author> > </properties> > <body> > + <release version="1.0-RC2" date="in CVS"> > + <action dev="polx" type="fix" issue="JELLY-85">Removed > instance-based ThreadLocal substituting a JellyContext-based > tag-caching.</action> > + <action dev="polx" type="add" issue="JELLY-145">jelly -h or --help > responds a help and jelly -v or --version responds the version.</action> > + </release> > <release version="1.0-RC1" date="2004-11-22"> > <action dev="dion" type="fix" issue="JELLY-148" due-to="Hans > Gilde">Huge memory leak resulting from the use of ThreadLocal.</action> > <action dev="dion" type="fix" issue="JELLY-138">Character data is > flushed by XMLOuput while XML data isn't.</action> > > > > 1.92 +25 -4 jakarta-commons/jelly/maven.xml > > Index: maven.xml > =================================================================== > RCS file: /home/cvs/jakarta-commons/jelly/maven.xml,v > retrieving revision 1.91 > retrieving revision 1.92 > diff -u -r1.91 -r1.92 > --- maven.xml 19 Jan 2005 10:08:45 -0000 1.91 > +++ maven.xml 24 Jan 2005 00:34:06 -0000 1.92 > @@ -43,10 +43,19 @@ > </copy> > </util:available> > </postGoal> > - <!-- ================================================================== > --> > + <!-- > ================================================================== --> > <!-- END: C O M M O N S - B U I L D > --> > <!-- ================================================================== > --> > > + <!-- build the timestamp after compiling --> > + <postGoal name="java:compile"> > + <echo > file="${maven.build.dest}/org/apache/commons/jelly/jelly-version.txt" > + >${pom.currentVersion}</echo> > + <tstamp><format property="now" pattern="yyyy-MM-dd kk:mm:ss > zzz"/></tstamp> > + <echo > file="${maven.build.dest}/org/apache/commons/jelly/jelly-build-date.txt" > + >${now}</echo> > + </postGoal> > + > <!-- create the lib and bin directories in the binary distro --> > <preGoal name="dist:build"> > <echo>About to create lib and bin directories in > ${maven.dist.assembly.dir}</echo> > @@ -383,6 +392,7 @@ > <property name="doBuildAll" value="false"/> > <property name="fatJarPath" > value="${maven.build.dir}/fatjelly.jar"/> > <property name="classpathFile" > value="${maven.build.dir}/classpath-with-deps.txt"/> > + <property name="mergedDepsFile" > value="${maven.build.dir}/mergedDeps.xml"/> > > <!-- if we need to build, we need to build first jelly --> > <j:if test="${doBuildAll}"><attainGoal > name="jar:install-snapshot"/></j:if> > @@ -417,9 +427,9 @@ > > <j:forEach var="reactorProject" items="${reactorProjects}"> > <j:forEach var="dep" items="${reactorProject.dependencies}"> > - <j:if test="${dep.artifactId eq > 'commons-jelly'}">${dep.setVersion("SNAPSHOT")}</j:if> > - ${deps.add(dep)} > - </j:forEach> > + <j:if test="${dep.artifactId eq > 'commons-jelly'}">${dep.setVersion("SNAPSHOT")}</j:if> > + ${deps.add(dep)} > + </j:forEach> > </j:forEach> > <j:forEach var="tl" items="${jellyTaglibNames}"> > <j:new var="tlD" > className="org.apache.maven.project.Dependency"/> > @@ -455,6 +465,17 @@ > <echo>Adding jar > ${maven.repo.local}/${dep.groupId}/${dep.type}s/${dep.artifact}.</echo> > </j:forEach> > </jar> > + </j:if> > + > + <j:if test="${!empty(mergedDepsFile)}"> > + <j:file prettyPrint="true" name="${mergedDepsFile}"> > + <dependencyList project="commons-jelly" > + withAddOns="${tagLibs}"> > + <j:forEach var="dep" items="${deps}"> > + <dependency groupId="${dep.groupId}" > artifactId="${dep.artifactId}" version="${dep.version}"/> > + </j:forEach> > + </dependencyList> > + </j:file> > </j:if> > > </goal> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]