Author: hlship
Date: Tue Nov 1 23:11:24 2011
New Revision: 1196373
URL: http://svn.apache.org/viewvc?rev=1196373&view=rev
Log:
TAP5-1739: Convert the remaining live reload integration test to use ASM to
generate bytecode
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/reload/ReloadTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClassCreationHelper.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImplTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/reload/ReloadTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/reload/ReloadTests.java?rev=1196373&r1=1196372&r2=1196373&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/reload/ReloadTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/reload/ReloadTests.java
Tue Nov 1 23:11:24 2011
@@ -1,4 +1,4 @@
-// Copyright 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2008, 2009, 2010, 2011 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.
@@ -14,26 +14,20 @@
package org.apache.tapestry5.integration.reload;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import javassist.CannotCompileException;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtMethod;
-import javassist.NotFoundException;
-
import org.apache.tapestry5.integration.TapestryCoreTestCase;
import org.apache.tapestry5.internal.TapestryInternalUtils;
+import org.apache.tapestry5.internal.plastic.asm.ClassWriter;
+import org.apache.tapestry5.internal.plastic.asm.MethodVisitor;
+import org.apache.tapestry5.internal.services.ClassCreationHelper;
import org.apache.tapestry5.test.TapestryTestConstants;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.xml.XmlTest;
+import java.io.*;
+
+import static org.apache.tapestry5.internal.plastic.asm.Opcodes.*;
+
/**
* Integration tests designed to test Tapestry's ability to dynamically reload
component classes,
* templates and message catalogs.
@@ -44,10 +38,11 @@ public class ReloadTests extends Tapestr
private File webinfDir;
private File classesDir;
private File pagesDir;
+ private ClassCreationHelper helper;
private static final String PACKAGE =
"org.apache.tapestry5.integration.reload.pages";
-
- @BeforeTest(groups = { "beforeStartup" })
+
+ @BeforeTest(groups = {"beforeStartup"})
public void beforeStartup(XmlTest xmlTest) throws Exception
{
String uid = Long.toHexString(System.currentTimeMillis());
@@ -66,40 +61,37 @@ public class ReloadTests extends Tapestr
copy("Index.1.tml", webappDir, "Index.tml");
copy("Index.1.properties", pagesDir, "Index.properties");
+ helper = new ClassCreationHelper(classesDir.getAbsolutePath());
+
createIndexClass(100);
-
+
// overwrite the web-app-folder parameter
xmlTest.addParameter(TapestryTestConstants.WEB_APP_FOLDER_PARAMETER,
webappDir.getAbsolutePath());
-
- System.err.println("Created: " + webappDir);
}
private void createIndexClass(int number) throws Exception
{
- ClassPool pool = new ClassPool(null);
-
- pool.appendSystemPath();
-
- CtClass ctClass = pool.makeClass(PACKAGE + ".Index");
+ String className = PACKAGE + ".Index";
- CtMethod method = new CtMethod(pool.get("int"), "getNumber", null,
ctClass);
+ ClassWriter cw = helper.createWriter(className, "java.lang.Object");
- method.setBody("return " + number + ";");
+ MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getNumber", "()I",
null, null);
+ mv.visitCode();
+ mv.visitLdcInsn(number);
+ mv.visitInsn(IRETURN);
+ cw.visitEnd();
- ctClass.addMethod(method);
+ cw.visitEnd();
- ctClass.writeFile(classesDir.getAbsolutePath());
+ helper.writeFile(cw, className);
}
/**
* Copies a source file (from the classpath) to a directory as a new file
name.
- *
- * @param sourceFile
- * source file (within in the reload package)
- * @param dir
- * directory to copy to
- * @param targetFile
- * name of file to be created or overwritten
+ *
+ * @param sourceFile source file (within in the reload package)
+ * @param dir directory to copy to
+ * @param targetFile name of file to be created or overwritten
*/
private void copy(String sourceFile, File dir, String targetFile) throws
IOException
{
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClassCreationHelper.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClassCreationHelper.java?rev=1196373&r1=1196372&r2=1196373&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClassCreationHelper.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClassCreationHelper.java
Tue Nov 1 23:11:24 2011
@@ -17,16 +17,12 @@ package org.apache.tapestry5.internal.se
import org.apache.tapestry5.internal.plastic.PlasticInternalUtils;
import org.apache.tapestry5.internal.plastic.asm.ClassWriter;
import org.apache.tapestry5.internal.plastic.asm.MethodVisitor;
-import org.apache.tapestry5.ioc.Registry;
-import org.apache.tapestry5.ioc.RegistryBuilder;
-import org.apache.tapestry5.services.TapestryModule;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URL;
-import java.net.URLClassLoader;
import java.net.URLConnection;
import java.util.UUID;
@@ -34,33 +30,19 @@ import static org.apache.tapestry5.inter
public class ClassCreationHelper
{
- private static final ClassLoader contextLoader =
Thread.currentThread().getContextClassLoader();
- private String tempDir;
+ public final String tempDir;
- public final Registry registry;
-
- public ClassCreationHelper(Class... extraModules) throws Exception
+ public ClassCreationHelper()
{
- tempDir = String.format("%s/tapestry-test-classpath/%s",
+ this(String.format("%s/tapestry-test-classpath/%s",
System.getProperty("java.io.tmpdir"),
- UUID.randomUUID().toString());
-
- File extraClasspath = new File(tempDir);
-
- extraClasspath.mkdirs();
-
- URL url = extraClasspath.toURL();
-
- URLClassLoader extraLoader = new URLClassLoader(new URL[]
- {url}, contextLoader);
-
- RegistryBuilder builder = new RegistryBuilder(extraLoader);
-
- builder.add(TapestryModule.class);
- builder.add(extraModules);
+ UUID.randomUUID().toString()));
+ }
- registry = builder.build();
+ public ClassCreationHelper(String tempDir)
+ {
+ this.tempDir = tempDir;
}
public void writeFile(ClassWriter writer, String className) throws
Exception
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImplTest.java?rev=1196373&r1=1196372&r2=1196373&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImplTest.java
Tue Nov 1 23:11:24 2011
@@ -20,12 +20,18 @@ import org.apache.tapestry5.internal.pla
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import org.apache.tapestry5.internal.transform.pages.BasicComponent;
import org.apache.tapestry5.ioc.Registry;
+import org.apache.tapestry5.ioc.RegistryBuilder;
import org.apache.tapestry5.runtime.Component;
+import org.apache.tapestry5.services.TapestryModule;
import org.apache.tapestry5.services.UpdateListenerHub;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+
import static org.apache.tapestry5.internal.plastic.asm.Opcodes.ACC_PUBLIC;
import static org.apache.tapestry5.internal.plastic.asm.Opcodes.ARETURN;
@@ -128,9 +134,22 @@ public class ComponentInstantiatorSource
@BeforeClass
public void setup_tests() throws Exception
{
- helper = new ClassCreationHelper(ForceDevelopmentModeModule.class,
AddTransformPagesToCISModule.class);
+ helper = new ClassCreationHelper();
+
+ File extraClasspath = new File(helper.tempDir);
+
+ extraClasspath.mkdirs();
+
+ URL url = extraClasspath.toURL();
+
+ URLClassLoader extraLoader = new URLClassLoader(new URL[]
+ {url}, Thread.currentThread().getContextClassLoader());
+
+ RegistryBuilder builder = new RegistryBuilder(extraLoader);
+
+ builder.add(TapestryModule.class, ForceDevelopmentModeModule.class,
AddTransformPagesToCISModule.class);
- registry = helper.registry;
+ registry = builder.build();
source = registry.getService(ComponentInstantiatorSource.class);
}