commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r522054 - in /jakarta/commons/sandbox/jci/trunk: compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/ compilers/janino/src/main/java/org/apache/commons/jci/compilers/ compilers/javac/src/main/java/org/apache/commons/jci/compile...
Date Sat, 24 Mar 2007 17:12:19 GMT
Author: tcurdt
Date: Sat Mar 24 10:12:18 2007
New Revision: 522054

URL: http://svn.apache.org/viewvc?view=rev&rev=522054
Log:
package.html files (still skeletons)
idientified an extension requirement for .java on the resource - would be nice to get rid
of that,
exposed a few more methods,
improved the jsp example


Added:
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
  (with props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java   (with
props)
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.java
  (with props)
    jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/package.html
  (with props)
    jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/package.html
  (with props)
Removed:
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/classes/
Modified:
    jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
    jakarta/commons/sandbox/jci/trunk/compilers/janino/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacJavaCompiler.java
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
    jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java
    jakarta/commons/sandbox/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java
    jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
    jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/web.xml

Modified: jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompiler.java
Sat Mar 24 10:12:18 2007
@@ -245,12 +245,6 @@
                 
             	log.debug("not in store " + pClazzName);
             	
-//                if (pReader.isAvailable(clazzName.replace('.', '/') + ".java")) {
-//                    log.debug("compile " + clazzName);
-//                    ICompilationUnit compilationUnit = new CompilationUnit(pReader, clazzName);
-//                    return new NameEnvironmentAnswer(compilationUnit, null);
-//                }
-
                 final InputStream is = pClassLoader.getResourceAsStream(resourceName);
                 if (is == null) {
                 	log.debug("class " + pClazzName + " not found");
@@ -296,6 +290,7 @@
             		return false;
             	}
             	
+            	// FIXME: this should not be tied to the extension
             	final String source = pClazzName.replace('.', '/') + ".java";
             	if (pReader.isAvailable(source)) {
                 	log.debug("found the source " + source + " for " + pClazzName + " - no package
");

Modified: jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/eclipse/src/main/java/org/apache/commons/jci/compilers/EclipseJavaCompilerSettings.java
Sat Mar 24 10:12:18 2007
@@ -27,4 +27,11 @@
     	
         return map;
     }
+    
+    public String toString() {
+        final StringBuffer sb = new StringBuffer();
+        sb.append(defaultEclipseSettings.toString());
+        // FIXME
+        return sb.toString();
+    }
 }

Modified: jakarta/commons/sandbox/jci/trunk/compilers/janino/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/compilers/janino/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/janino/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/janino/src/main/java/org/apache/commons/jci/compilers/JaninoJavaCompiler.java
Sat Mar 24 10:12:18 2007
@@ -79,6 +79,8 @@
             if (types.containsKey(pType)) {
                 return (IClass) types.get(pType);
             }
+            
+            // FIXME: should not be tied to the extension            
             final String resourceNameFromClass = className.replace('.', '/') + ".java";
 
             final byte[] content = resourceReader.getBytes(resourceNameFromClass);

Modified: jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacJavaCompiler.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacJavaCompiler.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacJavaCompiler.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/compilers/javac/src/main/java/org/apache/commons/jci/compilers/JavacJavaCompiler.java
Sat Mar 24 10:12:18 2007
@@ -70,7 +70,7 @@
 
 			final Method compile = renamedClass.getMethod("compile", new Class[] { String[].class,
PrintWriter.class });
 			final StringWriter out = new StringWriter();
-			final Integer ok = (Integer) compile.invoke(null, new Object[] { pSourcePaths, new PrintWriter(out)
});
+			final Integer ok = (Integer) compile.invoke(null, new Object[] { buildCompilerArguments(pSourcePaths,
pClasspathClassLoader), new PrintWriter(out) });
 
 			final CompilationResult result = parseModernStream(new BufferedReader(new StringReader(out.toString())));
 
@@ -189,7 +189,11 @@
 		return null;
 	}
 
