incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nickcha...@apache.org
Subject svn commit: rev 30975 - in incubator/depot/trunk/version/src: java java/org/apache/depot/version/ant/stamp java/org/apache/depot/version/generation templates test/java/org/apache/depot/version/ant/stamp
Date Fri, 30 Jul 2004 08:49:16 GMT
Author: nickchalko
Date: Fri Jul 30 01:49:14 2004
New Revision: 30975

Added:
   incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/stamp/VersionGeneratorTask.java
   incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/Skeleton.java
   incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/VersionSourceGenerator.java
   incubator/depot/trunk/version/src/templates/
   incubator/depot/trunk/version/src/templates/Version.java.jet
   incubator/depot/trunk/version/src/templates/version.skeleton
Modified:
   incubator/depot/trunk/version/src/java/depot-version-antlib.xml
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/VersionGeneratorTaskTest.java
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/version.xml
Log:
Using eclipse JET to generate the VersionSourceGenerator.

Modified: incubator/depot/trunk/version/src/java/depot-version-antlib.xml
==============================================================================
--- incubator/depot/trunk/version/src/java/depot-version-antlib.xml	(original)
+++ incubator/depot/trunk/version/src/java/depot-version-antlib.xml	Fri Jul 30 01:49:14 2004
@@ -13,6 +13,10 @@
 	<!-- Generate a version class in a *.java (does NOT compile it) -->
    	<taskdef name="version-stamp" 
 		classname="org.apache.depot.version.ant.stamp.VersionMarkerGeneratorTask"/>
+		
+	<!-- Generate a version class in a *.java (does NOT compile it) -->
+   	<taskdef name="version-stamp2" 
+		classname="org.apache.depot.version.ant.stamp.VersionGeneratorTask"/>
 
 	<!-- Document an environment -->
 	<taskdef name="version-environment"

Added: incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/stamp/VersionGeneratorTask.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/stamp/VersionGeneratorTask.java
Fri Jul 30 01:49:14 2004
@@ -0,0 +1,124 @@
+/*
+ * Copyright  2004 The Apache Software Foundation
+ *
+ *  Licensed 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.depot.version.ant.stamp;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.depot.version.VersionMarker;
+import org.apache.depot.version.ant.ClassGeneratorTask;
+import org.apache.depot.version.generation.VersionSourceGenerator;
+import org.apache.depot.version.generation.source.ClassGenerator;
+import org.apache.depot.version.generation.source.DependentVersionMarkerClassGenerator;
+import org.apache.depot.version.generation.source.StandaloneVersionMarkerClassGenerator;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+/**
+ * Generate Version class.
+ * 
+ * @author: $Author: arb_jack $
+ * @version: $Revision: 1.5 $
+ */
+public class VersionGeneratorTask extends ClassGeneratorTask {
+
+	private java.util.Date m_date = new java.util.Date();
+
+	private boolean m_debug = false;
+
+	private boolean m_dependent = false;
+
+	private final List m_attributeList = new ArrayList();
+
+	public VersionGeneratorTask() {
+		super();
+	}
+
+	/**
+	 * ant entry point: Creates the build version java file.
+	 */
+	public void performExecute() throws org.apache.tools.ant.BuildException {
+		Writer out = null;
+		try {
+			VersionMarker versionMarker = getVersionMarker();
+
+			String packageName = versionMarker.getId() + ".version";
+
+			VersionSourceGenerator vsg = new VersionSourceGenerator();
+			String source = vsg.generate(packageName, versionMarker);
+
+			out = getFileWriter(packageName);
+			out.write(source);
+
+		} catch (BuildException e) {
+			throw e;
+		} catch (Exception e) {
+			throw new BuildException(e, getLocation());
+		} finally {
+			if (out != null) {
+				try {
+					out.close();
+				} catch (IOException e) {
+					throw new BuildException(e, getLocation());
+				}
+			}
+		}
+	}
+
+	/**
+	 * @param packageName
+	 * @return @throws
+	 *         IOException
+	 */
+	private FileWriter getFileWriter(String packageName) throws IOException {
+		File fullPath = new File(getDest() ,packageName.replace('.', '/'));
+		if (!fullPath.exists()) {
+			if (!fullPath.mkdirs()) {
+				throw new BuildException("Unable to create dir " + fullPath);
+			}
+		}
+		File file = new File(fullPath, "Version.java");
+		FileWriter fw = new FileWriter(file);
+
+		return fw;
+	}
+
+	/**
+	 * Set the generated file's dependency (standalone or dependen upon k-v)..
+	 * 
+	 * @param newDependent
+	 *            boolean
+	 */
+	public void setDependent(boolean newDependent) {
+		m_dependent = newDependent;
+	}
+
+	/**
+	 * Set the generated file's debug field..
+	 * 
+	 * @param newDebug
+	 *            boolean
+	 */
+	public void setDebug(boolean newDebug) {
+		m_debug = newDebug;
+	}
+}
\ No newline at end of file

