commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r398200 - in /jakarta/commons/sandbox/jci/trunk: ./ compilers/eclipse/src/java/org/apache/commons/jci/compilers/ compilers/groovy/src/java/org/apache/commons/jci/compilers/ compilers/janino/src/java/org/apache/commons/jci/compilers/ core/sr...
Date Sat, 29 Apr 2006 16:31:14 GMT
Author: tcurdt
Date: Sat Apr 29 09:31:08 2006
New Revision: 398200

URL: http://svn.apache.org/viewcvs?rev=398200&view=rev
Log:
added some docs, since we store bytes also read bytes, always use the proper resources paths,
typesafe CompilationResult constructor, general cleanups

Modified:
    jakarta/commons/sandbox/jci/trunk/TODO
    jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/compilers/groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/compilers/janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/FileResourceReader.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/ResourceReader.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/FileResourceStore.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStore.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
    jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/TransactionalResourceStore.java
    jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
    jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java
    jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java

Modified: jakarta/commons/sandbox/jci/trunk/TODO
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/TODO?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/TODO (original)
+++ jakarta/commons/sandbox/jci/trunk/TODO Sat Apr 29 09:31:08 2006
@@ -1,12 +1,10 @@
 o integrate just4log into the build system (or a different logging solution?)
-o compiler factory
 o compiler implementations
   o javac 
   o jikes
   o pizza
   o jruby
   o jpython
-o make suffixes matching (*.java, *.class) configurable
 o turn the JavaCompilerFactory into an interface and maybe provide a simple default impl
 o documentation
 o dependency analysis for proper re-try after errors

Modified: jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
Sat Apr 29 09:31:08 2006
@@ -26,6 +26,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
+
 import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
