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/12/09 00:47:16 UTC

svn commit: r888632 - in /myfaces/extensions/scripting/trunk/core: core-java6/ core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ core/src/main/java/org/apache/myfaces/scripting/api/ core/src/main/java/org/apache/myfaces/scripti...

Author: werpu
Date: Tue Dec  8 23:47:16 2009
New Revision: 888632

URL: http://svn.apache.org/viewvc?rev=888632&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-20
save state of affairs, we move the compiler to a single compile step at the beginning of the lifecycle, not done yet but the jsr 199 full compile now is coded, we now also have to code the groovy part and move the entire groovy compile over to a full compile step

Added:
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java   (contents, props changed)
      - copied, changed from r888631, myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/JavaFileStrategy.java
Removed:
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/JavaFileStrategy.java
Modified:
    myfaces/extensions/scripting/trunk/core/core-java6/pom.xml
    myfaces/extensions/scripting/trunk/core/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/JSR199Compiler.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/reloading/ManagedBeanReloadingStrategy.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/ObjectRefreshedEvent.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/SystemEvent.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/AnnotatedArtefactLoadedEvent.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/BaseEvent.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/ClassRefreshedEvent.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/WeavingContext.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jdk5/JavacCompiler.java
    myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java

Modified: myfaces/extensions/scripting/trunk/core/core-java6/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core-java6/pom.xml?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core-java6/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/core/core-java6/pom.xml Tue Dec  8 23:47:16 2009
@@ -5,6 +5,7 @@
     <artifactId>core-java6</artifactId>
     <packaging>jar</packaging>
     <name>core java6 part</name>
+    <version>1.0-SNAPSHOT</version>
 
     <description>
         myfaces extension core java6 lib

Modified: myfaces/extensions/scripting/trunk/core/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/JSR199Compiler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/JSR199Compiler.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/JSR199Compiler.java (original)
+++ myfaces/extensions/scripting/trunk/core/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/JSR199Compiler.java Tue Dec  8 23:47:16 2009
@@ -19,7 +19,9 @@
 package org.apache.myfaces.scripting.loaders.java.jsr199;
 
 import org.apache.myfaces.scripting.api.DynamicCompiler;
+import org.apache.myfaces.scripting.api.ScriptingConst;
 import org.apache.myfaces.scripting.core.util.ClassUtils;
+import org.apache.myfaces.scripting.core.util.FileUtils;
 import org.apache.myfaces.scripting.loaders.java.RecompiledClassLoader;
 import org.apache.myfaces.scripting.loaders.java.jsr199.ContainerFileManager;
 import org.apache.commons.logging.LogFactory;
@@ -29,6 +31,7 @@
 import java.io.File;
 import java.util.Arrays;
 import java.util.Locale;
+import java.util.List;
 
 /**
  * <p>
@@ -49,9 +52,6 @@
  * to use commons-jci so we rolled our own small specialized facade for this
  * </p>
  *
- * TODO move this over to the unified compiler interface
- *
- *
  * @author Werner Punz (latest modification by $Author: werpu $)
  * @version $Revision: 812255 $ $Date: 2009-09-07 20:51:39 +0200 (Mo, 07 Sep 2009) $
  */
@@ -70,8 +70,20 @@
         }
     }
 
-    //ok this is a point of no return we cannot avoid it thanks to the dreaded
-    //windows file locking, but since this is not for production we can live with it
+    /**
+     * Compile a single file
+     *
+     * @param sourceRoot       the source search path (root of our source)
+     * @param classPath
+     * @param relativeFileName
+     * @return
+     * @throws ClassNotFoundException
+     * @deprecated note we will move over to a single
+     *             compile step in the beginning in the long run
+     *             we will deprecate it as soon as the full
+     *             compile at the beginning of the request
+     *             is implemented
+     */
     public Class compileFile(String sourceRoot, String classPath, String relativeFileName) throws ClassNotFoundException {
 
         Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjects(sourceRoot + FILE_SEPARATOR + relativeFileName);
@@ -101,19 +113,42 @@
     }
 
 
