Author: tfennelly
Date: 2009-11-30 15:55:50 -0500 (Mon, 30 Nov 2009)
New Revision: 18930
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/ProcessNodeType.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeDependency.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java
Removed:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/ProcessNodeType.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksRunTab.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5302
Perform project dependency checks before launching a Run Configuration
Copied:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/ProcessNodeType.java
(from rev 18918,
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/ProcessNodeType.java)
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/ProcessNodeType.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/ProcessNodeType.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.tools.smooks.configuration;
+
+/**
+ * Configuration process node type enumeration.
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public enum ProcessNodeType {
+ INPUT_CSV,
+ INPUT_EDI,
+ INPUT_JSON,
+
+ BASE,
+ CORE,
+ CALC,
+ DATASOURCE,
+ FIXED_LENGTH,
+ JAVA_BINDING,
+ PERSISTENCE,
+ ROUTING,
+ RULES,
+ SCRIPTING,
+ TEMPLATING,
+ VALIDATION,
+}
\ No newline at end of file
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeDependency.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeDependency.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeDependency.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -0,0 +1,177 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.tools.smooks.configuration;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.milyn.Smooks;
+import org.milyn.SmooksException;
+import org.milyn.container.ExecutionContext;
+import org.milyn.delivery.sax.SAXElement;
+import org.milyn.delivery.sax.SAXVisitBefore;
+
+/**
+ * Smooks runtime dependency.
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class RuntimeDependency {
+
+ /**
+ * Smooks runtime versions.
+ */
+ public static enum SmooksVersion {
+ v1_0,
+ v1_1,
+ v1_2,
+ v1_3,
+ }
+
+ /**
+ * The Maven Artfact ID of the Smooks dependency.
+ */
+ private String artifactId;
+ /**
+ * The configuration namespace URI for the config..
+ */
+ private URI namespaceURI;
+ /**
+ * Whether or not the configuration is supported by the Editor. Note that this property
being 'false' is not the
+ * same as saying the config is not supported by the Smooks Runtime (see the
'runtimeVersions' property).
+ */
+ private boolean supportedByEditor;
+ /**
+ * The list of Smooks Runtimes that can support this configuration. Note this does not
mean
+ * the editor can support the configuration (see the 'supportedByEditor'
property).
+ */
+ private List<SmooksVersion> runtimeVersions;
+
+ private RuntimeDependency(String artifactId, URI namespaceURI, boolean
supportedByEditor, List<SmooksVersion> runtimeVersions) {
+ this.artifactId = artifactId;
+ this.namespaceURI = namespaceURI;
+ this.supportedByEditor = supportedByEditor;
+ }
+
+ public String getGroupId() {
+ return "org.milyn";
+ }
+ public String getArtifactId() {
+ return artifactId;
+ }
+ public URI getNamespaceURI() {
+ return namespaceURI;
+ }
+ public boolean isSupportedByEditor() {
+ return supportedByEditor;
+ }
+ public boolean isSupportedBySmooksVersion(SmooksVersion smooksVersion) {
+ return runtimeVersions.contains(smooksVersion);
+ }
+ public boolean isOnProjectClasspath(ClassLoader projectClassloader) {
+ String resourcePath = "META-INF" + namespaceURI.getPath();
+ return (projectClassloader.getResource(resourcePath) != null);
+ }
+
+ public static void addDependencyChecklist(Smooks metadataExtractor) {
+ // Add the supported feature dependency details...
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-core", ProcessNodeType.BASE,
"smooks-1.1.xsd", true, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list");
+ metadataExtractor.addVisitor(new RuntimeDependencyTracker("milyn-smooks-csv",
ProcessNodeType.INPUT_CSV, "smooks/csv-1.2.xsd", true,
SmooksVersion.v1_2, SmooksVersion.v1_3), "/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new RuntimeDependencyTracker("milyn-smooks-edi",
ProcessNodeType.INPUT_EDI, "smooks/edi-1.2.xsd", true,
SmooksVersion.v1_2, SmooksVersion.v1_3), "/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-json", ProcessNodeType.INPUT_JSON,
"smooks/json-1.2.xsd", true, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-templating", ProcessNodeType.TEMPLATING,
"smooks/freemarker-1.1.xsd", true, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/freemarker");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-javabean",
ProcessNodeType.JAVA_BINDING, "smooks/javabean-1.2.xsd", true,
SmooksVersion.v1_2, SmooksVersion.v1_3), "/smooks-resource-list/bean");
+
+ // Add the unsupported feature dependency details...
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-core", ProcessNodeType.BASE,
"smooks-1.0.xsd", false, SmooksVersion.v1_0, SmooksVersion.v1_1,
SmooksVersion.v1_2, SmooksVersion.v1_3), "/smooks-resource-list");
+ metadataExtractor.addVisitor(new RuntimeDependencyTracker("milyn-smooks-csv",
ProcessNodeType.INPUT_CSV, "smooks/csv-1.1.xsd", false,
SmooksVersion.v1_1, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new RuntimeDependencyTracker("milyn-smooks-csv",
ProcessNodeType.INPUT_CSV, "smooks/csv-1.3.xsd", false,
SmooksVersion.v1_3), "/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new RuntimeDependencyTracker("milyn-smooks-edi",
ProcessNodeType.INPUT_EDI, "smooks/edi-1.1.xsd", false,
SmooksVersion.v1_1, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-json",
ProcessNodeType.INPUT_JSON, "smooks/json-1.1.xsd", false,
SmooksVersion.v1_1, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-fixed-length",
ProcessNodeType.FIXED_LENGTH, "smooks/fixed-length-1.3.xsd", false,
SmooksVersion.v1_3), "/smooks-resource-list/reader");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-core",
ProcessNodeType.DATASOURCE, "smooks/datasource-1.1.xsd", false,
SmooksVersion.v1_1, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/direct,/smooks-resource-list/JNDI");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-core",
ProcessNodeType.DATASOURCE, "smooks/datasource-1.3.xsd", false,
SmooksVersion.v1_3),
"/smooks-resource-list/direct,/smooks-resource-list/JNDI");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-core", ProcessNodeType.CORE,
"smooks/core-1.3.xsd", false, SmooksVersion.v1_3),
"/smooks-resource-list/filterSettings,/smooks-resource-list/namespaces,/smooks-resource-list/terminate");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-templating",
ProcessNodeType.TEMPLATING, "smooks/xsl-1.1.xsd", false,
SmooksVersion.v1_1, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/xsl");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-javabean",
ProcessNodeType.JAVA_BINDING, "smooks/javabean-1.1.xsd", false,
SmooksVersion.v1_1, SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/binding");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-javabean",
ProcessNodeType.JAVA_BINDING, "smooks/javabean-1.3.xsd", false,
SmooksVersion.v1_3), "/smooks-resource-list/bean");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-calc", ProcessNodeType.CALC,
"smooks/calc-1.1.xsd", false, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/counter");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-persistence",
ProcessNodeType.PERSISTENCE, "smooks/persistence-1.2.xsd", false,
SmooksVersion.v1_2, SmooksVersion.v1_3),
"/smooks-resource-list/inserter,/smooks-resource-list/updater,/smooks-resource-list/deleter,/smooks-resource-list/flusher,/smooks-resource-list/locator");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-routing", ProcessNodeType.ROUTING,
"smooks/db-routing-1.1.xsd", false, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3),
"/smooks-resource-list/executor,/smooks-resource-list/resultSetRowSelector");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-routing", ProcessNodeType.ROUTING,
"smooks/file-routing-1.1.xsd", false, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/outputStream");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-routing", ProcessNodeType.ROUTING,
"smooks/io-routing-1.1.xsd", false, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/router");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-routing", ProcessNodeType.ROUTING,
"smooks/jms-routing-1.1.xsd", false, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/router");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-routing", ProcessNodeType.ROUTING,
"smooks/jms-routing-1.2.xsd", false, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/router");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-rules", ProcessNodeType.RULES,
"smooks/rules-1.0.xsd", false, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/ruleBases");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-scripting", ProcessNodeType.SCRIPTING,
"smooks/groovy-1.1.xsd", false, SmooksVersion.v1_1, SmooksVersion.v1_2,
SmooksVersion.v1_3), "/smooks-resource-list/groovy");
+ metadataExtractor.addVisitor(new
RuntimeDependencyTracker("milyn-smooks-validation",
ProcessNodeType.VALIDATION, "smooks/validation-1.0.xsd", false,
SmooksVersion.v1_2, SmooksVersion.v1_3), "/smooks-resource-list/rule");
+ }
+
+ private static class RuntimeDependencyTracker implements SAXVisitBefore {
+
+ private String artifactId;
+ private ProcessNodeType nodeType;
+ private URI namespaceURI;
+ /**
+ * Whether or not the configuration is supported by the Editor. Note that this
property being 'false' is not the
+ * same as saying the config is not supported by the Smooks Runtime (see the
'runtimeVersions' property).
+ */
+ private boolean supportedByEditor;
+ /**
+ * The list of Smooks Runtimes that can support this configuration. Note this does not
mean
+ * the editor can support the configuration (see the 'supportedByEditor'
property).
+ */
+ private List<SmooksVersion> runtimeVersions = new
ArrayList<SmooksVersion>();
+
+ public RuntimeDependencyTracker(String artifactId, ProcessNodeType nodeType, String
xsd, boolean supportedByEditor, SmooksVersion... runtimeVersions) {
+ this.artifactId = artifactId;
+ this.nodeType = nodeType;
+ this.namespaceURI =
URI.create("http://www.milyn.org/xsd/" + xsd);
+ this.supportedByEditor = supportedByEditor;
+ if(runtimeVersions != null) {
+ this.runtimeVersions.addAll(Arrays.asList(runtimeVersions));
+ }
+ }
+
+ public void visitBefore(SAXElement configElement, ExecutionContext execContext) throws
SmooksException, IOException {
+ RuntimeMetadata metadata = (RuntimeMetadata)
execContext.getAttribute(RuntimeMetadata.class);
+ Set<URI> alreadyProcessed = (Set<URI>)
execContext.getAttribute(RuntimeDependencyTracker.class);
+
+ metadata.getNodeTypes().add(nodeType);
+
+ if(alreadyProcessed == null) {
+ alreadyProcessed = new HashSet<URI>();
+ execContext.setAttribute(RuntimeDependencyTracker.class, alreadyProcessed);
+ }
+
+ // If the config namespace hasn't already been added, we need to add it...
+ String configNS = configElement.getName().getNamespaceURI();
+ if(configNS.equals(namespaceURI.toString()) &&
!alreadyProcessed.contains(namespaceURI)) {
+ metadata.getDependencies().add(new RuntimeDependency(artifactId, namespaceURI,
supportedByEditor, runtimeVersions));
+ alreadyProcessed.add(namespaceURI);
+ }
+ }
+ }
+}
Copied:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java
(from rev 18918,
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java)
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/RuntimeMetadata.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -0,0 +1,217 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.tools.smooks.configuration;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.core.resources.IResource;
+import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
+import org.jboss.tools.smooks10.model.smooks.util.SmooksModelUtils;
+import org.milyn.Smooks;
+import org.milyn.SmooksException;
+import org.milyn.container.ExecutionContext;
+import org.milyn.delivery.sax.SAXElement;
+import org.milyn.delivery.sax.SAXVisitAfter;
+import org.milyn.delivery.sax.SAXVisitBefore;
+
+/**
+ * Smooks configuration runtime metadata.
+ * <p/>
+ * Verifies the specified config is a Smooks configuration and extracts metadata from the
+ * config e.g. input file, dependencies.
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class RuntimeMetadata {
+
+ private Smooks metadataExtractor;
+ private boolean isSmooksConfig;
+ private boolean isValidSmooksConfig;
+ private File configFile;
+ private String inputType;
+ private File inputFile;
+ private Set<ProcessNodeType> processNodeTypes = new
HashSet<ProcessNodeType>();
+ private List<RuntimeDependency> dependencies = new
ArrayList<RuntimeDependency>();
+
+ public RuntimeMetadata() {
+ metadataExtractor = new Smooks();
+ metadataExtractor.addVisitor(new SmooksConfigAsserter(),
"/smooks-resource-list", "http://www.milyn.org/xsd/smooks-1.1.xsd");
+ metadataExtractor.addVisitor(new InputParamExtractor(),
"/smooks-resource-list/params/param",
"http://www.milyn.org/xsd/smooks-1.1.xsd");
+
+ // Build dependency map...
+ RuntimeDependency.addDependencyChecklist(metadataExtractor);
+ }
+
+ public boolean isSmooksConfig() {
+ return isSmooksConfig;
+ }
+
+ public boolean isValidSmooksConfig() {
+ return isValidSmooksConfig;
+ }
+
+ public String getErrorMessage() {
+ if(isValidSmooksConfig) {
+ throw new IllegalStateException("Invalid call to 'getErrorMessage()'.
Smooks configuration is NOT invalid.");
+ }
+
+ if(configFile == null) {
+ return "Smooks configuration file not configured, or does not exist.";
+ } else if(!configFile.exists()) {
+ return "Specified Smooks configuration file not found.";
+ } else if(!configFile.isFile()) {
+ return "Specified Smooks configuration file is not a readable file.";
+ } else if(!isSmooksConfig) {
+ return "Specified Smooks configuration file is not a valid Smooks
Configuration.";
+ } else if(inputFile == null) {
+ return "Specified Smooks configuration 'Input' task is not configured
with a sample input file. Please configure the 'Input' task in the Process
flow.";
+ } else if(!inputFile.exists()) {
+ return "Specified Smooks configuration 'Input' task is configured with a
sample input file, but the file cannot be found. Please reconfigure the 'Input'
task in the Process flow.";
+ } else if(!inputFile.isFile()) {
+ return "Specified Smooks configuration 'Input' task is configured with a
sample input file, but the file cannot be read. Please reconfigure the 'Input'
task in the Process flow.";
+ }
+
+ return "";
+ }
+
+ public File getConfigFile() {
+ return configFile;
+ }
+
+ public String getInputType() {
+ return inputType;
+ }
+
+ public File getInputFile() {
+ return inputFile;
+ }
+
+ public List<RuntimeDependency> getDependencies() {
+ return dependencies;
+ }
+
+ public Set<ProcessNodeType> getNodeTypes() {
+ return processNodeTypes;
+ }
+
+ public String getNodeTypesString() {
+ StringBuilder builder = new StringBuilder();
+ for(ProcessNodeType nodeType : processNodeTypes) {
+ if(builder.length() > 0) {
+ builder.append(',');
+ }
+ builder.append(nodeType.toString());
+ }
+ return builder.toString();
+ }
+
+ public void setSmooksConfig(IResource smooksConfig) {
+ reset();
+
+ if(smooksConfig != null) {
+ configFile = new File(smooksConfig.getRawLocation().toOSString().trim());
+ if(configFile.exists() && configFile.isFile()) {
+ ExecutionContext execContext = metadataExtractor.createExecutionContext();
+ Properties inputParams = new Properties();
+
+ try {
+ // Filter the config and capture the input params...
+ execContext.setAttribute(InputParamExtractor.class, inputParams);
+ execContext.setAttribute(RuntimeMetadata.class, this);
+
+ metadataExtractor.filterSource(execContext, new StreamSource(new
FileInputStream(configFile)));
+
+ inputType = inputParams.getProperty(SmooksModelUtils.INPUT_TYPE);
+ if(inputType != null) {
+ String inputPath = inputParams.getProperty(inputType);
+ if(inputPath != null) {
+ String resolvedFilePath;
+ try {
+ resolvedFilePath = SmooksUIUtils.parseFilePath(inputPath.trim());
+ } catch(Exception e) {
+ // It's not a valid config...
+ inputFile = new File(inputPath.trim());
+ return;
+ }
+
+ inputFile = new File(resolvedFilePath);
+ if(inputFile.exists() && inputFile.isFile()) {
+ isValidSmooksConfig = true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ // Not a valid Smooks config file
+ }
+ }
+ }
+ }
+
+ private void reset() {
+ isSmooksConfig = false;
+ isValidSmooksConfig = false;
+ configFile = null;
+ inputType = null;
+ inputFile = null;
+ processNodeTypes.clear();
+ }
+
+ private static class SmooksConfigAsserter implements SAXVisitBefore {
+ public void visitBefore(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
+ RuntimeMetadata metadata = (RuntimeMetadata)
execContext.getAttribute(RuntimeMetadata.class);
+ metadata.isSmooksConfig = true;
+ }
+ }
+
+ private static class InputParamExtractor implements SAXVisitBefore, SAXVisitAfter {
+
+ public void visitBefore(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
+ paramElement.accumulateText();
+ }
+
+ public void visitAfter(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
+ Properties inputParams = (Properties)
execContext.getAttribute(InputParamExtractor.class);
+
+ if(inputParams != null) {
+ String paramName = paramElement.getAttribute("name");
+
+ if(paramName != null) {
+ if(paramName.equals(SmooksModelUtils.INPUT_TYPE)) {
+ inputParams.setProperty(SmooksModelUtils.INPUT_TYPE,
paramElement.getTextContent());
+ } else {
+ String paramType = paramElement.getAttribute("type");
+ if(paramType != null &&
paramType.equals(SmooksModelUtils.INPUT_ACTIVE_TYPE)) {
+ inputParams.setProperty(paramName, paramElement.getTextContent());
+ }
+ }
+ }
+ }
+ }
+ }
+}
Deleted:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/ProcessNodeType.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/ProcessNodeType.java 2009-11-30
20:12:24 UTC (rev 18929)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/ProcessNodeType.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -1,30 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006, JBoss Inc.
- */
-package org.jboss.tools.smooks.launch;
-
-/**
- * Configuration process node type enumeration.
- *
- * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
- */
-public enum ProcessNodeType {
- TEMPLATING,
- JAVA_BINDING
-}
\ No newline at end of file
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java 2009-11-30
20:12:24 UTC (rev 18929)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -36,6 +36,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate;
import org.eclipse.jdt.launching.ExecutionArguments;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
@@ -45,6 +46,10 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.smooks.configuration.ProcessNodeType;
+import org.jboss.tools.smooks.configuration.RuntimeDependency;
+import org.jboss.tools.smooks.configuration.RuntimeMetadata;
+import org.jboss.tools.smooks.configuration.editors.uitls.ProjectClassLoader;
import org.jboss.tools.smooks.core.SmooksInputType;
/**
@@ -60,39 +65,54 @@
* @see
org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration,
java.lang.String, org.eclipse.debug.core.ILaunch,
org.eclipse.core.runtime.IProgressMonitor)
*/
public void launch(ILaunchConfiguration launchConfig, String mode, ILaunch launch,
IProgressMonitor monitor) throws CoreException {
- IProject project = getJavaProject(launchConfig).getProject();
+ IJavaProject javaProject = getJavaProject(launchConfig);
+ IProject project = javaProject.getProject();
final String smooksConfigName =
launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
"");
- final SmooksLaunchMetadata launchMetadata = new SmooksLaunchMetadata();
+ final RuntimeMetadata launchMetadata = new RuntimeMetadata();
launchMetadata.setSmooksConfig(project.findMember(smooksConfigName));
- if(launchMetadata.isValidSmooksConfig()) {
- IVMRunner runner= getVMRunner(launchConfig, mode);
- VMRunnerConfiguration runConfig = buildRunnerConfig(launchConfig);
+ if(!launchMetadata.isValidSmooksConfig()) {
+ displayError(smooksConfigName, launchMetadata.getErrorMessage());
+ } else {
+ List<RuntimeDependency> dependencies = launchMetadata.getDependencies();
+ ProjectClassLoader projectClassLoader = new ProjectClassLoader(javaProject);
- // check for cancellation
- if (monitor.isCanceled()) {
- return;
- }
-
- String inputType = launchMetadata.getInputType();
- String inputPath = launchMetadata.getInputFile().getAbsolutePath();
- String nodeTypes = launchMetadata.getNodeTypesString();
-
- runConfig.setProgramArguments(new String[]
{launchMetadata.getConfigFile().getAbsolutePath(), inputType, inputPath, nodeTypes});
-
- runner.run(runConfig, launch, monitor);
- } else {
- final Display display = PlatformUI.getWorkbench().getDisplay();
- display.syncExec(new Runnable() {
- public void run(){
- Shell shell = display.getActiveShell();
- ErrorDialog.openError(shell, "Error", "Error Launching Smooks
Configuration '" + smooksConfigName + "'.", new
Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, launchMetadata.getErrorMessage(), new
Exception()));
- }
- });
+ for(RuntimeDependency dependency : dependencies) {
+ if(!dependency.isOnProjectClasspath(projectClassLoader)) {
+ displayError(smooksConfigName, "This configuration depends on the '" +
dependency.getGroupId() + ":" + dependency.getArtifactId() + "' Smooks
artifact. Download Smooks and add the Smooks jars to the Project classpath, or update
your Maven POM to include the missing artifact!!");
+ return;
+ }
+ }
}
+
+ IVMRunner runner= getVMRunner(launchConfig, mode);
+ VMRunnerConfiguration runConfig = buildRunnerConfig(launchConfig);
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
+
+ String inputType = launchMetadata.getInputType();
+ String inputPath = launchMetadata.getInputFile().getAbsolutePath();
+ String nodeTypes = launchMetadata.getNodeTypesString();
+
+ runConfig.setProgramArguments(new String[]
{launchMetadata.getConfigFile().getAbsolutePath(), inputType, inputPath, nodeTypes});
+
+ runner.run(runConfig, launch, monitor);
}
+ private void displayError(final String smooksConfigName, final String errorMessage) {
+ final Display display = PlatformUI.getWorkbench().getDisplay();
+ display.syncExec(new Runnable() {
+ public void run(){
+ Shell shell = display.getActiveShell();
+ ErrorDialog.openError(shell, "Error", "Error Launching Smooks
Configuration '" + smooksConfigName + "'.", new
Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, errorMessage, new Exception()));
+ }
+ });
+ }
+
private VMRunnerConfiguration buildRunnerConfig(ILaunchConfiguration launchConfig)
throws CoreException {
List<String> classpath = new
ArrayList<String>(Arrays.asList(getClasspath(launchConfig)));
Deleted:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java 2009-11-30
20:12:24 UTC (rev 18929)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -1,224 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006, JBoss Inc.
- */
-package org.jboss.tools.smooks.launch;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.xml.transform.stream.StreamSource;
-
-import org.eclipse.core.resources.IResource;
-import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
-import org.jboss.tools.smooks10.model.smooks.util.SmooksModelUtils;
-import org.milyn.Smooks;
-import org.milyn.SmooksException;
-import org.milyn.container.ExecutionContext;
-import org.milyn.delivery.sax.SAXElement;
-import org.milyn.delivery.sax.SAXVisitAfter;
-import org.milyn.delivery.sax.SAXVisitBefore;
-
-/**
- * Smooks configuration launch metadata.
- * <p/>
- * Verifies the specified config is a Smooks configuration and extracts launch
- * metadata from the config (input file etc).
- *
- * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
- */
-public class SmooksLaunchMetadata {
-
- private Smooks inputParamExtractor;
- private boolean isSmooksConfig;
- private boolean isValidSmooksConfig;
- private File configFile;
- private String inputType;
- private File inputFile;
- private Set<ProcessNodeType> processNodeTypes = new
HashSet<ProcessNodeType>();
-
- public SmooksLaunchMetadata() {
- inputParamExtractor = new Smooks();
- inputParamExtractor.addVisitor(new SmooksConfigAsserter(),
"/smooks-resource-list", "http://www.milyn.org/xsd/smooks-1.1.xsd");
- inputParamExtractor.addVisitor(new InputParamExtractor(),
"/smooks-resource-list/params/param",
"http://www.milyn.org/xsd/smooks-1.1.xsd");
- inputParamExtractor.addVisitor(new
ConfigTypeTracker().setNodeType(ProcessNodeType.TEMPLATING),
"/smooks-resource-list/freemarker");
- inputParamExtractor.addVisitor(new
ConfigTypeTracker().setNodeType(ProcessNodeType.JAVA_BINDING),
"/smooks-resource-list/bean");
- }
-
- public boolean isSmooksConfig() {
- return isSmooksConfig;
- }
-
- public boolean isValidSmooksConfig() {
- return isValidSmooksConfig;
- }
-
- public String getErrorMessage() {
- if(isValidSmooksConfig) {
- throw new IllegalStateException("Invalid call to 'getErrorMessage()'.
Smooks configuration is NOT invalid.");
- }
-
- if(configFile == null) {
- return "Smooks configuration file not configured, or does not exist.";
- } else if(!configFile.exists()) {
- return "Specified Smooks configuration file not found.";
- } else if(!configFile.isFile()) {
- return "Specified Smooks configuration file is not a readable file.";
- } else if(!isSmooksConfig) {
- return "Specified Smooks configuration file is not a valid Smooks
Configuration.";
- } else if(inputFile == null) {
- return "Specified Smooks configuration 'Input' task is not configured
with a sample input file. Please configure the 'Input' task in the Process
flow.";
- } else if(!inputFile.exists()) {
- return "Specified Smooks configuration 'Input' task is configured with a
sample input file, but the file cannot be found. Please reconfigure the 'Input'
task in the Process flow.";
- } else if(!inputFile.isFile()) {
- return "Specified Smooks configuration 'Input' task is configured with a
sample input file, but the file cannot be read. Please reconfigure the 'Input'
task in the Process flow.";
- }
-
- return "";
- }
-
- public File getConfigFile() {
- return configFile;
- }
-
- public String getInputType() {
- return inputType;
- }
-
- public File getInputFile() {
- return inputFile;
- }
-
- public Set<ProcessNodeType> getNodeTypes() {
- return processNodeTypes;
- }
-
- public String getNodeTypesString() {
- StringBuilder builder = new StringBuilder();
- for(ProcessNodeType nodeType : processNodeTypes) {
- if(builder.length() > 0) {
- builder.append(',');
- }
- builder.append(nodeType.toString());
- }
- return builder.toString();
- }
-
- public void setSmooksConfig(IResource smooksConfig) {
- reset();
-
- if(smooksConfig != null) {
- configFile = new File(smooksConfig.getRawLocation().toOSString().trim());
- if(configFile.exists() && configFile.isFile()) {
- ExecutionContext execContext = inputParamExtractor.createExecutionContext();
- Properties inputParams = new Properties();
-
- try {
- // Filter the config and capture the input params...
- execContext.setAttribute(InputParamExtractor.class, inputParams);
- execContext.setAttribute(SmooksLaunchMetadata.class, this);
-
- inputParamExtractor.filterSource(execContext, new StreamSource(new
FileInputStream(configFile)));
-
- inputType = inputParams.getProperty(SmooksModelUtils.INPUT_TYPE);
- if(inputType != null) {
- String inputPath = inputParams.getProperty(inputType);
- if(inputPath != null) {
- String resolvedFilePath;
- try {
- resolvedFilePath = SmooksUIUtils.parseFilePath(inputPath.trim());
- } catch(Exception e) {
- // It's not a valid config...
- inputFile = new File(inputPath.trim());
- return;
- }
-
- inputFile = new File(resolvedFilePath);
- if(inputFile.exists() && inputFile.isFile()) {
- isValidSmooksConfig = true;
- }
- }
- }
- } catch (Exception e) {
- // Not a valid Smooks config file
- }
- }
- }
- }
-
- private void reset() {
- isSmooksConfig = false;
- isValidSmooksConfig = false;
- configFile = null;
- inputType = null;
- inputFile = null;
- processNodeTypes.clear();
- }
-
- private static class SmooksConfigAsserter implements SAXVisitBefore {
- public void visitBefore(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
- SmooksLaunchMetadata metadata = (SmooksLaunchMetadata)
execContext.getAttribute(SmooksLaunchMetadata.class);
- metadata.isSmooksConfig = true;
- }
- }
-
- private static class InputParamExtractor implements SAXVisitBefore, SAXVisitAfter {
-
- public void visitBefore(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
- paramElement.accumulateText();
- }
-
- public void visitAfter(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
- Properties inputParams = (Properties)
execContext.getAttribute(InputParamExtractor.class);
-
- if(inputParams != null) {
- String paramName = paramElement.getAttribute("name");
-
- if(paramName != null) {
- if(paramName.equals(SmooksModelUtils.INPUT_TYPE)) {
- inputParams.setProperty(SmooksModelUtils.INPUT_TYPE,
paramElement.getTextContent());
- } else {
- String paramType = paramElement.getAttribute("type");
- if(paramType != null &&
paramType.equals(SmooksModelUtils.INPUT_ACTIVE_TYPE)) {
- inputParams.setProperty(paramName, paramElement.getTextContent());
- }
- }
- }
- }
- }
- }
-
- private static class ConfigTypeTracker implements SAXVisitBefore {
-
- private ProcessNodeType nodeType;
-
- public ConfigTypeTracker setNodeType(ProcessNodeType nodeType) {
- this.nodeType = nodeType;
- return this;
- }
-
- public void visitBefore(SAXElement paramElement, ExecutionContext execContext) throws
SmooksException, IOException {
- SmooksLaunchMetadata metadata = (SmooksLaunchMetadata)
execContext.getAttribute(SmooksLaunchMetadata.class);
- metadata.getNodeTypes().add(nodeType);
- }
- }
-}
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java 2009-11-30
20:12:24 UTC (rev 18929)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -32,6 +32,7 @@
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import org.jboss.tools.smooks.configuration.ProcessNodeType;
import org.jboss.tools.smooks.core.SmooksInputType;
import org.milyn.Smooks;
import org.milyn.payload.JavaResult;
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksRunTab.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksRunTab.java 2009-11-30
20:12:24 UTC (rev 18929)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksRunTab.java 2009-11-30
20:55:50 UTC (rev 18930)
@@ -69,6 +69,7 @@
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.jboss.tools.smooks.configuration.RuntimeMetadata;
import org.jboss.tools.smooks.editor.AbstractSmooksFormEditor;
/**
@@ -82,7 +83,7 @@
private Button fProjButton;
private Text fConfigurationText;
private Button fSearchButton;
- private SmooksLaunchMetadata launchMetaData = new SmooksLaunchMetadata();
+ private RuntimeMetadata launchMetaData = new RuntimeMetadata();
private ILaunchConfiguration fLaunchConfiguration;