myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r813070 - in /myfaces/extensions/scripting/trunk: core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ core/src/main/java/org/apache/myfaces/scripting/core/util/ core/src/main/java/org/apache/myfaces/scripting/loaders/...
Date Wed, 09 Sep 2009 18:39:20 GMT
Author: werpu
Date: Wed Sep  9 18:39:19 2009
New Revision: 813070

URL: http://svn.apache.org/viewvc?rev=813070&view=rev
Log:
http://issues.apache.org/jira/browse/EXTSCRIPT-14

refactoring of the code to enable bcel class rewriting on the jci part 


Added:
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java
Modified:
    myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.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/loaders/java/JavaScriptingWeaver.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java

Modified: myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java?rev=813070&r1=813069&r2=813070&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
(original)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
Wed Sep  9 18:39:19 2009
@@ -19,6 +19,7 @@
 package org.apache.myfaces.scripting.loaders.java.jsr199;
 
 import org.apache.myfaces.scripting.core.util.ClassUtils;
+import org.apache.myfaces.scripting.core.util.FileUtils;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -29,7 +30,7 @@
  */
 
 public class RecompiledClassLoader extends ClassLoader {
-    File tempDir = null;
+    static File tempDir = null;
     static double _tempMarker = Math.random();
 
 
@@ -41,16 +42,7 @@
                     return;
                 }
 
-                String baseTempPath = System.getProperty("java.io.tmpdir");
-                String tempDirName = "myfaces_compilation_" + _tempMarker;
-
-                tempDir = new File(baseTempPath + File.separator + tempDirName);
-                while (tempDir.exists()) {
-                    tempDirName = "myfaces_compilation_" + System.currentTimeMillis() + Math.random();
-                    tempDir = new File(baseTempPath + File.separator + tempDirName);
-                }
-                tempDir.mkdirs();
-                tempDir.deleteOnExit();
+                tempDir = FileUtils.getTempDir();
             }
         }
     }

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=813070&r1=813069&r2=813070&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
Wed Sep  9 18:39:19 2009
@@ -245,6 +245,11 @@
      * that way we dont have to hammer any data structure but can work over introspection
      * to check for an implemented marker interface
      *
+     * I cannot use the planned annotation for now
+     * because the BCEL has annotation support only
+     * in the trunk but in no official release,
+     * the annotation support will be added as soon as it is possible to use it
+     *
      * @param classPath the root classPath which hosts our class
      * @param className the className from the class which has to be rewritten
      * @throws ClassNotFoundException
@@ -253,6 +258,7 @@
         SyntheticRepository repo = SyntheticRepository.getInstance(new ClassPath(classPath));
         JavaClass javaClass = repo.loadClass(className);
         ClassGen classGen = new ClassGen(javaClass);
+        
         classGen.addInterface("org.apache.myfaces.scripting.loaders.java._ScriptingClass");
         classGen.update();
 
@@ -265,6 +271,8 @@
         }
     }
 