+    /**
+     * compile all files starting from a given root
+     * <p/>
+     * note, the java compiler interface does not allow per se
+     * wildcards due to its file object indirection
+     * we deal with that problem by determine all files manually and then
+     * push the list into the jsr compiler interface
+     *
+     * @param sourceRoot the root for all java sources to be compiled
+     * @param classPath  the classpath for the compilation
+     * @throws ClassNotFoundException in case of a compilation error
+     */
     public void compileAllFiles(String sourceRoot, String classPath) throws ClassNotFoundException {
-        //TODO implement this
+        List<File> sourceFiles = FileUtils.fetchSourceFiles(new File(sourceRoot), ScriptingConst.JAVA_WILDCARD);
+        Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjects(sourceFiles.toArray(new File[0]));
+        String[] options = new String[]{"-cp", fileManager.getClassPath(), "-d", fileManager.getTempDir().getAbsolutePath(), "-sourcepath", sourceRoot, "-g"};
+        javaCompiler.getTask(null, fileManager, diagnosticCollector, Arrays.asList(options), null, fileObjects).call();
+        handleDiagnostics(diagnosticCollector);
     }
 
+
+    /**
+     * internal diagnostics handler
+     * which just logs the errors
+     *
+     * @param diagnosticCollector the compilation results, the jsr 199 uses a DiagnosticsCollector object
+     *                            to keep the errors and warnings of the compiler
+     * @throws ClassNotFoundException in case of an error (this is enforced by the compiler interface
+     *                                and probably will be overhauled in the long run)
+     */
     private void handleDiagnostics(DiagnosticCollector<JavaFileObject> diagnosticCollector) throws ClassNotFoundException {
         if (diagnosticCollector.getDiagnostics().size() > 0) {
             Log log = LogFactory.getLog(this.getClass());
             StringBuilder errors = new StringBuilder();
             for (Diagnostic diagnostic : diagnosticCollector.getDiagnostics()) {
-                String error = "Error on line" +
-                               diagnostic.getMessage(Locale.getDefault()) + "------" +
-                               diagnostic.getLineNumber() + " File:" +
-                               diagnostic.getSource().toString();
+                String error = createErrorMessage(diagnostic);
                 log.error(error);
                 errors.append(error);
 
@@ -122,4 +157,23 @@
         }
     }
 
+    /**
+     * creates a standardized error message
+     *
+     * @param diagnostic the diagnostic of the compiler containing the error data
+     * @return a formatted string with the standardized error message which then later
+     *         can be processed by the user
+     */
+    private String createErrorMessage(Diagnostic diagnostic) {
+        StringBuilder retVal = new StringBuilder(256);
+        retVal.append("Java Compiler, Error on line: ");
+        retVal.append(diagnostic.getMessage(Locale.getDefault()));
+        retVal.append(diagnostic.getLineNumber());
+
+        retVal.append("\n\n");
+        retVal.append(diagnostic.getSource().toString());
+
+        return retVal.toString();
+    }
+
 }
\ No newline at end of file

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/BaseWeaver.java Tue Dec  8 23:47:16 2009
@@ -39,6 +39,7 @@
     public BaseWeaver(String fileEnding, int scriptingEngine) {
         this.fileEnding = fileEnding;
         this.scriptingEngine = scriptingEngine;
+        _reloadingStrategy = new GlobalReloadingStrategy(this);
     }
 
 

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingConst.java Tue Dec  8 23:47:16 2009
@@ -59,4 +59,5 @@
     public static final int ARTEFACT_TYPE_RESOURCEHANDLER = 19;
     public static final int ARTEFACT_TYPE_CLIENTBEHAVIORRENDERER = 20;
 
+    public static final String JAVA_WILDCARD = "*.java ";
 }

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/api/ScriptingWeaver.java Tue Dec  8 23:47:16 2009
@@ -41,15 +41,13 @@
 
 
     /**
-     * @param o the object which has to be reloaded
+     * @param o            the object which has to be reloaded
      * @param artefactType an identifier for the artefact type so that its reloading strategies can
-     * be adjusted depending on the type of artefact which has to be processed, we have to pass down
-     * this artefact because we cannot rely on instanceof here for several reasons first we do not know
-     * if a managed bean does not implement as well one of the artefact interfaces for one reason or the other
-     * secondly how do we deal with future extensions which provide new artefacts we cannot
-     * bind the code to just one implementation, hence we add some kind of type identifier here as well
-     * 
-     * 
+     *                     be adjusted depending on the type of artefact which has to be processed, we have to pass down
+     *                     this artefact because we cannot rely on instanceof here for several reasons first we do not know
+     *                     if a managed bean does not implement as well one of the artefact interfaces for one reason or the other
+     *                     secondly how do we deal with future extensions which provide new artefacts we cannot
+     *                     bind the code to just one implementation, hence we add some kind of type identifier here as well
      * @return reloads an existing objects with its attributes
      *         and assigns the reloaded class to the new object
      *         <p/>
@@ -111,4 +109,12 @@
      */
     public void fullRecompile();
 