Added: incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/Skeleton.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/Skeleton.java
Fri Jul 30 01:49:14 2004
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.depot.version.generation;
+
+import org.apache.depot.version.VersionMarker;
+
+/**
+ * @author nick
+ * 
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Generation - Code and Comments
+ */
+public class Skeleton {
+	final VersionMarker depotVersion;
+
+	public Skeleton() {
+		VersionMarker temp = VersionMarker.UNKNOWN;
+		try {
+			temp = new org.apache.depot.version.version.Version();
+
+		} catch (org.apache.depot.version.VersionException e) {
+			// Ignore
+		}
+		depotVersion = temp;
+	}
+
+	String getUser() {
+		return null;
+	}
+
+	String getHost() {
+		return null;
+	}
+
+	String getDate() {
+		return null;
+	}
+
+}
\ No newline at end of file

Added: incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/VersionSourceGenerator.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/VersionSourceGenerator.java
Fri Jul 30 01:49:14 2004
@@ -0,0 +1,90 @@
+package org.apache.depot.version.generation;
+
+import org.apache.depot.version.VersionMarker;
+
+/*
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.
+ */
+
+public final class VersionSourceGenerator extends org.apache.depot.version.generation.Skeleton
+{
+                     
+  protected final String NL = System.getProperties().getProperty("line.separator");
+  protected final String TEXT_1 = "/*" + NL + " * DO NOT CHECK IN." + NL + " *.This is a
autogenerated file.  " + NL + " */" + NL + "package ";
+  protected final String TEXT_2 = "; " + NL + "" + NL + "import java.util.Date;" + NL + ""
+ NL + "/**" + NL + " * ";
+  protected final String TEXT_3 = " version ";
+  protected final String TEXT_4 = " ." + NL + " * Generated at ";
+  protected final String TEXT_5 = " " + NL + " * at  HOST" + NL + " * by USER " + NL + "
* @author <a href=\"http://incubator.apache.org/depot\">Depot Version</a> " +
NL + " *         from the <a href=\"http://incubator.apache.org/\">Apache Incubator</a>,
" + NL + "           version ";
+  protected final String TEXT_6 = NL + " * @version ";
+  protected final String TEXT_7 = NL + " */" + NL + "public class Version {" + NL + "\tpublic
final static Version INSTANCE = new Version();" + NL + "\t" + NL + "\tprivate Version()  {}"
+ NL + "\t" + NL + "\t/**" + NL + "\t * The user that built ";
+  protected final String TEXT_8 = " was ";
+  protected final String TEXT_9 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_10 = "\"" + NL + "\t */" + NL + "\tpublic String getUser()
{return \"";
+  protected final String TEXT_11 = "\"; }" + NL + "\t" + NL + "\t\t" + NL + "\t/**" + NL
+ "\t * ";
+  protected final String TEXT_12 = " was built on ";
+  protected final String TEXT_13 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_14 = "\"" + NL + "\t */" + NL + "\tpublic String getHost()
{return \"";
+  protected final String TEXT_15 = "\"; }" + NL + "\t" + NL + "\t\t" + NL + "\t/**" + NL
+ "\t * ";
+  protected final String TEXT_16 = " was built at ";
+  protected final String TEXT_17 = "." + NL + "\t * @return the Date \"";
+  protected final String TEXT_18 = "\"" + NL + "\t */" + NL + "\tpublic Date getDate() {return
";
+  protected final String TEXT_19 = "; }" + NL + "\t" + NL + "\t" + NL + "\tpublic String
toString() {return \"";
+  protected final String TEXT_20 = "\";}" + NL + "}    ";
+
+    public String generate(String packageName,   VersionMarker marker)
+  {
+    StringBuffer stringBuffer = new StringBuffer();
+    stringBuffer.append(TEXT_1);
+    stringBuffer.append(packageName);
+    stringBuffer.append(TEXT_2);
+    stringBuffer.append(marker.getId());
+    stringBuffer.append(TEXT_3);
+    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_4);
+    stringBuffer.append(new java.util.Date() );
+    stringBuffer.append(TEXT_5);
+    stringBuffer.append(depotVersion.getLongVersion() );
+    stringBuffer.append(TEXT_6);
+    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_7);
+    stringBuffer.append(marker.getId());
+    stringBuffer.append(TEXT_8);
+    stringBuffer.append(getUser());
+    stringBuffer.append(TEXT_9);
+    stringBuffer.append(getUser());
+    stringBuffer.append(TEXT_10);
+    stringBuffer.append(getUser());
+    stringBuffer.append(TEXT_11);
+    stringBuffer.append(marker.getId());
+    stringBuffer.append(TEXT_12);
+    stringBuffer.append(getHost());
+    stringBuffer.append(TEXT_13);
+    stringBuffer.append(getHost());
+    stringBuffer.append(TEXT_14);
+    stringBuffer.append(getHost());
+    stringBuffer.append(TEXT_15);
+    stringBuffer.append(marker.getId());
+    stringBuffer.append(TEXT_16);
+    stringBuffer.append(getDate());
+    stringBuffer.append(TEXT_17);
+    stringBuffer.append(getDate());
+    stringBuffer.append(TEXT_18);
+    stringBuffer.append(getDate());
+    stringBuffer.append(TEXT_19);
+    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_20);
+    return stringBuffer.toString();
+  }
+}
\ No newline at end of file

