commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r331839 - in /jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers: AbstractJavaCompiler.java JavaCompiler.java eclipse/EclipseJavaCompiler.java groovy/GroovyJavaCompiler.java janino/JaninoJavaCompiler.java
Date Tue, 08 Nov 2005 16:34:24 GMT
Author: tcurdt
Date: Tue Nov  8 08:33:30 2005
New Revision: 331839

URL: http://svn.apache.org/viewcvs?rev=331839&view=rev
Log:
provide a classloader for the compiler

Modified:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java?rev=331839&r1=331838&r2=331839&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
Tue Nov  8 08:33:30 2005
@@ -1,6 +1,8 @@
 package org.apache.commons.jci.compilers;
 
 import org.apache.commons.jci.problems.CompilationProblemHandler;
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.stores.ResourceStore;
 
 
 public abstract class AbstractJavaCompiler implements JavaCompiler {
@@ -9,6 +11,24 @@
     
     public void setCompilationProblemHandler( final CompilationProblemHandler pHandler )
{
         problemHandler = pHandler;
+    }
+    
+    public CompilationResult compile(
+                              final String[] pClazzNames,
+                              final ResourceReader pReader,
+                              final ResourceStore pStore
+                              ) {
+        
+        ClassLoader classLoader = null;
+
+        classLoader = Thread.currentThread().getContextClassLoader();
+        
+        if ( classLoader == null ) {
+            classLoader = this.getClass().getClassLoader();
+        }
+
+        
+        return compile( pClazzNames, pReader, pStore, classLoader );               
     }
     
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java?rev=331839&r1=331838&r2=331839&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
Tue Nov  8 08:33:30 2005
@@ -27,10 +27,17 @@
 public interface JavaCompiler {
     
     void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
+    
+    CompilationResult compile(
+                              final String[] pClazzNames,
+                              final ResourceReader pReader,
+                              final ResourceStore pStore
+                              );    
 
     CompilationResult compile(
             final String[] pClazzNames,
             final ResourceReader pReader,
-            final ResourceStore pStore
+            final ResourceStore pStore,
+            final ClassLoader classLoader
             );
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java?rev=331839&r1=331838&r2=331839&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompiler.java
Tue Nov  8 08:33:30 2005
@@ -106,9 +106,10 @@
     public org.apache.commons.jci.compilers.CompilationResult compile(
             final String[] pClazzNames,
             final ResourceReader pReader,
-            final ResourceStore pStore
+            final ResourceStore pStore,
+            final ClassLoader classLoader
             ) {
-
+        
         final Map settingsMap = settings.getMap();
         final Set clazzIndex = new HashSet();
         ICompilationUnit[] compilationUnits = new ICompilationUnit[pClazzNames.length];
@@ -163,7 +164,7 @@
                     }
 
                     final String resourceName = clazzName.replace('.', '/') + ".class";
-                    final InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourceName);
+                    final InputStream is = classLoader.getResourceAsStream(resourceName);
                     if (is != null) {
                         final byte[] buffer = new byte[8192];
                         final ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length);
@@ -201,7 +202,7 @@
 
             private boolean isPackage( final String clazzName ) {
                 final String resourceName = clazzName.replace('.', '/') + ".class";
-                final URL resource = this.getClass().getClassLoader().getResource(resourceName);
+                final URL resource = classLoader.getResource(resourceName);
                 return resource == null;
             }
 

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java?rev=331839&r1=331838&r2=331839&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/groovy/GroovyJavaCompiler.java
Tue Nov  8 08:33:30 2005
@@ -29,11 +29,11 @@
     public CompilationResult compile(
             final String[] clazzNames,
             final ResourceReader reader,
-            final ResourceStore store
+            final ResourceStore store,
+            final ClassLoader classLoader
             ) {
      
         final CompilerConfiguration configuration = new CompilerConfiguration();
-        final ClassLoader classloader = this.getClass().getClassLoader();
         final ErrorCollector collector = new ErrorCollector(configuration);
         final CompilationUnit unit = new CompilationUnit(configuration);
         final SourceUnit[] source = new SourceUnit[clazzNames.length];
@@ -44,7 +44,7 @@
                     filename,
                     new String(reader.getContent(filename)), // FIXME delay the read
                     configuration,
-                    classloader,
+                    classLoader,
                     collector
                     );
             unit.addSource(source[i]);

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java?rev=331839&r1=331838&r2=331839&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/janino/JaninoJavaCompiler.java
Tue Nov  8 08:33:30 2005
@@ -63,8 +63,8 @@
         private final Map classes;
         private final Collection problems = new ArrayList();
 
-        private CompilingIClassLoader(final ResourceReader pResourceReader, final Map pClasses)
{
-            super(new ClassLoaderIClassLoader());
+        private CompilingIClassLoader(final ResourceReader pResourceReader, final Map pClasses,
final ClassLoader classLoader) {
+            super( new ClassLoaderIClassLoader( classLoader ) );
             resourceReader = pResourceReader;
             classes = pClasses;
             super.postConstruct();
@@ -140,10 +140,12 @@
     public CompilationResult compile(
             final String[] pClasses,
             final ResourceReader pResourceReader,
-            final ResourceStore pStore
+            final ResourceStore pStore,
+            final ClassLoader classLoader
             ) {
-        final Map classFilesByName = new HashMap();
-        final CompilingIClassLoader icl = new CompilingIClassLoader(pResourceReader, classFilesByName);
+        final Map classFilesByName = new HashMap();       
+        
+        final CompilingIClassLoader icl = new CompilingIClassLoader(pResourceReader, classFilesByName,
classLoader);
         for (int i = 0; i < pClasses.length; i++) {
             log.debug("compiling " + pClasses[i]);
             icl.loadIClass(Descriptor.fromClassName(pClasses[i]));



---------------------------------------------------------------------
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