+  
+
     public static File classNameToFile(String classPath, String className) {
         String classFileName = classNameToRelativeFileName(className);
         File target = new File(classPath + File.separator + classFileName);

Added: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java?rev=813070&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java
(added)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/FileUtils.java
Wed Sep  9 18:39:19 2009
@@ -0,0 +1,53 @@
+/*
+ * 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.core.util;
+
+import java.io.File;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class FileUtils {
+    static double _tempMarker = Math.random();
+
+    public static File getTempDir() {
+        File tempDir = null;
+
+        String baseTempPath = System.getProperty("java.io.tmpdir");
+        String tempDirName = "myfaces_compilation_" + _tempMarker;
+
+        tempDir = new File(baseTempPath + File.separator + tempDirName);
+        while (tempDir.exists()) {
+            tempDirName = "myfaces_compilation_" + System.currentTimeMillis() + Math.random();
+            tempDir = new File(baseTempPath + File.separator + tempDirName);
+        }
+
+        synchronized (FileUtils.class) {
+            if (tempDir.exists()) {
+                return tempDir;
+            }
+            tempDir.mkdirs();
+            tempDir.deleteOnExit();
+        }
+        return tempDir;
+    }
+
+}

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=813070&r1=813069&r2=813070&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
Wed Sep  9 18:39:19 2009
@@ -46,6 +46,8 @@
     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 JCI_COMPILER = "org.apache.myfaces.scripting.loaders.java.jci";
 
     /**
      * helper to allow initial compiler classpath scanning
@@ -109,7 +111,7 @@
         try {
             //we initialize the compiler lazy
             //because the facade itself is lazy
-            DynamicCompiler compiler = (DynamicCompiler) ClassUtils.instantiate("org.apache.myfaces.scripting.loaders.java.jsr199.CompilerFacade");//new
ReflectCompilerFacade();
+            DynamicCompiler compiler = (DynamicCompiler) ClassUtils.instantiate(getScriptingFacadeClass());//new
ReflectCompilerFacade();
             retVal = compiler.compileFile(sourceRoot, classPath, file);
         } catch (ClassNotFoundException e) {
             //can be safely ignored
@@ -122,6 +124,20 @@
         return retVal;
     }
 
+    private String getScriptingFacadeClass() {
+        String javaVer = System.getProperty("java.version");
+        String [] versionArr = javaVer.split("\\.");
+
+        int major = Integer.parseInt(versionArr[Math.min(versionArr.length, 1)]);
+
+        if(major > 5) {
+            //jsr199 compliant jdk
+            return JSR199_COMPILER;
+        }
+        //otherwise 
+        return JCI_COMPILER;
+    }
+
     public boolean isDynamic(Class clazz) {
         return identifier.isDynamic(clazz);  //To change body of implemented methods use
File | Settings | File Templates.
     }

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java?rev=813070&r1=813069&r2=813070&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jci/CompilerFacade.java
Wed Sep  9 18:39:19 2009
@@ -19,6 +19,7 @@
 package org.apache.myfaces.scripting.loaders.java.jci;
 
 import org.apache.myfaces.scripting.api.DynamicCompiler;
+import org.apache.myfaces.scripting.core.util.FileUtils;
 import org.apache.myfaces.shared_impl.util.ClassUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -31,6 +32,7 @@
 import org.apache.commons.jci.stores.MemoryResourceStore;
 import org.apache.commons.jci.stores.ResourceStore;
 import org.apache.commons.jci.stores.ResourceStoreClassLoader;
+import org.apache.commons.jci.stores.FileResourceStore;
 import org.apache.commons.jci.problems.CompilationProblem;
 
 import java.io.File;
@@ -42,6 +44,7 @@
 public class CompilerFacade implements DynamicCompiler {
     JavaCompiler compiler = null;
 
+    static File tempDir = FileUtils.getTempDir();
 
     public CompilerFacade() {
         super();
@@ -54,19 +57,16 @@
     public Class compileFile(String sourceRoot, String classPath, String filePath) throws
ClassNotFoundException {
 
         ResourceReader reader = new FileResourceReader(new File(sourceRoot));
-        MemoryResourceStore target = new MemoryResourceStore();
+        FileResourceStore target = new FileResourceStore(tempDir);
         CompilationResult result = null;
         String[] toCompile = new String[]{filePath};
         String className = filePath.replaceAll(File.separator, ".");
-        className = className.replaceAll("[\\\\\\/]", ".");
-        className = className.substring(0, className.length() - 5);
+        className = org.apache.myfaces.scripting.core.util.ClassUtils.relativeFileToClassName(className);
 
         result = compiler.compile(toCompile, reader, target);
 
         if (result.getErrors().length == 0) {
-            //TODO add marker mechanism for the compiled resources
-            //ClassUtils.markAsDynamicJava(fileManager.getTempDir().getAbsolutePath(), className);
-            //for now until we have this added please use the annotation
+            org.apache.myfaces.scripting.core.util.ClassUtils.markAsDynamicJava(tempDir.getAbsolutePath(),
className);
 
             ResourceStore[] stores = {target};
             ResourceStoreClassLoader loader = new ResourceStoreClassLoader(ClassUtils.getContextClassLoader(),
stores);

Modified: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java?rev=813070&r1=813069&r2=813070&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/servlet/CustomChainLoader.java
Wed Sep  9 18:39:19 2009
@@ -31,7 +31,7 @@
 import javax.servlet.ServletContext;
 
 /**
- * a custom chainloader which adds a groovy loading
+ * a custom chainloader which adds a groovy loading    F
  * facility to our myfaces loading plugin system
  *
  * @author Werner Punz



Mime
View raw message