+
+    /**
+     * callback for artefacting request refreshes
+     * some artefacts should be refreshed or cleared upon
+     * request time, others can be dealt with on on demand time
+     */
+    public void requestRefresh();
+
 }

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/reloading/ManagedBeanReloadingStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/reloading/ManagedBeanReloadingStrategy.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/reloading/ManagedBeanReloadingStrategy.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/reloading/ManagedBeanReloadingStrategy.java Tue Dec  8 23:47:16 2009
@@ -18,21 +18,22 @@
  */
 package org.apache.myfaces.scripting.core.reloading;
 
-import org.apache.myfaces.scripting.api.ReloadingStrategy;
-import org.apache.myfaces.scripting.api.BaseWeaver;
-import org.apache.myfaces.scripting.core.util.WeavingContext;
-import org.apache.myfaces.config.element.ManagedBean;
-import org.apache.myfaces.config.RuntimeConfig;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.config.annotation.LifecycleProvider;
+import org.apache.myfaces.config.annotation.LifecycleProviderFactory;
+import org.apache.myfaces.config.element.ManagedBean;
+import org.apache.myfaces.scripting.api.BaseWeaver;
+import org.apache.myfaces.scripting.api.ReloadingStrategy;
+import org.apache.myfaces.scripting.core.util.ReflectUtil;
+import org.apache.myfaces.scripting.core.util.WeavingContext;
 
 import javax.faces.context.FacesContext;
 import java.lang.reflect.InvocationTargetException;
-import java.util.Map;
 import java.util.List;
-import java.util.HashMap;
-import java.util.ArrayList;
+import java.util.Map;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -58,96 +59,16 @@
         _weaver = weaver;
     }
 
-    public Object reload(Object scriptingInstance, int artefactType) {
-        Map requestMap = WeavingContext.getRequestAttributesMap();
-        //only one reload per request allowed
-        if (requestMap != null && requestMap.containsKey(RELOAD_PERFORMED)) {
-            return scriptingInstance;
-        }
-
-        //TODO build up the managed bean idx at request time or make a request blocker
-        //so that we build up the idx only once per request
-
-        //reload the class to get new static content if needed
-        Class aclass = _weaver.reloadScriptingClass(scriptingInstance.getClass());
-        if (aclass.hashCode() == scriptingInstance.getClass().hashCode()) {
-            //class of this object has not changed although
-            // reload is enabled we can skip the rest now
-            return scriptingInstance;
-        }
-
-        reloadAllDynamicBeans();
-
-
-        getLog().info("possible reload for " + scriptingInstance.getClass().getName());
-        /*only recreation of empty constructor classes is possible*/
-        try {
-            //reload the object by instiating a new class and
-            // assigning the attributes properly
-            Object newObject = aclass.newInstance();
-
-            /*now we shuffle the properties between the objects*/
-            //TODO remove this we wont need it anymore for now
-            mapProperties(newObject, scriptingInstance);
-
-            if (requestMap != null) {
-                requestMap.put(RELOAD_PERFORMED, Boolean.TRUE);
-            }
-            return newObject;
-        } catch (Exception e) {
-            getLog().error(e);
-        }
-        return null;
-
-    }
-
-    private void removeBeanReferences(String beanName) {
-        getLog().info("ManagedBeanReloadingStrategy.removeBeanReferences(" + beanName + ")");
-    }
-
-
     /**
-     * the simplest solution for now is to dump and reload
-     * all managed beans via the config
-     * ie - we drop the managed beans from all the request, session
-     * and application scope for now by checking the bean maps
-     * for their names and removing the corresponding beans unless they implement
-     * a non droppable annotation
+     * In our case the dropping already has happend at request time
+     * no need for another reloading here
+     * 
+     * @param scriptingInstance
+     * @param artefactType
+     * @return
      */
