You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ps...@apache.org on 2006/01/14 06:40:29 UTC

svn commit: r368983 - in /logging/chainsaw/trunk: ./ anttasks-src/ anttasks-src/org/ anttasks-src/org/apache/ anttasks-src/org/apache/chainsaw/ anttasks-src/org/apache/chainsaw/ant/ packaging/

Author: psmith
Date: Fri Jan 13 21:40:22 2006
New Revision: 368983

URL: http://svn.apache.org/viewcvs?rev=368983&view=rev
Log:
Modified Chainsaw 'webstart' build process so that it can 
automatically generate the .sh and .bat files required.

I was getting really tired of having to manually change these, so created
a custom Ant task to assist.  Placed the Ant task source code in it's
own source folder out of the way of the rest of the app, as it is only
needed during the build process.

Added:
    logging/chainsaw/trunk/anttasks-src/
    logging/chainsaw/trunk/anttasks-src/README.txt
    logging/chainsaw/trunk/anttasks-src/org/
    logging/chainsaw/trunk/anttasks-src/org/apache/
    logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/
    logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/ant/
    logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/ant/CreateShellScripts.java
Removed:
    logging/chainsaw/trunk/packaging/chainsaw.bat
    logging/chainsaw/trunk/packaging/chainsaw.sh
Modified:
    logging/chainsaw/trunk/build.xml

Added: logging/chainsaw/trunk/anttasks-src/README.txt
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/anttasks-src/README.txt?rev=368983&view=auto
==============================================================================
--- logging/chainsaw/trunk/anttasks-src/README.txt (added)
+++ logging/chainsaw/trunk/anttasks-src/README.txt Fri Jan 13 21:40:22 2006
@@ -0,0 +1,3 @@
+This source folder contains Ant taskdefs used
+by the Chainsaw build system.  They are not needed 
+for running Chainsaw, only for packaging it.
\ No newline at end of file

Added: logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/ant/CreateShellScripts.java
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/ant/CreateShellScripts.java?rev=368983&view=auto
==============================================================================
--- logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/ant/CreateShellScripts.java (added)
+++ logging/chainsaw/trunk/anttasks-src/org/apache/chainsaw/ant/CreateShellScripts.java Fri Jan 13 21:40:22 2006
@@ -0,0 +1,121 @@
+package org.apache.chainsaw.ant;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+
+/**
+ * This Ant task creates the necessary .bat and .sh files required to run Chainsaw
+ * on the commandline.  This task was created because it was getting VERY annoying
+ * to constantly maintain 2 script files as the Jar file names kept changing during
+ * the log4j 1.3 alpha stage, and as we (the Chainsaw developers) added dependencies
+ * as we added functionality.
+ * 
+ * This task takes and outputLocation as a , and a set of FileSets which form the
+ * basis of the classpath that is required to run Chainsaw.
+ * 
+ * @author psmith
+ *
+ */
+public class CreateShellScripts extends Task {
+
+
+    private String outputLocation;
+
+    private Vector fileSets = new Vector();
+
+    public String getOutputLocation() {
+        return outputLocation;
+    }
+
+    public void setOutputLocation(String outputLocation) {
+        this.outputLocation = outputLocation;
+    }
+
+    public void execute() throws BuildException {
+        super.execute();
+        File outputLocationDir = new File(getOutputLocation());
+        if(!outputLocationDir.exists()) {
+            log("Creating director(ies) ->" + getOutputLocation());
+            outputLocationDir.mkdirs();
+        }
+        Collection filenames = getFilenames();
+        try {
+            createUnixShellScript(outputLocationDir, filenames);
+            createBatShellScript(outputLocationDir, filenames);
+        } catch (Exception e) {
+            throw new BuildException("Failed to create Scripts",e);
+        }        
+    }
+
+    public void addFileSet(FileSet fileSet) {
+        fileSets.add(fileSet);
+    }
+
+    private void createBatShellScript(File outputLocationDir, Collection filenames) throws IOException {
+        File unixScript = new File(outputLocationDir, "chainsaw.bat");
+        
+        log("Creating Windows .bat script: " + unixScript.getAbsolutePath());
+        
+        Writer writer = new FileWriter(unixScript);
+        writeExecutionLine(filenames, writer, ';');
+        writer.close();
+    }
+
+    private void createUnixShellScript(File outputLocationDir, Collection fileNames) throws IOException {
+        File unixScript = new File(outputLocationDir, "chainsaw.sh");
+        
+        log("Creating Unix script: " + unixScript.getAbsolutePath());
+        
+        Writer writer = new FileWriter(unixScript);
+        writer.write("#!/bin/sh\n");
+        writeExecutionLine(fileNames, writer, ':');
+        writer.close();
+    }
+
+    
+    private void writeExecutionLine(Collection fileNames, Writer writer, char jarSeparator) throws IOException {
+        writer.write("java -classpath ");
+        for (Iterator iter = fileNames.iterator(); iter.hasNext();) {
+            String fileName = (String) iter.next();
+            writer.write(fileName);
+            if(iter.hasNext()) {
+                writer.write(jarSeparator);
+            }
+        }
+        writer.write(" org.apache.log4j.chainsaw.LogUI" );
+        writer.write("\n");
+    }
+
+    private Collection getFilenames() {
+        List jars = new ArrayList();
+        for (Iterator iter = fileSets.iterator(); iter.hasNext();) {
+            FileSet fileSet = (FileSet) iter.next();
+            DirectoryScanner ds = fileSet.getDirectoryScanner(getProject()); // 3
+            String[] includedFiles = ds.getIncludedFiles();
+            for (int i = 0; i < includedFiles.length; i++) {
+                String filename = includedFiles[i].replace('\\', '/'); // 4
+                filename = filename.substring(filename.lastIndexOf("/") + 1);
+                // if (foundLocation==null && file.equals(filename)) {
+                // File base = ds.getBasedir(); // 5
+                // File found = new File(base, includedFiles[i]);
+                // foundLocation = found.getAbsolutePath();
+                // }
+                jars.add(filename);
+            }
+        }
+        return jars;
+    }
+
+}

