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 2012/03/14 16:46:07 UTC
svn commit: r1300598 [3/10] - in
/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src:
main/java/org/apache/myfaces/extensions/scripting/core/api/
main/java/org/apache/myfaces/extensions/scripting/core/common/
main/java/org/apache...
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseScanner.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseScanner.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseScanner.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/BaseScanner.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,129 @@
+/*
+ * 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.extensions.scripting.core.engine;
+
+import org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.engine.api.ScriptingEngine;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.StandardDependencyScanner;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api.DependencyScanner;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.filter.WhitelistFilter;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.loaders.ScannerClassloader;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.registry.ExternalFilterDependencyRegistry;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public abstract class BaseScanner
+{
+ List<String> _scanPaths = new LinkedList<String>();
+ DependencyScanner _depencyScanner = new StandardDependencyScanner();
+ Logger _log = Logger.getLogger(JavaDependencyScanner.class.getName());
+
+ public abstract int getEngineType();
+
+ public abstract String getFileEnding();
+
+ public synchronized void scanPaths()
+ {
+ //only one dependency check per refresh makes sense in our case
+ /* if (WeavingContext.getRefreshContext().isDependencyScanned(getEngineType())) {
+ return;
+ } else {
+ WeavingContext.getRefreshContext().setDependencyScanned(getEngineType(), true);
+ }*/
+ ScriptingEngine engine = WeavingContext.getInstance().getEngine(ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+
+ if (_log.isLoggable(Level.INFO))
+ {
+ _log.info("[EXT-SCRITPING] starting class dependency scan");
+ }
+ long start = System.currentTimeMillis();
+ final Set<String> possibleDynamicClasses = new HashSet<String>(engine.getPossibleDynamicClasses());
+
+ final ClassLoader loader = getClassLoader();
+ for (String dynamicClass : possibleDynamicClasses)
+ {
+ runScan(possibleDynamicClasses, loader, dynamicClass);
+ }
+
+ long end = System.currentTimeMillis();
+ if (_log.isLoggable(Level.FINE))
+ {
+ _log.log(Level.FINE, "[EXT-SCRITPING] class dependency scan finished, duration: {0} ms", Long.toString(end - start));
+ }
+
+ }
+
+ public void scanClass(Class clazz)
+ {
+ //TODO do nothing here
+ }
+
+ private void runScan(final Set<String> possibleDynamicClasses, final ClassLoader loader, String dynamicClass)
+ {
+ //TODO implement the dep registry
+ ExternalFilterDependencyRegistry scanRegistry = (ExternalFilterDependencyRegistry) WeavingContext.getInstance()
+ .getEngine(getEngineType()).getDependencyRegistry();
+
+ scanRegistry.clearFilters();
+ //We have to dynamically readjust the filters
+ scanRegistry.addFilter(new WhitelistFilter(possibleDynamicClasses));
+ _depencyScanner.fetchDependencies(loader, getEngineType(), dynamicClass,
+ WeavingContext.getInstance().getEngine(getEngineType()).getDependencyRegistry());
+ }
+
+ protected ClassLoader getClassLoader()
+ {
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<ScannerClassloader>()
+ {
+ public ScannerClassloader run()
+ {
+ return new ScannerClassloader(Thread.currentThread().getContextClassLoader(), getEngineType(),
+ getFileEnding(), WeavingContext.getInstance().getConfiguration().getCompileTarget());
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ _log.log(Level.SEVERE, "", e);
+ }
+ return null;
+ }
+
+ public void addScanPath(String scanPath)
+ {
+ _scanPaths.add(scanPath);
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineGroovy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineGroovy.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineGroovy.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineGroovy.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,101 @@
+/*
+ * 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.extensions.scripting.core.engine;
+
+import org.apache.myfaces.extensions.scripting.groovyloader.core.StandardGroovyReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.core.api.Configuration;
+import org.apache.myfaces.extensions.scripting.core.api.ReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
+import org.apache.myfaces.extensions.scripting.core.engine.api.CompilationResult;
+import org.apache.myfaces.extensions.scripting.core.engine.api.ScriptingEngine;
+import org.apache.myfaces.extensions.scripting.core.engine.compiler.GroovyCompiler;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import static org.apache.myfaces.extensions.scripting.core.api.ScriptingConst.*;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class EngineGroovy extends BaseEngine implements ScriptingEngine
+{
+ Logger log = Logger.getLogger(this.getClass().getName());
+
+ @Override
+ public void init(ServletContext context)
+ {
+ initPaths(context, INIT_PARAM_CUSTOM_GROOVY_LOADER_PATHS, GROOVY_SOURCE_ROOT);
+ }
+
+ @Override
+ public int getEngineType()
+ {
+ return ENGINE_TYPE_JSF_GROOVY;
+ }
+
+ public String getEngineTypeAsStr() {
+ return "Groovy";
+ }
+
+ @Override
+ public ReloadingStrategy getBasicReloadingStrategy()
+ {
+ return new StandardGroovyReloadingStrategy();
+ }
+
+ @Override
+ public String getFileEnding()
+ {
+ return "groovy";
+ }
+
+ @Override
+ //full compile
+ public CompilationResult compile()
+ {
+ WeavingContext context = WeavingContext.getInstance();
+ Configuration configuration = context.getConfiguration();
+ GroovyCompiler compiler = new GroovyCompiler();
+ File targetDir = configuration.getCompileTarget();
+ Collection<String> sourceDirs = configuration.getSourceDirs(ENGINE_TYPE_JSF_GROOVY);
+ CompilationResult res = null;
+ for (String sourceRoot : sourceDirs)
+ {
+ res = compiler.compile(new File(sourceRoot), targetDir, ClassUtils.getContextClassLoader());
+ }
+ return res;
+ }
+
+ public void scanDependencies()
+ {
+ log.info("[EXT-SCRIPTING] starting dependency scan");
+ GroovyDependencyScanner scanner = new GroovyDependencyScanner();
+ scanner.scanPaths();
+ log.info("[EXT-SCRIPTING] ending dependency scan");
+ }
+
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineJava.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineJava.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineJava.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/EngineJava.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,113 @@
+/*
+ * 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.extensions.scripting.core.engine;
+
+import org.apache.myfaces.extensions.scripting.core.api.Configuration;
+import org.apache.myfaces.extensions.scripting.core.api.ReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
+import org.apache.myfaces.extensions.scripting.core.engine.api.CompilationException;
+import org.apache.myfaces.extensions.scripting.core.engine.api.CompilationResult;
+import org.apache.myfaces.extensions.scripting.core.engine.api.ScriptingEngine;
+import org.apache.myfaces.extensions.scripting.core.engine.compiler.JSR199Compiler;
+import org.apache.myfaces.extensions.scripting.core.reloading.SimpleReloadingStrategy;
+
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.util.Collection;
+import java.util.logging.Logger;
+
+import static org.apache.myfaces.extensions.scripting.core.api.ScriptingConst.*;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class EngineJava extends BaseEngine implements ScriptingEngine
+{
+
+ Logger log = Logger.getLogger(this.getClass().getName());
+
+ @Override
+ public void init(ServletContext context)
+ {
+ initPaths(context, INIT_PARAM_CUSTOM_JAVA_LOADER_PATHS, JAVA_SOURCE_ROOT);
+ }
+
+ /**
+ * full compile will be called cyclicly
+ * from the startup and daemon thread
+ */
+ public CompilationResult compile()
+ {
+ WeavingContext context = WeavingContext.getInstance();
+ Configuration configuration = context.getConfiguration();
+ JSR199Compiler compiler = new JSR199Compiler();
+ File targetDir = configuration.getCompileTarget();
+ Collection<String> sourceDirs = configuration.getSourceDirs(getEngineType());
+ CompilationResult res = null;
+ for (String sourceRoot : sourceDirs)
+ {
+ res = compiler.compile(new File(sourceRoot), targetDir,
+ ClassUtils.getContextClassLoader());
+ if(res.hasErrors()) {
+ for(CompilationResult.CompilationMessage msg :res.getErrors()) {
+ log.severe(msg.getMessage());
+ }
+ // log.severe(res.getCompilerOutput());
+ }
+ }
+ return res;
+ }
+
+ public void scanDependencies()
+ {
+ log.info("[EXT-SCRIPTING] starting dependency scan "+getEngineTypeAsStr());
+ JavaDependencyScanner scanner = new JavaDependencyScanner();
+ scanner.scanPaths();
+ log.info("[EXT-SCRIPTING] ending dependency scan" + getEngineTypeAsStr());
+ }
+
+ //-------------------------------------------------------------------------------------
+
+ @Override
+ public int getEngineType()
+ {
+ return ENGINE_TYPE_JSF_JAVA;
+ }
+
+ public String getEngineTypeAsStr() {
+ return "Java";
+ }
+
+ @Override
+ public ReloadingStrategy getBasicReloadingStrategy()
+ {
+ return new SimpleReloadingStrategy();
+ }
+
+ @Override
+ public String getFileEnding()
+ {
+ return "java";
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/FactoryEngines.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/FactoryEngines.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/FactoryEngines.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/FactoryEngines.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,134 @@
+/*
+ * 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.extensions.scripting.core.engine;
+
+import org.apache.myfaces.extensions.scripting.core.common.util.ClassUtils;
+import org.apache.myfaces.extensions.scripting.core.common.util.FileStrategy;
+import org.apache.myfaces.extensions.scripting.core.common.util.FileUtils;
+import org.apache.myfaces.extensions.scripting.core.common.util.ReflectUtil;
+import org.apache.myfaces.extensions.scripting.core.engine.api.ScriptingEngine;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * holds references to the scripting engines
+ * initializes the engins dynamically
+ */
+public class FactoryEngines
+{
+ final Logger _log = Logger.getLogger(this.getClass().getName());
+
+ Map<Integer, ScriptingEngine> _engines = new ConcurrentHashMap<Integer, ScriptingEngine>();
+ List<ScriptingEngine> _engineOrder = new CopyOnWriteArrayList<ScriptingEngine>();
+
+ public void init() throws IOException
+ {
+ //loadEnginesDynamically();
+
+ EngineJava javaEngine = new EngineJava();
+ EngineGroovy groovyEngine = new EngineGroovy();
+ if (_engines.isEmpty())
+ {
+ _engines.put(javaEngine.getEngineType(), javaEngine);
+ _engines.put(groovyEngine.getEngineType(), groovyEngine);
+ _engineOrder.add(javaEngine);
+ _engineOrder.add(groovyEngine);
+ }
+ }
+
+ /**
+ * loads the engins dynamically from
+ * their corresponding package and name
+ *
+ * @throws IOException
+ */
+ private void loadEnginesDynamically() throws IOException
+ {
+ ClassLoader currentLoader = ClassUtils.getContextClassLoader();//this.getClass().getClassLoader();
+ String canonicalPackageName = this.getClass().getPackage().getName().replaceAll("\\.", File.separator);
+ //TODO not working in a servlet environment we for now map it hardcoded
+ Enumeration<URL> enumeration = currentLoader.getResources(canonicalPackageName);
+ while (enumeration.hasMoreElements())
+ {
+ //we load all classes which start with engine initially those are our
+ //enginesvTH
+ URL element = enumeration.nextElement();
+ File file = new File(element.getFile());
+ FileStrategy strategy = new FileStrategy(Pattern.compile("engine[^\\.(test)]+\\.class$"));
+ FileUtils.listFiles(file, strategy);
+ for (File foundFile : strategy.getFoundFiles())
+ {
+ String absoluteDir = foundFile.getAbsolutePath();
+
+ //TODO windows
+ String rootDir = absoluteDir.substring(0, absoluteDir.indexOf(canonicalPackageName));
+ String className = absoluteDir.substring(rootDir.length()).replaceAll(File.separator, ".");
+ className = className.substring(0, className.length() - 6);
+ try
+ {
+ ScriptingEngine engine = (ScriptingEngine) ReflectUtil.instantiate(currentLoader.loadClass
+ (className));
+ _engines.put(engine.getEngineType(), engine);
+ String supportedLanguage = className.substring(className.indexOf(".Engine") + ".Engine".length
+ ());
+ _log.info("[EXT-SCRIPTING] initializing Engine " + supportedLanguage);
+ _engineOrder.add(engine);
+ }
+ catch (ClassNotFoundException e)
+ {
+ //cannot happen
+ }
+ }
+ }
+ }
+
+ public Collection<ScriptingEngine> getEngines()
+ {
+ return _engineOrder;
+ }
+
+ public ScriptingEngine getEngine(int engineType)
+ {
+ return _engines.get(engineType);
+ }
+
+ private static FactoryEngines _ourInstance = new FactoryEngines();
+
+ public static FactoryEngines getInstance()
+ {
+ return _ourInstance;
+ }
+
+ private FactoryEngines()
+ {
+ }
+}
Copied: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/GroovyDependencyScanner.java (from r1300587, myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/GroovyDependencyScanner.java?p2=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/GroovyDependencyScanner.java&p1=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java&r1=1300587&r2=1300598&rev=1300598&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/GroovyDependencyScanner.java Wed Mar 14 15:46:00 2012
@@ -17,20 +17,28 @@
* under the License.
*/
-package org.apache.myfaces.extensions.scripting.scanningcore.probes;
+package org.apache.myfaces.extensions.scripting.core.engine;
+
+import org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.engine.api.ClassScanner;
/**
* @author Werner Punz (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class Probe2 {
-
- public Probe2(String[] test) {
+public class GroovyDependencyScanner extends BaseScanner implements ClassScanner
+{
+ public GroovyDependencyScanner() {
}
- public static Boolean myHello(String xxx) {
- return Boolean.TRUE;
+ public int getEngineType() {
+ return ScriptingConst.ENGINE_TYPE_JSF_GROOVY;
+ }
+ public String getFileEnding() {
+ return ScriptingConst.FILE_EXTENSION_GROOVY;
}
+
}
+
Copied: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/JavaDependencyScanner.java (from r1300587, myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/JavaDependencyScanner.java?p2=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/JavaDependencyScanner.java&p1=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java&r1=1300587&r2=1300598&rev=1300598&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/JavaDependencyScanner.java Wed Mar 14 15:46:00 2012
@@ -17,20 +17,28 @@
* under the License.
*/
-package org.apache.myfaces.extensions.scripting.scanningcore.probes;
+package org.apache.myfaces.extensions.scripting.core.engine;
+
+import org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.engine.api.ClassScanner;
/**
* @author Werner Punz (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class Probe2 {
-
- public Probe2(String[] test) {
+public class JavaDependencyScanner extends BaseScanner implements ClassScanner
+{
+ public JavaDependencyScanner() {
}
- public static Boolean myHello(String xxx) {
- return Boolean.TRUE;
+ public int getEngineType() {
+ return ScriptingConst.ENGINE_TYPE_JSF_JAVA;
+ }
+ public String getFileEnding() {
+ return ScriptingConst.JAVA_FILE_ENDING;
}
+
+
}
Copied: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ClassScanner.java (from r1300587, myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ClassScanner.java?p2=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ClassScanner.java&p1=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java&r1=1300587&r2=1300598&rev=1300598&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ClassScanner.java Wed Mar 14 15:46:00 2012
@@ -16,21 +16,24 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-package org.apache.myfaces.extensions.scripting.scanningcore.probes;
+package org.apache.myfaces.extensions.scripting.core.engine.api;
/**
+ * Generic class scanner interface
+ * which is a helper to plug in external scanners
+ * as adapters for the annotation and dependency handling
+ * we cannot deal with annotations directly in the core
+ * because we are bound by the jsf 1.2 lower threshold limit
+ * hence this indirection
+ *
* @author Werner Punz (latest modification by $Author$)
* @version $Revision$ $Date$
*/
+public interface ClassScanner {
-public class Probe2 {
-
- public Probe2(String[] test) {
+ public void scanPaths();
+ public void scanClass(Class clazz);
- }
+ public void addScanPath(String scanPath);
- public static Boolean myHello(String xxx) {
- return Boolean.TRUE;
- }
}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationException.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationException.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationException.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationException.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.extensions.scripting.core.engine.api;
+
+/**
+ * <p>This exception will usually be thrown if an error occurred while compiling a
+ * set of source files. However, note that it doesn't mean that the source files
+ * themselves contained errors but rather that the system couldn't managed to
+ * find an appropriate compiler implementation, etc.</p>
+ * <p/>
+ * <p>In order to determine whether the compiler successfully compiled a certain
+ * source file you have to look for the compilation result instead.</p>
+ */
+public class CompilationException extends Exception {
+
+ // ------------------------------------------ Constructors
+
+ /**
+ * <p>Constructs a new compilation exception with the specified detail message.</p>
+ *
+ * @param message the detail message. The detail message is saved for
+ * later retrieval by the {@link #getMessage()} method.
+ */
+ public CompilationException(String message) {
+ super(message);
+ }
+
+ /**
+ * <p>Constructs a compilation new exception with the specified detail message
+ * and cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.</p>
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ */
+ public CompilationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * <p>Constructs a new compilation exception with the specified cause and
+ * a detail message of <tt>(cause==null ? null : cause.toString())</tt>
+ * (which typically contains the class and detail message of
+ * <tt>cause</tt>).</p>
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ */
+ public CompilationException(Throwable cause) {
+ super(cause);
+ }
+
+}
+
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationResult.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationResult.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationResult.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilationResult.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,199 @@
+/*
+ * 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.extensions.scripting.core.engine.api;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>Contains all information regarding the result of a particular compilation process.</p>
+ */
+public class CompilationResult {
+
+ /**
+ * The compiler output, i.e. simply everything that the compiler would usually
+ * print to the console, if you executed the same process on the command line
+ * instead.
+ */
+ private String _compilerOutput;
+
+ /**
+ * A list of error messages that the compiler has produced. Note that if there
+ * are no error messages, it's safe to assume that compilation succeeded.
+ */
+ private List<CompilationMessage> _errors;
+
+ /**
+ * A list of warnings that the compiler has produced.
+ */
+ private List<CompilationMessage> _warnings;
+
+ // ------------------------------------------ Constructors
+
+ /**
+ * <p>Constructs a new compilation result object using the compiler output. However,
+ * note that this constructor doesn't attempt to parse the compiler output to get the
+ * error messages and warnings. You'll have to register those messages yourself
+ * afterwards.</p>
+ *
+ * @param compilerOutput the compiler output, i.e. simply everything that the compiler would
+ * usually print to the console, if you executed the same process on
+ * the command line instead
+ */
+ public CompilationResult(String compilerOutput) {
+ this._compilerOutput = compilerOutput;
+
+ this._errors = new ArrayList<CompilationMessage>();
+ this._warnings = new ArrayList<CompilationMessage>();
+ }
+
+ // ------------------------------------------ Public methods
+
+ /**
+ * <p>Returns the compiler output, i.e. simply everything that the compiler would usually
+ * print to the console, if you executed the same process on the command line
+ * instead.</p>
+ *
+ * @return the compiler output
+ */
+ public String getCompilerOutput() {
+ return _compilerOutput;
+ }
+
+ /**
+ * <p>Determines whether any error messages have been registered, i.e. whether compilation
+ * was successful.</p>
+ *
+ * @return <code>true</code if no error messages have been registered, i.e. if compilation
+ * was sucessful; <code>false</code> otherwise
+ */
+ public boolean hasErrors() {
+ return !_errors.isEmpty();
+ }
+
+ /**
+ * <p>Registers the given message as an error message.</p>
+ *
+ * @param message the error message you want to register
+ */
+ public void registerError(CompilationMessage message) {
+ if (message != null) {
+ _errors.add(message);
+ }
+ }
+
+ /**
+ * <p>Returns a list of error messages that the compiler has produced,
+ * i.e. the error messages that have been registered previously.</p>
+ *
+ * @return a list of error messages
+ */
+ public List<CompilationMessage> getErrors() {
+ return _errors;
+ }
+
+ /**
+ * <p>Registers the given message as a warning. You can register as many warnings as you want
+ * and it won't affect whether compilation was sucessful or not.</p>
+ *
+ * @param message the warning you want to register
+ */
+ public void registerWarning(CompilationMessage message) {
+ if (message != null) {
+ _warnings.add(message);
+ }
+ }
+
+ /**
+ * <p>Returns a list of warnings that the compiler has produced,
+ * i.e. the warnings that have been registered previously.</p>
+ *
+ * @return a list of warnings
+ */
+ public List<CompilationMessage> getWarnings() {
+ return _warnings;
+ }
+
+ // ------------------------------------------ Public static classes
+
+ /**
+ * <p>Utility class that contains all the required information regarding
+ * a single compilation message.</p>
+ */
+ public static class CompilationMessage {
+
+ /**
+ * the line number of this compilation message
+ */
+ private long lineNumber;
+
+ /**
+ * the actual compilation message
+ */
+ private String message;
+
+ // -------------------------------------- Constructors
+
+ /**
+ * <p>Constructs a new compilation message using the line number
+ * and the actual compilation message as a string.</p>
+ *
+ * @param lineNumber the line number
+ * @param message the actual compilation message
+ */
+ public CompilationMessage(long lineNumber, String message) {
+ this.lineNumber = lineNumber;
+ this.message = message;
+ }
+
+ // -------------------------------------- Public methods
+
+ /**
+ * <p>The number of the relevant line where this warning or error
+ * has occured, or <code>-1</code> if it is not known.</p>
+ *
+ * @return the line number
+ */
+ public long getLineNumber() {
+ return lineNumber;
+ }
+
+ /**
+ * <p>Returns the message itself as a string, i.e. the textual content
+ * of whatever the compiler complained about.</p>
+ *
+ * @return the message itself as a string
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * <p>Returns a string representation of this compilation message.</p>
+ *
+ * @return a string representation of this compilation message
+ */
+ @Override
+ public String toString() {
+ return String.format(
+ "CompilationMessage[lineNumber='%s', message='%s']", lineNumber, message);
+ }
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/Compiler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/Compiler.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/Compiler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/Compiler.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.extensions.scripting.core.engine.api;
+
+import java.io.File;
+
+/**
+ * <p>An abstract compiler interface that enables you to compile one particular file at a time.</p>
+ */
+public interface Compiler {
+
+
+
+ /**
+ * <p>Compiles the given file and creates an according class file in the given target path. Note that
+ * it is possible for the given class to reference any other classes as long as the dependent classes
+ * are available on the classpath. The given class loader determines the classes that are available
+ * on the classpath.</p>
+ *
+ * @param sourcePath the path to the source directory
+ * @param targetPath the path to the target directory
+ * @param classLoader the class loader for dependent classes
+ * @return the compilation result, i.e. the compiler output, a list of errors and a list of warnings
+ * @throws CompilationException
+ * if a severe error occurred while trying to compile a file
+ */
+ public CompilationResult compile(File sourcePath, File targetPath, ClassLoader classLoader);
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilerConst.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilerConst.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilerConst.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/CompilerConst.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,43 @@
+/*
+ * 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.extensions.scripting.core.engine.api;
+
+/**
+ * Various constants shared over the various compiler implementations
+ * JSR or non JSR!
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class CompilerConst {
+ public static final String STD_ERROR_HEAD = "Java Compiler, error on line: ";
+ public static final String STD_WARN_HEAD = "Java Compiler, warning on line: ";
+ public static final String STD_MANDATORY_WARN_HEAD = "Java Compiler, mandatory warning on line: ";
+ public static final String STD_OTHER_HEAD = "Java Compiler, other diagnostic on line: ";
+ public static final String STD_NOTE_HEAD = "Java Compiler, Info on line: ";
+ public static final String JC_CLASSPATH = "-cp";
+ public static final String JC_TARGET_PATH = "-d";
+ public static final String JC_SOURCEPATH = "-sourcepath";
+ public static final String JC_DEBUG = "-g";
+ public static final String JAVA_WILDCARD = "*.java ";
+ public static final String JC_VERBOSE = "-verbose";
+ @SuppressWarnings("unused")
+ public static final String JC_SOURCE = "-source";
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/api/ScriptingEngine.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,123 @@
+/*
+ * 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.extensions.scripting.core.engine.api;
+
+import org.apache.myfaces.extensions.scripting.core.api.ReloadingStrategy;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api.DependencyRegistry;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.core.ClassDependencies;
+import org.apache.myfaces.extensions.scripting.core.monitor.ClassResource;
+import org.apache.myfaces.extensions.scripting.core.monitor.WatchedResource;
+
+import javax.servlet.ServletContext;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface ScriptingEngine
+{
+ public void init(ServletContext context);
+
+ public Collection<String> getPossibleDynamicClasses();
+
+ public List<String> getSourcePaths();
+
+ public Map<String, ClassResource> getWatchedResources();
+
+ /**
+ * @return the identifier for the engine type
+ * each identifier must be unique to the system
+ */
+ public int getEngineType();
+
+ /**
+ * returns the file ending sufficient for this engine
+ * @return
+ */
+ public String getFileEnding();
+
+ /**
+ * runs a full scan of files to get a list of files which need to be processed
+ * for the future
+ */
+ public void scanForAddedDeleted();
+
+ /**
+ * runs the compile cycle for this engine
+ */
+ public CompilationResult compile();
+
+ /**
+ * checks if the current engine has tainted classes
+ * @return
+ */
+ public boolean isTainted();
+
+ /**
+ * checks if the current engine has a need for a recompile of certain classes
+ * @return
+ */
+ public boolean needsRecompile();
+
+ /**
+ * gets the dependency map hosted in this engine
+ *
+ * @return the dependency map
+ */
+ public ClassDependencies getDependencyMap();
+
+ /**
+ * fetches the dependency registry
+ *
+ * @return the dependency registry
+ */
+ public DependencyRegistry getDependencyRegistry();
+
+ /**
+ * Scan dependencies for this submodule
+ */
+ public void scanDependencies();
+
+ /**
+ * mark the classes which are dependend
+ * as tainted according to the dependency graph
+ * The function has to walk the graph recursively
+ * according to its state and mark all backward references
+ * as tainted.
+ */
+ public void markTaintedDependencies();
+
+ /**
+ *
+ * @return a string representation
+ * of the corresponding engine
+ */
+ public String getEngineTypeAsStr();
+
+ /**
+ * loads the basic strategy which hosts also the property copying algorithm
+ *
+ * @return the basic strategy
+ */
+ public ReloadingStrategy getBasicReloadingStrategy();
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ContainerFileManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ContainerFileManager.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ContainerFileManager.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/ContainerFileManager.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.extensions.scripting.core.engine.compiler;
+
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.common.util.ClassLoaderUtils;
+
+import javax.tools.FileObject;
+import javax.tools.ForwardingJavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * File manager, enforced by the Java Compiler API
+ * which handles the source files
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class ContainerFileManager extends ForwardingJavaFileManager<StandardJavaFileManager> {
+
+ StandardJavaFileManager _delegate = null;
+ String _classPath = null;
+
+
+ public ContainerFileManager(StandardJavaFileManager standardJavaFileManager) {
+ super(standardJavaFileManager);
+ _delegate = standardJavaFileManager;
+ }
+
+ @Override
+ public JavaFileObject getJavaFileForOutput(Location location, String s, JavaFileObject.Kind kind, FileObject fileObject) throws IOException {
+ return super.getJavaFileForOutput(location, s, kind, fileObject);
+ }
+
+ @Override
+ public ClassLoader getClassLoader(Location location) {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ public ClassLoader getClassLoader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+ 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;
+ }
+
+ String retStr = ClassLoaderUtils.buildClasspath(getClassLoader(null));
+
+ return (_classPath = retStr);
+ }
+
+ public File getTempDir() {
+ return WeavingContext.getInstance().getConfiguration().getCompileTarget();
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompiler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompiler.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompiler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/GroovyCompiler.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,160 @@
+/*
+ * 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.extensions.scripting.core.engine.compiler;
+
+import org.codehaus.groovy.control.CompilationFailedException;
+import org.codehaus.groovy.control.CompilationUnit;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.control.ErrorCollector;
+import org.codehaus.groovy.control.messages.Message;
+import org.codehaus.groovy.control.messages.SimpleMessage;
+import org.codehaus.groovy.control.messages.SyntaxErrorMessage;
+import org.apache.myfaces.extensions.scripting.core.api.Configuration;
+import org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.common.util.ClassLoaderUtils;
+import org.apache.myfaces.extensions.scripting.core.common.util.FileUtils;
+import org.apache.myfaces.extensions.scripting.core.engine.api.CompilationResult;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <p>A compiler implementation that can be used to compile Groovy source files.</p>
+ */
+public class GroovyCompiler implements org.apache.myfaces.extensions.scripting.core.engine.api.Compiler
+{
+
+ /**
+ * The logger instance for this class.
+ */
+ private static final Logger _logger = Logger.getLogger(GroovyCompiler.class.getName());
+
+ CompilationResult result = null;
+ // ------------------------------------------ Compiler methods
+
+
+ public CompilationResult compile(File sourcePath, File targetPath, ClassLoader classLoader) {
+ WeavingContext context = WeavingContext.getInstance();
+ Configuration configuration = context.getConfiguration();
+
+
+
+ List<File> sourceFiles = FileUtils.fetchSourceFiles(configuration.getWhitelistedSourceDirs(ScriptingConst
+ .ENGINE_TYPE_JSF_GROOVY), "*.groovy");
+
+ StringWriter compilerOutput = new StringWriter();
+
+ CompilationUnit compilationUnit = new CompilationUnit(
+ buildCompilerConfiguration(sourcePath, targetPath, classLoader));
+ compilationUnit.getConfiguration().setOutput(new PrintWriter(compilerOutput));
+
+ for (File sourceFile : sourceFiles) {
+ compilationUnit.addSource(sourceFile);
+ }
+
+ CompilationResult result;
+
+ try {
+ compilationUnit.compile();
+
+ result = new CompilationResult(compilerOutput.toString());
+ //context.setCompilationResult(ScriptingConst.ENGINE_TYPE_JSF_GROOVY, result);
+ //this.result = result;
+ } catch (CompilationFailedException ex) {
+ // Register all collected error messages from the Groovy compiler
+ result = new CompilationResult(compilerOutput.toString());
+ ErrorCollector collector = compilationUnit.getErrorCollector();
+ for (int i = 0; i < collector.getErrorCount(); ++i) {
+ result.registerError(convertMessage(collector.getError(i)));
+ }
+ }
+
+ // Register all collected warnings from the Groovy compiler
+ ErrorCollector collector = compilationUnit.getErrorCollector();
+ for (int i = 0; i < collector.getWarningCount(); ++i) {
+ result.registerWarning(convertMessage(collector.getWarning(i)));
+ }
+
+
+ return result;
+ }
+
+
+
+ // ------------------------------------------ Utility methods
+
+ /**
+ * <p>Converts the given Groovy compiler message into a compilation message that
+ * our compilation API consists of.</p>
+ *
+ * @param message the Groovy compiler message you want to convert
+ * @return the final converted compilation message
+ */
+ protected CompilationResult.CompilationMessage convertMessage(Message message) {
+ if (message instanceof SimpleMessage) {
+ SimpleMessage simpleMessage = (SimpleMessage) message;
+ return new CompilationResult.CompilationMessage(-1, simpleMessage.getMessage());
+ } else if (message instanceof SyntaxErrorMessage) {
+ SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message;
+ return new CompilationResult.CompilationMessage(
+ syntaxErrorMessage.getCause().getLine(), syntaxErrorMessage.getCause().getMessage());
+ } else {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "This compiler came across an unknown message kind ['{0}']. It will be ignored.", message);
+ }
+
+ return null;
+ }
+ }
+
+ /**
+ * <p>Configures the compiler by building its configuration object.</p>
+ *
+ * @param sourcePath the path to the source directory
+ * @param targetPath the path to the target directory
+ * @param classLoader the class loader to use to determine the classpath
+ * @return the compiler configuration
+ */
+ protected CompilerConfiguration buildCompilerConfiguration(File sourcePath, File targetPath, ClassLoader classLoader) {
+ CompilerConfiguration configuration = new CompilerConfiguration();
+
+ // Set the destination / target directory for the compiled .class files.
+ configuration.setTargetDirectory(targetPath.getAbsoluteFile());
+
+ // Specify the classpath of the given class loader. This enables the user to write new Java
+ // "scripts" that depend on classes that have already been loaded previously. Otherwise he
+ // wouldn't be able to use for example classes that are available in a library.
+ configuration.setClasspath(ClassLoaderUtils.buildClasspath(classLoader));
+
+ // Enable verbose output.
+ configuration.setVerbose(true);
+
+ // Generate debugging information.
+ configuration.setDebug(true);
+
+ return configuration;
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JSR199Compiler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JSR199Compiler.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JSR199Compiler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/compiler/JSR199Compiler.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,220 @@
+/*
+ * 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.extensions.scripting.core.engine.compiler;
+
+import org.apache.myfaces.extensions.scripting.core.api.Configuration;
+import org.apache.myfaces.extensions.scripting.core.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.api.WeavingContext;
+import org.apache.myfaces.extensions.scripting.core.common.util.FileUtils;
+import org.apache.myfaces.extensions.scripting.core.engine.api.CompilationException;
+import org.apache.myfaces.extensions.scripting.core.engine.api.CompilationResult;
+
+import javax.tools.Diagnostic;
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaFileObject;
+import javax.tools.ToolProvider;
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.apache.myfaces.extensions.scripting.core.api.ScriptingConst.ENGINE_TYPE_JSF_JAVA;
+import static org.apache.myfaces.extensions.scripting.core.engine.api.CompilerConst.*;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * a JSR 199 based compiler which implements
+ * our simplified compiler interface
+ */
+public class JSR199Compiler implements org.apache.myfaces.extensions.scripting.core.engine.api.Compiler
+{
+
+ javax.tools.JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
+ ContainerFileManager fileManager = null;
+
+
+ public JSR199Compiler()
+ {
+ super();
+ }
+
+ /**
+ * 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 loader the classpath holder for the compilation
+ * @return the collected compilation results as bundle
+ */
+ public CompilationResult compile(File sourceRoot, File destination, ClassLoader loader) {
+ WeavingContext context = WeavingContext.getInstance();
+ Configuration configuration = context.getConfiguration();
+ destination.mkdirs();
+ fileManager = new ContainerFileManager(javaCompiler.getStandardFileManager(new DiagnosticCollector<JavaFileObject>(), null, null));
+
+ DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
+
+ getLog().info("[EXT-SCRIPTING] Doing a full recompile");
+
+ List<File> sourceFiles = FileUtils.fetchSourceFiles(configuration.getWhitelistedSourceDirs
+ (ENGINE_TYPE_JSF_JAVA), JAVA_WILDCARD);
+
+ for (File sourceFile : sourceFiles)
+ {
+ if (!sourceFile.exists())
+ {
+ getLog().log(Level.WARNING, "[EXT-SCRIPTING] Source file with path {0} does not exist it might cause an error in the compilation process", sourceFile.getAbsolutePath());
+ }
+ }
+ Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjects(sourceFiles.toArray(new File[sourceFiles.size()]));
+ String[] options = new String[]{JC_CLASSPATH, fileManager.getClassPath(), JC_TARGET_PATH,
+ destination.getAbsolutePath(), JC_SOURCEPATH,
+ sourceRoot.getAbsolutePath(), JC_DEBUG};
+ javaCompiler.getTask(null, fileManager, diagnosticCollector, Arrays.asList(options), null, fileObjects).call();
+
+
+ CompilationResult result = handleDiagnostics(diagnosticCollector);
+
+
+ return result;
+
+ }
+
+ /**
+ * 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 CompilationResult handleDiagnostics(DiagnosticCollector<JavaFileObject> diagnosticCollector)
+ {
+ if (diagnosticCollector.getDiagnostics().size() > 0)
+ {
+ Logger log = Logger.getLogger(this.getClass().getName());
+ StringBuilder errors = new StringBuilder();
+ CompilationResult result = new CompilationResult("");
+ boolean hasError = false;
+ for (Diagnostic diagnostic : diagnosticCollector.getDiagnostics())
+ {
+ String error = createErrorMessage(diagnostic);
+ log.log(Level.WARNING, "[EXT-SCRIPTING] Compiler: {0}", error);
+
+ if (diagnostic.getKind().equals(Diagnostic.Kind.ERROR))
+ {
+ hasError = true;
+ result.getErrors().add(new CompilationResult.CompilationMessage(diagnostic.getLineNumber(), diagnostic.getMessage(Locale.getDefault())));
+ } else
+ {
+ result.getWarnings().add(new CompilationResult.CompilationMessage(diagnostic.getLineNumber(), diagnostic.getMessage(Locale.getDefault())));
+ }
+ errors.append(error);
+
+ }
+ return result;
+ } else
+ {
+ //WeavingContext.setCompilationResult(ENGINE_TYPE_JSF_JAVA, new CompilationResult(""));
+ return new CompilationResult("");
+ }
+ }
+
+ /**
+ * interruption of the compile flow should only
+ * happen if an error has occurred otherwise we will proceed
+ * as expected
+ *
+ * @param errors the errors messages found
+ * @param hasError marker if an error was found or not
+ * @throws ClassNotFoundException in case of a compile error
+ */
+ private void assertErrorFound(StringBuilder errors, boolean hasError) throws ClassNotFoundException
+ {
+ if (hasError)
+ {
+ throw new ClassNotFoundException("Compile error of java file:" + errors.toString());
+ }
+ }
+
+ /**
+ * 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);
+ if (diagnostic == null)
+ {
+ return retVal.toString();
+ }
+ if (diagnostic.getKind().equals(Diagnostic.Kind.ERROR))
+ {
+ retVal.append(STD_ERROR_HEAD);
+ } else if (diagnostic.getKind().equals(Diagnostic.Kind.NOTE))
+ {
+ retVal.append(STD_NOTE_HEAD);
+ } else if (diagnostic.getKind().equals(Diagnostic.Kind.WARNING))
+ {
+ retVal.append(STD_WARN_HEAD);
+ } else if (diagnostic.getKind().equals(Diagnostic.Kind.MANDATORY_WARNING))
+ {
+ retVal.append(STD_MANDATORY_WARN_HEAD);
+ } else if (diagnostic.getKind().equals(Diagnostic.Kind.OTHER))
+ {
+ retVal.append(STD_OTHER_HEAD);
+ }
+ String message = diagnostic.getMessage(Locale.getDefault());
+ message = (message == null) ? "" : message;
+ retVal.append(message);
+ retVal.append(diagnostic.getLineNumber());
+
+ retVal.append("\n\n");
+
+ String source = "No additional source info";
+
+ if (diagnostic.getSource() != null)
+ {
+ source = diagnostic.getSource().toString();
+ }
+ retVal.append(source);
+
+ return retVal.toString();
+ }
+
+ private Logger getLog()
+ {
+ return Logger.getLogger(this.getClass().getName());
+ }
+
+}
\ No newline at end of file
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/StandardDependencyScanner.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/StandardDependencyScanner.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/StandardDependencyScanner.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/StandardDependencyScanner.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,146 @@
+/*
+ * 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.extensions.scripting.core.engine.dependencyScan;
+
+import org.objectweb.asm.ClassReader;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api.DependencyRegistry;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api.DependencyScanner;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.core.ClassScanUtils;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.core.ClassScanVisitor;
+import org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.core.ExtendedClassReader;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A dependency scanner for
+ * our classes. This class is thread save on object level
+ * and can be used as a singleton
+ * <p/>
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class StandardDependencyScanner implements DependencyScanner
+{
+ final ClassScanVisitor _cp = new ClassScanVisitor();
+ Logger _logger = Logger.getLogger(this.getClass().getName());
+
+ public StandardDependencyScanner() {
+
+ }
+
+ public synchronized final void fetchDependencies(ClassLoader loader, Integer engineType, String className, DependencyRegistry registry) {
+ _cp.setEngineType(engineType);
+ _cp.setRootClass(className);
+ _cp.setDependencyRegistry(registry);
+ investigateInheritanceHierarchy(loader, className);
+ registry.flush(engineType);
+ }
+
+ /**
+ * this investigates the classes inheritance hierarchy for
+ * more dependencies, for now annotations and interfaces
+ * are omitted since they are not vital to our jsf dependency checks
+ * (maybe in the long run we will add interfaces and annotations as well
+ * but for now we will leave them away for speed reasons)
+ *
+ * @param loader the classLoader which should be used for the hierarchy scanning
+ * @param className the className which has to be investigated
+ */
+ private void investigateInheritanceHierarchy(ClassLoader loader, String className) {
+ //we now have to fetch the parent hierarchy
+
+ try {
+ Class toCheck = loader.loadClass(className);
+ if (toCheck == null) {
+ return;
+ }
+ scanCurrentClass(loader, className);
+
+ //we scan the hierarchy because we might have compiled-uncompiled-compiled connections, the same goes for the interfaces
+ //the basic stuff can be covered by our class scanning but for more advanced usecase we have to walk the entire hierarchy per class!
+ scanHierarchy(loader, toCheck);
+ //our asm code normally covers this but since the scanner has to work outside of asm we do it twice, the same goes for the hierarchy
+ scanInterfaces(loader, toCheck);
+ } catch (ClassNotFoundException e) {
+ _logger.log(Level.SEVERE, "DefaultDependencyScanner.investigateInheritanceHierarchy() ", e);
+ }
+ }
+
+ private void scanInterfaces(ClassLoader loader, Class toCheck) {
+ Class[] interfaces = toCheck.getInterfaces();
+ if (interfaces == null || interfaces.length == 0) {
+ return;
+ }
+
+ for (Class currentInterface : interfaces) {
+ if (ClassScanUtils.isStandardNamespace(currentInterface.getName())) {
+ continue;
+ }
+ scanCurrentClass(loader, currentInterface.getName());
+
+ //We scan also our parent interfaces to get a full coverage
+ //but since interfaces do not implement anything we can cover
+ //the parents
+ scanHierarchy(loader, currentInterface);
+ }
+ }
+
+ /**
+ * scans the parent child relationship hierarchy
+ * We have to go through the entire hierarchy except for standard
+ * namespaces due to the fact that we have to cover source <->binary<->source
+ * dependencies with binary being binary classes never to be refreshed
+ * <p/>
+ * Note we can optionally do some interface checks here
+ * for now annotations are only processed by the class scanner itself
+ * so we do not process any annotation inheritance on this level
+ * we will add the feature later
+ *
+ * @param loader the infrastructural classloader
+ * @param toCheck the class which needs to be checked
+ */
+ private void scanHierarchy(ClassLoader loader, Class toCheck) {
+ Class parent = toCheck.getSuperclass();
+
+ while (parent != null && !ClassScanUtils.isStandardNamespace(parent.getName())) {
+ scanCurrentClass(loader, parent.getName());
+ parent = parent.getSuperclass();
+ }
+ }
+
+ /**
+ * scans one level of the inheritance hierarchy
+ *
+ * @param loader the classLoader which should be used for the hierarchy scanning
+ * @param currentClassName the className which has to be investigated
+ */
+ private void scanCurrentClass(ClassLoader loader, String currentClassName) {
+ ClassReader cr;
+ try {
+ cr = new ExtendedClassReader(loader, currentClassName);
+ cr.accept(_cp, 0);
+ } catch (IOException e) {
+ _logger.log(Level.SEVERE, "scanCurrentClass() ", e);
+ }
+ }
+
+}
Copied: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/ClassFilter.java (from r1300587, myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/ClassFilter.java?p2=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/ClassFilter.java&p1=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java&r1=1300587&r2=1300598&rev=1300598&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/ClassFilter.java Wed Mar 14 15:46:00 2012
@@ -16,21 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-package org.apache.myfaces.extensions.scripting.scanningcore.probes;
+package org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api;
/**
- * @author Werner Punz (latest modification by $Author$)
- * @version $Revision$ $Date$
+ * Generic filter pattern interface
+ * used by our dependency registry to pre-filter the classes
*/
+public interface ClassFilter {
-public class Probe2 {
-
- public Probe2(String[] test) {
-
- }
-
- public static Boolean myHello(String xxx) {
- return Boolean.TRUE;
- }
+ /**
+ * checks whether the class is allowed to be processed by the filter or not
+ *
+ * @param engineType integer value of the engine type of the class
+ * @param clazz the class itself to be processed by the filter
+ * @return true if it is allowed to be processed false otherwise
+ */
+ public boolean isAllowed(Integer engineType, String clazz);
}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyRegistry.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyRegistry.java?rev=1300598&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyRegistry.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyRegistry.java Wed Mar 14 15:46:00 2012
@@ -0,0 +1,50 @@
+/*
+ * 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.extensions.scripting.core.engine.dependencyScan.api;
+
+/**
+ * General contractual interface for a dependency registry
+ * The dependency registry is a class which stores dependencies
+ * according to an internal whitelisting system.
+ * <p/>
+ * Only classes which pass the whitelisting check will be processed
+ */
+public interface DependencyRegistry {
+ /**
+ * adds a source dependency if it is able to pass the
+ * filters
+ * A dependency is only allowed to pass if it is able
+ * to pass the internal filter list
+ *
+ * @param engineType the engine type for this dependency
+ * @param rootClass the root class of this scan which all dependencies are referenced from
+ * @param currentlyVisitedClass the source which includes or casts the dependencies
+ * @param dependency the dependency to be added
+ */
+ void addDependency(Integer engineType, String rootClass, String currentlyVisitedClass, String dependency);
+
+ /**
+ * Flush which is issued at the end of processing to flush
+ * any content which has not been yet processed into our content holding
+ * data structures
+ *
+ * @param engineType the engine type which has issued the flush operation
+ */
+ void flush(Integer engineType);
+}
Copied: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyScanner.java (from r1300587, myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java)
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyScanner.java?p2=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyScanner.java&p1=myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java&r1=1300587&r2=1300598&rev=1300598&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/test/java/rewrite/org/apache/myfaces/extensions/scripting/scanningcore/probes/Probe2.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/engine/dependencyScan/api/DependencyScanner.java Wed Mar 14 15:46:00 2012
@@ -16,21 +16,22 @@
* specific language governing permissions and limitations
* under the License.
*/
-
-package org.apache.myfaces.extensions.scripting.scanningcore.probes;
+package org.apache.myfaces.extensions.scripting.core.engine.dependencyScan.api;
/**
+ * Standard dependency scanner interface
+ *
* @author Werner Punz (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-
-public class Probe2 {
-
- public Probe2(String[] test) {
-
- }
-
- public static Boolean myHello(String xxx) {
- return Boolean.TRUE;
- }
+public interface DependencyScanner {
+ /**
+ * main method every dependency scanner has to implement
+ *
+ * @param loader the classloader which is able to serve the requested class resources
+ * @param engineType integer value of the scanning triggering engine type
+ * @param className of the class to be scanned
+ * @param registry the registry which should receive the results of the scan
+ */
+ public void fetchDependencies(ClassLoader loader, Integer engineType, String className, DependencyRegistry registry);
}