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/08 09:35:44 UTC
svn commit: r812360 - in /myfaces/extensions/scripting/trunk: ./ core-java6/
core-java6/src/ core-java6/src/main/ core-java6/src/main/java/
core-java6/src/main/java/org/ core-java6/src/main/java/org/apache/
core-java6/src/main/java/org/apache/myfaces/ ...
Author: werpu
Date: Tue Sep 8 07:35:43 2009
New Revision: 812360
URL: http://svn.apache.org/viewvc?rev=812360&view=rev
Log:
http://issues.apache.org/jira/browse/EXTSCRIPT-12
major project reorg part 1
Added:
myfaces/extensions/scripting/trunk/core-java6/
myfaces/extensions/scripting/trunk/core-java6/pom.xml
myfaces/extensions/scripting/trunk/core-java6/src/
myfaces/extensions/scripting/trunk/core-java6/src/main/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java
myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/Array.java
Modified:
myfaces/extensions/scripting/trunk/core/pom.xml
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/examples/pom.xml
myfaces/extensions/scripting/trunk/pom.xml
Added: myfaces/extensions/scripting/trunk/core-java6/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/pom.xml?rev=812360&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/pom.xml (added)
+++ myfaces/extensions/scripting/trunk/core-java6/pom.xml Tue Sep 8 07:35:43 2009
@@ -0,0 +1,53 @@
+<project xmlns = "http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>core-java6</artifactId>
+ <packaging>jar</packaging>
+ <name>core java6 part</name>
+
+ <description>
+ myfaces extension core java6 lib
+ </description>
+
+ <parent>
+ <groupId>org.apache.myfaces.extension-scripting</groupId>
+ <artifactId>root</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <repositories>
+ <repository>
+ <id>maven2-repository.dev.java.net</id>
+ <name>Java.net Repository for Maven</name>
+ <url>http://download.java.net/maven/2/</url>
+ <layout>default</layout>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.myfaces.extension-scripting</groupId>
+ <artifactId>core</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ <version>1.8.0</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java?rev=812360&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/CompilerFacade.java Tue Sep 8 07:35:43 2009
@@ -0,0 +1,94 @@
+/*
+ * 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;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+import javax.tools.*;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Locale;
+
+/**
+ * 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: werpu $)
+ * @version $Revision: 812255 $ $Date: 2009-09-07 20:51:39 +0200 (Mo, 07 Sep 2009) $
+ */
+public class CompilerFacade implements DynamicCompiler {
+ //TODO add optional ecj dependencies here
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector();
+ ContainerFileManager fileManager = null;
+ private static final String FILE_SEPARATOR = File.separator;
+
+ public CompilerFacade() {
+ super();
+
+ //TODO move this all into the introspection domain
+ //so that we can shift to jdk5
+ fileManager = new ContainerFileManager(compiler.getStandardFileManager(diagnosticCollector, null, null));
+
+ }
+
+
+ public Class compileFile(String sourceRoot, String classPath, String filePath) throws ClassNotFoundException {
+ Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjects(sourceRoot + FILE_SEPARATOR + filePath);
+
+ //TODO add the core jar from our lib dir
+ //the compiler otherwise cannot find the file
+ 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
+ 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();
+ log.error(error);
+ errors.append(error);
+
+ }
+ throw new ClassNotFoundException("Compile error of java file:" + errors.toString());
+ }
+
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ if (!(oldClassLoader instanceof RecompiledClassLoader)) {
+ try {
+ RecompiledClassLoader classLoader = (RecompiledClassLoader) fileManager.getClassLoader(null);
+ Thread.currentThread().setContextClassLoader(classLoader);
+ String classFile = filePath.replaceAll("\\\\", ".").replaceAll("\\/", ".");
+ classFile = classFile.substring(0, classFile.lastIndexOf("."));
+
+ return classLoader.loadClass(classFile);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
Added: myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java?rev=812360&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ContainerFileManager.java Tue Sep 8 07:35:43 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.util.List;
+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;
+ RecompiledClassLoader classLoader = null;
+
+
+ public ContainerFileManager(StandardJavaFileManager standardJavaFileManager) {
+ super(standardJavaFileManager);
+ _delegate = standardJavaFileManager;
+ classLoader = new RecompiledClassLoader(ClassUtils.getContextClassLoader());
+ }
+
+
+ @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 classLoader;
+ }
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
+ return _delegate.getJavaFileObjects(files);
+ }
+
+ public Iterable<? extends JavaFileObject> getJavaFileObjects(String... files) {
+ return _delegate.getJavaFileObjects(files);
+ }
+
+ public Iterable<? extends JavaFileObject> getJavaFileObjectsSingle(String files) {
+ return _delegate.getJavaFileObjects(files);
+ }
+
+
+ public String getClassPath() {
+ if (_classPath != null) {
+ return _classPath;
+ }
+ ClassLoader cls = getClassLoader(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();
+ }
+
+ String retStr = retVal.toString();
+ if(retStr.length()>1) {
+ retStr = retStr.substring(0, retStr.length() - 1);
+ }
+
+ return (_classPath = retStr);
+ }
+
+
+ public File getTempDir() {
+ return classLoader.getTempDir();
+ }
+}
+
+
Added: 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=812360&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/RecompiledClassLoader.java Tue Sep 8 07:35:43 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-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java?rev=812360&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java (added)
+++ myfaces/extensions/scripting/trunk/core-java6/src/main/java/org/apache/myfaces/scripting/loaders/java/jsr199/ReflectCompilerFacade.java Tue Sep 8 07:35:43 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.scripting.core.util.Null;
+import org.apache.myfaces.scripting.core.util.Cast;
+import org.apache.myfaces.scripting.core.util.Array;
+import org.apache.myfaces.scripting.core.util.ClassUtils;
+
+
+import java.io.File;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.Collection;
+import java.nio.charset.Charset;
+
+import static org.apache.myfaces.scripting.core.util.ClassUtils.*;
+import org.apache.myfaces.scripting.api.DynamicCompiler;
+
+import javax.tools.StandardJavaFileManager;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * The Compiler facade based on the reflection api
+ * to allow jdk5 compilations
+ */
+
+public class ReflectCompilerFacade implements DynamicCompiler {
+ //TODO add optional ecj dependencies here
+ Object compiler = null;
+ Object diagnosticCollector = null;
+ Object fileManager = null;
+ private static final String FILE_SEPARATOR = File.separator;
+
+ public ReflectCompilerFacade() {
+ super();
+
+ //TODO move this all into the introspection domain
+ //so that we can shift to jdk5
+ Class toolProviderClass = ClassUtils.forName("javax.tools.ToolProvider");
+ compiler = ClassUtils.executeStaticFunction(toolProviderClass, "getSystemJavaCompiler");
+ diagnosticCollector = ClassUtils.instantiate("javax.tools.DiagnosticCollector");
+
+ fileManager = ClassUtils.instantiate("org.apache.myfaces.scripting.loaders.java.jsr199.ContainerFileManager",
+ new Cast(ClassUtils.forName("javax.tools.StandardJavaFileManager"), ClassUtils.executeFunction(compiler, "getStandardFileManager", new Cast(ClassUtils.forName("javax.tools.DiagnosticListener"),diagnosticCollector), new Null(Locale.class), new Null(Charset.class))));
+
+ }
+
+
+ public Class compileFile(String sourceRoot, String classPath, String filePath) throws ClassNotFoundException {
+ Object fileObjects = ClassUtils.executeFunction(fileManager, "getJavaFileObjectsSingle", sourceRoot + FILE_SEPARATOR + filePath) ;
+
+ //TODO add the core jar from our lib dir
+ //the compiler otherwise cannot find the file
+ String[] options = new String[]{"-cp",
+ (String) ClassUtils.executeFunction(fileManager, "getClassPath"), "-d", (String) ClassUtils.executeFunction(ClassUtils.executeFunction(fileManager, "getTempDir"), "getAbsolutePath"), "-sourcepath", sourceRoot, "-g"};
+
+ ClassUtils.executeMethod(ClassUtils.executeFunction(compiler, "getTask", new Null(Writer.class), new Cast(ClassUtils.forName("javax.tools.JavaFileManager"), fileManager),new Cast(ClassUtils.forName("javax.tools.DiagnosticListener"), diagnosticCollector),new Cast(java.lang.Iterable.class, Arrays.asList(options)), new Null(Iterable.class), new Cast(java.lang.Iterable.class,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
+ Collection diagnostics = (Collection) ClassUtils.executeFunction(diagnosticCollector, "getDiagnostics");
+ Integer size = diagnostics.size();
+ if (size > 0) {
+ Log log = LogFactory.getLog(this.getClass());
+ StringBuilder errors = new StringBuilder();
+ for (Object diagnostic : diagnostics) {
+ String error = "Error on line" +
+ ClassUtils.executeFunction(diagnostic, "getMessage", Locale.getDefault()) + "------" +
+ ClassUtils.executeFunction(diagnostic, "getLineNumber") + " File:" +
+ ClassUtils.executeFunction(diagnostic, "getSource").toString();
+ log.error(error);
+ errors.append(error);
+
+ }
+ throw new ClassNotFoundException("Compile error of java file:" + errors.toString());
+ }
+
+ ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+ if (!(oldClassLoader instanceof RecompiledClassLoader)) {
+ try {
+ RecompiledClassLoader classLoader = (RecompiledClassLoader) ClassUtils.executeFunction(fileManager, "getClassLoader");
+ Thread.currentThread().setContextClassLoader(classLoader);
+ String classFile = filePath.replaceAll("\\\\", ".").replaceAll("\\/", ".");
+ classFile = classFile.substring(0, classFile.lastIndexOf("."));
+
+ return classLoader.loadClass(classFile);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldClassLoader);
+ }
+ }
+ return null;
+ }
+}
Modified: myfaces/extensions/scripting/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/pom.xml?rev=812360&r1=812359&r2=812360&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/core/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/core/pom.xml Tue Sep 8 07:35:43 2009
@@ -25,6 +25,7 @@
</repositories>
<dependencies>
+
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
@@ -79,105 +80,10 @@
</dependency>
</dependencies>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>xslt-maven-plugin</artifactId>
- <version>1.0</version>
- <configuration>
- <xslFile>src/main/tld/misc/resolve_entities.xsl</xslFile>
- <srcIncludes>**/*.tld</srcIncludes>
- <srcDir>src/main/tld</srcDir>
- <destDir>target/classes/META-INF</destDir>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>transform</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
+
</plugins>
</build>
- <reporting>
- <plugins>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>changelog-maven-plugin</artifactId>
- <version>2.0-beta-1</version>
- <reportSets>
- <reportSet>
- <id>dual-report</id>
- <configuration>
- <type>range</type>
- <range>30</range>
- </configuration>
- <reports>
- <report>changelog</report>
- <report>file-activity</report>
- <report>dev-activity</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.0-beta-3</version>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>jxr-maven-plugin</artifactId>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>taglist-maven-plugin</artifactId>
- <version>2.0-beta-1</version>
- <configuration>
- <tags>TODO, FIXME, XXX, @deprecated</tags>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>surefire-report-maven-plugin</artifactId>
- </plugin>
-
- </plugins>
- </reporting>
-
- <profiles>
- <profile>
- <id>generate-assembly</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-javadoc</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
</project>
Added: myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/Array.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/Array.java?rev=812360&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/Array.java (added)
+++ myfaces/extensions/scripting/trunk/core/src/main/java/org/apache/myfaces/scripting/core/util/Array.java Tue Sep 8 07:35:43 2009
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class Array extends Cast{
+ public Array(Class clazz, Object ... value) {
+ super(java.lang.reflect.Array.newInstance(clazz,0).getClass(), value);
+ }
+}
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=812360&r1=812359&r2=812360&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 Tue Sep 8 07:35:43 2009
@@ -18,8 +18,10 @@
*/
package org.apache.myfaces.scripting.core.util;
+
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Constructor;
/**
* @author werpu
@@ -27,11 +29,52 @@
*/
public class ClassUtils {
+
+ public static Class forName(String name) {
+ try {
+ return Class.forName(name);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Object instantiate(String clazz, Object... varargs) {
+ return instantiate(forName(clazz), varargs);
+ }
+
+ public static Object instantiate(Class clazz, Object... varargs) {
+ Class[] classes = new Class[varargs.length];
+ for (int cnt = 0; cnt < varargs.length; cnt++) {
+
+ if (varargs[cnt] instanceof Cast) {
+ classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+ varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+ } else {
+ classes[cnt] = varargs[cnt].getClass();
+ }
+ }
+
+ Constructor constr = null;
+ try {
+ constr = clazz.getConstructor(classes);
+ return (Object) constr.newInstance(varargs);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
/*this is mostly just a helper to bypass a groovy bug in a more
- * complex delegation environemt. Groovy throws a classcast
- * exeption wrongly, delegating the instantiation code to java
- * fixes that
- * */
+ * complex delegation environemt. Groovy throws a classcast
+ * exeption wrongly, delegating the instantiation code to java
+ * fixes that
+ * */
public static Object newObject(Class clazz) throws IllegalAccessException, InstantiationException {
return clazz.newInstance();
}
@@ -59,7 +102,7 @@
}
try {
- Method m = obj.getClass().getMethod(methodName, classes);
+ Method m = getMethod(obj, methodName, classes);
m.invoke(obj, varargs);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
@@ -94,7 +137,54 @@
}
try {
- Method m = obj.getClass().getMethod(methodName, classes);
+ Method m = getMethod(obj, methodName, classes);
+ return m.invoke(obj, varargs);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ private static Method getMethod(Object obj, String methodName, Class[] classes) throws NoSuchMethodException {
+ Method m = null;
+ try {
+ m = obj.getClass().getDeclaredMethod(methodName, classes);
+ } catch (NoSuchMethodException e) {
+ m = obj.getClass().getMethod(methodName, classes);
+ }
+ return m;
+ }
+
+
+ /**
+ * executes a function method on a target object
+ *
+ * @param obj the target object
+ * @param methodName the method name
+ * @param varargs a list of objects casts or nulls defining the parameter classes and its values
+ * if something occurs on introspection level an unmanaged exception is throw, just like
+ * it would happen in a scripting class
+ * @return the result object for the function(method) call
+ * @throws RuntimeException an unmanaged runtime exception in case of an introspection error
+ */
+ public static Object executeStaticFunction(Class obj, String methodName, Object... varargs) {
+ Class[] classes = new Class[varargs.length];
+ for (int cnt = 0; cnt < varargs.length; cnt++) {
+
+ if (varargs[cnt] instanceof Cast) {
+ classes[cnt] = ((Cast) varargs[cnt]).getClazz();
+ varargs[cnt] = ((Cast) varargs[cnt]).getValue();
+ } else {
+ classes[cnt] = varargs[cnt].getClass();
+ }
+ }
+
+ try {
+ Method m = getStaticMethod(obj, methodName, classes);
return m.invoke(obj, varargs);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
@@ -106,6 +196,15 @@
}
+ private static Method getStaticMethod(Class obj, String methodName, Class[] classes) throws NoSuchMethodException {
+ Method m = null;
+ try {
+ m = obj.getDeclaredMethod(methodName, classes);
+ } catch (NoSuchMethodException e) {
+ m = obj.getMethod(methodName, classes);
+ }
+ return m;
+ }
/**
* convenience method which makes the code a little bit more readable
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=812360&r1=812359&r2=812360&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 Tue Sep 8 07:35:43 2009
@@ -25,7 +25,8 @@
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.loaders.java.jsr199.CompilerFacade;
+import org.apache.myfaces.scripting.core.util.ClassUtils;
+//import org.apache.myfaces.scripting.loaders.java.jsr199.ReflectCompilerFacade;
import javax.servlet.ServletContext;
import java.io.File;
@@ -106,7 +107,7 @@
try {
//we initialize the compiler lazy
//because the facade itself is lazy
- DynamicCompiler compiler = new CompilerFacade();
+ DynamicCompiler compiler = (DynamicCompiler) ClassUtils.instantiate("org.apache.myfaces.scripting.loaders.java.jsr199.ReflectCompilerFacade");//new ReflectCompilerFacade();
retVal = compiler.compileFile(sourceRoot, classPath, file);
} catch (ClassNotFoundException e) {
//can be safely ignored
Modified: myfaces/extensions/scripting/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/examples/pom.xml?rev=812360&r1=812359&r2=812360&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/examples/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/examples/pom.xml Tue Sep 8 07:35:43 2009
@@ -40,12 +40,18 @@
<artifactId>groovy-all</artifactId>
<version>1.5.6</version>
</dependency>
+
<dependency>
<groupId>org.apache.myfaces.extension-scripting</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.myfaces.extension-scripting</groupId>
+ <artifactId>core-java6</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>1.2.8-SNAPSHOT</version>
@@ -62,6 +68,7 @@
<artifactId>portlet-api</artifactId>
<version>1.0</version>
</dependency>
+
<dependency>
<groupId>com.sun.facelets</groupId>
Modified: myfaces/extensions/scripting/trunk/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/pom.xml?rev=812360&r1=812359&r2=812360&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/pom.xml (original)
+++ myfaces/extensions/scripting/trunk/pom.xml Tue Sep 8 07:35:43 2009
@@ -13,7 +13,13 @@
<modules>
<module>core</module>
- <module>examples</module>
+ <module>core-java6</module>
+
+ <!--
+ <module>myfaces12-extensions</module>
+ <module>myfaces2-extensions</module>
+ -->
+ <module>examples</module>
<module>spring-example</module>
</modules>
@@ -172,6 +178,13 @@
<version>1.0</version>
</dependency>
+ <!--
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-jci-jsr199</artifactId>
+ <version>1.0</version>
+ </dependency>
+ -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jci-javac</artifactId>
@@ -183,17 +196,15 @@
<build>
<plugins>
-
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
-
+ <source>1.5</source>
+ <target>1.5</target>
</configuration>
</plugin>
</plugins>
-</build>
+ </build>
<reporting>
<plugins>