-//	private String[] buildCompilerArguments( final String[] resourcePaths )
+	private String[] buildCompilerArguments( final String[] resourcePaths, final ClassLoader
classloader ) {
+		
+		// FIXME: build classpath from classloader information
+		return resourcePaths;
+		
 //	{
 //		final List args = new ArrayList();
 //		for (int i = 0; i < resourcePaths.length; i++) {
@@ -257,5 +261,5 @@
 //		}
 //
 //		return (String[]) args.toArray(new String[args.size()]);
-//	}
+	}
 }

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/compilers/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Modified: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java
Sat Mar 24 10:12:18 2007
@@ -64,6 +64,18 @@
         lastResult = null;
     }
     
+    public JavaCompiler getCompiler() {
+    	return compiler;
+    }
+    
+    public String getSourceFileExtension() {
+    	return ".java";
+    }
+
+    public ResourceReader getReader( final FilesystemAlterationObserver pObserver ) {
+    	return new FileResourceReader(pObserver.getRootDirectory());
+    }
+    
     public ResourceStore getStore() {
         return transactionalStore;
     }
@@ -75,7 +87,7 @@
     public void onStart( final FilesystemAlterationObserver pObserver ) {
         super.onStart(pObserver);
 
-        reader = new FileResourceReader(pObserver.getRootDirectory());
+        reader = getReader(pObserver);
 
         transactionalStore.onStart();
     }
@@ -95,9 +107,8 @@
 
                 final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(),
deletedFile));
                 