-    private void reloadAllDynamicBeans() {
-        //TODO iterate over the bean list, identify which classes are dynamic and drop those
-        //via their bean names
-        Map<String, ManagedBean> mbeans = RuntimeConfig.getCurrentInstance(FacesContext.getCurrentInstance().getExternalContext()).getManagedBeans();
-        for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
-            Class managedBeanClass = entry.getValue().getManagedBeanClass();
-            if (WeavingContext.isDynamic(managedBeanClass)) {
-                //managed bean class found we drop the class from our session
-                removeBeanReferences(entry.getValue().getManagedBeanName());
-            }
-        }
-    }
-
-
-    /**
-     * helper to map the properties wherever possible
-     *
-     * @param target
-     * @param src
-     */
-    protected void mapProperties(Object target, Object src) {
-        try {
-
-            BeanUtils.copyProperties(target, src);
-        } catch (IllegalAccessException e) {
-            getLog().debug(e);
-            //this is wanted
-        } catch (InvocationTargetException e) {
-            getLog().debug(e);
-            //this is wanted
-        }
+    public Object reload(Object scriptingInstance, int artefactType) {
+        return scriptingInstance;
     }
 
-    private final Log getLog() {
-        return LogFactory.getLog(this.getClass());
-    }
 }

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/ObjectRefreshedEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/ObjectRefreshedEvent.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/ObjectRefreshedEvent.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/ObjectRefreshedEvent.java Tue Dec  8 23:47:16 2009
@@ -37,7 +37,7 @@
         _target = target;
     }
 