Modified: logging/chainsaw/trunk/build.xml
URL: http://svn.apache.org/viewcvs/logging/chainsaw/trunk/build.xml?rev=368983&r1=368982&r2=368983&view=diff
==============================================================================
--- logging/chainsaw/trunk/build.xml (original)
+++ logging/chainsaw/trunk/build.xml Fri Jan 13 21:40:22 2006
@@ -254,27 +254,61 @@
     </jar>
   </target>
   
-  <target name="webstart" >
+	<target name="shellscript-taskdef">
+	    <javac deprecation="${deprecation}"
+	           srcdir="anttasks-src"
+	    	   debug="${debug}"
+	           destdir="${javac.dest}">
+	      <patternset>
+	        <include name="**/*.java"/>
+	      </patternset>
+	      <classpath refid="compile.classpath"/>   
+	    </javac>	
+		
+		<taskdef name="createshellscripts" classpathref="compile.classpath" classname="org.apache.chainsaw.ant.CreateShellScripts" />
+	</target>
+	
+	<target name="testshellscripts" depends="shellscript-taskdef">
+
+	</target>
+	
+  <target name="webstart" depends="shellscript-taskdef">
     <property name="webstart" value="true"/>
     <antcall target="chainsaw.jar"/>
     <antcall target="webstart-dependant-receivers.jar"/>
     
+  	<delete dir="webstart-dist"></delete>
+  	
+  	<!-- TODO Now copy all the jars into a new webstart-dist directory -->
+     <copy todir="webstart-dist">
+  		<fileset file="packaging/chainsaw.*"/>
+     	<fileset dir="lib" />
+     	<fileset dir=".">
+     		<include name="log4j-chain*.jar"/>
+     		<include name="webstart*.jar"/>
+     	</fileset>
+  	</copy>
+  	
+	<createshellscripts outputLocation="webstart-dist">
+		<fileset dir="webstart-dist" includes="*.jar"/>
+	</createshellscripts>
+  	
     <input
      message="Please enter key password:"
      addproperty="keypass"
      />
     <signjar verbose="false" keystore="${keystore}" alias="${alias}" storepass="${storepass}" keypass="${keypass}" >
-      <fileset dir=".">
+      <fileset dir="webstart-dist">
         <include name="*.jar"/>
       </fileset>
     </signjar>
     
     <zip destfile="chainsaw-bundle.zip" >
-      <zipfileset dir="."> 
+      <zipfileset dir="webstart-dist"> 
         <include name="*.jar"/>
+        <include name="*.bat"/>
+        <include name="*.sh"/>
       </zipfileset>
-      <fileset file="${jakarta-oro.jar}"/>
-      <fileset file="packaging/chainsaw.*"/>
     </zip>
   </target>
 	



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org