activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r378480 - in /incubator/activemq/trunk/activemq-core/src/gram: java/org/activemq/openwire/tool/ java/org/apache/ java/org/apache/activemq/ java/org/apache/activemq/openwire/ java/org/apache/activemq/openwire/tool/ script/
Date Fri, 17 Feb 2006 10:52:28 GMT
Author: jstrachan
Date: Fri Feb 17 02:52:25 2006
New Revision: 378480

URL: http://svn.apache.org/viewcvs?rev=378480&view=rev
Log:
Refactor of OpenWire code generation together with move to apache package

Added:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/OpenWireScript.java
      - copied unchanged from r368056, incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java
    incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/TestDataGenerator.java
    incubator/activemq/trunk/activemq-core/src/gram/script/GenerateJavaTests.groovy   (with
props)
Removed:
    incubator/activemq/trunk/activemq-core/src/gram/java/org/activemq/openwire/tool/OpenWireScript.java

Added: incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/TestDataGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/TestDataGenerator.java?rev=378480&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/TestDataGenerator.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/gram/java/org/apache/activemq/openwire/tool/TestDataGenerator.java
Fri Feb 17 02:52:25 2006
@@ -0,0 +1,67 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * 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.activemq.openwire.tool;
+
+/**
+ * A simple helper class to help auto-generate test data when code generating test cases
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class TestDataGenerator {
+    private int stringCounter;
+
+    private boolean boolCounter;
+    private byte byteCounter;
+    private char charCounter = 'a';
+    private short shortCounter;
+    private int intCounter;
+    private long longCounter;
+    
+    public String createByte() {
+        return "(byte) " + (++byteCounter);
+    }
+    
+    public String createChar() {
+        return "'" + (charCounter++) + "'";
+    }
+    
+    public String createShort() {
+        return "(short) " + (++shortCounter);
+    }
+
+    public int createInt() {
+        return ++intCounter;
+    }
+
+    public long createLong() {
+        return ++longCounter;
+    }
+
+    public String createString(String property) {
+        return property + ":" + (++stringCounter);
+    }
+
+    public boolean createBool() {
+        boolCounter = !boolCounter;
+        return boolCounter;
+    }
+    
+    public String createByteArray(String property) {
+        return "\"" + createString(property) + "\".getBytes()";
+    }
+}

Added: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateJavaTests.groovy
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/gram/script/GenerateJavaTests.groovy?rev=378480&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/gram/script/GenerateJavaTests.groovy (added)
+++ incubator/activemq/trunk/activemq-core/src/gram/script/GenerateJavaTests.groovy Fri Feb
17 02:52:25 2006
@@ -0,0 +1,202 @@
+/**
+ *
+ * Copyright 2005-2006 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.
+ */
+import org.apache.activemq.openwire.tool.OpenWireScript
+import org.apache.activemq.openwire.tool.TestDataGenerator
+
+/**
+ * Generates the Java test code for the Open Wire Format
+ *
+ * @version $Revision: $
+ */
+class GenerateJavaTests extends OpenWireScript {
+
+    Object run() {
+    
+        def openwireVersion = System.getProperty("openwire.version");
+        
+        def destDir = new File("src/test/java/org/apache/activemq/openwire/v${openwireVersion}")
+        println "Generating Java test code to directory ${destDir}"
+        
+        def openwireClasses = classes.findAll {
+        		it.getAnnotation("openwire:marshaller")!=null
+        }
+
+        def concreteClasses = new ArrayList()
+        def buffer = new StringBuffer()
+        int counter = 0
+        Map map = [:]
+
+        destDir.mkdirs()
+        for (jclass in openwireClasses) {
+
+            println "Processing ${jclass.simpleName}"
+            def abstractText = "abstract "
+            def isAbstract = isAbstract(jclass);
+            if( !isAbstract ) {
+              concreteClasses.add(jclass)
+              abstractText = ""
+            }
+            
+            def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
+            
+            def file = new File(destDir, jclass.simpleName + "Test.java")
+
+            buffer << """
+${jclass.simpleName}Test.class
+"""
+
+            file.withWriter { out |
+out << """/**
+ *
+ * Copyright 2005-2006 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.activemq.openwire.v${openwireVersion};
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.apache.activemq.openwire.*;
+import org.apache.activemq.command.*;
+"""
+for (pkg in jclass.importedPackages) {
+    for (clazz in pkg.classes) {
+       out << "import "+clazz.qualifiedName+";"
+    }
+}
+
+def baseClass = "DataFileGeneratorTestSupport"
+if( !jclass.superclass.simpleName.equals("Object") ) {
+   baseClass = jclass.superclass.simpleName + "Test";
+}
+
+def marshallerAware = isMarshallAware(jclass);
+
+out << """
+
+/**
+ * Test case for the OpenWire marshalling for ${jclass.simpleName}
+ *
+ *
+ * NOTE!: This file is auto generated - do not modify!
+ *        if you need to make a change, please see the modify the groovy scripts in the
+ *        under src/gram/script and then use maven openwire:generate to regenerate 
+ *        this file.
+ *
+ * @version \$Revision: \$
+ */
+public ${abstractText}class ${jclass.simpleName}Test extends $baseClass {
+"""
+	if (!isAbstract) 
+		out << """
+
+    public static ${jclass.simpleName}Test SINGLETON = new ${jclass.simpleName}Test();
+
+    public Object createObject() throws Exception {
+    		${jclass.simpleName} info = new ${jclass.simpleName}();
+    		populateObject(info);
+    		return info;
+    }
+"""
+	out << """
+    
+    protected void populateObject(Object object) throws Exception {
+    		super.populateObject(object);
+    		${jclass.simpleName} info = (${jclass.simpleName}) object;
+"""
+
+def generator = new TestDataGenerator();
+
+for (property in properties) {
+    def annotation = property.getter.getAnnotation("openwire:property");
+    def size = annotation.getValue("size");
+    def testSize = stringValue(annotation, "testSize");
+    def type = property.type.simpleName
+    def cached = isCachedProperty(property);
+    def propertyName = property.simpleName;
+    
+    out << "        "
+    switch (type) {
+    case "boolean":
+        out << "info.${property.setter.simpleName}(${generator.createBool()});"; break;
+    case "byte":
+        out << "info.${property.setter.simpleName}(${generator.createByte()});"; break;
+    case "char":
+        out << "info.${property.setter.simpleName}(${generator.createChar()});"; break;
+    case "short":
+        out << "info.${property.setter.simpleName}(${generator.createShort()});"; break;
+    case "int":
+        out << "info.${property.setter.simpleName}(${generator.createInt()});"; break;
+    case "long":
+	    out << "info.${property.setter.simpleName}(${generator.createLong()});"; break;
+    case "byte[]":
+	    out << """info.${property.setter.simpleName}(${generator.createByteArray(propertyName)});""";
break;
+    case "String":
+	    out << """info.${property.setter.simpleName}("${generator.createString(propertyName)}");""";
break;
+    case "ByteSequence":
+    		out << """
+    		{
+        		byte data[] = ${generator.createByteArray(propertyName)};
+        		info.${property.setter.simpleName}(new org.activeio.ByteSequence(data,0,data.length));
+    		}
+    		""";
+        break;
+    case "Throwable":
+	    out << """info.${property.setter.simpleName}(createThrowable("${generator.createString(propertyName)}"));""";
break;
+    default:
+    	    if( property.type.arrayType ) {
+      	    def arrayType = property.type.arrayComponentType.simpleName;
+      	    if (size == null) 
+      	      size = 2
+      	    if (arrayType == jclass.simpleName)
+      	      size = 0
+      	     	
+      	    out << """
+    		    {
+	            ${arrayType} value[] = new ${arrayType}[${size}];
+	            for( int i=0; i < ${size}; i++ ) {
+	                value[i] = create${arrayType}("${generator.createString(propertyName)}");
+	            }
+	            info.${property.setter.simpleName}(value);
+            }"""
+        		} 
+        		else {
+        			out << """info.${property.setter.simpleName}(create${type}("${generator.createString(propertyName)}"));"""
+            }
+        }
+        out.newLine() 
+    }
+        out << """
+            }
+        }
+"""
+}
+		}
+    }
+}
\ No newline at end of file

Propchange: incubator/activemq/trunk/activemq-core/src/gram/script/GenerateJavaTests.groovy
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message