commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r231127 - in /jakarta/commons/sandbox/jci/trunk: ./ lib/ src/java/ src/java/org/apache/commons/jci/ src/java/org/apache/commons/jci/compilers/ src/java/org/apache/commons/jci/compilers/eclipse/ src/java/org/apache/commons/jci/monitor/ src/j...
Date Tue, 09 Aug 2005 22:34:56 GMT
Author: tcurdt
Date: Tue Aug  9 15:34:33 2005
New Revision: 231127

URL: http://svn.apache.org/viewcvs?rev=231127&view=rev
Log:
removed false bcel dep,
reloading listener support,
logging properties for simplelog,
first compiling classloader testcase (FIXME!),
inject compiler into classloader,
inject compiler settings into compiler,
compiling classloader now extends reloading classloader,
ATTN: after creation you now have to call "start()" 


Added:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingListener.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
      - copied, changed from r230478, jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ResourceStoreClassLoader.java
    jakarta/commons/sandbox/jci/trunk/src/java/simplelog.properties
Removed:
    jakarta/commons/sandbox/jci/trunk/lib/jakarta-bcel-20040329.jar
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ResourceStoreClassLoader.java
Modified:
    jakarta/commons/sandbox/jci/trunk/.classpath
    jakarta/commons/sandbox/jci/trunk/project.properties
    jakarta/commons/sandbox/jci/trunk/project.xml
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.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/JavaCompilerFactory.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/monitor/FilesystemAlterationMonitor.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/.classpath
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/.classpath?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/.classpath (original)
+++ jakarta/commons/sandbox/jci/trunk/.classpath Tue Aug  9 15:34:33 2005
@@ -3,7 +3,6 @@
 	<classpathentry kind="src" path="src/java"/>
 	<classpathentry kind="src" path="src/test"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry sourcepath="/jakarta-bcel-trunk/src/java" kind="lib" path="lib/jakarta-bcel-20040329.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-io/jars/commons-io-1.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-2.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-logging/jars/commons-logging-1.0.4.jar"/>
@@ -11,6 +10,6 @@
 	<classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-3.1.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/janino/jars/janino-2.3.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/eclipse/jars/jdtcore-3.1.0.jar"/>
+	<classpathentry kind="lib" path="lib/jdtcore-3.1.0.jar"/>
 	<classpathentry kind="output" path="eclipse"/>
 </classpath>

Modified: jakarta/commons/sandbox/jci/trunk/project.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/project.properties?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/project.properties (original)
+++ jakarta/commons/sandbox/jci/trunk/project.properties Tue Aug  9 15:34:33 2005
@@ -36,5 +36,6 @@
 # ------------------------------------------------------------------------
 # Jars set explicity by path.
 # ------------------------------------------------------------------------
-maven.jar.jdtcore = ${basedir}/lib/jdtcore-3.1.0.jar
-maven.jar.bcel = ${basedir}/lib/jakarta-bcel-20040329.jar
+#maven.jar.jdtcore = ${basedir}/lib/jdtcore-3.1.0.jar
+#maven.jar.bcel = ${basedir}/lib/jakarta-bcel-20040329.jar
+

Modified: jakarta/commons/sandbox/jci/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/project.xml?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/project.xml (original)
+++ jakarta/commons/sandbox/jci/trunk/project.xml Tue Aug  9 15:34:33 2005
@@ -74,42 +74,41 @@
   <dependencies>
 
     <dependency>
-      <groupId>bcel</groupId>
-      <artifactId>bcel</artifactId>
-      <version>20040329</version>
-      <jar>${basedir}/lib/jakarta-bcel-20040329.jar</jar>
-      <type>jar</type>
-    </dependency>
-    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>1.0</version>
     </dependency>
+
     <dependency>
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>2.0</version>
     </dependency>
+
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <version>1.0.4</version>
     </dependency>
+
     <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
       <version>3.1</version>
     </dependency>
+
     <dependency>
       <groupId>eclipse</groupId>
       <artifactId>jdtcore</artifactId>
       <version>3.1.0</version>
     </dependency>
+
     <dependency>
       <groupId>janino</groupId>
       <artifactId>janino</artifactId>
       <version>2.3.0</version>
     </dependency>