Added: incubator/depot/trunk/version/src/templates/Version.java.jet
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/templates/Version.java.jet	Fri Jul 30 01:49:14 2004
@@ -0,0 +1,52 @@
+<%@ jet
+    package="org.apache.depot.version.generation"
+    class="VersionSourceGenerator"
+    skeleton="version.skeleton"
+    imports="org.apache.depot.version.VersionMarker "
+    %>
+/*
+ * DO NOT CHECK IN.
+ *.This is a autogenerated file.  
+ */
+package <%=packageName%>; 
+
+import java.util.Date;
+
+/**
+ * <%=marker.getId()%> version <%=marker.getLongVersion()%> .
+ * Generated at <%=new java.util.Date() %> 
+ * at  HOST
+ * by USER 
+ * @author <a href="http://incubator.apache.org/depot">Depot Version</a> 
+ *         from the <a href="http://incubator.apache.org/">Apache Incubator</a>,

+           version <%=depotVersion.getLongVersion() %>
+ * @version <%=marker.getLongVersion()%>
+ */
+public class Version {
+	public final static Version INSTANCE = new Version();
+	
+	private Version()  {}
+	
+	/**
+	 * The user that built <%=marker.getId()%> was <%=getUser()%>.
+	 * @return the String "<%=getUser()%>"
+	 */
+	public String getUser() {return "<%=getUser()%>"; }
+	
+		
+	/**
+	 * <%=marker.getId()%> was built on <%=getHost()%>.
+	 * @return the String "<%=getHost()%>"
+	 */
+	public String getHost() {return "<%=getHost()%>"; }
+	
+		
+	/**
+	 * <%=marker.getId()%> was built at <%=getDate()%>.
+	 * @return the Date "<%=getDate()%>"
+	 */
+	public Date getDate() {return <%=getDate()%>; }
+	
+	
+	public String toString() {return "<%=marker.getLongVersion()%>";}
+}    
\ No newline at end of file

Added: incubator/depot/trunk/version/src/templates/version.skeleton
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/version/src/templates/version.skeleton	Fri Jul 30 01:49:14 2004
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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.
+ */
+
+public final class CLASS extends org.apache.depot.version.generation.Skeleton
+{
+                     
+    public String generate(String packageName,   VersionMarker marker)
+    {
+        return "";
+    }   
+
+}
\ No newline at end of file

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/VersionGeneratorTaskTest.java
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/VersionGeneratorTaskTest.java
(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/VersionGeneratorTaskTest.java
Fri Jul 30 01:49:14 2004
@@ -45,6 +45,10 @@
         executeTarget("testVersionString");
     }
 
+    public void testVersion2String() {
+        executeTarget("testVersion2String");
+    }
+    
     public void testVersionString2() {
         executeTarget("testVersionString2");
     }

Modified: incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/version.xml
==============================================================================
--- incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/version.xml
(original)
+++ incubator/depot/trunk/version/src/test/java/org/apache/depot/version/ant/stamp/version.xml
Fri Jul 30 01:49:14 2004
@@ -63,6 +63,17 @@
         </version-stamp>
         <antcall target="compile"/>
     </target>
+    
+        <target name="testVersion2String" depends="init">
+        <version-stamp2 dest="transient/test" overWrite="true">
+            <versionMarker versionId="org.apache.acorn.version" version="1.2">
+                <attribute name="foo" value="bar"/>
+            </versionMarker>
+        </version-stamp2>
+        <antcall target="compile"/>
+    </target>
+    
+    
     <target name="compile">
         <javac srcdir="transient/test" destdir="transient/classes">
             <classpath path="transient/classes"/>

Mime
View raw message