@@ -90,7 +91,7 @@
         }
 
         public char[] getContents() {
-            return reader.getContent(fileName);
+            return new String(reader.getBytes(fileName)).toCharArray();
         }
 
         public char[] getMainTypeName() {
@@ -266,6 +267,8 @@
 
         compiler.compile(compilationUnits);
 
-        return new org.apache.commons.jci.compilers.CompilationResult(problems);
+        final CompilationProblem[] result = new CompilationProblem[problems.size()];
+        problems.toArray(result);
+        return new org.apache.commons.jci.compilers.CompilationResult(result);
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/compilers/groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/groovy/src/java/org/apache/commons/jci/compilers/GroovyJavaCompiler.java
Sat Apr 29 09:31:08 2006
@@ -28,21 +28,21 @@
     private final static Log log = LogFactory.getLog(GroovyJavaCompiler.class);
     
     public CompilationResult compile(
-            final String[] clazzNames,
-            final ResourceReader reader,
-            final ResourceStore store,
-            final ClassLoader classLoader
+            final String[] pResourceNames,
+            final ResourceReader pReader,
+            final ResourceStore pStore,
+            final ClassLoader pClassLoader
             ) {
         final CompilerConfiguration configuration = new CompilerConfiguration();
         final ErrorCollector collector = new ErrorCollector(configuration);
-        final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(classLoader);
+        final GroovyClassLoader groovyClassLoader = new GroovyClassLoader(pClassLoader);
         final CompilationUnit unit = new CompilationUnit(configuration, null, groovyClassLoader);
-        final SourceUnit[] source = new SourceUnit[clazzNames.length];
+        final SourceUnit[] source = new SourceUnit[pResourceNames.length];
         for (int i = 0; i < source.length; i++) {
-            final String filename = clazzNames[i].replace('.','/') + ".groovy";
+            final String resourceName = pResourceNames[i];
             source[i] = new SourceUnit(
-                    filename,
-                    new String(reader.getContent(filename)), // FIXME delay the read
+                    convertResourceNameToClassName(resourceName),
+                    new String(pReader.getBytes(resourceName)), // FIXME delay the read
                     configuration,
                     groovyClassLoader,
                     collector
@@ -60,7 +60,7 @@
             for (final Iterator it = classes.iterator(); it.hasNext();) {
                 final GroovyClass clazz = (GroovyClass) it.next();
                 final byte[] bytes = clazz.getBytes();
-                store.write(clazz.getName(), bytes);
+                pStore.write(clazz.getName(), bytes);
             }
         } catch (final MultipleCompilationErrorsException e) {
             final ErrorCollector col = e.getErrorCollector();
@@ -90,7 +90,9 @@
         } catch (CompilationFailedException e) {
             throw new RuntimeException("no expected");
         }
-        
-        return new CompilationResult(problems);
+
+        final CompilationProblem[] result = new CompilationProblem[problems.size()];
+        problems.toArray(result);
+        return new CompilationResult(result);
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/compilers/janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/compilers/janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/janino/src/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
Sat Apr 29 09:31:08 2006
@@ -16,15 +16,15 @@
 package org.apache.commons.jci.compilers;
 
 import java.io.BufferedReader;
-import java.io.CharArrayReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.Reader;
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+
 import org.apache.commons.jci.problems.CompilationProblem;
 import org.apache.commons.jci.readers.ResourceReader;
 import org.apache.commons.jci.stores.ResourceStore;
@@ -76,16 +76,16 @@
             if (types.containsKey(pType)) {
                 return (IClass) types.get(pType);
             }
-            final String fileNameForClass = className.replace('.', File.separatorChar) +
".java";
+            final String resourceNameFromClass = className.replace('.', '/') + ".java";
 
-            final char[] content = resourceReader.getContent(fileNameForClass);
+            final byte[] content = resourceReader.getBytes(resourceNameFromClass);
             if (content == null) {
                 return null;
             }
-            final Reader reader = new BufferedReader(new CharArrayReader(content));
+            final Reader reader = new BufferedReader(new StringReader(new String(content)));
             Scanner scanner = null;
             try {
-                scanner = new Scanner(fileNameForClass, reader);
+                scanner = new Scanner(resourceNameFromClass, reader);
                 final Java.CompilationUnit unit = new Parser(scanner).parseCompilationUnit();
                 final UnitCompiler uc = new UnitCompiler(unit, this);
                 uc.setCompileErrorHandler(new ErrorHandler() {
@@ -120,9 +120,9 @@
             } catch (final LocatedException e) {
                 problems.add(new JaninoCompilationProblem(e));
             } catch (final IOException e) {
-                problems.add(new JaninoCompilationProblem(fileNameForClass, "IOException:"
+ e.getMessage(), true));
+                problems.add(new JaninoCompilationProblem(resourceNameFromClass, "IOException:"
+ e.getMessage(), true));
             } catch (final Exception e) {
-                problems.add(new JaninoCompilationProblem(fileNameForClass, "Exception:"
+ e.getMessage(), true));
+                problems.add(new JaninoCompilationProblem(resourceNameFromClass, "Exception:"
+ e.getMessage(), true));
             } finally {
                 if (scanner != null) {
                     try {
@@ -155,7 +155,10 @@
             pStore.write((String)entry.getKey(), (byte[])entry.getValue());
         }
         
-        return new CompilationResult(icl.getProblems());
+        final Collection problems = icl.getProblems();
+        final CompilationProblem[] result = new CompilationProblem[problems.size()];
+        problems.toArray(result);
+        return new CompilationResult(result);
     }
     
 }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java
Sat Apr 29 09:31:08 2006
@@ -28,4 +28,22 @@
         return compile(pClazzNames, pReader, pStore, classLoader);
     }
     
+    /**
+     * Please do not use - internal
+     * org/my/Class.xxx -> org/my/Class
+     */
+    public static String stripExtension( final String pResourceName ) {
+    	final int i = pResourceName.lastIndexOf('.');
+    	final String withoutExtension = pResourceName.substring(0, i);
+    	return withoutExtension;
+    }
+    
+    /**
+     * Please do not use - internal
+     * org/my/Class.xxx -> org.my.Class
+     */
+    public static String convertResourceNameToClassName( final String pResourceName ) {
+    	return stripExtension(pResourceName).replace('/', '.');
+    }
+
 }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/CompilationResult.java
Sat Apr 29 09:31:08 2006
@@ -2,35 +2,39 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import org.apache.commons.jci.problems.CompilationProblem;
 
 
 public final class CompilationResult {
     
-    final Collection errors = new ArrayList();
-    final Collection warnings = new ArrayList();
-
-    public CompilationResult( final Collection pProblems ) {
-        for (final Iterator it = pProblems.iterator(); it.hasNext();) {
-            final CompilationProblem problem = (CompilationProblem) it.next();
+    private final CompilationProblem[] errors;
+    private final CompilationProblem[] warnings;
+        
+    public CompilationResult( final CompilationProblem[] pProblems ) {
+    	final Collection errorsColl = new ArrayList();
+        final Collection warningsColl = new ArrayList();
+    	
+    	for (int i = 0; i < pProblems.length; i++) {
+    		final CompilationProblem problem = pProblems[i];
             if (problem.isError()) {
-                errors.add(problem);
+                errorsColl.add(problem);
             } else {
-                warnings.add(problem);
-            }
-        }
+                warningsColl.add(problem);
+            }			
+		}
+        
+    	errors = new CompilationProblem[errorsColl.size()];
+        errorsColl.toArray(errors);
+
+        warnings = new CompilationProblem[warningsColl.size()];
+        warningsColl.toArray(warnings);
     }
     
     public CompilationProblem[] getErrors() {
-        final CompilationProblem[] result = new CompilationProblem[errors.size()];
-        errors.toArray(result);
-        return result;
+        return errors;
     }
 
     public CompilationProblem[] getWarnings() {
-        final CompilationProblem[] result = new CompilationProblem[warnings.size()];
-        warnings.toArray(result);
-        return result;
+    	return warnings;
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompiler.java
Sat Apr 29 09:31:08 2006
@@ -22,20 +22,47 @@
 
 /**
  * @author tcurdt
- *
  */
 public interface JavaCompiler {
-    
+
+	/**
+	 * Set the the handler that gets the notification of an error
+	 * or warning as soon as this information is available from
+	 * the compiler.
+	 * Note: Some compilers might not support this feature.
+	 * 
+	 * @param pHandler
+	 */
     void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
-    
+
+    /**
+     * Compiles the java resources "some/path/to/MyJava.java"
+     * read through the ResourceReader and then stores the resulting
+     * classes in the ResourceStore under "some/path/to/MyJava.class".
+     * Note: As these are resource path you always have to use "/" 
+     * 
+     * The result of the compilation run including detailed error
+     * information is returned as CompilationResult. If you need to
+     * get notified already during the compilation process you can
+     * register a CompilationProblemHandler.
+     * Note: Not all compilers might support this notification mechanism.
+     * 
+     * @param pResourcePaths
+     * @param pReader
+     * @param pStore
+     * @return always a CompilationResult
+     */
     CompilationResult compile(
-            final String[] pClazzNames,
+            final String[] pResourcePaths,
             final ResourceReader pReader,
             final ResourceStore pStore );
 
-
+    /**
+     * As the usual compiler but you can provide the classloader
+     * and therefor the classpath you are compiling with.
+     */
     CompilationResult compile(
-            final String[] pClazzNames,
+            final String[] pResourcePaths,
             final ResourceReader pReader,
             final ResourceStore pStore,
             final ClassLoader classLoader );

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java
Sat Apr 29 09:31:08 2006
@@ -22,55 +22,34 @@
 
 public final class JavaCompilerFactory {
 
-    private Map classCache = new HashMap();
-    
     private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();
     
     public static JavaCompilerFactory getInstance() {
         return JavaCompilerFactory.INSTANCE;
     }
 
+    private final Map classCache = new HashMap();
+    
     private JavaCompilerFactory() {
     }
     
-
-//    private Map getImplementations() {
-//        final String[] jars = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
-//        final Map implementations = new HashMap(jars.length);        
-//        for (int i = 0; i < jars.length; i++) {
-//            try {
-//                final JarFile jar = new JarFile(jars[i]);
-//                final Manifest manifest = jar.getManifest();
-//                final String revision = (String) manifest.getMainAttributes().getValue(""
+ JavaCompiler.class);
-//                implementations.put(jars[i], revision);
-//            } catch (IOException e) {                
-//            }
-//        }
-//
-//      return implementations;
-//    }
-    
-//    public JavaCompiler createCompiler(final JavaCompilerSettings pSettings) {
-//        if (pSettings instanceof EclipseJavaCompilerSettings) {
-//            return new EclipseJavaCompiler((EclipseJavaCompilerSettings) pSettings);
-//        }
-        
-        // FIXME create settings for the other compilers and add here
-        
-//        return null;
-//    }
-    
     private String toJavaCasing(final String pName) {
         final char[] name = pName.toLowerCase().toCharArray();
         name[0] = Character.toUpperCase(name[0]);
         return new String(name);
     }
     /**
-     * Can accept the following strings "eclipse", "janino", "groovy" and returns the appropriate
-     * JavaCompiler. Return null for any other type of string.
+     * Tries to guess the class name by convention. So for compilers
+     * following the naming convention
+     * 
+     *   org.apache.commons.jci.compilers.SomeJavaCompiler
+     *   
+     * you can use the short-hands "some"/"Some"/"SOME". Otherwise
+     * you have to provide the full class name. The compiler is
+     * getting instanciated via (cached) reflection.
      * 
-     * @param compiler
-     * @return
+     * @param pHint
+     * @return JavaCompiler or null
      */
     public JavaCompiler createCompiler(final String pHint) {
         

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/monitor/FilesystemAlterationMonitor.java
Sat Apr 29 09:31:08 2006
@@ -393,7 +393,7 @@
 
 
     public void run() {
-        log.info("fam running");
+        log.debug("fam running");
         while (true) {
             synchronized (mutexRunning) {
                 if (!running) {
@@ -425,7 +425,7 @@
             } catch (final InterruptedException e) {
             }
         }
-        log.info("fam exiting");
+        log.debug("fam exiting");
     }
 
 

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/FileResourceReader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/FileResourceReader.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/FileResourceReader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/FileResourceReader.java
Sat Apr 29 09:31:08 2006
@@ -33,14 +33,14 @@
         root = pRoot;        
     }
     
-    public boolean isAvailable(String filename) {
-        return new File(root,filename).exists();
+    public boolean isAvailable( final String pResourceName ) {
+        return new File(root, pResourceName).exists();
     }
 
-    public char[] getContent( final String fileName ) {
+    public byte[] getBytes( final String pResourceName ) {
         try {
             return FileUtils.readFileToString(
-                    new File(root,fileName), "UTF-8").toCharArray();
+                    new File(root, pResourceName), "UTF-8").getBytes();
         } catch(Exception e) {
         }
         return null;

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
Sat Apr 29 09:31:08 2006
@@ -5,40 +5,40 @@
 
 public class MemoryResourceReader implements ResourceReader {
     
-    private Map files;
+    private Map resources;
 
-    public boolean isAvailable(final String pFileName) {
-        if (files == null) {
+    public boolean isAvailable(final String pResourceName) {
+        if (resources == null) {
             return false;
         }
 
-        return files.containsKey( pFileName );
+        return resources.containsKey( pResourceName );
     }
     
-    public void addFile(final String pFileName, final char[] pFile) {
-        if (files == null) {
-            files = new HashMap();
+    public void add(final String pResourceName, final char[] pContent) {
+        if (resources == null) {
+            resources = new HashMap();
         }
         
-        files.put(pFileName, pFile);
+        resources.put(pResourceName, pContent);
     }
     
-    public void removeFile(final String pFileName) {
-        if (files != null) {
-            files.remove(pFileName);
+    public void remove(final String pResourceName) {
+        if (resources != null) {
+            resources.remove(pResourceName);
         }    
     }    
     
 
-    public char[] getContent(final String pFileName)
+    public byte[] getBytes(final String pResourceName)
     {
-        return (char[]) files.get(pFileName);
+        return (byte[]) resources.get(pResourceName);
     }
 
     public String[] list() {
-        if (files == null) {
+        if (resources == null) {
             return new String[0];
         }
-        return (String[]) files.keySet().toArray(new String[files.size()]);
+        return (String[]) resources.keySet().toArray(new String[resources.size()]);
     }
 }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/ResourceReader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/ResourceReader.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/ResourceReader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/readers/ResourceReader.java
Sat Apr 29 09:31:08 2006
@@ -17,10 +17,8 @@
 
 /**
  * @author tcurdt
- *
  */
 public interface ResourceReader {
-    boolean isAvailable( final String filename );
-    char[] getContent( final String fileName );
-
+    boolean isAvailable( final String pResourceName );
+    byte[] getBytes( final String pResourceName );
 }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/FileResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/FileResourceStore.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/FileResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/FileResourceStore.java
Sat Apr 29 09:31:08 2006
@@ -29,7 +29,6 @@
 
 /**
  * @author tcurdt
- *
  */
 public final class FileResourceStore implements ResourceStore {
 
@@ -38,10 +37,10 @@
     public FileResourceStore(final File pFile) {
         root = pFile;
     }
-    public byte[] read( final String resourceName ) {
+    public byte[] read( final String pResourceName ) {
         InputStream is = null;
         try {
-            is = new FileInputStream(getFile(resourceName));
+            is = new FileInputStream(getFile(pResourceName));
             final byte[] data = IOUtils.toByteArray(is);
             return data;
         } catch (FileNotFoundException e) {
@@ -57,10 +56,10 @@
 
         return null;
     }
-    public void write( final String resourceName, final byte[] clazzData ) {
+    public void write( final String pResourceName, final byte[] pData ) {
         OutputStream os = null;
         try {
-            final File file = getFile(resourceName);
+            final File file = getFile(pResourceName);
             final File parent = file.getParentFile();
             if (!parent.exists()) {
                 if (!parent.mkdirs()) {
@@ -68,7 +67,7 @@
                 }
             }
             os = new FileOutputStream(file);
-            os.write(clazzData);
+            os.write(pData);
         } catch (FileNotFoundException e) {
         } catch (IOException e) {
         } finally {
@@ -86,7 +85,7 @@
     }
 
     private File getFile(final String pResourceName) {
-        final String fileName = pResourceName.replace('.', File.separatorChar) + ".class";
+        final String fileName = pResourceName.replace('/', File.separatorChar);
         return new File(root, fileName);
     }
 

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
Sat Apr 29 09:31:08 2006
@@ -26,7 +26,6 @@
 
 /**
  * @author tcurdt
- *
  */
 public final class MemoryResourceStore implements ResourceStore {
 
@@ -34,18 +33,18 @@
 
 	private final Map store = new HashMap();
 	
-	public byte[] read( final String resourceName ) {
-		return (byte[]) store.get(resourceName.replace('.', '/') + ".class");
+	public byte[] read( final String pResourceName ) {
+		return (byte[]) store.get(pResourceName);
 	}
 
-	public void write( final String resourceName, final byte[] clazzData ) {
-		log.debug("storing resource " + resourceName + "(" + clazzData.length + ")");
-		store.put(resourceName.replace('.', '/') + ".class", clazzData);
+	public void write( final String pResourceName, final byte[] pData ) {
+		log.debug("storing resource " + pResourceName + "(" + pData.length + ")");
+		store.put(pResourceName, pData);
 	}
 	
-    public void remove( final String resourceName ) {
-        log.debug("removing resource " + resourceName);
-        store.remove(resourceName.replace('.', '/') + ".class");
+    public void remove( final String pResourceName ) {
+        log.debug("removing resource " + pResourceName);
+        store.remove(pResourceName);
     }
 
     public String[] list() {
@@ -56,7 +55,7 @@
         
         for (final Iterator it = store.keySet().iterator(); it.hasNext();) {
             final String name = (String) it.next();
-            names.add(name.replace('/', '.').substring(0, name.length()-6));
+            names.add(name);
         }
 
         return (String[]) names.toArray(new String[store.size()]);

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStore.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStore.java
Sat Apr 29 09:31:08 2006
@@ -21,9 +21,9 @@
  */
 public interface ResourceStore {
 
-    void write( final String resourceName, final byte[] resourceData );
+    void write( final String pResourceName, final byte[] pResourceData );
 	
-	byte[] read( final String resourceName );
+	byte[] read( final String pResourceName );
 	
-	void remove( final String resourceName );
+	void remove( final String pResourceName );
 }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java
Sat Apr 29 09:31:08 2006
@@ -28,11 +28,11 @@
     private final static Log log = LogFactory.getLog(ResourceStoreClassLoader.class);
 
     private final ResourceStore[] stores;
-    private final ClassLoader parent;
+    //private final ClassLoader parent;
 
     public ResourceStoreClassLoader( final ClassLoader pParent, final ResourceStore[] pStores
) {
         super(pParent);
-        parent = pParent;
+        //parent = pParent;
         stores = pStores;
     }
 

Modified: jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/TransactionalResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/TransactionalResourceStore.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/TransactionalResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/java/org/apache/commons/jci/stores/TransactionalResourceStore.java
Sat Apr 29 09:31:08 2006
@@ -18,7 +18,6 @@
 
 /**
  * @author tcurdt
- *
  */
 public class TransactionalResourceStore implements ResourceStore, Transactional {
 

Modified: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/CompilerUtils.java
Sat Apr 29 09:31:08 2006
@@ -18,11 +18,11 @@
         compiler.compile(
                 pClazzes,
                 new ResourceReader() {
-                    public char[] getContent( String pFileName ) {
+                    public byte[] getBytes( String pResourceName ) {
                         for (int i = 0; i < pPrograms.length; i++) {
                             final String clazzName = pClazzes[i].replace('.', '/') + ".java";
-                            if (clazzName.equals(pFileName)) {
-                                return pPrograms[i].toCharArray();
+                            if (clazzName.equals(pResourceName)) {
+                                return pPrograms[i].getBytes();
                             }
                         }
                         return null;
@@ -48,8 +48,8 @@
         compiler.compile(
                 new String[] { pClazz },
                 new ResourceReader() {
-                    public char[] getContent( String pFileName ) {
-                        return pProgramm.toCharArray();
+                    public byte[] getBytes( String pFileName ) {
+                        return pProgramm.getBytes();
                     }
                     public boolean isAvailable( String pFilename ) {
                         return false;

Modified: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java (original)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/MyBar.java Sat
Apr 29 09:31:08 2006
@@ -8,4 +8,8 @@
     public void setFoo( MyFoo foo) {
         this.foo = foo;
     }
+
+    public MyFoo getFoo() {
+        return foo;
+    }
 }

Modified: jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java?rev=398200&r1=398199&r2=398200&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/tests/src/test/org/apache/commons/jci/readers/FileResourceReaderTestCase.java
Sat Apr 29 09:31:08 2006
@@ -9,11 +9,11 @@
         writeFile("test", "test");
 
         assertTrue(reader.isAvailable("test"));
-        final char[] content = reader.getContent("test");
+        final byte[] content = reader.getBytes("test");
         assertTrue(content != null);
         assertTrue("test".equals(new String(content)));        
 
         assertTrue(!reader.isAvailable("bla"));
-        assertTrue(reader.getContent("bla") == null);
+        assertTrue(reader.getBytes("bla") == null);
     }
 }



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