+
   </dependencies>
 
 

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/CompilingClassLoader.java
Tue Aug  9 15:34:33 2005
@@ -16,53 +16,37 @@
 package org.apache.commons.jci;
 
 import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.compilers.eclipse.EclipseJavaCompiler;
 import org.apache.commons.jci.monitor.FilesystemAlterationListener;
-import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
 import org.apache.commons.jci.problems.ConsoleCompilationProblemHandler;
-import org.apache.commons.jci.readers.FileResourceReader;
-import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.TransactionalResourceStore;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * @author tcurdt
  *
  */
-public class CompilingClassLoader extends ClassLoader {
+public class CompilingClassLoader extends ReloadingClassLoader {
     
     private final static Log log = LogFactory.getLog(CompilingClassLoader.class);
     
-    private final ClassLoader parent;
-    private final File repository;
-    private ClassLoader delegate;
-    private final TransactionalResourceStore store;
-    private final ResourceReader reader;
+    private final TransactionalResourceStore transactionalStore;
     private final JavaCompiler compiler; 
-    private final FilesystemAlterationMonitor fam;
-
+    
     public CompilingClassLoader(final ClassLoader pParent, final File pRepository) {
-        this(pParent, pRepository, new EclipseJavaCompiler());
-    }    
- 
-    public CompilingClassLoader(final ClassLoader pParent, final File pRepository, final
JavaCompiler compiler) {
-        this(pParent, pRepository,
-                new TransactionalResourceStore(new MemoryResourceStore()) {
+        this(pParent, pRepository, new TransactionalResourceStore(
+                new MemoryResourceStore()) {
                     public void onStart() {
                         };
                     public void onStop() {
                         };
-                },
-                compiler
+                }
         );
     }
     
@@ -70,44 +54,38 @@
         this(pParent, pRepository, pStore, new EclipseJavaCompiler());
     }
     
-    public CompilingClassLoader(final ClassLoader pParent, final File pRepository, final
TransactionalResourceStore pStore,
-            final JavaCompiler compiler) {
-        super(pParent);
-        parent = pParent;        
-        repository = pRepository;
-        
-        reader = new FileResourceReader(repository);
-        store = pStore;
-        this.compiler = compiler;
-                
-        fam = new FilesystemAlterationMonitor(); 
+    public CompilingClassLoader(final ClassLoader pParent, final File pRepository, final
TransactionalResourceStore pStore, final JavaCompiler pCompiler) {
+        super(pParent, pRepository, pStore);
+
+        transactionalStore = pStore;
+        compiler = pCompiler;                
+    }
 
-        fam.addListener(new FilesystemAlterationListener() {
+    protected FilesystemAlterationListener createListener( final File pRepository ) {
 
-            private Collection created = new ArrayList();
-            private Collection changed = new ArrayList();
-            private Collection deleted = new ArrayList();
+        return new FilesystemAlterationListener() {
+            private final Collection created = new ArrayList();
+            private final Collection changed = new ArrayList();
+            private final Collection deleted = new ArrayList();
             
             public void onStart() {
                 created.clear();
                 changed.clear();
                 deleted.clear();
-                store.onStart();
+                transactionalStore.onStart();
             }
             public void onStop() {
-                /*
                 log.debug("resources " +
                         created.size() + " created, " + 
                         changed.size() + " changed, " + 
                         deleted.size() + " deleted");
-                        */
-
+    
                 boolean reload = false;
                 
                 if (deleted.size() > 0) {
                     for (Iterator it = deleted.iterator(); it.hasNext();) {
                         final File file = (File) it.next();
-                        store.remove(clazzName(repository, file));
+                        transactionalStore.remove(clazzName(repository, file));
                     }
                     reload = true;
                 }
@@ -115,7 +93,7 @@
                 final Collection compileables = new ArrayList();
                 compileables.addAll(created);
                 compileables.addAll(changed);
-
+    
                 final String[] clazzes = new String[compileables.size()];
                 
                 if (compileables.size() > 0) {
@@ -129,11 +107,11 @@
                     }
                     
                     final ConsoleCompilationProblemHandler problemHandler = new ConsoleCompilationProblemHandler();
-
+    
                     compiler.compile(
                             clazzes,
                             reader,
-                            store,
+                            transactionalStore,
                             problemHandler
                             );
                     
@@ -145,23 +123,21 @@
                 
                     if (problemHandler.getErrorCount() > 0) {
                         for (int j = 0; j < clazzes.length; j++) {
-                            store.remove(clazzes[j]);
+                            transactionalStore.remove(clazzes[j]);
                         }
                     }
                     
                     reload = true;                    
-
+    
                 }
-
-                store.onStop();
-
-                //log.debug(store);
-                
+    
+                transactionalStore.onStop();
+    
                 if (reload) {
                     reload();
                 }                
             }
-
+    
             public void onCreateFile( final File file ) {
                 if (file.getName().endsWith(".java")) {
                     created.add(file);
@@ -177,58 +153,13 @@
                     deleted.add(file);
                 }
             }
-
+    
             public void onCreateDirectory( final File file ) {                
             }
             public void onChangeDirectory( final File file ) {                
             }
             public void onDeleteDirectory( final File file ) {
             }
-            }, repository);
-        
-        delegate = new ResourceStoreClassLoader(parent, store);
-
-        Thread myThread = new Thread(fam); 
-        myThread.start();        
-    }
-
-    private void reload() {
-        log.debug("reloading");
-        delegate = new ResourceStoreClassLoader(parent, store );
-        
-    }
-    
-    public static String clazzName( final File base, final File file ) {
-        final int rootLength = base.getAbsolutePath().length();
-        final String absFileName = file.getAbsolutePath();
-        final String relFileName = absFileName.substring(
-                rootLength + 1,
-                absFileName.length() - ".java".length()
-                );
-        final String clazzName = relFileName.replace(File.separatorChar,'.');
-        return clazzName;
-    }
-
-
-    public void clearAssertionStatus() {
-        delegate.clearAssertionStatus();
-    }
-    public URL getResource(String name) {
-        return delegate.getResource(name);
-    }
-    public InputStream getResourceAsStream(String name) {
-        return delegate.getResourceAsStream(name);
-    }
-    public Class loadClass(String name) throws ClassNotFoundException {
-        return delegate.loadClass(name);
-    }
-    public void setClassAssertionStatus(String className, boolean enabled) {
-        delegate.setClassAssertionStatus(className, enabled);
-    }
-    public void setDefaultAssertionStatus(boolean enabled) {
-        delegate.setDefaultAssertionStatus(enabled);
-    }
-    public void setPackageAssertionStatus(String packageName, boolean enabled) {
-        delegate.setPackageAssertionStatus(packageName, enabled);
+        };
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingClassLoader.java
Tue Aug  9 15:34:33 2005
@@ -21,8 +21,8 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
-
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.jci.monitor.FilesystemAlterationListener;
 import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
@@ -30,6 +30,7 @@
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.jci.stores.ResourceStoreClassLoader;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -42,30 +43,47 @@
     private final static Log log = LogFactory.getLog(ReloadingClassLoader.class);
     
     private final ClassLoader parent;
-    private final File repository;
-    private ClassLoader delegate;
     private final ResourceStore store;
-    private final ResourceReader reader;
     private final FilesystemAlterationMonitor fam;
+    private final Thread thread;
+    private final Collection reloadingListeners = new HashSet();
+    private ClassLoader delegate;
 
+    protected final ResourceReader reader;
+    protected final File repository;
+
+    
     public ReloadingClassLoader(final ClassLoader pParent, final File pRepository) {
         this(pParent, pRepository, new MemoryResourceStore());
     }
-    
-    public ReloadingClassLoader(final ClassLoader pParent, final File pRepository, final
ResourceStore pStore) {
+
+    public ReloadingClassLoader(final ClassLoader pParent, final File pRepository, final
ResourceStore pStore) {        
         super(pParent);
+
         parent = pParent;        
         repository = pRepository;        
         reader = new FileResourceReader(repository);
         store = pStore;
                 
         fam = new FilesystemAlterationMonitor(); 
+        fam.addListener(createListener(repository), repository);
+
+        thread = new Thread(fam); 
+        
+        delegate = new ResourceStoreClassLoader(parent, store);
+    }
+    
+    public void start() {
+        thread.start();
+        reload();        
+    }
 
-        fam.addListener(new FilesystemAlterationListener() {
+    protected FilesystemAlterationListener createListener(final File pRepository) {
+        return new FilesystemAlterationListener() {
 
-            private Collection created = new ArrayList();
-            private Collection changed = new ArrayList();
-            private Collection deleted = new ArrayList();
+            private final Collection created = new ArrayList();
+            private final Collection changed = new ArrayList();
+            private final Collection deleted = new ArrayList();
             
             public void onStart() {
                 created.clear();
@@ -127,18 +145,31 @@
             }
             public void onDeleteDirectory( final File file ) {
             }
-            }, repository);
-        
-        delegate = new ResourceStoreClassLoader(parent, store);
-
-        Thread myThread = new Thread(fam); 
-        myThread.start();        
+            
+        };
     }
 
-    private void reload() {
+    public void addListener(final ReloadingListener pListener) {
+        synchronized (reloadingListeners) {
+            reloadingListeners.add(pListener);
+        }                
+    }
+    
+    public boolean removeListener(final ReloadingListener pListener) {
+        synchronized (reloadingListeners) {
+            return reloadingListeners.remove(pListener);
+        }        
+    }
+    
+    protected void reload() {
         log.debug("reloading");
-        delegate = new ResourceStoreClassLoader(parent, store );
-        
+        delegate = new ResourceStoreClassLoader(parent, store);
+        synchronized (reloadingListeners) {
+            for (final Iterator it = reloadingListeners.iterator(); it.hasNext();) {
+                final ReloadingListener listener = (ReloadingListener) it.next();
+                listener.reload();
+            }            
+        }
     }
     
     public static String clazzName( final File base, final File file ) {

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingListener.java?rev=231127&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingListener.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ReloadingListener.java
Tue Aug  9 15:34:33 2005
@@ -0,0 +1,24 @@
+/*
+ * Copyright 1999-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci;
+
+
+/**
+ * @author tcurdt
+ */
+public interface ReloadingListener {
+    void reload();
+}

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=231127&r1=231126&r2=231127&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 Aug  9 15:34:33 2005
@@ -25,10 +25,10 @@
  *
  */
 public interface JavaCompiler {
-	void compile(
-	        final String[] classes,
-	        final ResourceReader in,
-	        final ResourceStore store,
-	        final CompilationProblemHandler problemHandler
-	        );
+    void compile(
+            final String[] pClazzNames,
+            final ResourceReader pReader,
+            final ResourceStore pStore,
+            final CompilationProblemHandler pProblemHandler
+    );
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
Tue Aug  9 15:34:33 2005
@@ -1,10 +1,7 @@
 package org.apache.commons.jci.compilers;
 
-
-public final class JavaCompilerFactory {
-
-    public JavaCompiler createCompiler(final String compiler) {
-        return null;
-    }
+public interface JavaCompilerFactory {
+    
+    JavaCompiler createCompiler(final Object pHint);
 
 }

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java?rev=231127&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java
Tue Aug  9 15:34:33 2005
@@ -0,0 +1,5 @@
+package org.apache.commons.jci.compilers;
+
+
+public interface JavaCompilerSettings {
+}

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=231127&r1=231126&r2=231127&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 Aug  9 15:34:33 2005
@@ -17,16 +17,11 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.commons.jci.compilers.JavaCompiler;
 import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.problems.CompilationProblemHandler;
@@ -35,6 +30,9 @@
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.eclipse.jdt.core.compiler.IProblem;
 import org.eclipse.jdt.internal.compiler.ClassFile;
 import org.eclipse.jdt.internal.compiler.CompilationResult;
@@ -48,13 +46,21 @@
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
 import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
-import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
 import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
 
 public final class EclipseJavaCompiler implements JavaCompiler {
 
     private final static Log log = LogFactory.getLog(EclipseJavaCompiler.class);
-
+    private final EclipseJavaCompilerSettings settings;
+    
+    public EclipseJavaCompiler() {
+        this(new EclipseJavaCompilerSettings());
+    }
+    
+    public EclipseJavaCompiler(final EclipseJavaCompilerSettings pSettings) {
+        settings = pSettings;
+    }    
+    
     final class CompilationUnit implements ICompilationUnit {
 
         final private String clazzName;
@@ -103,27 +109,19 @@
     }
 
     public void compile(
-            final String[] clazzNames,
-            final ResourceReader reader,
-            final ResourceStore store,
-            final CompilationProblemHandler problemHandler
+            final String[] pClazzNames,
+            final ResourceReader pReader,
+            final ResourceStore pStore,
+            final CompilationProblemHandler pProblemHandler
             ) {
 
-        final Map settings = new HashMap();
-        settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
-        settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
-        settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
-        settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
-        settings.put(CompilerOptions.OPTION_Encoding, "UTF-8");
-        settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
-        settings.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
-        settings.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
-
+        final Map settingsMap = settings.getMap();
+        
         final Set clazzIndex = new HashSet();
-        ICompilationUnit[] compilationUnits = new ICompilationUnit[clazzNames.length];
+        ICompilationUnit[] compilationUnits = new ICompilationUnit[pClazzNames.length];
         for (int i = 0; i < compilationUnits.length; i++) {
-            final String clazzName = clazzNames[i];
-            compilationUnits[i] = new CompilationUnit(reader, clazzName);
+            final String clazzName = pClazzNames[i];
+            compilationUnits[i] = new CompilationUnit(pReader, clazzName);
             clazzIndex.add(clazzName);
             log.debug("compiling " + clazzName);
         }
@@ -167,7 +165,7 @@
             private NameEnvironmentAnswer findType(final String clazzName) {
                 //log.debug("NameEnvironment.findType " + clazzName);
 
-                byte[] clazzBytes = store.read(clazzName);
+                byte[] clazzBytes = pStore.read(clazzName);
                 if (clazzBytes != null) {
                     //log.debug("loading from store " + clazzName);
 
@@ -182,9 +180,9 @@
                 }
                 else {
 
-                    if (reader.isAvailable(clazzName.replace('.', '/') + ".java")) {
+                    if (pReader.isAvailable(clazzName.replace('.', '/') + ".java")) {
 	                    log.debug("compile " + clazzName);
-	                    ICompilationUnit compilationUnit = new CompilationUnit(reader, clazzName);
+	                    ICompilationUnit compilationUnit = new CompilationUnit(pReader, clazzName);
 	                    return new NameEnvironmentAnswer(compilationUnit, null);           
                                
                     }
                     else {
@@ -193,7 +191,7 @@
                         
                         if (is != null) {
                             
-    	                    //log.debug("loading from classloader " + clazzName);
+    	                        //log.debug("loading from classloader " + clazzName);
                             final byte[] buffer = new byte[8192];
                             ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length);
                             int count;
@@ -265,11 +263,11 @@
             public void acceptResult(CompilationResult result) {
                 try {
                     if (result.hasProblems()) {
-                        if (problemHandler != null) {
+                        if (pProblemHandler != null) {
 	                        final IProblem[] problems = result.getProblems();
 	                        for (int i = 0; i < problems.length; i++) {
 	                            final IProblem problem = problems[i];
-	                            problemHandler.handle(
+	                            pProblemHandler.handle(
 	                                    new CompilationProblem(
 	                                            problem.getID(),
 	                                            new String(problem.getOriginatingFileName()),
@@ -280,7 +278,9 @@
 	                                            ));
 	                        }
                         }
-                    } else {
+                    }
+                    
+                    if (!result.hasErrors()) {
 
                         final ClassFile[] clazzFiles = result.getClassFiles();
                         for (int i = 0; i < clazzFiles.length; i++) {
@@ -295,7 +295,7 @@
                                 clazzName.append(compoundName[j]);
                             }
 
-                            store.write(clazzName.toString(), clazzFile.getBytes());
+                            pStore.write(clazzName.toString(), clazzFile.getBytes());
                         }
                     }
                 } catch (Exception exc) {
@@ -305,7 +305,7 @@
 
         };
 
-        final Compiler compiler = new Compiler(nameEnvironment, policy, settings, compilerRequestor,
problemFactory);
+        final Compiler compiler = new Compiler(nameEnvironment, policy, settingsMap, compilerRequestor,
problemFactory);
 
         compiler.compile(compilationUnits);
 

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java?rev=231127&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/compilers/eclipse/EclipseJavaCompilerSettings.java
Tue Aug  9 15:34:33 2005
@@ -0,0 +1,26 @@
+package org.apache.commons.jci.compilers.eclipse;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.jci.compilers.JavaCompilerSettings;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+
+
+public class EclipseJavaCompilerSettings implements JavaCompilerSettings {
+    private final Map map = new HashMap();
+    
+    public EclipseJavaCompilerSettings() {
+        map.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
+        map.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
+        map.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
+        map.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
+        map.put(CompilerOptions.OPTION_Encoding, "UTF-8");
+        map.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
+        map.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
+        map.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
+    }
+    
+    public Map getMap() {
+        return map;
+    }
+}

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
Tue Aug  9 15:34:33 2005
@@ -196,7 +196,7 @@
     }
 
     private void onStart( final File root ) {
-        log.debug("* start checking " + root);
+        log.debug("start checking " + root);
 
         Map directories;
         synchronized(mutex) {
@@ -213,7 +213,7 @@
 
 
     private void onStop( final File root ) {
-        log.debug("* stop checking " + root);
+        log.debug("stop checking " + root);
                 
         Map directories;
         synchronized(mutex) {
@@ -231,7 +231,7 @@
 
     private void onCreate( final File root, final Entry entry ) {
         
-        log.debug("* created " + ((entry.isDirectory())?"dir ":"file ") + entry);
+        log.debug("created " + ((entry.isDirectory())?"dir ":"file ") + entry);
         
         Map directories;
         synchronized(mutex) {
@@ -259,7 +259,7 @@
 
     private void onChange( final File root, final Entry entry ) {
         
-        log.debug("* changed " + ((entry.isDirectory())?"dir ":"file ") + entry);
+        log.debug("changed " + ((entry.isDirectory())?"dir ":"file ") + entry);
         
         Map directories;
         synchronized(mutex) {
@@ -287,7 +287,7 @@
 
     private void onDelete( final File root, final Entry entry ) {
         
-        log.debug("* deleted " + ((entry.isDirectory())?"dir ":"file ") + entry);
+        log.debug("deleted " + ((entry.isDirectory())?"dir ":"file ") + entry);
         
         Map directories;
         synchronized(mutex) {
@@ -361,7 +361,7 @@
 
 
     public void run() {
-        System.out.println("fam running");
+        log.info("fam running");
         while (running) {
             Map directories;
             
@@ -393,6 +393,6 @@
             } catch (InterruptedException e) {
             }
         }
-        System.out.println("fam exiting");
+        log.info("fam exiting");
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/ConsoleCompilationProblemHandler.java
Tue Aug  9 15:34:33 2005
@@ -34,11 +34,11 @@
     public void handle( final CompilationProblem pProblem ) {
         if (pProblem.isFatal()) {
             errors++;
+            System.err.println("error(" + errors + "):" + pProblem);
         } else {
             warnings++;
-        }
-        
-        log.debug(pProblem);
+            System.err.println("warning(" + warnings + "):" + pProblem);
+        }        
     }
     
     

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java?rev=231127&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/problems/LogCompilationProblemHandler.java
Tue Aug  9 15:34:33 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 1999-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jci.problems;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+
+/**
+ * @author tcurdt
+ *
+ */
+public class LogCompilationProblemHandler implements CompilationProblemHandler {
+    
+    private final static Log log = LogFactory.getLog(ConsoleCompilationProblemHandler.class);
+
+    private int errors;
+    private int warnings;
+    
+    public void handle( final CompilationProblem pProblem ) {
+        if (pProblem.isFatal()) {
+            errors++;
+            log.debug("error(" + errors + "):" + pProblem);
+        } else {
+            warnings++;
+            log.debug("warning(" + warnings + "):" + pProblem);
+        }        
+    }
+    
+    
+    public int getErrorCount() {
+        return errors;
+    }
+    public int getWarningCount() {
+        return warnings;
+    }
+}

Copied: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
(from r230478, jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ResourceStoreClassLoader.java)
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java?p2=jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java&p1=jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ResourceStoreClassLoader.java&r1=230478&r2=231127&rev=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/ResourceStoreClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
Tue Aug  9 15:34:33 2005
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.jci;
+package org.apache.commons.jci.stores;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -58,7 +58,7 @@
                 final ClassLoader parent = getParent();
                 if (parent != null) {
                     clazz = parent.loadClass(name);
-                    //log.debug("loaded from parent: " + name);
+                    log.debug("loaded from parent: " + name);
                 } else {
                     throw new ClassNotFoundException(name);
                 }

Added: jakarta/commons/sandbox/jci/trunk/src/java/simplelog.properties
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/simplelog.properties?rev=231127&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/simplelog.properties (added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/simplelog.properties Tue Aug  9 15:34:33 2005
@@ -0,0 +1,2 @@
+org.apache.commons.logging.simplelog.defaultlog=debug
+org.apache.commons.logging.simplelog.showdatetime=true
\ No newline at end of file

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/CompilingClassLoaderTestCase.java
Tue Aug  9 15:34:33 2005
@@ -1,17 +1,126 @@
 package org.apache.commons.jci;
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import junit.framework.TestCase;
 
 
 public final class CompilingClassLoaderTestCase extends TestCase {
+
+    private final static Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
+    
+    private CompilingClassLoader cl;
+    private ReloadingListener listener;
+    private File repository;
+    private boolean reloaded; //FIXME
     
-    public void testCreateCompilation() {        
+    protected void setUp() throws Exception {
+        
+        repository = createTempDirectory();
+        assertTrue(repository.exists());
+        assertTrue(repository.isDirectory());
+
+        listener = new ReloadingListener() {
+            public void reload() {
+                log.debug("notifying about the reload");
+                reloaded = true; //FIXME
+            }
+        };
+
+        cl = new CompilingClassLoader(this.getClass().getClassLoader(), repository);
+        cl.addListener(listener);
+        cl.start();
+        
+        // FIXME
+        log.debug("waiting for reload");
+        while(true) {
+            if (reloaded) break;
+            Thread.sleep(200);
+        }
+        log.debug("reloaded");
+
+        reloaded = false;
+    }
+    
+    public void testCreateCompilation() throws Exception {
+
+        log.debug("creating java files");
+        
+        writeFile(new File(repository, "jci/Simple.java"),
+                  "package jci;\n"
+                + "public class Simple { \n"
+                + "  public String toString() { \n"
+                + "    return \"Simple\"; \n"
+                + "  } \n"
+                + "} \n"
+                );
+
+        writeFile(new File(repository, "jci/Extended.java"),
+                "package jci;\n"
+              + "public class Extended extends Simple { \n"
+              + "  public String toString() { \n"
+              + "    return \"Extended:\" + super.toString(); \n"
+              + "  } \n"
+              + "} \n"
+              );
+        
+        // FIXME
+        log.debug("waiting for reload");
+        while(true) {
+            if (reloaded) break;
+            Thread.sleep(200);
+        }
+        log.debug("reloaded");
+        
+        Object o;
+        
+        o = cl.loadClass("jci.Simple").newInstance();        
+        assertTrue("Simple".equals(o.toString()));
+        
+        o = cl.loadClass("jci.Extended").newInstance();        
+        assertTrue("Extended:Simple".equals(o.toString()));
     }
 
     public void testChangeCompilation() {        
     }
 
     public void testDeleteCompilation() {        
+    }
+
+    
+    protected void tearDown() throws Exception {
+        FileUtils.deleteDirectory(repository);
+    }
+    
+    
+    private static void writeFile( final File pFile, final String pText ) throws IOException
{
+        final File parent = pFile.getParentFile();
+        if (!parent.exists()) {
+            if (!parent.mkdirs()) {
+                throw new IOException("could not create" + parent);
+            }
+        }
+        final FileWriter writer = new FileWriter(pFile);
+        writer.write(pText);
+        writer.close();
+    }
+    
+    private static File createTempDirectory() throws IOException {
+        final File tempFile = File.createTempFile("jci", null);
+        
+        if (!tempFile.delete()) {
+            throw new IOException();
+        }
+        
+        if (!tempFile.mkdir()) {
+            throw new IOException();
+        }
+        
+        return tempFile;         
     }
 
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java?rev=231127&r1=231126&r2=231127&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/test/org/apache/commons/jci/ReloadingClassLoaderTestCase.java
Tue Aug  9 15:34:33 2005
@@ -1,11 +1,19 @@
 package org.apache.commons.jci;
 
+import java.io.File;
 import junit.framework.TestCase;
 
 
 public final class ReloadingClassLoaderTestCase extends TestCase {
 
-    public void testCreate() {        
+    private ReloadingClassLoader cl;
+    private File repository;
+    
+    protected void setUp() throws Exception {
+    }
+
+
+    public void testCreate() {
     }
 
     public void testChange() {        
@@ -13,5 +21,9 @@
 
     public void testDelete() {        
     }
+
     
+    protected void tearDown() throws Exception {
+    }
+
 }



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