chirino 2005/03/21 18:22:36
Modified: modules/core/src/java/org/openejb/corba/compiler
AntCompiler.java
Log:
Chanaged the AntCompiler so that it also adds the TCCL's classpath to to the
compile.
Revision Changes Path
1.5 +57 -30
openejb/modules/core/src/java/org/openejb/corba/compiler/AntCompiler.java
Index: AntCompiler.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/compiler/AntCompiler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AntCompiler.java 18 Mar 2005 08:26:09 -0000 1.4
+++ AntCompiler.java 21 Mar 2005 23:22:36 -0000 1.5
@@ -45,18 +45,18 @@
package org.openejb.corba.compiler;
import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Iterator;
import java.util.Set;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Javac;
-import org.apache.tools.ant.types.Path;
-
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Javac;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.util.FileUtils;
/**
@@ -65,33 +65,60 @@
public class AntCompiler implements Compiler {
public void compileDirectory(File srcDirectory, File destDirectory, Set
classpaths) throws CompilerException {
- try {
- Project project = new Project();
+ Project project = new Project();
- Path path = new Path(project);
- path.setLocation(srcDirectory);
+ Path path = new Path(project);
+ path.setLocation(srcDirectory);
- Javac javac = new Javac();
- javac.setProject(project);
- javac.setSrcdir(path);
- javac.setDestdir(destDirectory);
- javac.setFork(false);
- javac.setDebug(true);
-
- for (Iterator iter = classpaths.iterator(); iter.hasNext();) {
- path = new Path(project);
- path.setLocation(new File(new URI(iter.next().toString())));
- if (javac.getClasspath() == null) {
- javac.setClasspath(path);
- } else {
- javac.getClasspath().addExisting(path);
- }
+ Javac javac = new Javac();
+ javac.setProject(project);
+ javac.setSrcdir(path);
+ javac.setDestdir(destDirectory);
+ javac.setFork(false);
+ javac.setDebug(true);
+
+ FileUtils utils = FileUtils.newFileUtils();
+ Path classPath = new Path(project);
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ addPathsFromClassLoader(project, classPath, utils, cl);
+
+ for (Iterator iter = classpaths.iterator(); iter.hasNext();) {
+ URL url = (URL) iter.next();
+ // We only can add file based paths.
+ if( url.getProtocol().equals("file") ) {
+ Path p = new Path(project);
+ p.setLocation(utils.normalize(url.getPath()));
+ classPath.addExisting(p);
}
+ }
+ javac.setClasspath(classPath);
- javac.execute();
- } catch (URISyntaxException e) {
- throw new CompilerException(e);
+ javac.execute();
+ }
+
+ private void addPathsFromClassLoader(Project project, Path classPath,
FileUtils utils, ClassLoader cl) {
+ if( cl == null ) {
+ classPath.addJavaRuntime();
+ } else {
+ // Add the parent first.
+ addPathsFromClassLoader(project, classPath, utils,
cl.getParent());
+ // We can only add paths if it is a URLClassLoader
+ if( cl instanceof URLClassLoader ) {
+ URLClassLoader ucl = (URLClassLoader)cl;
+ URL[] urls = ucl.getURLs();
+ for (int i = 0; i < urls.length; i++) {
+ URL url = urls[i];
+ // We only can add file based paths.
+ if( url.getProtocol().equals("file") ) {
+ Path p = new Path(project);
+ p.setLocation(utils.normalize(url.getPath()));
+ classPath.addExisting(p);
+ }
+ }
+ }
}
+
}
public static final GBeanInfo GBEAN_INFO;