myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From we...@apache.org
Subject svn commit: r812255 - in /myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199: CompilerFacade.java ContainerFileManager.java RecompiledClassLoader.java ReflectCompilerFacade.java
Date Mon, 07 Sep 2009 18:51:39 GMT
Author: werpu
Date: Mon Sep  7 18:51:39 2009
New Revision: 812255

URL: http://svn.apache.org/viewvc?rev=812255&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-11
removed splitted the file to get a better encapsulation of functionality next step will be

to move the jci part into the reflection api to be able to go down to jdk5



Added:
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
    myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
Modified:
    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/loaders/java/jsr199/ContainerFileManager.java

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=812255&r1=812254&r2=812255&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 18:51:39 2009
@@ -24,7 +24,6 @@
 
 import javax.tools.*;
 import java.io.File;
-import java.io.FileInputStream;
 import java.util.Arrays;
 import java.util.Locale;
 
@@ -41,72 +40,15 @@
     JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
     DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector();
     ContainerFileManager fileManager = null;
-    private static File tempDir = null;
     private static final String FILE_SEPARATOR = File.separator;
 
     public CompilerFacade() {
         super();
-        fileManager = new ContainerFileManager(compiler.getStandardFileManager(diagnosticCollector,
null, null));
 
-        if (tempDir == null) {
-            synchronized (this.getClass()) {
-                if (tempDir != null) {
-                    return;
-                }
-                String baseTempPath = System.getProperty("java.io.tmpdir");
-                String tempDirName = "myfaces_compilation_" + Math.random();
-
-                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();
-            }
-        }
-    }
-
-
-    class RecompiledJavaClassloader extends ClassLoader {
-        RecompiledJavaClassloader(ClassLoader classLoader) {
-            super(classLoader);
-        }
-
-        RecompiledJavaClassloader() {
-        }
-
-        @Override
-        public Class<?> loadClass(String className) throws ClassNotFoundException {
-            //check if our class exists in the tempDir
-            String classFile = className.replaceAll("\\.", FILE_SEPARATOR) + ".class";
-            File target = new File(tempDir.getAbsolutePath() + FILE_SEPARATOR + classFile);
-            if (target.exists()) {
-
-                FileInputStream iStream = null;
-                int fileLength = (int) target.length();
-                byte[] fileContent = new byte[fileLength];
-
-                try {
-                    iStream = new FileInputStream(target);
-                    iStream.read(fileContent);
-                    // Erzeugt aus dem byte Feld ein Class Object.
-                    return super.defineClass(className, fileContent, 0, fileLength);
-
-                } catch (Exception e) {
-                    throw new ClassNotFoundException(e.toString());
-                } finally {
-                    if (iStream != null) {
-                        try {
-                            iStream.close();
-                        } catch (Exception e) {
-                        }
-                    }
-                }
-            }
+        //TODO move this all into the introspection domain
+        //so that we can shift to jdk5
+        fileManager = new ContainerFileManager(compiler.getStandardFileManager(diagnosticCollector,
null, null));
 
-            return super.loadClass(className);    //To change body of overridden methods
use File | Settings | File Templates.
-        }
     }
 
 
@@ -115,7 +57,7 @@
 
         //TODO add the core jar from our lib dir
         //the compiler otherwise cannot find the file
-        String[] options = new String[]{"-cp", fileManager.getClassPath(), "-d", tempDir.getAbsolutePath(),
"-sourcepath", sourceRoot, "-g"};
+        String[] options = new String[]{"-cp", fileManager.getClassPath(), "-d", fileManager.getTempDir().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
@@ -135,9 +77,9 @@
         }
 
         ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
