commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r515379 - in /jakarta/commons/sandbox/jci/trunk/compilers/javac/src: main/java/org/apache/commons/jci/compilers/JavacClassLoader.java test/java/org/apache/commons/jci/compilers/JavacJavaCompilerTestCase.java
Date Wed, 07 Mar 2007 00:01:36 GMT
Author: tcurdt
Date: Tue Mar  6 16:01:35 2007
New Revision: 515379

URL: http://svn.apache.org/viewvc?view=rev&rev=515379
Log:
check for the tools jar


Modified:
    jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacClassLoader.java
    jakarta/commons/sandbox/jci/trunk/compilers/javac/src/test/java/org/apache/commons/jci/compilers/JavacJavaCompilerTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacClassLoader.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacClassLoader.java?view=diff&rev=515379&r1=515378&r2=515379
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacClassLoader.java
Tue Mar  6 16:01:35 2007
@@ -1,9 +1,14 @@
 package org.apache.commons.jci.compilers;
 
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Locale;
 
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassWriter;
@@ -11,10 +16,46 @@
 import org.vafer.dependency.asm.RenamingVisitor;
 import org.vafer.dependency.utils.ResourceRenamer;
 
-public final class JavacClassLoader extends ClassLoader {
+public final class JavacClassLoader extends URLClassLoader {
+	
+	
+	private static URL[] getToolsJar() {
+		try {
+			Class.forName("com.sun.tools.javac.Main");
+			
+			// found - no addtional classpath entry required
+			return new URL[0];
+
+		} catch (Exception e) {
+		}
+
+		// no compiler in current classpath, let's try to find the tools.jar
+
+		String javaHome = System.getProperty("java.home");
+		if (javaHome.toLowerCase(Locale.US).endsWith(File.separator + "jre")) {
+			javaHome = javaHome.substring(0, javaHome.length()-4);
+		}
+		
+		final File toolsJar = new File(javaHome + "/lib/tools.jar");
+
+		if (toolsJar.exists()) {
+			try {
+				return new URL[] { toolsJar.toURL() };
+			} catch (MalformedURLException e) {
+			}
+		}
+		
+		final StringBuffer sb = new StringBuffer();
+		sb.append("Could not find javac compiler class (should be in the tools.jar/classes.jar
in your JRE/JDK). ");
+		sb.append("os.name").append('=').append(System.getProperty("os.name")).append(", ");
+		sb.append("os.version").append('=').append(System.getProperty("os.version")).append(",
");
+		sb.append("java.class.path").append('=').append(System.getProperty("java.class.path"));
+
+		throw new RuntimeException(sb.toString());
+	}
 	
 	public JavacClassLoader( final ClassLoader pParent ) {
-		super(pParent);
+		super(getToolsJar(), pParent);
 	}
 	
 	protected Class findClass( final String name ) throws ClassNotFoundException {

Modified: jakarta/commons/sandbox/jci/trunk/compilers/javac/src/test/java/org/apache/commons/jci/compilers/JavacJavaCompilerTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/compilers/javac/src/test/java/org/apache/commons/jci/compilers/JavacJavaCompilerTestCase.java?view=diff&rev=515379&r1=515378&r2=515379
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/javac/src/test/java/org/apache/commons/jci/compilers/JavacJavaCompilerTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/javac/src/test/java/org/apache/commons/jci/compilers/JavacJavaCompilerTestCase.java
Tue Mar  6 16:01:35 2007
@@ -10,16 +10,4 @@
 		return "javac";
 	}
 
-	public void testForToolsJar() {
-		try {
-			Class.forName("com.sun.tools.javac.Main");
-		} catch (ClassNotFoundException e) {
-			final StringBuffer sb = new StringBuffer();
-			sb.append("Could not find javac compiler class (should be in the tools.jar/classes.jar
in your JRE/JDK). ");
-			sb.append("os.name").append('=').append(System.getProperty("os.name")).append(", ");
-			sb.append("os.version").append('=').append(System.getProperty("os.version")).append(",
");
-			sb.append("java.class.path").append('=').append(System.getProperty("java.class.path"));
-			fail(sb.toString());
-		}
-	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message