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 35644 - in incubator/depot/trunk/version/src: java/org/apache/depot/version/generation templates
Date Tue, 03 Aug 2004 20:59:18 GMT
Author: nickchalko
Date: Tue Aug  3 13:59:17 2004
New Revision: 35644

Modified:
   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/VersionSourceGenerator.java.jet
Log:
Added attributes.

Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/Skeleton.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/Skeleton.java
(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/Skeleton.java
Tue Aug  3 13:59:17 2004
@@ -26,50 +26,65 @@
  * @version
  */
 public class Skeleton {
-	final VersionMarker depotVersion;
+    final VersionMarker depotVersion;
 
-	final Date date = new Date();
+    final Date date = new Date();
 
-	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;
-	}
-
-	/**
-	 * The user name from the System Property user.name
-	 * 
-	 * @return the user name as a String.
-	 */
-	String getUser() {
-		return System.getProperty("user.name");
-	}
-
-	/**
-	 * The IP and hostname of this machine
-	 * 
-	 * @return hostname/ip as a String.
-	 */
-	String getHost() {
-		try {
-			return java.net.InetAddress.getLocalHost().toString();
-		} catch (UnknownHostException e) {
-			return "UknownHost";
-		}
-	}
-
-	/**
-	 * The date the build was started.
-	 * 
-	 * @return Date the build was started.
-	 */
-	Date getDate() {
-		return date;
-	}
+    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;
+    }
+
+    /**
+     * The user name from the System Property user.name
+     * 
+     * @return the user name as a String.
+     */
+    String getUser() {
+        return System.getProperty("user.name");
+    }
+
+    /**
+     * The IP and hostname of this machine
+     * 
+     * @return hostname/ip as a String.
+     */
+    String getHost() {
+        try {
+            return java.net.InetAddress.getLocalHost().toString();
+        } catch (UnknownHostException e) {
+            return "UknownHost";
+        }
+    }
+
+    /**
+     * The date the build was started.
+     * 
+     * @return Date the build was started.
+     */
+    Date getDate() {
+        return date;
+    }
+
+    String getValueFrom(Object value) {
+
+        if (value instanceof String) {
+            return "\"" + value.toString() + "\"";
+        }
+        if (value instanceof Date) {
+            return "new java.util.Date(" + Long.toString(((Date) value).getTime()) + "L)";
+        }
+        if (value instanceof Integer) {
+            return value.toString();
+        }
+        return ((null == value) ? "null" : "\"" + value.getClass() + " = " + value.toString()
+ "\"");
+        // TODO better defualt case
+    }
 
 }

Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/VersionSourceGenerator.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/VersionSourceGenerator.java
(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/generation/VersionSourceGenerator.java
Tue Aug  3 13:59:17 2004
@@ -1,6 +1,8 @@
 package org.apache.depot.version.generation;
 
 import org.apache.depot.version.VersionMarker;
+import java.util.Iterator;
+import java.util.Map;
 
 /*
  * Copyright 2004 The Apache Software Foundation
@@ -24,47 +26,52 @@
   protected final String NL = System.getProperties().getProperty("line.separator");
   protected final String TEXT_1 = NL + "/* " + NL + " *" + NL + " * NOTE: Automatically Generated
File (see Depot Version for the Apache Incubator)" + NL + " * NOTE: http://incubator.apache.org/depot/version"
+ NL + " * NOTE: Ant Task: version-stamp" + NL + " * NOTE: AntLib:   apache-version" + NL
+ " *" + NL + " * $Header: ";
   protected final String TEXT_2 = ".java $" + NL + " *" + NL + " */" + NL + "package ";
-  protected final String TEXT_3 = "; " + NL + "" + NL + "import java.util.Date;" + NL + ""
+ NL + "/**" + NL + " * A autogenerated VersionStamp class for ";
+  protected final String TEXT_3 = "; " + NL + "" + NL + "import java.util.Collections;" +
NL + "import java.util.Date;" + NL + "import java.util.HashMap;" + NL + "import java.util.Map;"
+ NL + "/**" + NL + " * A autogenerated VersionStamp class for ";
   protected final String TEXT_4 = " ." + NL + " * Generated at ";
   protected final String TEXT_5 = " " + NL + " * on ";
   protected final String TEXT_6 = NL + " * by ";
   protected final String TEXT_7 = 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_8 = NL + " * @version ";
   protected final String TEXT_9 = NL + " */" + NL + "public final class ";
-  protected final String TEXT_10 = " {" + NL + "\tprivate final static  ";
+  protected final String TEXT_10 = " { " + NL + "\t/* SINGLETON PATTERN */" + NL + "\tprivate
final static  ";
   protected final String TEXT_11 = " INSTANCE = new  ";
-  protected final String TEXT_12 = "();" + NL + "\t" + NL + "\tpublic static ";
-  protected final String TEXT_13 = " getInstance() {return INSTANCE ;}" + NL + "\t" + NL
+ "\tprivate  ";
-  protected final String TEXT_14 = "()  {}" + NL + "\t" + NL + "\t/**" + NL + "\t * The user
that built ";
-  protected final String TEXT_15 = " was ";
-  protected final String TEXT_16 = "." + NL + "\t * @return the String \"";
-  protected final String TEXT_17 = "\"" + NL + "\t */" + NL + "\tpublic String getUser()
{return \"";
-  protected final String TEXT_18 = "\"; }" + NL + "\t" + NL + "\t\t" + NL + "\t/**" + NL
+ "\t * ";
-  protected final String TEXT_19 = " was built on ";
-  protected final String TEXT_20 = "." + NL + "\t * @return the String \"";
-  protected final String TEXT_21 = "\"" + NL + "\t */" + NL + "\tpublic String getHost()
{return \"";
-  protected final String TEXT_22 = "\"; }" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
-  protected final String TEXT_23 = " was built at ";
-  protected final String TEXT_24 = "." + NL + "\t * @return the Date \"";
-  protected final String TEXT_25 = "\"" + NL + "\t */" + NL + "\tpublic Date getDate() {return
new Date(";
-  protected final String TEXT_26 = "l); }" + NL + "\t" + NL + "\t/**" + NL + "\t * The ID
of the Version Specification." + NL + "\t * @return ID of the Version Specification." + NL
+ "\t * @see org.apache.depot.version.specification.VersionSpecificationFactory" + NL + "\t
*/" + NL + "\tpublic String getSpecificationId(){return \"";
-  protected final String TEXT_27 = "\";} " + NL + "\t" + NL + "\t" + NL + "\t/**" + NL +
"\t * ";
-  protected final String TEXT_28 = " ";
-  protected final String TEXT_29 = "." + NL + "\t * @return the String \"";
-  protected final String TEXT_30 = "\"" + NL + "\t */" + NL + "\tpublic String getShortVersion()
{return \"";
-  protected final String TEXT_31 = "\";}" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
-  protected final String TEXT_32 = " ";
-  protected final String TEXT_33 = "." + NL + "\t * @return the String \"";
-  protected final String TEXT_34 = "\"" + NL + "\t */" + NL + "\tpublic String getLongVersion()
{return \"";
-  protected final String TEXT_35 = "\";}" + NL + "" + NL + "\t/**" + NL + "\t * ";
-  protected final String TEXT_36 = " ";
-  protected final String TEXT_37 = "." + NL + "\t * @return the String \"";
-  protected final String TEXT_38 = "\"" + NL + "\t */" + NL + "\tpublic String getDefaultVersion()
{return \"";
-  protected final String TEXT_39 = "\";}\t" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
-  protected final String TEXT_40 = " ";
-  protected final String TEXT_41 = "." + NL + "\t * @return the String \"";
-  protected final String TEXT_42 = "\"" + NL + "\t */" + NL + "\tpublic String toString()
{return \"";
-  protected final String TEXT_43 = "\";}" + NL + "}    ";
+  protected final String TEXT_12 = "();" + NL + "    public static ";
+  protected final String TEXT_13 = " getInstance() {return INSTANCE ;}" + NL + "    " + NL
+ "    " + NL + "    private final Map  attributes;" + NL + "" + NL + "" + NL + "\t" + NL
+ "\tprivate  ";
+  protected final String TEXT_14 = "()  {" + NL + "\tMap temp = new HashMap();" + NL + "\t";
+  protected final String TEXT_15 = NL + "    temp.put(";
+  protected final String TEXT_16 = ",";
+  protected final String TEXT_17 = NL + "             ";
+  protected final String TEXT_18 = ");// ";
+  protected final String TEXT_19 = NL + "\tattributes = Collections.unmodifiableMap(temp);"
+ NL + "\t" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * The user that built ";
+  protected final String TEXT_20 = " was ";
+  protected final String TEXT_21 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_22 = "\"" + NL + "\t */" + NL + "\tpublic String getUser()
{return \"";
+  protected final String TEXT_23 = "\"; }" + NL + "\t" + NL + "\t\t" + NL + "\t/**" + NL
+ "\t * ";
+  protected final String TEXT_24 = " was built on ";
+  protected final String TEXT_25 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_26 = "\"" + NL + "\t */" + NL + "\tpublic String getHost()
{return \"";
+  protected final String TEXT_27 = "\"; }" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
+  protected final String TEXT_28 = " was built at ";
+  protected final String TEXT_29 = "." + NL + "\t * @return the Date \"";
+  protected final String TEXT_30 = "\"" + NL + "\t */" + NL + "\tpublic Date getDate() {return
new Date(";
+  protected final String TEXT_31 = "l); }" + NL + "\t" + NL + "\t/**" + NL + "\t * The ID
of the Version Specification." + NL + "\t * @return ID of the Version Specification." + NL
+ "\t * @see org.apache.depot.version.specification.VersionSpecificationFactory" + NL + "\t
*/" + NL + "\tpublic String getSpecificationId(){return \"";
+  protected final String TEXT_32 = "\";} " + NL + "\t" + NL + "\t" + NL + "\t/**" + NL +
"\t * ";
+  protected final String TEXT_33 = " ";
+  protected final String TEXT_34 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_35 = "\"" + NL + "\t */" + NL + "\tpublic String getShortVersion()
{return \"";
+  protected final String TEXT_36 = "\";}" + NL + "\t" + NL + "\t/**" + NL + "\t * ";
+  protected final String TEXT_37 = " ";
+  protected final String TEXT_38 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_39 = "\"" + NL + "\t */" + NL + "\tpublic String getLongVersion()
{return \"";
+  protected final String TEXT_40 = "\";}" + NL + "" + NL + "\t/**" + NL + "\t * ";
+  protected final String TEXT_41 = " ";
+  protected final String TEXT_42 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_43 = "\"" + NL + "\t */" + NL + "\tpublic String getDefaultVersion()
{return \"";
+  protected final String TEXT_44 = "\";}\t" + NL + "" + NL + "" + NL + "\tpublic Map getAttributes
() {" + NL + "\t    return attributes;" + NL + "\t}" + NL + "" + NL + "" + NL + "\t" + NL
+ "\t/**" + NL + "\t * ";
+  protected final String TEXT_45 = " ";
+  protected final String TEXT_46 = "." + NL + "\t * @return the String \"";
+  protected final String TEXT_47 = "\"" + NL + "\t */" + NL + "\tpublic String toString()
{return \"";
+  protected final String TEXT_48 = "\";}" + NL + "}    ";
 
     public String generate(String packageName,  String className, VersionMarker marker)
   {
@@ -96,64 +103,79 @@
     stringBuffer.append(TEXT_13);
     stringBuffer.append(className);
     stringBuffer.append(TEXT_14);
-    stringBuffer.append(marker.getId());
+    
+	for (Iterator i = marker.getAttributes().entrySet().iterator(); i.hasNext();) {
+         Map.Entry entry = (Map.Entry) i.next();
+         // TODO need to escape key and value.
+         
     stringBuffer.append(TEXT_15);
-    stringBuffer.append(getUser());
+    stringBuffer.append(getValueFrom(entry.getKey()));
     stringBuffer.append(TEXT_16);
-    stringBuffer.append(getUser());
     stringBuffer.append(TEXT_17);
-    stringBuffer.append(getUser());
+    stringBuffer.append(getValueFrom(entry.getValue()));
     stringBuffer.append(TEXT_18);
-    stringBuffer.append(marker.getId());
+    stringBuffer.append(entry.getValue());
+    
+    }
     stringBuffer.append(TEXT_19);
-    stringBuffer.append(getHost());
+    stringBuffer.append(marker.getId());
     stringBuffer.append(TEXT_20);
-    stringBuffer.append(getHost());
+    stringBuffer.append(getUser());
     stringBuffer.append(TEXT_21);
-    stringBuffer.append(getHost());
+    stringBuffer.append(getUser());
     stringBuffer.append(TEXT_22);
-    stringBuffer.append(marker.getId());
+    stringBuffer.append(getUser());
     stringBuffer.append(TEXT_23);
-    stringBuffer.append(getDate());
+    stringBuffer.append(marker.getId());
     stringBuffer.append(TEXT_24);
-    stringBuffer.append(getDate());
+    stringBuffer.append(getHost());
     stringBuffer.append(TEXT_25);
-    stringBuffer.append(getDate().getTime());
+    stringBuffer.append(getHost());
     stringBuffer.append(TEXT_26);
-    stringBuffer.append(marker.getSpecification().getId());
+    stringBuffer.append(getHost());
     stringBuffer.append(TEXT_27);
     stringBuffer.append(marker.getId());
     stringBuffer.append(TEXT_28);
-    stringBuffer.append(marker.getShortVersion());
+    stringBuffer.append(getDate());
     stringBuffer.append(TEXT_29);
-    stringBuffer.append(marker.getShortVersion());
+    stringBuffer.append(getDate());
     stringBuffer.append(TEXT_30);
-    stringBuffer.append(marker.getShortVersion());
+    stringBuffer.append(getDate().getTime());
     stringBuffer.append(TEXT_31);
-    stringBuffer.append(marker.getId());
+    stringBuffer.append(marker.getSpecification().getId());
     stringBuffer.append(TEXT_32);
-    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(marker.getId());
     stringBuffer.append(TEXT_33);
-    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(marker.getShortVersion());
     stringBuffer.append(TEXT_34);
-    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(marker.getShortVersion());
     stringBuffer.append(TEXT_35);
-    stringBuffer.append(marker.getId());
+    stringBuffer.append(marker.getShortVersion());
     stringBuffer.append(TEXT_36);
-    stringBuffer.append(marker.getDefaultVersion());
+    stringBuffer.append(marker.getId());
     stringBuffer.append(TEXT_37);
-    stringBuffer.append(marker.getDefaultVersion());
+    stringBuffer.append(marker.getLongVersion());
     stringBuffer.append(TEXT_38);
-    stringBuffer.append(marker.getDefaultVersion());
+    stringBuffer.append(marker.getLongVersion());
     stringBuffer.append(TEXT_39);
-    stringBuffer.append(marker.getId());
-    stringBuffer.append(TEXT_40);
     stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_40);
+    stringBuffer.append(marker.getId());
     stringBuffer.append(TEXT_41);
-    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(marker.getDefaultVersion());
     stringBuffer.append(TEXT_42);
-    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(marker.getDefaultVersion());
     stringBuffer.append(TEXT_43);
+    stringBuffer.append(marker.getDefaultVersion());
+    stringBuffer.append(TEXT_44);
+    stringBuffer.append(marker.getId());
+    stringBuffer.append(TEXT_45);
+    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_46);
+    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_47);
+    stringBuffer.append(marker.getLongVersion());
+    stringBuffer.append(TEXT_48);
     return stringBuffer.toString();
   }
 }

Modified: incubator/depot/trunk/version/src/templates/VersionSourceGenerator.java.jet
==============================================================================
--- incubator/depot/trunk/version/src/templates/VersionSourceGenerator.java.jet	(original)
+++ incubator/depot/trunk/version/src/templates/VersionSourceGenerator.java.jet	Tue Aug  3
13:59:17 2004
@@ -2,7 +2,7 @@
     package="org.apache.depot.version.generation"
     class="VersionSourceGenerator"
     skeleton="version.skeleton"
-    imports="org.apache.depot.version.VersionMarker "
+    imports="org.apache.depot.version.VersionMarker java.util.Iterator java.util.Map"
     %>
 
 /* 
@@ -17,8 +17,10 @@
  */
 package <%=packageName%>; 
 
+import java.util.Collections;
 import java.util.Date;
-
+import java.util.HashMap;
+import java.util.Map;
 /**
  * A autogenerated VersionStamp class for <%=marker.getId()%> .
  * Generated at <%=new java.util.Date() %> 
@@ -29,12 +31,30 @@
            version <%=depotVersion.getLongVersion() %>
  * @version <%=marker.getLongVersion()%>
  */
-public final class <%=className%> {
+public final class <%=className%> { 
+	/* SINGLETON PATTERN */
 	private final static  <%=className%> INSTANCE = new  <%=className%>();
+    public static <%=className%> getInstance() {return INSTANCE ;}
+    
+    
+    private final Map  attributes;
+
+
 	
-	public static <%=className%> getInstance() {return INSTANCE ;}
+	private  <%=className%>()  {
+	Map temp = new HashMap();
+	<%
+	for (Iterator i = marker.getAttributes().entrySet().iterator(); i.hasNext();) {
+         Map.Entry entry = (Map.Entry) i.next();
+         // TODO need to escape key and value.
+         %>
+    temp.put(<%=getValueFrom(entry.getKey())%>,
+             <%=getValueFrom(entry.getValue())%>);// <%=entry.getValue()%>
+       <%
+    }%>
+	attributes = Collections.unmodifiableMap(temp);
 	
-	private  <%=className%>()  {}
+	}
 	
 	/**
 	 * The user that built <%=marker.getId()%> was <%=getUser()%>.
@@ -80,6 +100,13 @@
 	 * @return the String "<%=marker.getDefaultVersion()%>"
 	 */
 	public String getDefaultVersion() {return "<%=marker.getDefaultVersion()%>";}	
+
+
+	public Map getAttributes () {
+	    return attributes;
+	}
+
+
 	
 	/**
 	 * <%=marker.getId()%> <%=marker.getLongVersion()%>.

Mime
View raw message