-        if (!(oldClassLoader instanceof RecompiledJavaClassloader)) {
+        if (!(oldClassLoader instanceof RecompiledClassLoader)) {
             try {
-                RecompiledJavaClassloader classLoader = new RecompiledJavaClassloader(oldClassLoader);
+                RecompiledClassLoader classLoader = (RecompiledClassLoader) fileManager.getClassLoader(null);
                 Thread.currentThread().setContextClassLoader(classLoader);
                 String classFile = filePath.replaceAll("\\\\", ".").replaceAll("\\/", ".");
                 classFile = classFile.substring(0, classFile.lastIndexOf("."));

Modified: 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=812255&r1=812254&r2=812255&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
(original)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
Mon Sep  7 18:51:39 2009
@@ -24,6 +24,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.ArrayList;
+import java.util.List;
 import java.net.URLClassLoader;
 import java.net.URL;
 
@@ -39,11 +40,13 @@
 
     StandardJavaFileManager _delegate = null;
     String _classPath = null;
+    RecompiledClassLoader classLoader = null;
 
 
     protected ContainerFileManager(StandardJavaFileManager standardJavaFileManager) {
         super(standardJavaFileManager);
         _delegate = standardJavaFileManager;
+        classLoader = new RecompiledClassLoader(ClassUtils.getContextClassLoader());
     }
 
 
@@ -54,7 +57,7 @@
 
     @Override
     public ClassLoader getClassLoader(Location location) {
-        return ClassUtils.getContextClassLoader();
+        return classLoader;
     }
 
     Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
@@ -65,34 +68,43 @@
         return _delegate.getJavaFileObjects(files);
     }
 
+
     String getClassPath() {
         if (_classPath != null) {
             return _classPath;
         }
         ClassLoader cls = getClassLoader(null);
-        while (!(cls instanceof URLClassLoader) && cls != null) {
+
+        StringBuilder retVal = new StringBuilder(500);
+        while (cls != null) {
+            if(cls instanceof URLClassLoader ) {
+                URL[] urls = ((URLClassLoader) cls).getURLs();
+                int len = urls.length;
+                
+                for (int cnt = 0; cnt < len; cnt++) {
+
+                    retVal.append(urls[cnt].getFile());
+                    if (cnt < len - 1) {
+                        retVal.append(File.pathSeparator);
+                    }
+                }
+            }
+
             cls = cls.getParent();
         }
-        if (cls == null) {
-            return "";
-        }
 
-        URL[] urls = ((URLClassLoader) cls).getURLs();
-        int len = urls.length;
-        if (len == 0) {
-            return "";
+        String retStr = retVal.toString();
+        if(retStr.length()>1) {
+            retStr = retStr.substring(0, retStr.length() - 1);
         }
-        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());
+        return (_classPath = retStr);
     }
 
+
+    public File getTempDir() {
+        return classLoader.getTempDir();
+    }
 }
 
 

Added: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java?rev=812255&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
(added)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
Mon Sep  7 18:51:39 2009
@@ -0,0 +1,96 @@
+/*
+ * 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 java.io.File;
+import java.io.FileInputStream;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RecompiledClassLoader extends ClassLoader {
+    File tempDir = null;
+
+    RecompiledClassLoader(ClassLoader classLoader) {
+        super(classLoader);
+        if (tempDir == null) {
+            synchronized (this.getClass()) {
+                if (tempDir != null) {
+                    return;
+                }
+                String baseTempPath = System.getProperty("java.io.tmpdir");
+                String tempDirName = "myfaces_compilation_" + Math.random();
+
+                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();
+            }
+        }
+    }
+
+    RecompiledClassLoader() {
+    }
+
+
+    @Override
+    public Class<?> loadClass(String className) throws ClassNotFoundException {
+        //check if our class exists in the tempDir
+        String classFile = className.replaceAll("\\.", File.separator) + ".class";
+        File target = new File(tempDir.getAbsolutePath() + File.separator + classFile);
+        if (target.exists()) {
+
+            FileInputStream iStream = null;
+            int fileLength = (int) target.length();
+            byte[] fileContent = new byte[fileLength];
+
+            try {
+                iStream = new FileInputStream(target);
+                iStream.read(fileContent);
+                // Erzeugt aus dem byte Feld ein Class Object.
+                return super.defineClass(className, fileContent, 0, fileLength);
+
+            } catch (Exception e) {
+                throw new ClassNotFoundException(e.toString());
+            } finally {
+                if (iStream != null) {
+                    try {
+                        iStream.close();
+                    } catch (Exception e) {
+                    }
+                }
+            }
+        }
+
+        return super.loadClass(className);    //To change body of overridden methods use
File | Settings | File Templates.
+    }
+
+    public File getTempDir() {
+        return tempDir;
+    }
+
+    public void setTempDir(File tempDir) {
+        this.tempDir = tempDir;
+    }
+}

Added: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java?rev=812255&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
(added)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
Mon Sep  7 18:51:39 2009
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ReflectCompilerFacade {
+}



Mime
View raw message