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 2010/04/12 21:43:37 UTC
svn commit: r933379 [3/15] - in /myfaces/extensions/scripting/trunk:
extscript-core-root/extscript-core-java6/src/main/java/org/apache/myfaces/extensions/
extscript-core-root/extscript-core-java6/src/main/java/org/apache/myfaces/extensions/scripting/
e...
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponent.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponent.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponent.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponent.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,128 @@
+/*
+ * 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.components;
+
+import org.apache.myfaces.extensions.scripting.core.util.StringUtils;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import java.util.Locale;
+
+/**
+ * Compiler component which currently
+ * just shows the last compile output in the system
+ * <p/>
+ * Not to keep backwards compatibility to JSF 1.2
+ * we do not use the StateHelper but go the old route
+ * instead
+ */
+@SuppressWarnings("unused")
+public class CompilerComponent extends UIOutput {
+
+ String _scriptingLanguage = null;
+ String _errorsLabel = null;
+ String _warningsLabel = null;
+ private static final String RENDERER_TYPE = "org.apache.myfaces.extensions.scripting.components.CompilerComponentRenderer";
+ private static final String ERRORS_LABEL = "errorsLabel";
+ private static final String WARNINGS_LABEL = "warningsLabel";
+ private static final String SCRIPTING_LANGUAGE = "scriptingLanguage";
+
+ public CompilerComponent() {
+ super();
+ setRendererType(RENDERER_TYPE);
+ }
+
+ @Override
+ public boolean isTransient() {
+ return true;
+ }
+
+ @Override
+ public Object saveState(FacesContext facesContext) {
+ Object values[] = new Object[4];
+ values[0] = super.saveState(facesContext); //To change body of overridden methods use File | Settings | File Templates.
+ values[1] = _scriptingLanguage;
+ values[2] = _errorsLabel;
+ values[3] = _warningsLabel;
+ return values;
+ }
+
+ @Override
+ public void restoreState(FacesContext facesContext, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(facesContext, values[0]);
+
+ _scriptingLanguage = (String) values[1];
+ _errorsLabel = (String) values[2];
+ _warningsLabel = (String) values[3];
+ }
+
+
+ public String getScriptingLanguage() {
+ if (_scriptingLanguage != null) {
+ return _scriptingLanguage;
+ }
+ ValueExpression vb = getValueExpression(SCRIPTING_LANGUAGE);
+ return vb != null ? ((String) vb.getValue(getFacesContext().getELContext())) : null;
+ }
+
+ public Integer getScriptingLanguageAsInt() {
+ if (StringUtils.isBlank(_scriptingLanguage)) {
+ return ScriptingConst.ENGINE_TYPE_JSF_ALL;
+ } else {
+ String scriptingLanguage = _scriptingLanguage.toLowerCase(Locale.getDefault()).trim();
+ if (scriptingLanguage.equals("java")) {
+ return ScriptingConst.ENGINE_TYPE_JSF_JAVA;
+ } else if (_scriptingLanguage.toLowerCase(Locale.getDefault()).trim().equals("groovy")) {
+ return ScriptingConst.ENGINE_TYPE_JSF_GROOVY;
+ }
+ }
+ return ScriptingConst.ENGINE_TYPE_JSF_NO_ENGINE;
+ }
+
+ public void setScriptingLanguage(String scriptingLanguage) {
+ _scriptingLanguage = scriptingLanguage;
+ }
+
+ public String getErrorsLabel() {
+ if (_errorsLabel != null) {
+ return _errorsLabel;
+ }
+ ValueExpression vb = getValueExpression(ERRORS_LABEL);
+ return vb != null ? ((String) vb.getValue(getFacesContext().getELContext())) : null;
+ }
+
+ public void setErrorsLabel(String _errorsLabel) {
+ this._errorsLabel = _errorsLabel;
+ }
+
+ public String getWarningsLabel() {
+ if (_warningsLabel != null) {
+ return _warningsLabel;
+ }
+ ValueExpression vb = getValueExpression(WARNINGS_LABEL);
+ return vb != null ? ((String) vb.getValue(getFacesContext().getELContext())) : null;
+ }
+
+ public void setWarningsLabel(String _warningsLabel) {
+ this._warningsLabel = _warningsLabel;
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponentRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponentRenderer.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponentRenderer.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/CompilerComponentRenderer.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,150 @@
+/*
+ * 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.components;
+
+import org.apache.myfaces.extensions.scripting.api.CompilationResult;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.StringUtils;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+/**
+ * Renderer for the compiler component
+ * <p/>
+ * This renderer is responsible for rendering the last compiler output
+ * hosted in our weavingContext
+ */
+@SuppressWarnings("unchecked")
+public class CompilerComponentRenderer extends Renderer {
+
+ @Override
+ public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
+ super.encodeBegin(context, component);
+
+ ResponseWriter responseWriter = FacesContext.getCurrentInstance().getResponseWriter();
+ CompilerComponent compilerComp = (CompilerComponent) component;
+
+ Integer scriptingLanguage = compilerComp.getScriptingLanguageAsInt();
+ CompilationResult result = null;
+ switch (scriptingLanguage) {
+ case ScriptingConst.ENGINE_TYPE_JSF_JAVA:
+ result = WeavingContext.getCompilationResult(ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ break;
+ case ScriptingConst.ENGINE_TYPE_JSF_GROOVY:
+ result = WeavingContext.getCompilationResult(ScriptingConst.ENGINE_TYPE_JSF_GROOVY);
+ break;
+ case ScriptingConst.ENGINE_TYPE_JSF_ALL:
+ result = new CompilationResult("");
+ CompilationResult tempResult = WeavingContext.getCompilationResult(ScriptingConst.ENGINE_TYPE_JSF_JAVA);
+ if (tempResult != null) {
+ copyCompilationResult(result, tempResult);
+ }
+
+ tempResult = WeavingContext.getCompilationResult(ScriptingConst.ENGINE_TYPE_JSF_GROOVY);
+ if (tempResult != null) {
+ copyCompilationResult(result, tempResult);
+ }
+
+ break;
+ case ScriptingConst.ENGINE_TYPE_JSF_NO_ENGINE:
+ Logger log = Logger.getLogger(this.getClass().getName());
+ log.warning(RendererConst.WARNING_ENGINE_NOT_FOUND);
+ break;
+ }
+
+ startDiv(component, responseWriter, RendererConst.ERROR_BOX);
+ if (result == null || (!result.hasErrors() && result.getWarnings().isEmpty())) {
+ responseWriter.write(RendererConst.NO_COMPILE_ERRORS);
+ } else {
+ writeErrorsLabel(component, responseWriter, compilerComp);
+ writeErrors(component, responseWriter, result);
+ writeWarningsLabel(component, responseWriter, compilerComp);
+ writeWarnings(component, responseWriter, result);
+ }
+ endDiv(responseWriter);
+
+ responseWriter.flush();
+
+ }
+
+ private void writeWarnings(UIComponent component, ResponseWriter responseWriter, CompilationResult result) throws IOException {
+ startDiv(component, responseWriter, RendererConst.WARNINGS);
+ for (CompilationResult.CompilationMessage msg : result.getWarnings()) {
+ startDiv(component, responseWriter, RendererConst.LINE);
+ writeDiv(component, responseWriter, RendererConst.LINE_NO, String.valueOf(msg.getLineNumber()));
+ writeDiv(component, responseWriter, RendererConst.MESSAGE, msg.getMessage());
+ endDiv(responseWriter);
+ }
+ endDiv(responseWriter);
+ }
+
+ private void writeWarningsLabel(UIComponent component, ResponseWriter responseWriter, CompilerComponent compilerComp) throws IOException {
+ if (!StringUtils.isBlank(compilerComp.getWarningsLabel())) {
+ startDiv(component, responseWriter, RendererConst.WARNINGS_LABEL);
+ responseWriter.write(compilerComp.getWarningsLabel());
+ endDiv(responseWriter);
+ }
+ }
+
+ private void writeErrors(UIComponent component, ResponseWriter responseWriter, CompilationResult result) throws IOException {
+ startDiv(component, responseWriter, RendererConst.ERRORS);
+ for (CompilationResult.CompilationMessage msg : result.getErrors()) {
+ startDiv(component, responseWriter, RendererConst.LINE);
+ writeDiv(component, responseWriter, RendererConst.LINE_NO, String.valueOf(msg.getLineNumber()));
+ writeDiv(component, responseWriter, RendererConst.MESSAGE, msg.getMessage());
+ endDiv(responseWriter);
+ }
+ endDiv(responseWriter);
+ }
+
+ private String writeDiv(UIComponent component, ResponseWriter responseWriter, String styleClass, String value) throws IOException {
+ startDiv(component, responseWriter, styleClass);
+ responseWriter.write(value);
+ endDiv(responseWriter);
+ return "";
+ }
+
+ private void endDiv(ResponseWriter responseWriter) throws IOException {
+ responseWriter.endElement(RendererConst.HTML_DIV);
+ }
+
+ private void startDiv(UIComponent component, ResponseWriter responseWriter, String styleClass) throws IOException {
+ responseWriter.startElement(RendererConst.HTML_DIV, component);
+ responseWriter.writeAttribute(RendererConst.HTML_CLASS, styleClass, null);
+ }
+
+ private void writeErrorsLabel(UIComponent component, ResponseWriter responseWriter, CompilerComponent compilerComp) throws IOException {
+ if (!StringUtils.isBlank(compilerComp.getErrorsLabel())) {
+ startDiv(component, responseWriter, RendererConst.ERRORS_LABEL);
+ responseWriter.write(compilerComp.getErrorsLabel());
+ endDiv(responseWriter);
+ }
+ }
+
+ private void copyCompilationResult(CompilationResult result, CompilationResult tempResult) {
+ result.getErrors().addAll(tempResult.getErrors());
+ result.getWarnings().addAll(tempResult.getWarnings());
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/RendererConst.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/RendererConst.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/RendererConst.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/RendererConst.java Mon Apr 12 19:43:30 2010
@@ -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.components;
+
+/**
+ * Renderer Constant shared by both renderers
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class RendererConst {
+ static final String ERROR_BOX = "errorBox";
+ static final String WARNING_ENGINE_NOT_FOUND = "Warning engine not found";
+ static final String LINE_NO = "lineNo";
+ static final String MESSAGE = "message";
+ static final String NO_COMPILE_ERRORS = "No compile errors";
+ static final String HTML_DIV = "div";
+ static final String HTML_CLASS = "class";
+ static final String NO_TAINT_HISTORY_FOUND = "No taint history found";
+ static final String LINE = "line";
+ static final String TIMESTAMP = "timestamp";
+ static final String CHANGED_FILE = "changedFile";
+ static final String ERRORS_LABEL = "errorsLabel";
+ static final String WARNINGS_LABEL = "warningsLabel";
+ static final String ERRORS = "errors";
+ static final String WARNINGS = "warnings";
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistory.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistory.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistory.java Mon Apr 12 19:43:30 2010
@@ -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.components;
+
+import javax.el.ValueExpression;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+
+/**
+ * Component which allows to check which files
+ * have been marked as possibly modified in the recent history
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class TaintHistory extends UIOutput {
+
+ public static final int DEFAULT_NO_ENTRIES = 10;
+
+ Integer _noEntries;
+ String _filter;
+ private static final String RENDERER_TYPE = "org.apache.myfaces.extensions.scripting.components.TaintHistoryRenderer";
+ private static final String NO_ENTRIES = "noEntries";
+
+ public TaintHistory() {
+ setRendererType(RENDERER_TYPE);
+ }
+
+ @SuppressWarnings("unused")
+ public void setNoEntries(Integer entries) {
+ _noEntries = entries;
+ }
+
+ @Override
+ public Object saveState(FacesContext facesContext) {
+ Object values[] = new Object[3];
+ values[0] = super.saveState(facesContext); //To change body of overridden methods use File | Settings | File Templates.
+ values[1] = _noEntries;
+ values[2] = _filter;
+ return values;
+ }
+
+ @Override
+ public void restoreState(FacesContext facesContext, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(facesContext, values[0]);
+ _noEntries = (Integer) values[1];
+ _filter = (String) values[2];
+ }
+
+ public Integer getNoEntries() {
+ if (_noEntries != null) {
+ return _noEntries;
+ }
+ ValueExpression vb = getValueExpression(NO_ENTRIES);
+ return vb != null ? ((Integer) vb.getValue(getFacesContext().getELContext())) : DEFAULT_NO_ENTRIES;
+ }
+
+ @SuppressWarnings("unused")
+ public void setFilter(String filter) {
+ _filter = filter;
+ }
+
+ @SuppressWarnings("unused")
+ public String getFilter() {
+ if (_filter != null) {
+ return _filter;
+ }
+ ValueExpression vb = getValueExpression(NO_ENTRIES);
+ return vb != null ? ((String) vb.getValue(getFacesContext().getELContext())) : null;
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistoryRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistoryRenderer.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistoryRenderer.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/components/TaintHistoryRenderer.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.components;
+
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+import org.apache.myfaces.extensions.scripting.refresh.ReloadingMetadata;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * A renderer which displays our taint history
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("unchecked")
+//we have to suppress here because of the component cast
+public class TaintHistoryRenderer extends Renderer {
+
+ @Override
+ public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
+ super.encodeBegin(context, component);
+
+ ResponseWriter responseWriter = FacesContext.getCurrentInstance().getResponseWriter();
+
+ startDiv(component, responseWriter, "historyBox");
+ int lastTainted = ((TaintHistory) component).getNoEntries();
+
+ Collection<ReloadingMetadata> result = WeavingContext.getRefreshContext().getLastTainted(lastTainted);
+ if (result == null || result.isEmpty()) {
+ responseWriter.write(RendererConst.NO_TAINT_HISTORY_FOUND);
+ } else {
+ writeHistory(component, responseWriter, result);
+ }
+ endDiv(responseWriter);
+
+ responseWriter.flush();
+
+ }
+
+ private void writeHistory(UIComponent component, ResponseWriter responseWriter, Collection<ReloadingMetadata> result) throws IOException {
+ startDiv(component, responseWriter, "history");
+ for (ReloadingMetadata entry : result) {
+ startDiv(component, responseWriter, RendererConst.LINE);
+ writeDiv(component, responseWriter, RendererConst.TIMESTAMP, DateFormat.getInstance().format(new Date(entry.getTimestamp())));
+ writeDiv(component, responseWriter, RendererConst.CHANGED_FILE, entry.getFileName());
+ endDiv(responseWriter);
+ }
+
+ endDiv(responseWriter);
+ }
+
+ private String writeDiv(UIComponent component, ResponseWriter responseWriter, String styleClass, String value) throws IOException {
+ startDiv(component, responseWriter, styleClass);
+ responseWriter.write(value);
+ endDiv(responseWriter);
+ return "";
+ }
+
+ private void endDiv(ResponseWriter responseWriter) throws IOException {
+ responseWriter.endElement(RendererConst.HTML_DIV);
+ }
+
+ private void startDiv(UIComponent component, ResponseWriter responseWriter, String styleClass) throws IOException {
+ responseWriter.startElement(RendererConst.HTML_DIV, component);
+ responseWriter.writeAttribute(RendererConst.HTML_CLASS, styleClass, null);
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/CoreWeaver.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/CoreWeaver.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/CoreWeaver.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/CoreWeaver.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,147 @@
+/*
+ * 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;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+
+import java.io.Serializable;
+import java.util.*;
+
+/**
+ * @author werpu
+ * <p/>
+ * Facade which holds multiple weavers
+ * and implements a chain of responsibility pattern
+ * on them
+ */
+public class CoreWeaver implements Serializable, ScriptingWeaver {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3034995032644947216L;
+
+ List<ScriptingWeaver> _weavers = new ArrayList<ScriptingWeaver>();
+
+ public CoreWeaver(ScriptingWeaver... weavers) {
+ _weavers.addAll(Arrays.asList(weavers));
+ }
+
+ public void appendCustomScriptPath(String scriptPaths) {
+ throw new RuntimeException("Method not supported from this facade");
+ }
+
+ public Object reloadScriptingInstance(Object o, int artefactType) {
+
+ for (ScriptingWeaver weaver : _weavers) {
+ if (weaver.isDynamic(o.getClass())) {
+ return weaver.reloadScriptingInstance(o, artefactType);
+ }
+ }
+ return o;
+
+ }
+
+ public Class reloadScriptingClass(Class aclass) {
+
+ for (ScriptingWeaver weaver : _weavers) {
+ if (weaver.isDynamic(aclass)) {
+ return weaver.reloadScriptingClass(aclass);
+ }
+ }
+ return aclass;
+
+ }
+
+ public Class loadScriptingClassFromName(String className) {
+ for (ScriptingWeaver weaver : _weavers) {
+ Class retVal = weaver.loadScriptingClassFromName(className);
+ if (retVal != null) {
+ return retVal;
+ }
+ }
+ return null;
+ }
+
+ public int getScriptingEngine() {
+ return ScriptingConst.ENGINE_TYPE_JSF_ALL; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isDynamic(Class clazz) {
+ for (ScriptingWeaver weaver : _weavers) {
+ if (weaver.isDynamic(clazz)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public ScriptingWeaver getWeaverInstance(Class weaverClass) {
+ for (ScriptingWeaver weaver : _weavers) {
+ ScriptingWeaver retVal = weaver.getWeaverInstance(weaverClass);
+ if (retVal != null) {
+ return retVal;
+ }
+ }
+ return null;
+ }
+
+ public void fullClassScan() {
+ for (ScriptingWeaver weaver : _weavers) {
+ weaver.fullClassScan();
+ }
+ }
+
+ /**
+ * @deprecated the full recompile now is done at the beginning of a request
+ */
+ public void fullRecompile() {
+ for (ScriptingWeaver weaver : _weavers) {
+ weaver.fullRecompile();
+ }
+ }
+
+ public void postStartupActions() {
+ for (ScriptingWeaver weaver : _weavers) {
+ weaver.postStartupActions();
+ }
+ }
+
+ public void requestRefresh() {
+
+ for (ScriptingWeaver weaver : _weavers) {
+ weaver.requestRefresh();
+ }
+ }
+
+ public Collection<String> loadPossibleDynamicClasses() {
+ LinkedList<String> retVal = new LinkedList<String>();
+ for (ScriptingWeaver weaver : _weavers) {
+ retVal.addAll(weaver.loadPossibleDynamicClasses());
+ }
+ return retVal;
+ }
+
+ public void scanForAddedClasses() {
+ for (ScriptingWeaver weaver : _weavers) {
+ weaver.scanForAddedClasses();
+ }
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/DummyWeaver.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/DummyWeaver.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/DummyWeaver.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/DummyWeaver.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,88 @@
+/*
+ * 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;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.api.ScriptingConst;
+import org.apache.myfaces.extensions.scripting.core.util.ClassUtils;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * a dummy weaver in case the filter has not been set
+ */
+
+public class DummyWeaver implements Serializable, ScriptingWeaver {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1504583349449148143L;
+
+ public void appendCustomScriptPath(String scriptPaths) {
+ }
+
+ public Object reloadScriptingInstance(Object o, int artifactType) {
+ return o;
+ }
+
+ public Class reloadScriptingClass(Class aclass) {
+ return aclass;
+ }
+
+ public Class loadScriptingClassFromName(String className) {
+ return ClassUtils.forName(className);
+ }
+
+ public int getScriptingEngine() {
+ return ScriptingConst.ENGINE_TYPE_JSF_ALL;
+ }
+
+ public boolean isDynamic(Class clazz) {
+ return false;
+ }
+
+ public ScriptingWeaver getWeaverInstance(Class weaverClass) {
+ return this;
+ }
+
+ public void fullClassScan() {
+ }
+
+ public void fullRecompile() {
+
+ }
+
+ public void postStartupActions() {
+ }
+
+ public void requestRefresh() {
+ }
+
+ public Collection<String> loadPossibleDynamicClasses() {
+ return null;
+ }
+
+ public void scanForAddedClasses() {
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/MethodLevelReloadingHandler.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/MethodLevelReloadingHandler.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/MethodLevelReloadingHandler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/MethodLevelReloadingHandler.java Mon Apr 12 19:43:30 2010
@@ -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;
+
+import org.apache.myfaces.extensions.scripting.api.ScriptingWeaver;
+import org.apache.myfaces.extensions.scripting.core.util.WeavingContext;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Generic artifact invocation handler
+ * which should be able to cover
+ * all interfaceable artifacts which
+ * only have reloading logic
+ * and can cope with reloading on method level
+ * <p/>
+ * Note this works only for a minority of the artifacts
+ * the reason, most artifacts do not rely on interfaces but
+ * on base classes
+ *
+ * @author Werner Punz
+ */
+@SuppressWarnings("unused")
+public class MethodLevelReloadingHandler extends ReloadingInvocationHandler implements Serializable {
+
+ private static final long serialVersionUID = -3034995032644947216L;
+
+ transient ScriptingWeaver _weaver = null;
+ int _artifactType;
+
+ public MethodLevelReloadingHandler(Object rootObject, int artifactType) {
+ _loadedClass = rootObject.getClass();
+ _delegate = rootObject;
+ _artifactType = artifactType;
+ }
+
+ /**
+ * outside interface to the invoke method
+ * which gets called every time a method
+ * is called
+ *
+ * @param object the object holding the method
+ * @param method the method
+ * @param paramHolders the param holders
+ * @return the return value of the operation
+ * @throws Throwable in case of an error
+ */
+ public Object invoke(Object object, Method method, Object[] paramHolders) throws Throwable {
+ return reloadInvoke(method, paramHolders);
+ }
+
+ /**
+ * invoke handler which is triggered
+ * by every method call which takes care of the reload
+ *
+ * @param method the method to call
+ * @param paramHolders the params
+ * @return the return value of the operation
+ * @throws InstantiationException standard throw caused by reflection
+ * @throws IllegalAccessException standard throw caused by reflection
+ * @throws InvocationTargetException standard throw caused by reflection
+ */
+
+ protected Object reloadInvoke(Method method, Object[] paramHolders) throws InstantiationException, IllegalAccessException, InvocationTargetException {
+ if (_weaver == null)
+ _weaver = WeavingContext.getWeaver();
+
+ if (_delegate == null) {
+ //stateless or lost state due to a lifecycle iteration we trigger anew
+ _delegate = (_weaver.reloadScriptingClass(_loadedClass)).newInstance();
+ } else {
+ //if we are stateful only a tainted artifact is reloaded
+ _delegate = _weaver.reloadScriptingInstance(_delegate, _artifactType);
+
+ //we work our way through all proxies and fetch the class for further reference
+ Object delegate = WeavingContext.getDelegateFromProxy(_delegate);
+ _loadedClass = delegate.getClass();
+ }
+ //check for proxies and unproxy them before calling the methods
+ //to avoid unnecessary cast problems
+ //this is slow on long param lists but it is better
+ //to be slow than to have casts an calls in the code
+ //for production we can compile the classes anyway and avoid
+ //this
+ unmapProxies(paramHolders);
+ return method.invoke(_delegate, paramHolders);
+ }
+
+ /**
+ * unmap proxied objects
+ *
+ * @param objects the objects to be unmapped
+ */
+ private void unmapProxies(Object[] objects) {
+ if (objects == null) return;
+ for (int cnt = 0; cnt < objects.length; cnt++) {
+ objects[cnt] = WeavingContext.getDelegateFromProxy(objects[cnt]);
+ }
+ }
+
+ public int getArtifactType() {
+ return _artifactType;
+ }
+
+ public void setArtifactType(int artifactType) {
+ _artifactType = artifactType;
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ _weaver = null;
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/ReloadingInvocationHandler.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/ReloadingInvocationHandler.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/ReloadingInvocationHandler.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/ReloadingInvocationHandler.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,51 @@
+package org.apache.myfaces.extensions.scripting.core;
+
+import org.apache.myfaces.extensions.scripting.api.Decorated;
+import org.apache.myfaces.extensions.scripting.core.util.ReflectUtil;
+
+import java.lang.reflect.InvocationHandler;
+
+/**
+ * <p/>
+ * We set our own invocation handler
+ * here to allow reflection utils directly targeting our
+ * _delegate.
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("unused")
+public abstract class ReloadingInvocationHandler implements InvocationHandler, Decorated {
+ Class _loadedClass = null;
+ Object _delegate = null;
+
+ /**
+ * simplified invoke for more dynamic upon invocation
+ * on our reloading objects
+ *
+ * @param object the object to be invoked on
+ * @param method the method to be invoked
+ * @param arguments the arguments passed down
+ * @return the return value of the operation
+ */
+ public Object invoke(Object object, String method, Object... arguments) {
+ return ReflectUtil.executeMethod(object, method, arguments);
+ }
+
+ public Class getLoadedClass() {
+ return _loadedClass;
+ }
+
+ public Object getDelegate() {
+ return _delegate;
+ }
+
+ public void setDelegate(Object delegate) {
+ _delegate = delegate;
+ }
+
+ public void setLoadedClassName(Class loadedClass) {
+ this._loadedClass = loadedClass;
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/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/dependencyScan/StandardDependencyScanner.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/StandardDependencyScanner.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/StandardDependencyScanner.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,145 @@
+/*
+ * 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.dependencyScan;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyScanner;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.core.ClassScanUtils;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.core.ClassScanVisitor;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.core.ExtendedClassReader;
+import org.objectweb.asm.ClassReader;
+
+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);
+ }
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/ClassFilter.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/dependencyScan/api/ClassFilter.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/ClassFilter.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/ClassFilter.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,17 @@
+package org.apache.myfaces.extensions.scripting.core.dependencyScan.api;
+
+/**
+ * Generic filter pattern interface
+ * used by our dependency registry to pre-filter the classes
+ */
+public interface ClassFilter {
+
+ /**
+ * 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/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/dependencyScan/api/DependencyRegistry.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/DependencyRegistry.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/DependencyRegistry.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,32 @@
+package org.apache.myfaces.extensions.scripting.core.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);
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/DependencyScanner.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/dependencyScan/api/DependencyScanner.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/DependencyScanner.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/api/DependencyScanner.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.dependencyScan.api;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.registry.ExternalFilterDependencyRegistry;
+
+/**
+ * Standard dependency scanner interface
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+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);
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassDependencies.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/dependencyScan/core/ClassDependencies.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassDependencies.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassDependencies.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,102 @@
+/*
+ * 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.dependencyScan.core;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * class dependency maps
+ * note this class is thread save
+ */
+public class ClassDependencies {
+
+ /**
+ * reverse index which shows which
+ * a class name and which classes in the system depend on that
+ * classname
+ * <p/>
+ * <p/>
+ * the key is a dependency a class has the _value is a set of classes which depend on the current class
+ */
+ private Map<String, Set<String>> reverseIndex = new ConcurrentHashMap<String, Set<String>>();
+
+ public void addDependency(String referencingClass, String referencedClass) {
+ Set<String> reverseDependencies = getReverseDependencies(referencedClass);
+ reverseDependencies.add(referencingClass);
+ }
+
+ /**
+ * adds a set of dependencies to the
+ * reverse lookup index
+ *
+ * @param referencingClass the referencing class of this dependency
+ * @param referencedClasses the referenced class of this dependency
+ */
+ public void addDependencies(String referencingClass, Collection<String> referencedClasses) {
+ for (String referencedClass : referencedClasses) {
+ addDependency(referencingClass, referencedClass);
+ }
+ }
+
+ /**
+ * removes a referenced class an all its referencing classes!
+ *
+ * @param clazz the referenced class to be deleted
+ */
+ public void removeReferenced(String clazz) {
+ reverseIndex.remove(clazz);
+ }
+
+ /**
+ * removes a referencing class
+ * and deletes the referenced
+ * entry if it is not referenced anymore
+ *
+ * @param clazz the referencing class to delete
+ */
+ @SuppressWarnings("unused")
+ public void removeReferrer(String clazz) {
+ List<String> emptyReferences = new ArrayList<String>(reverseIndex.size());
+ for (Map.Entry<String, Set<String>> entry : reverseIndex.entrySet()) {
+ Set<String> entrySet = entry.getValue();
+ entrySet.remove(clazz);
+ if (entrySet.isEmpty()) {
+ emptyReferences.add(entry.getKey());
+ }
+ }
+ for (String toDelete : emptyReferences) {
+ removeReferenced(toDelete);
+ }
+ }
+
+ public Set<String> getReferringClasses(String referencedClass) {
+ return reverseIndex.get(referencedClass);
+ }
+
+ private Set<String> getReverseDependencies(String dependency) {
+ Set<String> dependencies = reverseIndex.get(dependency);
+ if (dependencies == null) {
+ dependencies = Collections.synchronizedSet(new HashSet<String>());
+ reverseIndex.put(dependency, dependencies);
+ }
+ return dependencies;
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassScanUtils.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/dependencyScan/core/ClassScanUtils.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassScanUtils.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassScanUtils.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.dependencyScan.core;
+
+/**
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ * <p/>
+ * Utils which store the shared code
+ */
+public class ClassScanUtils {
+
+ private static final String DOMAIN_JAVA = "java.";
+ private static final String DOMAIN_JAVAX = "javax.";
+ private static final String DOMAIN_COM_SUN = "com.sun";
+ private static final String DOMAIN_APACHE = "org.apache.";
+ private static final String DOMAIN_MYFACES = "org.apache.myfaces";
+ private static final String DOMAIN_JBOSS = "org.jboss";
+ private static final String DOMAIN_SPRING = "org.springframework";
+ private static final String DOMAIN_JUNIT = "org.junit";
+ private static final String DOMAIN_ECLIPSE = "org.eclipse";
+ private static final String DOMAIN_NETBEANS = "org.netbeans";
+ private static final String DOMAIN_GROOVY = "groovy.";
+ private static final String DOMAIN_SCALA = "scala.";
+ private static final String DOMAIN_JYTHON = "jython.";
+ private static final String DOMAIN_JRUBY = "jruby.";
+
+ /**
+ * checks if a given package or class
+ * belongs to a standard namespaces which is
+ * untouchable by an implementer
+ *
+ * @param in the page or fully qualified classname
+ * @return true if it belongs to one of the standard namespaces, false if not
+ */
+ public static boolean isStandardNamespace(String in) {
+ //We don't use a regexp here, because an test has shown that direct startsWith is 5 times as fast as applying
+ //a precompiled regexp with match
+
+ //shortcuts for a faster killing of the add before going into the heavier
+ //whitelist check, this one kills off classes which belong to standard
+ //and semi standard namespaces before whitelisting the rest
+ return in.startsWith(DOMAIN_JAVA) ||
+ in.startsWith(DOMAIN_JAVAX) ||
+ in.startsWith(DOMAIN_COM_SUN) ||
+ in.startsWith(DOMAIN_GROOVY) ||
+ in.startsWith(DOMAIN_JYTHON) ||
+ in.startsWith(DOMAIN_JRUBY) ||
+ in.startsWith(DOMAIN_SCALA) ||
+ in.startsWith(DOMAIN_JBOSS) ||
+ in.startsWith(DOMAIN_SPRING) ||
+ in.startsWith(DOMAIN_JUNIT) ||
+ in.startsWith(DOMAIN_ECLIPSE) ||
+ in.startsWith(DOMAIN_NETBEANS) ||
+
+ //apache domain has to be treated specially myfaces can be referenced due to our tests and demos, otherwise this one
+ //is also treated as taboo zone
+ ((in.startsWith(DOMAIN_APACHE) &&
+ !in.startsWith(DOMAIN_MYFACES)));
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassScanVisitor.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/dependencyScan/core/ClassScanVisitor.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassScanVisitor.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ClassScanVisitor.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,159 @@
+/*
+ * 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.dependencyScan.core;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.registry.ExternalFilterDependencyRegistry;
+import org.objectweb.asm.*;
+import org.objectweb.asm.signature.SignatureReader;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The central visitor for the class scanner. ASM uses a visitor interface for high performance
+ * to step through classes.
+ * <p/>
+ * We reuse this pattern to get the best performance possible in this critical part of the application
+ * which also is triggered by the startup process.
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ClassScanVisitor implements ClassVisitor {
+
+ DependencyRegistry _dependencyRegistry;
+ String _currentlyVistedClass;
+ Integer _engineType;
+ String _rootClass;
+ static final Logger _log = Logger.getLogger(ClassScanVisitor.class.getName());
+
+ public ClassScanVisitor() {
+ }
+
+ public ClassScanVisitor(Integer engineType, String rootClass, ExternalFilterDependencyRegistry registry) {
+ _dependencyRegistry = registry;
+ _engineType = engineType;
+ _rootClass = rootClass;
+ }
+
+ public void visit(int version, int access, String name,
+ String signature, String superName, String[] interfaces) {
+ _currentlyVistedClass = Type.getObjectType(name).getClassName();
+ registerDependency(Type.getObjectType(superName));
+ handleGenerics(signature, true);
+
+ if (interfaces != null && interfaces.length > 0) {
+ for (String currInterface : interfaces) {
+ registerDependency(Type.getObjectType(currInterface));
+ }
+ }
+ }
+
+ public void visitSource(String source, String debug) {
+ _log.log(Level.FINEST, "visitSource: {0}", source);
+ }
+
+ public void visitOuterClass(String owner, String name, String description) {
+ //nothing has to be done here I guess because
+ //we only try to fetch the dependencies
+ _log.log(Level.FINEST, "visitOuterClass: {0} {1} {2}", new String [] {owner, name, description});
+
+ }
+
+ public AnnotationVisitor visitAnnotation(String description,
+ boolean visible) {
+ registerDependency(Type.getType(description));
+
+ return null;
+ }
+
+ public void visitAttribute(Attribute attribute) {
+ //_log._log(Level.INFO, "Attribute: {0}", attribute.type);
+ System.out.println(attribute.getClass().getName());
+ }
+
+ public void visitInnerClass(String name, String outerName,
+ String innerName, int access) {
+ //same as outer class
+ _log.log(Level.FINEST, "visitInnerClass: {0} {1} {2} ", new String [] {name, outerName, innerName});
+ }
+
+ public FieldVisitor visitField(int access, String name, String description,
+ String signature, Object value) {
+ //_log._log(Level.INFO, "Field:{0} {1} ", new Object[]{description, name});
+ handleGenerics(signature, false);
+ registerDependency(Type.getType(description));
+
+ return null;
+ }
+
+ private void registerDependency(Type dependency) {
+ String className = dependency.getClassName();
+ if (className.endsWith("[]")) {
+ className = className.substring(0, className.indexOf("["));
+ }
+
+ if (_dependencyRegistry != null) {
+ _dependencyRegistry.addDependency(_engineType, _rootClass, _currentlyVistedClass, className);
+ }
+
+ }
+
+ public MethodVisitor visitMethod(int access, String name,
+ String description, String signature, String[] exceptions) {
+
+ registerDependency(Type.getReturnType(description));
+
+ handleGenerics(signature, true);
+
+ for (Type argumentType : Type.getArgumentTypes(description)) {
+ registerDependency(argumentType);
+ }
+ return new MethodScanVisitor(_engineType, _rootClass, _currentlyVistedClass, _dependencyRegistry);
+ }
+
+ private void handleGenerics(String signature, boolean accept) {
+ if(signature != null && signature.contains("<")) {
+ SignatureReader reader = new SignatureReader(signature);
+ if(accept)
+ reader.accept(new DependencySignatureVisitor(_dependencyRegistry,_engineType, _rootClass, _currentlyVistedClass));
+ else
+ reader.acceptType(new DependencySignatureVisitor(_dependencyRegistry,_engineType, _rootClass, _currentlyVistedClass));
+ }
+ }
+
+ public void visitEnd() {
+ //_log.info("}");
+ }
+
+ public void setDependencyRegistry(DependencyRegistry dependencyRegistry) {
+ _dependencyRegistry = dependencyRegistry;
+ }
+
+ public void setEngineType(Integer engineType) {
+ _engineType = engineType;
+ }
+
+ public void setRootClass(String rootClass) {
+ _rootClass = rootClass;
+ }
+}
+
+
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/DependencySignatureVisitor.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/dependencyScan/core/DependencySignatureVisitor.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/DependencySignatureVisitor.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/DependencySignatureVisitor.java Mon Apr 12 19:43:30 2010
@@ -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.dependencyScan.core;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+import org.objectweb.asm.signature.SignatureVisitor;
+import org.objectweb.asm.*;
+
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * We need the signature visitor to get a grip on generics
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+public class DependencySignatureVisitor implements SignatureVisitor {
+
+ static final Logger _log = Logger.getLogger(DependencySignatureVisitor.class.getName());
+
+ String _rootClass;
+ String _currentClass;
+ DependencyRegistry _registry;
+ Integer _engineType;
+
+ public DependencySignatureVisitor(DependencyRegistry registry, Integer engineType, String currentClass, String rootClass) {
+ _registry = registry;
+ _currentClass = currentClass;
+ _rootClass = rootClass;
+ _engineType = engineType;
+ }
+
+ public void visitFormalTypeParameter(String className) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitFormalTypeParameter: {0}", className);
+ //the information is lacking the package information on this level no fully qualified name here
+ // _registry.addDependency(_engineType, _rootClass, _currentClass, Type.getObjectType(className).getClassName());
+ }
+
+ public SignatureVisitor visitClassBound() {
+ return this;
+ }
+
+ public SignatureVisitor visitInterfaceBound() {
+ return this;
+ }
+
+ public SignatureVisitor visitSuperclass() {
+ return this;
+ }
+
+ public SignatureVisitor visitInterface() {
+ return this;
+ }
+
+ public SignatureVisitor visitParameterType() {
+ return this;
+ }
+
+ public SignatureVisitor visitReturnType() {
+ return this;
+ }
+
+ public SignatureVisitor visitExceptionType() {
+ return this;
+ }
+
+ public void visitBaseType(char c) {
+
+ }
+
+ public void visitTypeVariable(String className) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitTypeVariable: {0}", className);
+ }
+
+ public SignatureVisitor visitArrayType() {
+ return this;
+ }
+
+ public void visitClassType(String className) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitClassType: {0}", className);
+ _registry.addDependency(_engineType, _rootClass, _currentClass, Type.getObjectType(className).getClassName());
+ }
+
+ public void visitInnerClassType(String className) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitInnerClassType: {0}", className);
+ }
+
+ public void visitTypeArgument() {
+
+ }
+
+ public SignatureVisitor visitTypeArgument(char c) {
+ return this;
+ }
+
+ public void visitEnd() {
+
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ExtendedClassReader.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/dependencyScan/core/ExtendedClassReader.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ExtendedClassReader.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/ExtendedClassReader.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.dependencyScan.core;
+
+import org.objectweb.asm.ClassReader;
+
+import java.io.IOException;
+
+/**
+ * Class reader for ASM which allows to plug our own loader instead
+ * of the default one
+ * <p/>
+ * (ASM makes too many assumptions regarding the loader)
+ */
+public class ExtendedClassReader extends ClassReader {
+ /**
+ * classloader pluggable classreader
+ *
+ * @param loader the loader which has to be plugged into the system
+ * @param className the class name for the class which has to be investigated
+ * @throws IOException in case of a loading error (class cannot be loaded for whatever reason)
+ */
+ public ExtendedClassReader(ClassLoader loader, String className) throws IOException {
+ super(loader.getResourceAsStream(className.replace('.', '/')
+ + ".class"));
+ }
+
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/MethodScanVisitor.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/dependencyScan/core/MethodScanVisitor.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/MethodScanVisitor.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/core/MethodScanVisitor.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,225 @@
+/*
+ * 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.dependencyScan.core;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.DependencyRegistry;
+import org.objectweb.asm.*;
+import org.objectweb.asm.signature.SignatureReader;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A scan visitor on method level
+ * to cope with method scoped dependencies like inlined
+ * fully qualified names, annotations, local variables
+ * etc...
+ *
+ * @author Werner Punz (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+
+class MethodScanVisitor implements MethodVisitor {
+
+ // static final Logger log = Logger.getLogger("ClassScanVisitor");
+
+ String _currentlyVisitedClass = null;
+ String _rootClass;
+ Integer _engineType = null;
+ DependencyRegistry _dependencyRegistry = null;
+
+ static Logger _log = Logger.getLogger(MethodScanVisitor.class.getName());
+
+ public MethodScanVisitor(Integer engineType, String rootClass, String currentlyVisitedClass, DependencyRegistry registry) {
+ _currentlyVisitedClass = currentlyVisitedClass;
+ _dependencyRegistry = registry;
+ _engineType = engineType;
+ _rootClass = rootClass;
+ }
+
+ public AnnotationVisitor visitAnnotationDefault() {
+ return null;
+ }
+
+ public AnnotationVisitor visitAnnotation(String description, boolean b) {
+ registerDependency(Type.getType(description));
+
+ return null;
+ }
+
+ public AnnotationVisitor visitParameterAnnotation(int opCode, String description, boolean b) {
+ registerDependency(Type.getType(description));
+
+ return null;
+ }
+
+ public void visitAttribute(Attribute attribute) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitAttribute {0}", attribute.type);
+ }
+
+ public void visitCode() {
+ //log.log(Level.INFO, "Method code");
+ }
+
+ public void visitFrame(int opCode1, int opCode2, Object[] objects, int opCode3, Object[] objects1) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitFrame {0}", "");
+
+ }
+
+ public void visitInsn(int opCode) {
+ }
+
+ public void visitIntInsn(int opCode1, int opCode2) {
+ }
+
+ public void visitVarInsn(int opCode1, int opCode2) {
+ }
+
+ public void visitTypeInsn(int opCode, String castType) {
+ //cast
+ // log.log(Level.INFO, "TypeInsn: {0} ", new String[]{castType});
+ registerDependency(Type.getObjectType(castType));
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitTypeInsn {0}", castType);
+
+ }
+
+ private void registerDependency(Type dependency) {
+
+ String className = dependency.getClassName();
+ if (className.endsWith("[]")) {
+ className = className.substring(0, className.indexOf("["));
+ }
+
+ if (_dependencyRegistry != null) {
+ _dependencyRegistry.addDependency(_engineType, _rootClass, _currentlyVisitedClass, className);
+ }
+ }
+
+ /**
+ * @param opCode the opCode of the insert statement
+ * @param owner hosting classname of field (always the calling class afaik)
+ * @param name internal descriptor
+ * @param descriptor field type
+ */
+ public void visitFieldInsn(int opCode, String owner, String name, String descriptor) {
+ // log.log(Level.INFO, "visitFieldInsn {0} {1} {2}", new Object[]{owner, name, descriptor});
+ //we have to deal with static imports as special case of field insertions
+ if (name != null && name.length() > 6 && name.startsWith("class$")) {
+ //special fallback for groovy static imports which are added as fields
+ name = "L" + name.substring(6).replaceAll("\\$", ".") + ";";
+ registerDependency(Type.getType(name));
+ }
+ if (descriptor != null) {
+ registerDependency(Type.getType(descriptor));
+ }
+
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitFieldInsn {0}", descriptor);
+
+ }
+
+ /**
+ * Method call
+ *
+ * @param opc internal opcode
+ * @param owner hosting classname of the method
+ * @param name method name
+ * @param desc descriptor string
+ */
+ public void visitMethodInsn(int opc, String owner, String name, String desc) {
+ //s2 arguments list
+ if (desc != null) {
+ registerDependency(Type.getReturnType(desc));
+ Type[] argumentTypes = Type.getArgumentTypes(desc);
+ if (argumentTypes != null) {
+ for (Type argumentType : argumentTypes) {
+ registerDependency(argumentType);
+ }
+ }
+ }
+
+ if (owner != null)
+ registerDependency(Type.getObjectType(owner));
+
+ }
+
+ public void visitJumpInsn(int i, Label label) {
+
+ }
+
+ public void visitLabel(Label label) {
+
+ }
+
+ public void visitLdcInsn(Object o) {
+
+ }
+
+ public void visitIincInsn(int i, int i1) {
+
+ }
+
+ public void visitTableSwitchInsn(int i, int i1, Label label, Label[] labels) {
+
+ }
+
+ public void visitLookupSwitchInsn(Label label, int[] ints, Label[] labels) {
+
+ }
+
+ public void visitMultiANewArrayInsn(String s, int i) {
+ if (_log.isLoggable(Level.FINEST))
+ _log.log(Level.FINEST, "visitMultiANewArrayInsn {0}", s);
+ }
+
+ public void visitTryCatchBlock(Label label, Label label1, Label label2, String catchType) {
+ //try catch block type information in the last string
+ //log.log(Level.INFO, "visitTryCatchBlock: {0} {1} {2} {3}", new Object[]{label.toString(), label1.toString(), label2.toString(), catchType});
+ registerDependency(Type.getObjectType(catchType));
+
+ }
+
+ public void visitLocalVariable(String name, String description, String signature, Label label, Label label1, int i) {
+ //local variable on method level
+ registerDependency(Type.getType(description));
+ handleGenerics(signature);
+ }
+
+ public void visitLineNumber(int i, Label label) {
+
+ }
+
+ public void visitMaxs(int i, int i1) {
+
+ }
+
+ public void visitEnd() {
+
+ }
+
+ private void handleGenerics(String signature) {
+ if (signature != null && signature.contains("<")) {
+ SignatureReader reader = new SignatureReader(signature);
+ reader.acceptType(new DependencySignatureVisitor(_dependencyRegistry, _engineType, _rootClass, _currentlyVisitedClass));
+ }
+ }
+}
Added: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/ScanIdentifierFilter.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/dependencyScan/filter/ScanIdentifierFilter.java?rev=933379&view=auto
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/ScanIdentifierFilter.java (added)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/core/dependencyScan/filter/ScanIdentifierFilter.java Mon Apr 12 19:43:30 2010
@@ -0,0 +1,28 @@
+package org.apache.myfaces.extensions.scripting.core.dependencyScan.filter;
+
+import org.apache.myfaces.extensions.scripting.core.dependencyScan.api.ClassFilter;
+
+import java.util.Arrays;
+
+/**
+ * a filter which works on the scan identifiers
+ * only classes which trigger on the same identifier
+ * are allowed to be passed through
+ */
+public class ScanIdentifierFilter implements ClassFilter {
+
+ private final int [] _engineType;
+
+ public ScanIdentifierFilter(int ... engineType) {
+ _engineType = Arrays.copyOf(engineType, engineType.length);
+ }
+
+ public boolean isAllowed(Integer identifier, String clazz) {
+ int id = identifier;
+ for(int engineType: _engineType) {
+ boolean allowed = engineType == id;
+ if(allowed) return true;
+ }
+ return false;
+ }
+}