-    public ObjectRefreshedEvent( int artefactType, Object origin, Object target) {
+    public ObjectRefreshedEvent(int artefactType, Object origin, Object target) {
         super(origin.getClass().getName(), artefactType);
         _origin = origin;
         _target = target;

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/SystemEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/SystemEvent.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/SystemEvent.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/SystemEvent.java Tue Dec  8 23:47:16 2009
@@ -6,6 +6,8 @@
  */
 public interface SystemEvent {
     public Integer getEventType();
+
     public String getAffectedClassName();
+
     public Integer getArtefactType();
 }

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/AnnotatedArtefactLoadedEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/AnnotatedArtefactLoadedEvent.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/AnnotatedArtefactLoadedEvent.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/AnnotatedArtefactLoadedEvent.java Tue Dec  8 23:47:16 2009
@@ -23,7 +23,7 @@
  * @version $Revision$ $Date$
  */
 
-public class AnnotatedArtefactLoadedEvent extends BaseEvent  {
+public class AnnotatedArtefactLoadedEvent extends BaseEvent {
     private static final int EVT_TYPE_BEAN_ADDED = 1;
 
 

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/BaseEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/BaseEvent.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/BaseEvent.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/BaseEvent.java Tue Dec  8 23:47:16 2009
@@ -42,7 +42,7 @@
     }
 
     public String getAffectedClassName() {
-        return _scannedClass;  
+        return _scannedClass;
     }
 
     public Integer getEventType() {

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/ClassRefreshedEvent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/ClassRefreshedEvent.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/ClassRefreshedEvent.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/scanEvents/events/ClassRefreshedEvent.java Tue Dec  8 23:47:16 2009
@@ -23,7 +23,7 @@
  * @version $Revision$ $Date$
  */
 
-public class ClassRefreshedEvent extends BaseEvent  {
+public class ClassRefreshedEvent extends BaseEvent {
     public static final int EVT_TYPE_CLASSREFRESH = 2;
 
     public ClassRefreshedEvent(String className) {

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java Tue Dec  8 23:47:16 2009
@@ -18,7 +18,11 @@
  */
 package org.apache.myfaces.scripting.core.util;
 
+import org.apache.myfaces.scripting.loaders.java.util.DirStrategy;
+import org.apache.myfaces.scripting.loaders.java.util.FileStrategy;
+
 import java.io.File;
+import java.util.List;
 
 /**
  * @author Werner Punz (latest modification by $Author$)
@@ -28,6 +32,9 @@
 public class FileUtils {
     static double _tempMarker = Math.random();
 
+
+    
+
     public static File getTempDir() {
         File tempDir = null;
 
@@ -98,4 +105,47 @@
             path.deleteOnExit();
         }
     }
+
+
+    /**
+     * fetches recursively the files under the current root
+     *
+     * @param sourcePath the source path from which the walker should start from
+     * @param fileType the pattern upon which the file has to be matched to aka *.java etc...
+     * @return
+     */
+    public static List<File> fetchSourceFiles(File sourcePath, String fileType) {
+        FileStrategy strategy = new FileStrategy(fileType);
+        listFiles(sourcePath, strategy);
+
+        return strategy.getFoundFiles();
+    }
+
+
+    /**
+     * fetches the source paths from a given root directory in the format
+     * <path>/<appendix>;...
+     *
+     * @param sourcePath the sourcePath from which the directory traversal should happen from
+     * @param appendix the appendix which has to be appended to every path found
+     * @return a string builder of the paths found
+     */
+    public static StringBuilder fetchSourcePaths(File sourcePath,  String appendix) {
+        DirStrategy dirStrategy = new DirStrategy();
+        listFiles(sourcePath, dirStrategy);
+
+        StringBuilder sourcesList = new StringBuilder(512);
+
+        String root = sourcePath.getAbsolutePath();
+        int rootLen = root.length() + 1;
+        for (File foundDir : dirStrategy.getFoundFiles()) {
+            String dirName = foundDir.getAbsolutePath();
+            dirName = dirName.substring(rootLen);
+            sourcesList.append(dirName);
+            sourcesList.append( File.separator);
+            sourcesList.append(appendix);
+        }
+        sourcesList.append(appendix);
+        return sourcesList;
+    }
 }

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/WeavingContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/WeavingContext.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/WeavingContext.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/core/util/WeavingContext.java Tue Dec  8 23:47:16 2009
@@ -113,6 +113,13 @@
     }
 
     /**
+     * some artefacts need a full request refresh
+     */
+    public static void doRequestRefreshes() {
+
+    }
+
+    /**
      * checks whether the system
      * has scripting enabled or not
      *

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/JavaScriptingWeaver.java Tue Dec  8 23:47:16 2009
@@ -24,6 +24,11 @@
 import org.apache.myfaces.scripting.api.*;
 import org.apache.myfaces.scripting.core.util.ReflectUtil;
 import org.apache.myfaces.scripting.core.util.ClassUtils;
+import org.apache.myfaces.scripting.core.util.WeavingContext;
+import org.apache.myfaces.scripting.refresh.FileChangedDaemon;
+import org.apache.myfaces.scripting.refresh.ReloadingMetadata;
+import org.apache.myfaces.config.element.ManagedBean;
+import org.apache.myfaces.config.RuntimeConfig;
 //import org.apache.myfaces.scripting.loaders.java.jsr199.ReflectCompilerFacade;
 
 import javax.servlet.ServletContext;
@@ -33,6 +38,8 @@
 import java.lang.reflect.InvocationTargetException;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 /**
  * @author werpu
@@ -47,7 +54,7 @@
     DynamicClassIdentifier identifier = new DynamicClassIdentifier();
 
     private static final String JAVA_FILE_ENDING = ".java";
-    private static final String JSR199_COMPILER = "org.apache.myfaces.scripting.loaders.java.jsr199.CompilerFacade";
+    private static final String JSR199_COMPILER = "org.apache.myfaces.scripting.loaders.java.jsr199.JSR199Compiler";
     private static final String JAVA5_COMPILER = "org.apache.myfaces.scripting.loaders.java.jdk5.CompilerFacade";
 
     AnnotationScanner _scanner = null;
@@ -214,6 +221,74 @@
         markAsFullyRecompiled();
     }
 
+    public void requestRefresh() {
+        if (FileChangedDaemon.getInstance().getSystemRecompileMap().get(ScriptingConst.ENGINE_TYPE_JAVA)) {
+            fullRecompile();
+            //TODO if managed beans are tainted we have to do a full drop
+            refreshManagedBeans();
+        }
+    }
+
+    private void refreshManagedBeans() {
+        Set<String> tainted = new HashSet<String>();
+        for (Map.Entry<String, ReloadingMetadata> it : FileChangedDaemon.getInstance().getClassMap().entrySet()) {
+            if (it.getValue().getScriptingEngine() == ScriptingConst.ENGINE_TYPE_JAVA && it.getValue().isTainted()) {
+                tainted.add(it.getValue().getAClass().getName());
+            }
+        }
+        if (tainted.size() > 0) {
+            boolean managedBeanTainted = false;
+            //We now have to check if the tainted classes belong to the managed beans
+            Set<String> managedBeanClasses = new HashSet<String>();
+            Map<String, ManagedBean> mbeans = RuntimeConfig.getCurrentInstance(FacesContext.getCurrentInstance().getExternalContext()).getManagedBeans();
+            for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
+                managedBeanClasses.add(entry.getValue().getManagedBeanClassName());
+            }
+            for (String taintedClass : tainted) {
+                if (managedBeanClasses.contains(taintedClass)) {
+                    managedBeanTainted = true;
+                    break;
+                }
+            }
+            if (managedBeanTainted) {
+                for (Map.Entry<String, ManagedBean> entry : mbeans.entrySet()) {
+                    Class managedBeanClass = entry.getValue().getManagedBeanClass();
+                    if (WeavingContext.isDynamic(managedBeanClass)) {
+                        //managed bean class found we drop the class from our session
+                        removeBeanReferences(entry.getValue());
+                    }
+                }
+
+            }
+        }
+    }
+
+    /**
+     * removes the references from out static scope
+     * for jsf2 we probably have some kind of notification mechanism
+     * which notifies custom scopes
+     *
+     * @param bean
+     */
+    private void removeBeanReferences(ManagedBean bean) {
+        getLog().info("JavaScriptingWeaver.removeBeanReferences(" + bean.getManagedBeanName() + ")");
+
+        String scope = bean.getManagedBeanScope();
+
+        if (scope != null && scope.equalsIgnoreCase("session")) {
+            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(bean.getManagedBeanName());
+        } else if (scope != null && scope.equalsIgnoreCase("application")) {
+            FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().remove(bean.getManagedBeanName());
+        } else if (scope != null) {
+            Object scopeImpl = FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(scope);
+            if (scopeImpl == null) return; //scope not implemented
+            //we now have to revert to introspection here because scopes are a pure jsf2 construct
+            //so we use a messaging pattern here to cope with it
+            ReflectUtil.executeMethod(scopeImpl, "remove", bean.getManagedBeanName());
+        }
+    }
+    
+
     private void markAsFullyRecompiled() {
         FacesContext context = FacesContext.getCurrentInstance();
         if (context != null) {

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jdk5/JavacCompiler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jdk5/JavacCompiler.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jdk5/JavacCompiler.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jdk5/JavacCompiler.java Tue Dec  8 23:47:16 2009
@@ -4,7 +4,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.scripting.core.util.ClassUtils;
 import org.apache.myfaces.scripting.core.util.FileUtils;
-import org.apache.myfaces.scripting.loaders.java.util.DirStrategy;
+import org.apache.myfaces.scripting.api.ScriptingConst;
 
 import java.io.File;
 import java.io.PrintWriter;
@@ -45,7 +45,6 @@
      * The class reference to the internal Javac compiler.
      */
     private Class compilerClass;
-    private static final String JAVA_WILDCARD = "*.java ";
 
     // ------------------------------------------ Constructors
 
@@ -174,21 +173,7 @@
      * @return an array of arguments that you have to pass to the Javac compiler
      */
     protected String[] buildCompilerArguments(File sourcePath, File targetPath, String classPath) {
-        DirStrategy dirStrategy = new DirStrategy();
-        FileUtils.listFiles(sourcePath, dirStrategy);
-
-        StringBuilder sourcesList = new StringBuilder(512);
-
-        String root = sourcePath.getAbsolutePath();
-        int rootLen = root.length() + 1;
-        for (File foundDir : dirStrategy.getFoundFiles()) {
-            String dirName = foundDir.getAbsolutePath();
-            dirName = dirName.substring(rootLen);
-            sourcesList.append(dirName);
-            sourcesList.append(File.separator);
-            sourcesList.append(JAVA_WILDCARD);
-        }
-        sourcesList.append(JAVA_WILDCARD);
+        StringBuilder sourcesList = FileUtils.fetchSourcePaths(sourcePath, ScriptingConst.JAVA_WILDCARD);
 
         List arguments = getDefaultArguments(sourcePath, targetPath, classPath);
 

Copied: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java (from r888631, myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/JavaFileStrategy.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java?p2=myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java&p1=myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/JavaFileStrategy.java&r1=888631&r2=888632&rev=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/JavaFileStrategy.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java Tue Dec  8 23:47:16 2009
@@ -22,8 +22,12 @@
 
 import java.util.List;
 import java.util.LinkedList;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 import java.io.File;
 
+import com.sun.org.apache.xerces.internal.impl.xpath.regex.RegularExpression;
+
 /**
  * @author Werner Punz (latest modification by $Author$)
  * @version $Revision$ $Date$
@@ -32,14 +36,27 @@
  *          so that we can recompile them
  */
 
-public class JavaFileStrategy implements Strategy {
+public class FileStrategy implements Strategy {
+    Pattern rePattern;
+
+    public FileStrategy( String pattern) {
+        pattern = pattern.replace("\\.", "\\.");
+        pattern = "^.*"+pattern+"$";
+
+
+        rePattern = Pattern.compile("[+-]?[0-9]+");
+
+    }
+
 
     List<File> _foundFiles = new LinkedList<File>();
 
     public void apply(Object element) {
         File foundFile = (File) element;
         String fileName = foundFile.getName().toLowerCase();
-        if (!fileName.endsWith(".java")) return;
+        Matcher matcher = rePattern.matcher(fileName);
+
+        if (!matcher.matches()) return;
         _foundFiles.add(foundFile);
     }
 

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/loaders/java/util/FileStrategy.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java?rev=888632&r1=888631&r2=888632&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java (original)
+++ myfaces/extensions/scripting/trunk/core/core/src/main/java/org/apache/myfaces/scripting/refresh/FileChangedDaemon.java Tue Dec  8 23:47:16 2009
@@ -31,7 +31,7 @@
 /**
  * @author werpu
  *         Reimplementation of the file changed daemon thread
- *         in java, the original one was done in groovy
+ *         in java. The original one was done in groovy
  *         this threads purpose is to watch the files
  *         loaded by the various engine loaders for
  *         for file changes and then if one has changed we have to mark
@@ -42,15 +42,6 @@
 
     static FileChangedDaemon instance = null;
 
-    //TODO replace the synchronized map with a segmented map to reduce
-    //the number of synchronisation locks on parallel access
-    //we have to have in mind that the compiler facades access this map
-    //in a writable way as well to update their meta data so we
-    //should replace the map with something segmented, probably
-    //a balanced tree of depth 2
-
-    // ConcurrentHashMap<String, Renderer>(8, 0.75f, 1)
-    // segmented map here because we have to deal with multithreaded access
     Map<String, ReloadingMetadata> classMap = new ConcurrentHashMap<String, ReloadingMetadata>(8, 0.75f, 1);
 
     /**
@@ -105,15 +96,15 @@
                 if (!it.getValue().isTainted()) {
 
                     File proxyFile = new File(it.getValue().getSourcePath() + File.separator + it.getValue().getFileName());
-                    it.getValue().setTainted(proxyFile.lastModified() != it.getValue().getTimestamp());
-                    if (it.getValue().isTainted()) {
+                    if(!it.getValue().isTainted() && isModified(it, proxyFile)) {
+                        it.getValue().setTainted(true);
+
                         systemRecompileMap.put(it.getValue().getScriptingEngine(), Boolean.TRUE);
                         it.getValue().setTaintedOnce(true);
                         printInfo(it, proxyFile);
+                        it.getValue().setTimestamp(proxyFile.lastModified());
                     }
-                    it.getValue().setTimestamp(proxyFile.lastModified());
-
-                }
+               }
             }
         }
         if (log.isInfoEnabled()) {
@@ -121,6 +112,10 @@
         }
     }
 
+    private final boolean isModified(Map.Entry<String, ReloadingMetadata> it, File proxyFile) {
+        return proxyFile.lastModified() != it.getValue().getTimestamp();
+    }
+
     private void printInfo(Map.Entry<String, ReloadingMetadata> it, File proxyFile) {
         if (log.isInfoEnabled()) {
             log.info("comparing" + it.getKey() + "Dates:" + proxyFile.lastModified() + "-" + it.getValue().getTimestamp());