diff options
author | aclement <aclement> | 2008-08-28 02:47:05 +0000 |
---|---|---|
committer | aclement <aclement> | 2008-08-28 02:47:05 +0000 |
commit | 4e4299ef560badce91ed62acff384f21311bb417 (patch) | |
tree | 051bc08e23642fcb59394fd25f0fe5563d4d63a8 /loadtime/testsrc | |
parent | 65f73464a4eff01b32a7789ca0a798e6a9898b6f (diff) | |
download | aspectj-4e4299ef560badce91ed62acff384f21311bb417.tar.gz aspectj-4e4299ef560badce91ed62acff384f21311bb417.zip |
fixed eclipse warnings
Diffstat (limited to 'loadtime/testsrc')
-rw-r--r-- | loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java | 12 | ||||
-rw-r--r-- | loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java | 179 |
2 files changed, 100 insertions, 91 deletions
diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java index e55ce2ced..b89209c3b 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java @@ -18,13 +18,15 @@ import junit.framework.TestCase; public class AjTest extends TestCase { public void testAj() { - Aj aj = new Aj(); + // Aj aj = + new Aj(); } public void testAjIWeavingContext() { ClassLoader loader = new URLClassLoader(new URL[] {}, null); IWeavingContext weavingContext = new DefaultWeavingContext(loader); - Aj aj = new Aj(weavingContext); + // Aj aj = + new Aj(weavingContext); } public void testInitialize() { @@ -42,14 +44,14 @@ public class AjTest extends TestCase { ClassLoader loader = new URLClassLoader(new URL[] {}, null); Aj aj = new Aj(); String namespace = aj.getNamespace(loader); - assertEquals("Namespace should be empty","",namespace); + assertEquals("Namespace should be empty", "", namespace); } public void testGeneratedClassesExist() { ClassLoader loader = new URLClassLoader(new URL[] {}, null); Aj aj = new Aj(); boolean exist = aj.generatedClassesExist(loader); - assertFalse("There should be no generated classes",exist); + assertFalse("There should be no generated classes", exist); } public void testFlushGeneratedClasses() { @@ -57,7 +59,7 @@ public class AjTest extends TestCase { Aj aj = new Aj(); aj.flushGeneratedClasses(loader); boolean exist = aj.generatedClassesExist(loader); - assertFalse("There should be no generated classes",exist); + assertFalse("There should be no generated classes", exist); } } diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java index 1448619c9..1233489a3 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java @@ -24,11 +24,11 @@ import java.util.List; import java.util.jar.JarFile; import java.util.zip.ZipEntry; +import junit.framework.TestCase; + import com.bea.jvm.ClassPreProcessor; import com.bea.jvm.JVMFactory; -import junit.framework.TestCase; - public class JRockitAgentTest extends TestCase { protected void setUp() throws Exception { @@ -42,16 +42,16 @@ public class JRockitAgentTest extends TestCase { public void testJRockitAgent() { ClassPreProcessor preProcessor = new JRockitAgent(); ClassPreProcessor expectedPreProcessor = JVMFactory.getJVM().getClassLibrary().getClassPreProcessor(); - assertEquals("JRocketAgent must be registered",expectedPreProcessor,preProcessor); + assertEquals("JRocketAgent must be registered", expectedPreProcessor, preProcessor); } public void testPreProcess() { ClassPreProcessor preProcessor = new JRockitAgent(); - preProcessor.preProcess(null,"foo.Bar",new byte[] {}); + preProcessor.preProcess(null, "foo.Bar", new byte[] {}); } - public void testJrockitRecursionProtection () { - URLClassLoader thisLoader = (URLClassLoader)getClass().getClassLoader(); + public void testJrockitRecursionProtection() { + URLClassLoader thisLoader = (URLClassLoader) getClass().getClassLoader(); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { @@ -60,29 +60,26 @@ public class JRockitAgentTest extends TestCase { ClassLoader loader = new JRockitClassLoader(thisLoader); - Class clazz; - clazz = Class.forName("java.lang.Object",false,loader); - clazz = Class.forName("junit.framework.TestCase",false,loader); - } - catch (Exception ex) { + Class.forName("java.lang.Object", false, loader); + Class.forName("junit.framework.TestCase", false, loader); + } catch (Exception ex) { ex.printStackTrace(); fail(ex.toString()); - } - finally { + } finally { Thread.currentThread().setContextClassLoader(contextLoader); } } private class JRockitClassLoader extends ClassLoader { - + public final static boolean debug = false; - + private List path = new LinkedList(); -// private com.bea.jvm.ClassPreProcessor agent; + // private com.bea.jvm.ClassPreProcessor agent; private Object agent; private Method preProcess; - - public JRockitClassLoader (URLClassLoader clone) throws Exception { + + public JRockitClassLoader(URLClassLoader clone) throws Exception { /* Use extensions loader */ super(clone.getParent()); @@ -90,132 +87,142 @@ public class JRockitAgentTest extends TestCase { for (int i = 0; i < urls.length; i++) { Object pathElement; URL url = urls[i]; - if (debug) System.out.println("JRockitClassLoader.JRockitClassLoader() url=" + url.getPath()); + if (debug) + System.out.println("JRockitClassLoader.JRockitClassLoader() url=" + url.getPath()); File file = new File(encode(url.getFile())); - if (debug) System.out.println("JRockitClassLoader.JRockitClassLoader() file" + file); - if (file.isDirectory()) pathElement = file; - else if (file.exists() && file.getName().endsWith(".jar")) pathElement = new JarFile(file); - else throw new RuntimeException(file.getAbsolutePath().toString()); + if (debug) + System.out.println("JRockitClassLoader.JRockitClassLoader() file" + file); + if (file.isDirectory()) + pathElement = file; + else if (file.exists() && file.getName().endsWith(".jar")) + pathElement = new JarFile(file); + else + throw new RuntimeException(file.getAbsolutePath().toString()); path.add(pathElement); } - - Class agentClazz = Class.forName("org.aspectj.weaver.loadtime.JRockitAgent",false,this); + + Class agentClazz = Class.forName("org.aspectj.weaver.loadtime.JRockitAgent", false, this); Object obj = agentClazz.newInstance(); - if (debug) System.out.println("JRockitClassLoader.JRockitClassLoader() obj=" + obj); + if (debug) + System.out.println("JRockitClassLoader.JRockitClassLoader() obj=" + obj); this.agent = obj; byte[] bytes = new byte[] {}; - Class[] parameterTypes = new Class[] { java.lang.ClassLoader.class, java.lang.String.class, bytes.getClass() }; - preProcess = agentClazz.getMethod("preProcess",parameterTypes); + Class[] parameterTypes = new Class[] { java.lang.ClassLoader.class, java.lang.String.class, bytes.getClass() }; + preProcess = agentClazz.getMethod("preProcess", parameterTypes); } - + /* Get rid of escaped characters */ - private String encode (String s) { + private String encode(String s) { StringBuffer result = new StringBuffer(); int i = s.indexOf("%"); while (i != -1) { - result.append(s.substring(0,i)); - String escaped = s.substring(i+1,i+3); - s = s.substring(i+3); - Integer value = Integer.valueOf(escaped,16); - result.append(new Character((char)value.intValue())); + result.append(s.substring(0, i)); + String escaped = s.substring(i + 1, i + 3); + s = s.substring(i + 3); + Integer value = Integer.valueOf(escaped, 16); + result.append(new Character((char) value.intValue())); i = s.indexOf("%"); } result.append(s); return result.toString(); } - + protected Class findClass(String name) throws ClassNotFoundException { - if (debug) System.out.println("> JRockitClassLoader.findClass() name=" + name); + if (debug) + System.out.println("> JRockitClassLoader.findClass() name=" + name); Class clazz = null; try { clazz = super.findClass(name); - } - catch (ClassNotFoundException ex) { - for (Iterator i = path.iterator(); clazz == null && i.hasNext();) { + } catch (ClassNotFoundException ex) { + for (Iterator i = path.iterator(); clazz == null && i.hasNext();) { byte[] classBytes = null; try { Object pathElement = i.next(); if (pathElement instanceof File) { - File dir = (File)pathElement; - String className = name.replace('.','/') + ".class"; - File classFile = new File(dir,className); - if (classFile.exists()) classBytes = loadClassFromFile(name,classFile); - } - else { - JarFile jar = (JarFile)pathElement; - String className = name.replace('.','/') + ".class"; + File dir = (File) pathElement; + String className = name.replace('.', '/') + ".class"; + File classFile = new File(dir, className); + if (classFile.exists()) + classBytes = loadClassFromFile(name, classFile); + } else { + JarFile jar = (JarFile) pathElement; + String className = name.replace('.', '/') + ".class"; ZipEntry entry = jar.getEntry(className); - if (entry != null) classBytes = loadBytesFromZipEntry(jar,entry); + if (entry != null) + classBytes = loadBytesFromZipEntry(jar, entry); } - + if (classBytes != null) { - clazz = defineClass(name,classBytes); + clazz = defineClass(name, classBytes); } - } - catch (IOException ioException) { + } catch (IOException ioException) { ex.printStackTrace(); } } } - - if (debug) System.out.println("< JRockitClassLoader.findClass() name=" + name); + + if (debug) + System.out.println("< JRockitClassLoader.findClass() name=" + name); return clazz; } - - private Class defineClass (String name, byte[] bytes) { - if (debug) System.out.println("> JRockitClassLoader.defineClass() name=" + name); + + private Class defineClass(String name, byte[] bytes) { + if (debug) + System.out.println("> JRockitClassLoader.defineClass() name=" + name); try { - if (agent != null) preProcess.invoke(agent,new Object[] { this, name, bytes }); - } - catch (IllegalAccessException iae) { + if (agent != null) + preProcess.invoke(agent, new Object[] { this, name, bytes }); + } catch (IllegalAccessException iae) { iae.printStackTrace(); throw new ClassFormatError(iae.getMessage()); - } - catch (InvocationTargetException ite) { + } catch (InvocationTargetException ite) { ite.printStackTrace(); throw new ClassFormatError(ite.getTargetException().getMessage()); } - if (debug) System.out.println("< JRockitClassLoader.defineClass() name=" + name); - return super.defineClass(name,bytes,0,bytes.length); + if (debug) + System.out.println("< JRockitClassLoader.defineClass() name=" + name); + return super.defineClass(name, bytes, 0, bytes.length); } - - private byte[] loadClassFromFile (String name, File file) throws IOException { - if (debug) System.out.println("JRockitClassLoader.loadClassFromFile() file=" + file); + + private byte[] loadClassFromFile(String name, File file) throws IOException { + if (debug) + System.out.println("JRockitClassLoader.loadClassFromFile() file=" + file); byte[] bytes; - bytes = new byte[(int)file.length()]; + bytes = new byte[(int) file.length()]; FileInputStream fis = null; try { fis = new FileInputStream(file); - bytes = readBytes(fis,bytes); + bytes = readBytes(fis, bytes); + } finally { + if (fis != null) + fis.close(); } - finally { - if (fis != null) fis.close(); - } - + return bytes; } - - private byte[] loadBytesFromZipEntry (JarFile jar, ZipEntry entry) throws IOException { - if (debug) System.out.println("JRockitClassLoader.loadBytesFromZipEntry() entry=" + entry); + + private byte[] loadBytesFromZipEntry(JarFile jar, ZipEntry entry) throws IOException { + if (debug) + System.out.println("JRockitClassLoader.loadBytesFromZipEntry() entry=" + entry); byte[] bytes; - bytes = new byte[(int)entry.getSize()]; + bytes = new byte[(int) entry.getSize()]; InputStream is = null; try { is = jar.getInputStream(entry); - bytes = readBytes(is,bytes); + bytes = readBytes(is, bytes); + } finally { + if (is != null) + is.close(); } - finally { - if (is != null) is.close(); - } - + return bytes; } - - private byte[] readBytes (InputStream is, byte[] bytes) throws IOException { + + private byte[] readBytes(InputStream is, byte[] bytes) throws IOException { for (int offset = 0; offset < bytes.length;) { - int read = is.read(bytes,offset,bytes.length - offset); + int read = is.read(bytes, offset, bytes.length - offset); offset += read; } return bytes; |