You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2009/09/07 19:05:08 UTC

svn commit: r812225 - in /myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting: core/ core/util/ jsf/dynamicdecorators/factories/ jsf/dynamicdecorators/implemetations/ loaders/java/ loaders/java/jsr199/ refresh/ scratchpad...

Author: werpu
Date: Mon Sep  7 17:05:08 2009
New Revision: 812225

URL: http://svn.apache.org/viewvc?rev=812225&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-11
removed the jar scanning code, the URL classloader does the trick

Added:
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
Modified:
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ConstructorLevelReloadingHandler.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/MethodLevelReloadingHandler.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/factories/ScriptingFacesContextFactory.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/FacesContextProxy.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/jci/TempFileClassLoader.java

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ConstructorLevelReloadingHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ConstructorLevelReloadingHandler.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ConstructorLevelReloadingHandler.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/ConstructorLevelReloadingHandler.java Mon Sep  7 17:05:08 2009
@@ -32,10 +32,12 @@
  * Reloading handler which
  * tries to reload classes and objects
  * on instantiation
- *
+ * <p/>
  * TODO check if this is still needed seems deprecated to me
  *
  * @author Werner Punz
+ * @Deprecated not used anymore since we have to do most
+ * of our object instantiation brute force we cannot use proxies here
  */
 public class ConstructorLevelReloadingHandler implements InvocationHandler, Serializable, Decorated {
 

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/CoreWeaver.java Mon Sep  7 17:05:08 2009
@@ -28,22 +28,20 @@
 
 /**
  * @author werpu
- *
- * Facade which holds multiple weavers
- * and implements a chain of responsibility pattern
- * on them
+ *         <p/>
+ *         Facade which holds multiple weavers
+ *         and implements a chain of responsibility pattern
+ *         on them
  */
-public class CoreWeaver implements Serializable,ScriptingWeaver {
+public class CoreWeaver implements Serializable, ScriptingWeaver {
 
-    ScriptingWeaver _groovyWeaver = null;
-    ScriptingWeaver _javaWeaver = null;
     List<ScriptingWeaver> _weavers = new ArrayList<ScriptingWeaver>();
 
-    public CoreWeaver(ScriptingWeaver ... weavers) {
+    public CoreWeaver(ScriptingWeaver... weavers) {
         //_groovyWeaver = groovyWeaver;
         //_javaWeaver = javaWeaver;
 
-        for(ScriptingWeaver weaver: weavers) {
+        for (ScriptingWeaver weaver : weavers) {
             _weavers.add(weaver);
         }
     }
@@ -55,12 +53,12 @@
 
     @Override
     public Object reloadScriptingInstance(Object o) {
-        if(o.getClass().getName().contains("TestBean2")) {
+        if (o.getClass().getName().contains("TestBean2")) {
             System.out.println("Debugpoint found");
         }
-  
-        for(ScriptingWeaver weaver: _weavers) {
-            if(weaver.isDynamic(o.getClass())) {
+
+        for (ScriptingWeaver weaver : _weavers) {
+            if (weaver.isDynamic(o.getClass())) {
                 return weaver.reloadScriptingInstance(o);
             }
         }
@@ -70,12 +68,12 @@
 
     @Override
     public Class reloadScriptingClass(Class aclass) {
-         if(aclass.getName().contains("TestBean2")) {
+        if (aclass.getName().contains("TestBean2")) {
             System.out.println("Debugpoint found");
         }
 
-        for(ScriptingWeaver weaver: _weavers) {
-            if(weaver.isDynamic(aclass)) {
+        for (ScriptingWeaver weaver : _weavers) {
+            if (weaver.isDynamic(aclass)) {
                 return weaver.reloadScriptingClass(aclass);
             }
         }
@@ -85,15 +83,15 @@
 
     @Override
     public Class loadScriptingClassFromName(String className) {
-         if(className.contains("TestBean2")) {
+        if (className.contains("TestBean2")) {
             System.out.println("Debugpoint found");
         }
 
-        for(ScriptingWeaver weaver: _weavers) {
+        for (ScriptingWeaver weaver : _weavers) {
             Class retVal = weaver.loadScriptingClassFromName(className);
-               if(retVal != null) {
-                   return retVal;
-               }
+            if (retVal != null) {
+                return retVal;
+            }
         }
         return null;
     }
@@ -103,30 +101,13 @@
     }
 
     public boolean isDynamic(Class clazz) {
-        for(ScriptingWeaver weaver:_weavers) {
-            if(weaver.isDynamic(clazz)) {
+        for (ScriptingWeaver weaver : _weavers) {
+            if (weaver.isDynamic(clazz)) {
                 return true;
             }
         }
         return false;
     }
 
-    public ScriptingWeaver get_groovyWeaver() {
-        return _groovyWeaver;
-    }
-
-    public void set_groovyWeaver(ScriptingWeaver _groovyWeaver) {
-        this._groovyWeaver = _groovyWeaver;
-    }
-
-    public ScriptingWeaver get_javaWeaver() {
-        return _javaWeaver;
-    }
-
-    public void set_javaWeaver(ScriptingWeaver _javaWeaver) {
-        this._javaWeaver = _javaWeaver;
-    }
-
-
 }
 

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/MethodLevelReloadingHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/MethodLevelReloadingHandler.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/MethodLevelReloadingHandler.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/MethodLevelReloadingHandler.java Mon Sep  7 17:05:08 2009
@@ -35,6 +35,10 @@
  * only have reloading logic
  * and can cope with reloading on method level
  *
+ * Note this works only for a minority of the artefacts
+ * the reason, most artefacts do not rely on interfaces but
+ * on base classes
+ *
  * @author Werner Punz
  */
 public class MethodLevelReloadingHandler implements InvocationHandler, Serializable, Decorated {

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ClassUtils.java Mon Sep  7 17:05:08 2009
@@ -71,7 +71,7 @@
     }
 
     /**
-     * executes a function on a target object
+     * executes a function method on a target object
      *
      * @param obj        the target object
      * @param methodName the method name

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/ProxyUtils.java Mon Sep  7 17:05:08 2009
@@ -72,6 +72,10 @@
      * we create a proxy to an existing object
      * which does reloading of the internal class
      * on method level
+     *
+     * this works only on classes which implement contractual interfaces
+     * it cannot work on things like the navigation handler
+     * which rely on base classes
      * 
      * @param o the source object to be proxied
      * @param theInterface the proxying interface

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/factories/ScriptingFacesContextFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/factories/ScriptingFacesContextFactory.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/factories/ScriptingFacesContextFactory.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/factories/ScriptingFacesContextFactory.java Mon Sep  7 17:05:08 2009
@@ -51,6 +51,9 @@
         FacesContext retVal = _delegate.getFacesContext(o, o1, o2, lifecycle);  //To change body of implemented methods use File | Settings | File Templates.
         //TODO check if we weave thise around our original
         //faces context to bypass our groovy dynamic reflection problems
+        //TODO this is not fully done yet, the faces context is not
+        //Woven around our method reloading weaver or our instantiation
+        //mechanism
         if (scriptingEnabled && !(retVal instanceof FacesContextProxy))
             return new FacesContextProxy(retVal);
         return retVal;

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/FacesContextProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/FacesContextProxy.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/FacesContextProxy.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/FacesContextProxy.java Mon Sep  7 17:05:08 2009
@@ -19,6 +19,7 @@
 package org.apache.myfaces.scripting.jsf.dynamicdecorators.implemetations;
 
 import org.apache.myfaces.scripting.api.Decorated;
+import org.apache.myfaces.scripting.core.util.ProxyUtils;
 
 import javax.faces.context.FacesContext;
 import javax.faces.context.ExternalContext;
@@ -28,6 +29,7 @@
 import javax.faces.application.FacesMessage;
 import javax.faces.render.RenderKit;
 import javax.faces.component.UIViewRoot;
+import javax.faces.lifecycle.Lifecycle;
 import javax.el.ELContext;
 import java.util.Iterator;
 
@@ -44,8 +46,13 @@
  */
 public class FacesContextProxy extends FacesContext implements Decorated {
 
+
     public FacesContext _delegate = null;
 
+    private void weaveDelegate() {
+        if (_delegate != null)
+            _delegate = (FacesContext) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
+    }
 
 
     public ELContext getELContext() {
@@ -109,6 +116,7 @@
     }
 
     public void setViewRoot(UIViewRoot uiViewRoot) {
+        weaveDelegate();//perfect place no matter what the viewRoot is about once per request set
         _delegate.setViewRoot(uiViewRoot);
     }
 
@@ -131,6 +139,7 @@
 
     public FacesContextProxy(FacesContext delegate) {
         _delegate = delegate;
+        weaveDelegate();
     }
 
     public Object getDelegate() {

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/jsf/dynamicdecorators/implemetations/ViewHandlerProxy.java Mon Sep  7 17:05:08 2009
@@ -35,10 +35,12 @@
  */
 public class ViewHandlerProxy extends ViewHandler implements Decorated {
 
-    
+    ViewHandler _delegate = null;
 
     private void weaveDelegate() {
-        _delegate = (ViewHandler) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
+        if (_delegate != null) {
+            _delegate = (ViewHandler) ProxyUtils.getWeaver().reloadScriptingInstance(_delegate);
+        }
     }
 
 
@@ -96,7 +98,6 @@
         _delegate.writeState(facesContext);
     }
 
-    ViewHandler _delegate = null;
 
 
     public Object getDelegate() {

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java Mon Sep  7 17:05:08 2009
@@ -21,19 +21,16 @@
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.scripting.loaders.java.jsr199.CompilerFacade;
+import org.apache.myfaces.scripting.api.BaseWeaver;
 import org.apache.myfaces.scripting.api.DynamicCompiler;
 import org.apache.myfaces.scripting.api.ScriptingConst;
 import org.apache.myfaces.scripting.api.ScriptingWeaver;
-import org.apache.myfaces.scripting.api.BaseWeaver;
+import org.apache.myfaces.scripting.loaders.java.jsr199.CompilerFacade;
 
 import javax.servlet.ServletContext;
 import java.io.File;
-import java.io.FilenameFilter;
 import java.lang.reflect.InvocationTargetException;
 import java.util.Iterator;
-import java.util.List;
-import java.util.LinkedList;
 
 /**
  * @author werpu
@@ -47,14 +44,6 @@
     String classPath = "";
     DynamicClassIdentifier identifier = new DynamicClassIdentifier();
 
-    /**
-     * this override is needed because we cannot sanely determine all jar
-     * paths we need for our compiler in the various web container configurations
-     */
-    static final String CUSTOM_JAR_PATHS = "org.apache.myfaces.scripting.java.JAR_PATHS";
-    /*comma separated list of additional classpaths*/
-    static final String CUSTOM_CLASS_PATHS = "org.apache.myfaces.scripting.java.CLASS_PATHS";
-
     private static final String JAVA_FILE_ENDING = ".java";
 
     /**
@@ -64,7 +53,8 @@
      */
     public JavaScriptingWeaver(ServletContext servletContext) {
         super(JAVA_FILE_ENDING, ScriptingConst.ENGINE_TYPE_JAVA);
-        initClasspath(servletContext);
+        //init classpath removed we can resolve that over the
+        //url classloader at the time myfaces is initialized
     }
 
     public JavaScriptingWeaver() {
@@ -73,123 +63,6 @@
 
 
     /**
-     * recursive directory scan
-     *
-     * @param rootPath
-     * @return
-     */
-    private List<String> scanPath(String rootPath) {
-        File jarRoot = new File(rootPath);
-
-        List<String> retVal = new LinkedList<String>();
-        String[] dirs = jarRoot.list(new FilenameFilter() {
-            public boolean accept(File dir,
-                                  String name) {
-
-                String dirPath = dir.getAbsolutePath();
-                File checkFile = new File(dirPath + File.separator + name);
-                return checkFile.isDirectory() && !(name.equals(".") && !name.equals(".."));
-            }
-        });
-
-        for (String dir : dirs) {
-            retVal.addAll(scanPath(rootPath + File.separator + dir));
-        }
-
-        String[] foundNames = jarRoot.list(new FilenameFilter() {
-            public boolean accept(File dir,
-                                  String name) {
-
-                name = name.toLowerCase();
-                name = name.trim();
-                String dirPath = dir.getAbsolutePath();
-                File checkFile = new File(dirPath + File.separator + name);
-                return (!checkFile.isDirectory()) && name.endsWith(".jar") || name.endsWith(".zip");
-            }
-        });
-
-        for (String foundPath : foundNames) {
-            retVal.add(rootPath + File.separator + foundPath);
-        }
-        return retVal;
-    }
-
-    private void initClasspath(ServletContext context) {
-        String webInf = context.getRealPath(File.separator + "WEB-INF");
-        StringBuilder classPath = new StringBuilder(255);
-        File jarRoot = new File(webInf + File.separator + "lib");
-
-        classPath.append(webInf);
-        classPath.append(File.separator);
-        classPath.append("classes");
-
-        List<String> fileNames = new LinkedList<String>();
-        if (jarRoot.exists()) {
-            log.info("Scanning paths for possible java compiler classpaths");
-
-            this.classPath = classPath.toString() + File.pathSeparatorChar + addExternalClassPaths(context) + File.pathSeparator + addStandardJarPaths(jarRoot) + addExternalJarPaths(context);
-
-        } else {
-            log.warn("web-inf/lib not found, you might have to adjust the jar scan paths manually");
-        }
-    }
-
-    private String addStandardJarPaths(File jarRoot) {
-        List<String> fileNames = new LinkedList<String>();
-        StringBuilder retVal = new StringBuilder();
-        fileNames.addAll(scanPath(jarRoot.getAbsolutePath()));
-        int cnt = 0;
-        for (String classPath : fileNames) {
-            cnt++;
-            retVal.append(classPath);
-            if (cnt < fileNames.size()) {
-                retVal.append(File.pathSeparator);
-            }
-        }
-        return retVal.toString();
-    }
-
-    private String addExternalClassPaths(ServletContext context) {
-        String classPaths = context.getInitParameter(CUSTOM_CLASS_PATHS);
-        if (classPaths != null && !classPaths.trim().equals("")) {
-            String[] classPathArr = classPaths.split(",");
-            StringBuilder retVal = new StringBuilder();
-            int cnt = 0;
-            for (String classPath : classPathArr) {
-                cnt++;
-                retVal.append(classPath);
-                if (cnt < classPathArr.length) {
-                    retVal.append(File.pathSeparator);
-                }
-            }
-            return retVal.toString();
-        }
-        return "";
-    }
-
-
-    private String addExternalJarPaths(ServletContext context) {
-        List<String> fileNames = new LinkedList<String>();
-        String jarPaths = context.getInitParameter(CUSTOM_JAR_PATHS);
-        StringBuilder retVal = new StringBuilder();
-        if (jarPaths != null && !jarPaths.trim().equals("")) {
-            String[] jarPathsArr = jarPaths.split(",");
-            for (String jarPath : jarPathsArr) {
-                fileNames.addAll(scanPath(jarPath));
-            }
-        }
-        int cnt = 0;
-        for (String classPath : fileNames) {
-            cnt++;
-            retVal.append(classPath);
-            if (cnt < fileNames.size()) {
-                retVal.append(File.pathSeparator);
-            }
-        }
-        return retVal.toString();
-    }
-
-    /**
      * helper to map the properties wherever possible
      *
      * @param target

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java Mon Sep  7 17:05:08 2009
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.myfaces.scripting.loaders.java.jsr199;
 
 import org.apache.myfaces.scripting.api.DynamicCompiler;
@@ -14,18 +32,21 @@
  * A compiler facade encapsulating the JSR 199
  * so that we can switch the implementations
  * of connecting to javac on the fly
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
  */
 public class CompilerFacade implements DynamicCompiler {
-
+    //TODO add optional ecj dependencies here
     JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
     DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector();
-    StandardJavaFileManager fileManager = null;
+    ContainerFileManager fileManager = null;
     private static File tempDir = null;
     private static final String FILE_SEPARATOR = File.separator;
 
     public CompilerFacade() {
         super();
-        fileManager = compiler.getStandardFileManager(diagnosticCollector, null, null);
+        fileManager = new ContainerFileManager(compiler.getStandardFileManager(diagnosticCollector, null, null));
 
         if (tempDir == null) {
             synchronized (this.getClass()) {
@@ -94,23 +115,23 @@
 
         //TODO add the core jar from our lib dir
         //the compiler otherwise cannot find the file
-        String[] options = new String[]{"-cp",classPath,"-d", tempDir.getAbsolutePath(), "-sourcepath", sourceRoot, "-g"};
+        String[] options = new String[]{"-cp", fileManager.getClassPath(), "-d", tempDir.getAbsolutePath(), "-sourcepath", sourceRoot, "-g"};
         compiler.getTask(null, fileManager, diagnosticCollector, Arrays.asList(options), null, fileObjects).call();
         //TODO collect the diagnostics and if an error was issued dump it on the log
         //and throw an unmanaged exeption which routes later on into myfaces
-        if(diagnosticCollector.getDiagnostics().size() > 0) {
+        if (diagnosticCollector.getDiagnostics().size() > 0) {
             Log log = LogFactory.getLog(this.getClass());
             StringBuilder errors = new StringBuilder();
-            for (Diagnostic diagnostic : diagnosticCollector.getDiagnostics())  {
+            for (Diagnostic diagnostic : diagnosticCollector.getDiagnostics()) {
                 String error = "Error on line" +
-                                  diagnostic.getMessage(Locale.getDefault())+"------"+
-                                  diagnostic.getLineNumber()+" File:"+
-                                  diagnostic.getSource().toString();
+                               diagnostic.getMessage(Locale.getDefault()) + "------" +
+                               diagnostic.getLineNumber() + " File:" +
+                               diagnostic.getSource().toString();
                 log.error(error);
                 errors.append(error);
 
             }
-            throw new ClassNotFoundException("Compile error of java file:"+errors.toString());
+            throw new ClassNotFoundException("Compile error of java file:" + errors.toString());
         }
 
         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();

Added: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java?rev=812225&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java (added)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java Mon Sep  7 17:05:08 2009
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.myfaces.scripting.loaders.java.jsr199;
+
+import javax.tools.*;
+import java.io.IOException;
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.ArrayList;
+import java.net.URLClassLoader;
+import java.net.URL;
+
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ContainerFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
+
+    StandardJavaFileManager _delegate = null;
+    String _classPath = null;
+
+
+    protected ContainerFileManager(StandardJavaFileManager standardJavaFileManager) {
+        super(standardJavaFileManager);
+        _delegate = standardJavaFileManager;
+    }
+
+
+    @Override
+    public JavaFileObject getJavaFileForOutput(Location location, String s, JavaFileObject.Kind kind, FileObject fileObject) throws IOException {
+        return super.getJavaFileForOutput(location, s, kind, fileObject);
+    }
+
+    @Override
+    public ClassLoader getClassLoader(Location location) {
+        return ClassUtils.getContextClassLoader();
+    }
+
+    Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
+        return _delegate.getJavaFileObjects(files);
+    }
+
+    Iterable<? extends JavaFileObject> getJavaFileObjects(String... files) {
+        return _delegate.getJavaFileObjects(files);
+    }
+
+    String getClassPath() {
+        if (_classPath != null) {
+            return _classPath;
+        }
+        ClassLoader cls = getClassLoader(null);
+        while (!(cls instanceof URLClassLoader) && cls != null) {
+            cls = cls.getParent();
+        }
+        if (cls == null) {
+            return "";
+        }
+
+        URL[] urls = ((URLClassLoader) cls).getURLs();
+        int len = urls.length;
+        if (len == 0) {
+            return "";
+        }
+        StringBuilder retVal = new StringBuilder(len * 16);
+
+        for (int cnt = 0; cnt < len; cnt++) {
+            retVal.append(urls[cnt].getFile());
+            if (cnt < len - 1) {
+                retVal.append(File.pathSeparator);
+            }
+        }
+        return (_classPath = retVal.toString());
+    }
+
+}
+
+

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java Mon Sep  7 17:05:08 2009
@@ -36,6 +36,17 @@
  *         loaded by the various engine loaders for
  *         for file changes and then if one has changed we have to mark
  *         it for further processing
+ *
+ * TODO to get optimal performance we operate on a deep copy of the underlying map
+ * the map itself has read write access and access the map can only happen synchronized
+ * the write acces has to happen through this class which is sort of the gatekeeper,
+ * the read access happens on a non synchronized instance of the map
+ * which is accessed for readonly reasons, non synchronized map
+ * is refreshed after every interval if something was tainted with
+ * an assignment operation so that nothing can happen
+ * (lisp trick again, immutable data structure == thread safety)
+ *
+ *
  */
 public class FileChangedDaemon extends Thread {
 

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/jci/TempFileClassLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/jci/TempFileClassLoader.java?rev=812225&r1=812224&r2=812225&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/jci/TempFileClassLoader.java (original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/scratchpad/jci/TempFileClassLoader.java Mon Sep  7 17:05:08 2009
@@ -37,7 +37,7 @@
             this.newClassPath[cnt] = path;
         }
         //TODO add a JSR 199 facade for java6
-        compiler = new JavaCompilerFactory().createCompiler("eclipse");
+            compiler = new JavaCompilerFactory().createCompiler("eclipse");
     }
 
     @Override