-                if (resourceName.endsWith(".java")) {
-                    transactionalStore.remove(
-                    		ConversionUtils.stripExtension(resourceName) + ".class");
+                if (resourceName.endsWith(getSourceFileExtension())) {
+                    transactionalStore.remove(ConversionUtils.stripExtension(resourceName)
+ ".class");
                 } else {
                     transactionalStore.remove(resourceName);                	
                 }
@@ -113,14 +124,14 @@
         
         for (final Iterator it = created.iterator(); it.hasNext();) {
             final File createdFile = (File) it.next();
-            if (createdFile.getName().endsWith(".java")) {
+            if (createdFile.getName().endsWith(getSourceFileExtension())) {
                 compileables.add(createdFile);
             }
         }
         
         for (final Iterator it = changed.iterator(); it.hasNext();) {
             final File changedFile = (File) it.next();
-            if (changedFile.getName().endsWith(".java")) {
+            if (changedFile.getName().endsWith(getSourceFileExtension())) {
                 compileables.add(changedFile);
             }
         }

Modified: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java
Sat Mar 24 10:12:18 2007
@@ -52,7 +52,7 @@
     public ReloadingListener( final ResourceStore pStore ) {
         store = pStore;
     }
-    
+
     public ResourceStore getStore() {
         return store;
     }

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/listeners/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/problems/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/readers/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/stores/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/core/src/main/java/org/apache/commons/jci/utils/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Modified: jakarta/commons/sandbox/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java
Sat Mar 24 10:12:18 2007
@@ -46,18 +46,7 @@
     private ReloadingClassLoader classloader;
     private CompilingListener listener;
     private FilesystemAlterationMonitor fam;
-    
-//    private final static class BeanUtils {
-//        
-//        public static void setProperty( Object object, String property, Object value) throws
SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
-//            final Class clazz = object.getClass();
-//            
-//            final Method setter = clazz.getMethod("set" + property, new Class[]{ value.getClass()});
-//            setter.invoke(object, new Object[]{ value });   
-//        }
-//    }
-    
-    
+        
     private final static class MockJavaCompiler implements JavaCompiler {
 
         private final Log log = LogFactory.getLog(MockJavaCompiler.class);
@@ -141,15 +130,6 @@
         log.debug("*** ready to test");        
     }
     
-    
-//    public void testCompileProblems() throws Exception {
-//        delay();        
-//        writeFile("jci/Simple.java", "JavaSources.error");
-//        listener.waitForEvent();
-//        
-//        // FIXME
-//    }
-    
     public void testCreate() throws Exception {
         initialCompile();
         
@@ -247,106 +227,6 @@
         }
         
     }
-
-
-//    public void testReference1() throws Exception {        
-//        delay();        
-//        writeFile("jci/Foo.java",
-//                "package jci;\n" + 
-//                "\n" + 
-//                "public class Foo {\n" + 
-//                "    public String toString() {\n" + 
-//                "        return \"foo1\";\n" + 
-//                "    }\n" + 
-//                "}"
-//                );        
-//        writeFile("jci/Bar.java",
-//                "package jci;\n" + 
-//                "\n" + 
-//                "public class Bar {\n" + 
-//                "    \n" + 
-//                "    private Foo foo;\n" + 
-//                "    \n" + 
-//                "    public void setFoo( Foo foo) {\n" + 
-//                "        this.foo = foo;\n" + 
-//                "    }\n" + 
-//                "    \n" + 
-//                "    public String toString() {\n" + 
-//                "        return \"bar1\";\n" + 
-//                "    }\n" + 
-//                "}"
-//                );        
-//        listener.waitForEvent();
-//        
-//        final Object foo1 = classloader.loadClass("jci.Foo").newInstance();        
-//        assertTrue("foo1".equals(foo1.toString()));
-//
-//        final Object bar1 = classloader.loadClass("jci.Bar").newInstance();        
-//        assertTrue("bar1".equals(bar1.toString()));
-//        
-//        BeanUtils.setProperty(bar1, "Foo", foo1);
-//        
-//        delay();
-//        writeFile("jci/Foo.java",
-//                "package jci;\n" + 
-//                "\n" + 
-//                "public class Foo {\n" + 
-//                "    public String toString() {\n" + 
-//                "        return \"foo2\";\n" + 
-//                "    }\n" + 
-//                "}"
-//                );        
-//        listener.waitForEvent();
-//
-//        final Object foo2 = classloader.loadClass("jci.Foo").newInstance();        
-//        assertTrue("foo2".equals(foo2.toString()));
-//
-//        final Object bar2 = classloader.loadClass("jci.Bar").newInstance();        
-//        // has not change -> still bar1
-//        assertTrue("bar1".equals(bar2.toString()));
-//    
-//        BeanUtils.setProperty(bar2, "Foo", foo2);
-//        BeanUtils.setProperty(bar1, "Foo", foo2);
-//
-//    }
-//
-//    public void testReference2() throws Exception {        
-//        delay();        
-//        writeFile("jci/Foo.java",
-//                "package jci;\n" + 
-//                "\n" + 
-//                "public class Foo implements org.apache.commons.jci.MyFoo {\n" + 
-//                "    public String toString() {\n" + 
-//                "        return \"foo1\";\n" + 
-//                "    }\n" + 
-//                "}"
-//                );        
-//        listener.waitForEvent();
-//        
-//        final MyFoo foo1 = (MyFoo) classloader.loadClass("jci.Foo").newInstance();    
   
-//        assertTrue("foo1".equals(foo1.toString()));
-//
-//
-//        final MyBar bar1 = new MyBar();
-//        bar1.setFoo(foo1);
-//        
-//        delay();
-//        writeFile("jci/Foo.java",
-//                "package jci;\n" + 
-//                "\n" + 
-//                "public class Foo implements org.apache.commons.jci.MyFoo {\n" + 
-//                "    public String toString() {\n" + 
-//                "        return \"foo2\";\n" + 
-//                "    }\n" + 
-//                "}"
-//                );        
-//        listener.waitForEvent();
-//
-//        final MyFoo foo2 = (MyFoo) classloader.loadClass("jci.Foo").newInstance();    
   
-//        assertTrue("foo2".equals(foo2.toString()));
-//
-//        bar1.setFoo(foo2);
-//    }
 
     protected void tearDown() throws Exception {
         fam.removeListener(listener);

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java?view=auto&rev=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
Sat Mar 24 10:12:18 2007
@@ -0,0 +1,171 @@
+package org.apache.commons.jci.examples.serverpages;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.commons.jci.readers.ResourceReader;
+import org.apache.commons.jci.utils.ConversionUtils;
+
+public final class JspReader implements ResourceReader {
+
+	private final ResourceReader reader;
+	
+	
+	public JspReader( final ResourceReader pReader ) {
+		reader = pReader;
+	}
+	
+	private String quote( final String s ) {
+		
+		final StringBuffer sb = new StringBuffer();
+		final char[] input = s.toCharArray();
+		
+		for (int i = 0; i < input.length; i++) {
+			final char c = input[i];
+			if (c == '"') {
+				sb.append('\\');
+			}
+			if (c == '\\') {
+				sb.append('\\');
+			}
+			
+			if (c == '\n') {
+				sb.append("\");\n").append("    out.write(\"");
+				continue;
+			}
+			sb.append(c);
+		}
+		
+		return sb.toString();
+	}
+	
+	private void generateJavaCodeFor( final StringBuffer pInput, final Writer pOutput ) throws
IOException {
+		
+		pOutput.append("    out.write(\"");
+		
+		pOutput.append(quote(pInput.toString()));
+
+		pOutput.append("\");").append('\n');
+	}
+	
+	private byte[] transform( String pResourceName, byte[] pBytes ) {
+
+		try {
+			final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+			final Reader input = new InputStreamReader(new ByteArrayInputStream(pBytes));
+			final Writer output = new OutputStreamWriter(outputStream);
+			
+			final int p = pResourceName.lastIndexOf('/');
+
+			final String className;
+			final String packageName;
+
+			if (p < 0) {
+				className = ConversionUtils.stripExtension(pResourceName);
+				packageName = "";
+			} else {
+				className = ConversionUtils.stripExtension(pResourceName.substring(p+1));
+				packageName = pResourceName.substring(0, p).replace('/', '.');
+				output.append("package ").append(packageName).append(";").append('\n');				
+			}
+			
+			
+			output.append("import java.io.PrintWriter;").append('\n');
+			output.append("import java.io.IOException;").append('\n');
+			output.append("import javax.servlet.http.HttpServlet;").append('\n');
+			output.append("import javax.servlet.http.HttpServletRequest;").append('\n');
+			output.append("import javax.servlet.http.HttpServletResponse;").append('\n');
+			output.append("import javax.servlet.ServletException;").append('\n');
+			output.append("public class ").append(className).append(" extends HttpServlet {").append('\n');
+			output.append("  protected void service(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {").append('\n');
+			output.append("    final PrintWriter out = response.getWriter();").append('\n');
+			
+			
+			final char[] open = "<?".toCharArray();
+			final char[] close = "?>".toCharArray();
+
+			StringBuffer sb = new StringBuffer();
+			char[] watch = open;
+			int w = 0;
+			while(true) {
+				int c = input.read();
+				
+				if (c < 0) {
+					break;
+				}
+
+				if (c == watch[w]) {
+					w++;
+					if (watch.length == w) {
+						if (watch == open) {
+							// found open
+							
+							generateJavaCodeFor(sb, output);
+
+							sb = new StringBuffer();
+							watch = close;
+						} else if (watch == close) {
+							// found close
+
+							// <? ... ?> is java
+							output.append(sb.toString());
+							
+							sb = new StringBuffer();
+							watch = open;
+						}
+						w = 0;
+					}
+				} else {
+					if (w > 0) {
+						sb.append(watch, 0, w);
+					}
+
+					sb.append((char)c);
+
+					w = 0;
+				}
+			}
+
+			if (watch == open) {
+				generateJavaCodeFor(sb, output);
+			}
+
+			
+			output.append("    out.close();").append('\n');
+			output.append("    out.flush();").append('\n');
+			output.append("  }").append('\n');
+			output.append("}").append('\n');
+			
+			
+			output.close();
+			
+			return outputStream.toByteArray();
+		} catch (IOException e) {
+			return null;
+		}
+	}
+	
+	public byte[] getBytes( String pResourceName ) {
+		final byte[] resourceBytes = reader.getBytes(pResourceName);
+		
+		if (resourceBytes == null) {
+			return null;
+		}
+		
+		final byte[] jspServletCode = transform(pResourceName, resourceBytes);
+		
+		System.out.println(new String(jspServletCode));
+		
+		return jspServletCode;
+	}
+
+	public boolean isAvailable( String pResourceName ) {
+		return reader.isAvailable(pResourceName);
+	}
+
+}

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java
Sat Mar 24 10:12:18 2007
@@ -19,10 +19,12 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Collection;
+import java.io.PrintWriter;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -30,9 +32,16 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.jci.ReloadingClassLoader;
+import org.apache.commons.jci.compilers.CompilationResult;
+import org.apache.commons.jci.compilers.JavaCompilerFactory;
 import org.apache.commons.jci.listeners.CompilingListener;
 import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
 import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
+import org.apache.commons.jci.problems.CompilationProblem;
+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.jci.utils.ConversionUtils;
 
 
 /**
@@ -43,111 +52,92 @@
 	private static final long serialVersionUID = 1L;
 
 	private final ReloadingClassLoader classloader = new ReloadingClassLoader(ServerPageServlet.class.getClassLoader());
-	private CompilingListener listener;
 	private FilesystemAlterationMonitor fam;
+	private CompilingListener jspListener; 
 
-	private Map serverPagesByClassName = new HashMap();
+	private Map servletsByClassname = new HashMap();
 
 	public void init() throws ServletException {
 		super.init();
 		
-		final File directory = new File(getServletContext().getRealPath("/") + getInitParameter("directory"));
+		final File serverpagesDir = new File(getServletContext().getRealPath("/") + getInitParameter("serverpagesDir"));
 		
-		log("monitoring classes in " + directory);
+		log("monitoring serverpages in " + serverpagesDir);
+		
+		final TransactionalResourceStore store = new TransactionalResourceStore(new MemoryResourceStore())
{
 
-        listener = new CompilingListener() {
+			private Set newClasses;
+			private Map newServletsByClassname;
+			
+			public void onStart() {
+				super.onStart();
 
-			public void onStop( final FilesystemAlterationObserver pObserver ) {
-				super.onStop(pObserver);
+				newClasses = new HashSet();
+				newServletsByClassname = new HashMap(servletsByClassname);				
+			}
 
-				final File root = pObserver.getRootDirectory();
-								
-				final Collection changedFiles = getChangedFiles();
-				changedFiles.addAll(getCreatedFiles());
-				final Collection deletedFiles = getDeletedFiles();
-				
-				boolean reload = false;
-				
-				final Map newServerPagesByClassName = new HashMap(serverPagesByClassName);
-				
-				for (Iterator it = deletedFiles.iterator(); it.hasNext();) {
-					final File file = (File) it.next();
-					final String serverPageClassName = convertFileToServerPageClassName(root, file);
-					newServerPagesByClassName.remove(serverPageClassName);
-					reload = true;
-					log("removing " + serverPageClassName);
-				}
+			public void onStop() {
+				super.onStop();
 
-				for (Iterator it = changedFiles.iterator(); it.hasNext();) {
-					final File file = (File) it.next();
-					
-					final String serverPageClassName = convertFileToServerPageClassName(root, file);
-					
-					if (serverPageClassName == null) {
-						continue;
-					}
+				boolean reload = false;
+				for (Iterator it = newClasses.iterator(); it.hasNext();) {
+					final String clazzName = (String) it.next();
 					
 					try {
-						final Class clazz = classloader.loadClass(serverPageClassName);
-						final HttpServlet serverPage = (HttpServlet) clazz.newInstance();
-						newServerPagesByClassName.put(serverPageClassName, serverPage);
+						final Class clazz = classloader.loadClass(clazzName);
+
+//						if (!clazz.isAssignableFrom(HttpServlet.class)) {
+//							log(clazzName + " is not a servlet");
+//							continue;
+//						}
+
+						final HttpServlet servlet = (HttpServlet) clazz.newInstance();
+						newServletsByClassname.put(clazzName, servlet);
 						reload = true;
-						log("compiled " + serverPageClassName);
-					} catch (ClassNotFoundException e) {
+					} catch(Exception e) {
 						log("", e);
-					} catch (InstantiationException e) {
-						log("", e);
-					} catch (IllegalAccessException e) {
-						log("", e);
-					}
+					}					
 				}
 
 				if (reload) {
-					log("activating new map of serverpages "+ newServerPagesByClassName);
-					serverPagesByClassName = newServerPagesByClassName;					
+					log("activating new map of servlets "+ newServletsByClassname);
+					servletsByClassname = newServletsByClassname;					
 				}
+			}
 
-			}        	
+			public void write(String pResourceName, byte[] pResourceData) {
+				super.write(pResourceName, pResourceData);
+				
+				if (pResourceName.endsWith(".class")) {
+					newClasses.add(pResourceName.replace('/', '.').substring(0, pResourceName.length() -
".class".length()));
+				}
+			}
+			
+		};
+		
+		jspListener = new CompilingListener(new JavaCompilerFactory().createCompiler("eclipse"),
store) {
+
+			public String getSourceFileExtension() {
+				return ".java";
+			}
+			
+			public ResourceReader getReader( final FilesystemAlterationObserver pObserver ) {
+				return new JspReader(super.getReader(pObserver));
+			}
         };
-        listener.addReloadNotificationListener(classloader);
+        jspListener.addReloadNotificationListener(classloader);
         
         fam = new FilesystemAlterationMonitor();
-        fam.addListener(directory, listener);
+        fam.addListener(serverpagesDir, jspListener);
         fam.start();
 	}
 
-	private String convertFileToServerPageClassName( final File root, final File file ) {
-
-		if (!file.getName().endsWith(".java")) {
-			return null;
-		}
-		
-		final String relativeName = file.getAbsolutePath().substring(root.getAbsolutePath().length()
+ 1);
-
-		log("relative: " + relativeName);
-		
-		final String clazzName = relativeName.replace('/', '.').substring(0, relativeName.length()
- 5); 
-
-		log("clazz: " + clazzName);
-
-		return clazzName;
-	}
 	
-	private String convertRequestToServerPageClassName( final HttpServletRequest request ) {
+	private String convertRequestToServletClassname( final HttpServletRequest request ) {
 
 		final String path = request.getPathInfo().substring(1);
 
-//		log("1 " + request.getContextPath());
-//		log("2 " + request.getPathInfo());
-//		log("3 " + request.getPathTranslated());
-//		log("4 " + request.getRequestURI());
-//		log("5 " + request.getServletPath());
-//		log("6 " + request.getRequestURL());
-		
-		// FIXME
-		// /some/page/bla.jsp -> some.page.Bla
-		
-		final String clazz = path;
+		final String clazz = ConversionUtils.stripExtension(path).replace('/', '.');
 		
 		return clazz;
 	}
@@ -155,21 +145,41 @@
 	protected void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
 		log("request " + request.getRequestURI());
 		
-		final String serverPageNameClassName = convertRequestToServerPageClassName(request);
+		final CompilationResult result = jspListener.getCompilationResult();
+		final CompilationProblem[] errors = result.getErrors();
+
+		if (errors.length > 0) {
+			final PrintWriter out = response.getWriter();
+			
+			out.append("<html><body>");
+
+			for (int i = 0; i < errors.length; i++) {
+				final CompilationProblem problem = errors[i];
+				out.append(problem.toString()).append("<br/>").append('\n');
+			}
+			
+			out.append("</body></html>");
+			
+			out.flush();
+			out.close();
+			return;			
+		}
+		
+		final String servletClassname = convertRequestToServletClassname(request);
 
-		log("checking for serverpage " + serverPageNameClassName);
+		log("checking for serverpage " + servletClassname);
 		
-		final HttpServlet serverPage = (HttpServlet) serverPagesByClassName.get(serverPageNameClassName);
+		final HttpServlet servlet = (HttpServlet) servletsByClassname.get(servletClassname);
 		
-		if (serverPage == null) {
-			log("no serverpage  for " + request.getRequestURI());
+		if (servlet == null) {
+			log("no servlet  for " + request.getRequestURI());
 			response.sendError(404);
 			return;
 		}
 
-		log("delegating request to " + serverPageNameClassName);
+		log("delegating request to " + servletClassname);
 		
-		serverPage.service(request, response);
+		servlet.service(request, response);
 	}
 
 	public void destroy() {

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java?view=auto&rev=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java (added)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java Sat Mar
24 10:12:18 2007
@@ -0,0 +1,6 @@
+<html><body>
+    TEST
+    <?
+    System.out.println("TEST");
+    ?>
+</body></html>
\ No newline at end of file

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/Test.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.java?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/web.xml?view=diff&rev=522054&r1=522053&r2=522054
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/web.xml (original)
+++ jakarta/commons/sandbox/jci/trunk/examples/src/main/webapp/WEB-INF/web.xml Sat Mar 24
10:12:18 2007
@@ -4,8 +4,8 @@
         <servlet-name>serverpages</servlet-name>
         <servlet-class>org.apache.commons.jci.examples.serverpages.ServerPageServlet</servlet-class>
         <init-param>
-            <param-name>directory</param-name>
-            <param-value>/WEB-INF/classes</param-value>
+            <param-name>serverpagesDir</param-name>
+            <param-value>/WEB-INF/jsp</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>

Added: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/listeners/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/package.html?view=auto&rev=522054
==============================================================================
    (empty)

Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: jakarta/commons/sandbox/jci/trunk/fam/src/main/java/org/apache/commons/jci/monitor/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html



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