Author: tfennelly
Date: 2009-11-26 16:38:48 -0500 (Thu, 26 Nov 2009)
New Revision: 18869
Added:
trunk/smooks/docs/reference/test.txt
trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/xstream-1.2.2.jar
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/
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/SmooksLaunchMetadata.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchTabGroup.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
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.runtime/.classpath
trunk/smooks/plugins/org.jboss.tools.smooks.runtime/META-INF/MANIFEST.MF
trunk/smooks/plugins/org.jboss.tools.smooks.ui/.classpath
trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
trunk/smooks/plugins/org.jboss.tools.smooks.ui/build.properties
trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-5259
Implement rudimentary Test facility for Smooks Config
Added: trunk/smooks/docs/reference/test.txt
===================================================================
--- trunk/smooks/docs/reference/test.txt (rev 0)
+++ trunk/smooks/docs/reference/test.txt 2009-11-26 21:38:48 UTC (rev 18869)
@@ -0,0 +1 @@
+svn commit test
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.runtime/.classpath
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.runtime/.classpath 2009-11-26 18:16:38 UTC
(rev 18868)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.runtime/.classpath 2009-11-26 21:38:48 UTC
(rev 18869)
@@ -1,16 +1,16 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry exported="true" kind="lib"
path="libs/freemarker-2.3.11.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/opencsv-1.8.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/jackson-core-lgpl-1.0.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/milyn-commons-1.2.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/milyn-edisax-parser-1.2.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-core-1.2.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-csv-1.2.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-edi-1.2.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-json-1.2.1.jar"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib"
path="libs/freemarker-2.3.11.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/opencsv-1.8.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/jackson-core-lgpl-1.0.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/milyn-commons-1.2.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/milyn-edisax-parser-1.2.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-core-1.2.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-csv-1.2.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-edi-1.2.1.jar"/>
+ <classpathentry exported="true" kind="lib"
path="libs/milyn-smooks-json-1.2.1.jar"
sourcepath="/Users/tfennelly/milyn/trunk/smooks-cartridges/json/src/main/java"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.runtime/META-INF/MANIFEST.MF
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.runtime/META-INF/MANIFEST.MF 2009-11-26
18:16:38 UTC (rev 18868)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.runtime/META-INF/MANIFEST.MF 2009-11-26
21:38:48 UTC (rev 18869)
@@ -35,4 +35,7 @@
org.milyn.json,
org.milyn.payload,
org.milyn.smooks.edi,
- org.milyn.xml
+ org.milyn.xml,
+ org.milyn.container,
+ org.milyn.delivery,
+ org.milyn.delivery.sax
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/.classpath
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/.classpath 2009-11-26 18:16:38 UTC (rev
18868)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/.classpath 2009-11-26 21:38:48 UTC (rev
18869)
@@ -1,8 +1,10 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry exported="true" kind="lib"
path="libs/dom4j-1.6.1.jar"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib"
path="libs/xstream-1.2.2.jar"/>
+ <classpathentry exported="true" kind="lib"
path="bin/"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib"
path="libs/dom4j-1.6.1.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-11-26
18:16:38 UTC (rev 18868)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-11-26
21:38:48 UTC (rev 18869)
@@ -31,13 +31,20 @@
org.eclipse.ui.views.properties.tabbed,
org.eclipse.wst.xsl.core,
org.eclipse.zest.core,
- org.eclipse.zest.layouts
+ org.eclipse.zest.layouts,
+ org.eclipse.debug.core;bundle-version="3.5.0",
+ org.eclipse.debug.ui;bundle-version="3.5.1",
+ org.eclipse.jdt.debug.ui;bundle-version="3.4.1",
+ org.eclipse.jdt.junit;bundle-version="3.5.1",
+ org.eclipse.ui.console;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Vendor: %providerName
-Bundle-ClassPath: libs/dom4j-1.6.1.jar,
- .
+Bundle-ClassPath: bin/,
+ libs/dom4j-1.6.1.jar,
+ .,
+ libs/xstream-1.2.2.jar
Export-Package: org.jboss.template,
org.jboss.template.csv,
org.jboss.template.exception,
@@ -52,4 +59,5 @@
org.jboss.tools.smooks.configuration.editors_10,
org.jboss.tools.smooks.edimap.editor,
org.jboss.tools.smooks.editor,
+ org.jboss.tools.smooks.launch,
org.jboss.tools.smooks.graphical.editors
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/build.properties
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/build.properties 2009-11-26 18:16:38
UTC (rev 18868)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/build.properties 2009-11-26 21:38:48
UTC (rev 18869)
@@ -4,7 +4,6 @@
META-INF/,\
.,\
icons/,\
- libs/,\
libs/dom4j-1.6.1.jar,\
about.html,\
about.ini,\
@@ -12,4 +11,6 @@
about.properties,\
jboss_about.png,\
plugin.properties,\
- schema/
+ schema/,\
+ bin/,\
+ libs/xstream-1.2.2.jar
Added: trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/xstream-1.2.2.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/libs/xstream-1.2.2.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml 2009-11-26 18:16:38 UTC (rev
18868)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/plugin.xml 2009-11-26 21:38:48 UTC (rev
18869)
@@ -245,4 +245,28 @@
</propertyContributor>
</extension>
+ <extension
+ point="org.eclipse.debug.core.launchConfigurationTypes">
+ <launchConfigurationType
+ name="Smooks Configuration"
+
delegate="org.jboss.tools.smooks.launch.SmooksLaunchConfigurationDelegate"
+ modes="run"
+ id="org.jboss.tools.smooks.ui.smooksLauncher">
+ </launchConfigurationType>
+ </extension>
+ <extension point="org.eclipse.debug.ui.launchConfigurationTypeImages">
+ <launchConfigurationTypeImage
+ icon="icons/smooks-sm.gif"
+ configTypeID="org.jboss.tools.smooks.ui.smooksLauncher"
+
id="org.jboss.tools.smooks.ui.launchConfigurationTypeImage.smooksLauncher">
+ </launchConfigurationTypeImage>
+ </extension>
+ <extension point="org.eclipse.debug.ui.launchConfigurationTabGroups">
+ <launchConfigurationTabGroup
+ type="org.jboss.tools.smooks.ui.smooksLauncher"
+ class="org.jboss.tools.smooks.launch.SmooksLaunchTabGroup"
+
id="org.jboss.tools.smooks.ui.launchConfigurationTabGroup.smooksLauncher">
+ </launchConfigurationTabGroup>
+ </extension>
+
</plugin>
Added:
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
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java 2009-11-26
21:38:48 UTC (rev 18869)
@@ -0,0 +1,124 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate;
+import org.eclipse.jdt.launching.ExecutionArguments;
+import org.eclipse.jdt.launching.IVMRunner;
+import org.eclipse.jdt.launching.VMRunnerConfiguration;
+import org.eclipse.osgi.baseadaptor.loader.BaseClassLoader;
+import org.eclipse.osgi.baseadaptor.loader.ClasspathEntry;
+import org.eclipse.osgi.baseadaptor.loader.ClasspathManager;
+import org.osgi.framework.BundleException;
+
+/**
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class SmooksLaunchConfigurationDelegate extends JUnitLaunchConfigurationDelegate
{
+
+ public static final String SMOOKS_INPUT = "SmooksInput";
+ public static final String SMOOKS_INPUT_TYPE = "SmooksInputType";
+ public static final String SMOOKS_PROCESS_TYPES = "SmooksProcessTypes";
+
+ /* (non-Javadoc)
+ * @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 {
+ IVMRunner runner= getVMRunner(launchConfig, mode);
+ VMRunnerConfiguration runConfig = buildRunnerConfig(launchConfig);
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
+
+ IResource smooksConfig = SmooksRunTab.getSmooksConfig(launchConfig);
+ if(smooksConfig != null) {
+ String inputType = launchConfig.getAttribute(SMOOKS_INPUT_TYPE, "");
+ String inputPath = launchConfig.getAttribute(SMOOKS_INPUT, "");
+ String nodeTypes = launchConfig.getAttribute(SMOOKS_PROCESS_TYPES, "");
+
+ runConfig.setProgramArguments(new String[]
{smooksConfig.getRawLocation().toOSString(), inputType, inputPath, nodeTypes});
+
+ runner.run(runConfig, launch, monitor);
+ }
+ }
+
+ private VMRunnerConfiguration buildRunnerConfig(ILaunchConfiguration launchConfig)
throws CoreException {
+ List<String> classpath = new
ArrayList<String>(Arrays.asList(getClasspath(launchConfig)));
+
+ //
====================================================================================================================
+ // TODO Total Hack... Fixme: We're using classes here that we shouldn't, as
well as adding bundle paths that we
+ // probably shouldn't, but how do I get the SmooksLauncher class on the launcher
classpath?
+ // I added the "bin" folder to the bundle classpath as a workaround (with the
following code) for getting
+ // the SmooksLauncher class onto the classpath. Need to fix this properly!!!!
+ //
+ ClassLoader classloader = getClass().getClassLoader();
+ if(classloader instanceof BaseClassLoader) {
+ ClasspathManager cpManager = ((BaseClassLoader)classloader).getClasspathManager();
+ ClasspathEntry[] entries = cpManager.getHostClasspathEntries();
+
+ for(ClasspathEntry entry : entries) {
+ File baseFile = entry.getBundleFile().getBaseFile();
+ try {
+ String[] bundleEntries = entry.getBaseData().getClassPath();
+ for(String bundleEntry : bundleEntries) {
+ String path = baseFile.getAbsolutePath() + "/" + bundleEntry;
+ if(!classpath.contains(path)) {
+ classpath.add(path);
+ }
+ }
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ //
+ //
====================================================================================================================
+
+ VMRunnerConfiguration runConfig= new
VMRunnerConfiguration(SmooksLauncher.class.getName(), classpath.toArray(new
String[classpath.size()]));
+ String[] envp= getEnvironment(launchConfig);
+ ArrayList<String> vmArguments= new ArrayList<String>();
+ String vmArgs= getVMArguments(launchConfig);
+ ExecutionArguments execArgs= new ExecutionArguments(vmArgs, "");
+ File workingDir = verifyWorkingDirectory(launchConfig);
+
+ vmArguments.addAll(Arrays.asList(execArgs.getVMArgumentsArray()));
+ runConfig.setVMArguments((String[]) vmArguments.toArray(new
String[vmArguments.size()]));
+ runConfig.setEnvironment(envp);
+ if(workingDir != null) {
+ runConfig.setWorkingDirectory(workingDir.getAbsolutePath());
+ }
+ runConfig.setVMSpecificAttributesMap(getVMSpecificAttributesMap(launchConfig));
+ runConfig.setBootClassPath(getBootpath(launchConfig));
+
+ return runConfig;
+ }
+}
Added:
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
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java 2009-11-26
21:38:48 UTC (rev 18869)
@@ -0,0 +1,196 @@
+/*
+ * 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 {
+
+ public static enum ProcessNodeType {
+ TEMPLATING,
+ JAVA_BINDING
+ }
+
+ private Smooks inputParamExtractor;
+ 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 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 isValidSmooksConfig() {
+ return isValidSmooksConfig;
+ }
+
+ 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 static Set<ProcessNodeType> fromNodeTypeString(String nodeTypeString) {
+ String[] tokens = nodeTypeString.split(",");
+ Set<ProcessNodeType> nodeTypes = new HashSet<ProcessNodeType>();
+
+ for(String token : tokens) {
+ nodeTypes.add(ProcessNodeType.valueOf(token));
+ }
+
+ return nodeTypes;
+ }
+
+ public void setSmooksConfig(IResource smooksConfig) {
+ reset();
+
+ if(smooksConfig != null) {
+ configFile = new File(smooksConfig.getRawLocation().toOSString());
+ 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)));
+
+ String inputType = inputParams.getProperty(SmooksModelUtils.INPUT_TYPE);
+ if(inputType != null) {
+ String inputPath = inputParams.getProperty(inputType);
+ if(inputPath != null) {
+ File inputFile = new File(SmooksUIUtils.parseFilePath(inputPath));
+
+ if(inputFile.exists() && inputFile.isFile()) {
+ this.inputType = inputType;
+ this.inputFile = inputFile;
+ isValidSmooksConfig = true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ // Not a valid Smooks config file
+ }
+ }
+ }
+ }
+
+ private void reset() {
+ isValidSmooksConfig = false;
+ configFile = null;
+ inputType = null;
+ inputFile = null;
+ processNodeTypes.clear();
+ }
+
+ 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);
+ }
+ }
+}
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchTabGroup.java
===================================================================
---
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchTabGroup.java
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchTabGroup.java 2009-11-26
21:38:48 UTC (rev 18869)
@@ -0,0 +1,48 @@
+/*
+ * 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 org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
+
+/**
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class SmooksLaunchTabGroup extends AbstractLaunchConfigurationTabGroup {
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.debug.ui.ILaunchConfigurationTabGroup#createTabs(org.eclipse.debug.ui.ILaunchConfigurationDialog,
java.lang.String)
+ */
+ public void createTabs(ILaunchConfigurationDialog lcDialog, String mode) {
+ ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
+ new SmooksRunTab(),
+ new JavaArgumentsTab(),
+ new JavaJRETab(),
+ new JavaClasspathTab(),
+ new CommonTab()
+ };
+ setTabs(tabs);
+ }
+}
Added:
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
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java 2009-11-26
21:38:48 UTC (rev 18869)
@@ -0,0 +1,99 @@
+/*
+ * 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.Set;
+import java.util.Map.Entry;
+
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.jboss.tools.smooks.launch.SmooksLaunchMetadata.ProcessNodeType;
+import org.jboss.tools.smooks10.model.smooks.util.SmooksModelUtils;
+import org.milyn.Smooks;
+import org.milyn.payload.JavaResult;
+import org.xml.sax.SAXException;
+
+import com.thoughtworks.xstream.XStream;
+
+/**
+ * Smooks runtime Launcher class.
+ *
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class SmooksLauncher {
+
+ /**
+ * Launcher Main.
+ * @param args Args.
+ */
+ public static void main(String[] args) throws IOException, SAXException {
+ if(args.length != 4) {
+ throw new RuntimeException("Expected 4 Launch arguments: <Smooks Config>
<Input Type> <Input Path> <Node Types>");
+ }
+
+ if(args[1].equals(SmooksModelUtils.INPUT_TYPE_JAVA)) {
+ System.out.println("Sorry... we don't support Java Inputs yet.");
+ } else {
+ File smooksConfig = new File(args[0]);
+ File input = new File(args[2]);
+
+ assertFile(smooksConfig, "Smooks");
+ assertFile(input, "Input");
+
+ Smooks smooks = new Smooks(smooksConfig.getAbsolutePath());
+ try {
+ Set<ProcessNodeType> processNodeTypes =
SmooksLaunchMetadata.fromNodeTypeString(args[3]);
+ JavaResult javaResult = new JavaResult();
+
+ if(processNodeTypes.contains(ProcessNodeType.TEMPLATING)) {
+ smooks.filterSource(new StreamSource(new FileInputStream(input)), new
StreamResult(System.out), javaResult);
+ } else {
+ smooks.filterSource(new StreamSource(new FileInputStream(input)), javaResult);
+ if(processNodeTypes.contains(ProcessNodeType.JAVA_BINDING)) {
+ System.out.println("[Java Bindings (XML Serialized)...]");
+ Set<Entry<String, Object>> bindings =
javaResult.getResultMap().entrySet();
+
+ for(Entry<String, Object> binding : bindings) {
+ System.out.println("\n" + binding.getKey() + ":");
+ System.out.println("\n" + (new XStream()).toXML(binding.getValue()));
+ System.out.println("=============================================");
+ }
+ }
+ }
+
+ } finally {
+ smooks.close();
+ }
+ }
+ }
+
+ private static void assertFile(File file, String name) {
+ if(!file.exists()) {
+ throw new RuntimeException("Specified '" + name + "' File
'" + file.getAbsolutePath() + "' not found.");
+ }
+ if(file.isDirectory()) {
+ throw new RuntimeException("Specified '" + name + "' File
'" + file.getAbsolutePath() + "' is a Directory.");
+ }
+ }
+}
Added:
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
(rev 0)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksRunTab.java 2009-11-26
21:38:48 UTC (rev 18869)
@@ -0,0 +1,431 @@
+/*
+ * 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 org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.window.Window;
+
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.part.FileEditorInput;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+
+import org.eclipse.jdt.core.IJavaModel;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+
+import org.eclipse.jdt.internal.junit.ui.JUnitMessages;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+
+import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.jboss.tools.smooks.editor.AbstractSmooksFormEditor;
+
+/**
+ * @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
+ */
+public class SmooksRunTab extends AbstractLaunchConfigurationTab {
+
+ // Project UI widgets
+ private Text fProjText;
+ private Button fProjButton;
+ private Text fConfigurationText;
+ private Button fSearchButton;
+ private SmooksLaunchMetadata launchMetaData = new SmooksLaunchMetadata();
+
+ private ILaunchConfiguration fLaunchConfiguration;
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite comp = new Composite(parent, SWT.NONE);
+ setControl(comp);
+
+ GridLayout topLayout = new GridLayout();
+ topLayout.numColumns= 3;
+ comp.setLayout(topLayout);
+
+ createFormElements(comp);
+
+ Dialog.applyDialogFont(comp);
+ validatePage();
+ }
+
+ private void createSpacer(Composite comp) {
+ Label label= new Label(comp, SWT.NONE);
+ GridData gd= new GridData();
+ gd.horizontalSpan= 3;
+ label.setLayoutData(gd);
+ }
+
+ private void createFormElements(Composite comp) {
+ GridData gd = new GridData();
+
+ Label fProjLabel = new Label(comp, SWT.NONE);
+ gd.horizontalIndent = 10;
+ fProjLabel.setText("Project:");
+ fProjLabel.setLayoutData(gd);
+
+ fProjText= new Text(comp, SWT.SINGLE | SWT.BORDER);
+ fProjText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ fProjText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent evt) {
+ validatePage();
+ updateLaunchConfigurationDialog();
+ fSearchButton.setEnabled(fProjText.getText().length() > 0);
+ }
+ });
+
+ fProjButton = new Button(comp, SWT.PUSH);
+ fProjButton.setText("Browse");
+ fProjButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent evt) {
+ handleProjectButtonSelected();
+ }
+ });
+ setButtonGridData(fProjButton);
+
+ Label fConfigLabel = new Label(comp, SWT.NONE);
+ gd = new GridData();
+ gd.horizontalIndent = 10;
+ fConfigLabel.setLayoutData(gd);
+ fConfigLabel.setText("Configuration:");
+
+
+ fConfigurationText = new Text(comp, SWT.SINGLE | SWT.BORDER);
+ fConfigurationText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ fConfigurationText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent evt) {
+ handleSmooksConfigChange();
+ validatePage();
+ updateLaunchConfigurationDialog();
+ }
+ });
+
+ fSearchButton = new Button(comp, SWT.PUSH);
+ fSearchButton.setEnabled(fProjText.getText().length() > 0);
+ fSearchButton.setText("Search");
+ fSearchButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent evt) {
+ handleSearchButtonSelected();
+ }
+ });
+ setButtonGridData(fSearchButton);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ public void setDefaults(ILaunchConfigurationWorkingCopy launchConfigWC) {
+ IWorkbenchPage activePage =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+
+ launchConfigWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
""); //$NON-NLS-1$
+ launchConfigWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
""); //$NON-NLS-1$
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_INPUT,
""); //$NON-NLS-1$
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_INPUT_TYPE,
""); //$NON-NLS-1$
+
+ if(activePage != null) {
+ IEditorPart editor = activePage.getActiveEditor();
+
+ if(editor instanceof AbstractSmooksFormEditor) {
+ IEditorInput editorInput = editor.getEditorInput();
+
+ launchConfigWC.rename(editor.getTitle());
+ if(editorInput instanceof FileEditorInput) {
+ FileEditorInput fileEI = (FileEditorInput) editorInput;
+ IFile file = fileEI.getFile();
+
+ launchConfigWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
file.getProject().getName()); //$NON-NLS-1$
+ launchConfigWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
file.getProjectRelativePath().toString()); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ public void initializeFrom(ILaunchConfiguration config) {
+ fLaunchConfiguration = config;
+ try {
+ fProjText.setText(config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
"")); //$NON-NLS-1$
+ fConfigurationText.setText(config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
"")); //$NON-NLS-1$
+ } catch (CoreException ce) {
+ }
+ IResource smooksConfig = getSmooksConfig();
+ if(smooksConfig != null) {
+ launchMetaData.setSmooksConfig(smooksConfig);
+ }
+ validatePage();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ public void performApply(ILaunchConfigurationWorkingCopy launchConfigWC) {
+ launchConfigWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
fProjText.getText());
+ launchConfigWC.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
fConfigurationText.getText());
+ if(launchMetaData.isValidSmooksConfig()) {
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_INPUT,
launchMetaData.getInputFile().getAbsolutePath()); //$NON-NLS-1$
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_INPUT_TYPE,
launchMetaData.getInputType()); //$NON-NLS-1$
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_PROCESS_TYPES,
launchMetaData.getNodeTypesString()); //$NON-NLS-1$
+ } else {
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_INPUT,
""); //$NON-NLS-1$
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_INPUT_TYPE,
""); //$NON-NLS-1$
+ launchConfigWC.setAttribute(SmooksLaunchConfigurationDelegate.SMOOKS_PROCESS_TYPES,
""); //$NON-NLS-1$
+ }
+ }
+
+ /*
+ * Show a dialog that lists all main types
+ */
+ private void handleSearchButtonSelected() {
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new
WorkbenchLabelProvider(), new WorkbenchContentProvider());
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = root.getProject(fProjText.getText());
+
+ if(assertProjectOK(project)) {
+ dialog.setInput(project);
+ } else {
+ dialog.setInput(root);
+ }
+
+ dialog.setTitle("Select Smooks Configuration File...");
+ if (dialog.open() == Window.CANCEL) {
+ return;
+ }
+
+ Object[] results = dialog.getResult();
+ if ((results == null) || (results.length < 1)) {
+ return;
+ }
+
+ IResource resource = (IResource)results[0];
+ fConfigurationText.setText(resource.getProjectRelativePath().toString());
+ }
+
+ private void handleSmooksConfigChange() {
+ launchMetaData.setSmooksConfig(getSmooksConfig());
+ }
+
+ /*
+ * Show a dialog that lets the user select a project. This in turn provides
+ * context for the main type, allowing the user to key a main type name, or
+ * constraining the search for main types to the specified project.
+ */
+ private void handleProjectButtonSelected() {
+ IJavaProject project = chooseJavaProject();
+ if (project == null) {
+ return;
+ }
+
+ String projectName = project.getElementName();
+ fProjText.setText(projectName);
+ }
+
+ /*
+ * Realize a Java Project selection dialog and return the first selected project,
+ * or null if there was none.
+ */
+ private IJavaProject chooseJavaProject() {
+ IJavaProject[] projects;
+ try {
+ projects= JavaCore.create(getWorkspaceRoot()).getJavaProjects();
+ } catch (JavaModelException e) {
+ projects= new IJavaProject[0];
+ }
+
+ ILabelProvider labelProvider= new
JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
+ ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(),
labelProvider);
+ dialog.setTitle(JUnitMessages.JUnitLaunchConfigurationTab_projectdialog_title);
+ dialog.setMessage(JUnitMessages.JUnitLaunchConfigurationTab_projectdialog_message);
+ dialog.setElements(projects);
+
+ IJavaProject javaProject = getJavaProject();
+ if (javaProject != null) {
+ dialog.setInitialSelections(new Object[] { javaProject });
+ }
+ if (dialog.open() == Window.OK) {
+ return (IJavaProject) dialog.getFirstResult();
+ }
+ return null;
+ }
+
+ /*
+ * Return the IJavaProject corresponding to the project name in the project name
+ * text field, or null if the text does not match a project name.
+ */
+ private IJavaProject getJavaProject() {
+ String projectName = fProjText.getText().trim();
+ if (projectName.length() < 1) {
+ return null;
+ }
+ return getJavaModel().getJavaProject(projectName);
+ }
+
+ /*
+ * Convenience method to get the workspace root.
+ */
+ private static IWorkspaceRoot getWorkspaceRoot() {
+ return ResourcesPlugin.getWorkspace().getRoot();
+ }
+
+ /*
+ * Convenience method to get access to the java model.
+ */
+ private IJavaModel getJavaModel() {
+ return JavaCore.create(getWorkspaceRoot());
+ }
+
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.debug.ui.AbstractLaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ public boolean isValid(ILaunchConfiguration config) {
+ validatePage();
+ return getErrorMessage() == null;
+ }
+
+ private void validatePage() {
+
+ setErrorMessage(null);
+ setMessage(null);
+
+ String projectName= fProjText.getText().trim();
+ if (projectName.length() == 0) {
+ setErrorMessage("Project name not configured.");
+ return;
+ }
+
+ IStatus status= ResourcesPlugin.getWorkspace().validatePath(IPath.SEPARATOR +
projectName, IResource.PROJECT);
+ if (!status.isOK() || !Path.ROOT.isValidSegment(projectName)) {
+ setErrorMessage("Invalid project name '" + projectName +
"'.");
+ return;
+ }
+
+ IProject project= getWorkspaceRoot().getProject(projectName);
+ if (!project.exists()) {
+ setErrorMessage("Unknown project name '" + projectName +
"'.");
+ return;
+ }
+ IJavaProject javaProject= JavaCore.create(project);
+
+ String configName= fConfigurationText.getText().trim();
+ try {
+ if (!project.hasNature(JavaCore.NATURE_ID)) {
+ setErrorMessage("Project '" + projectName + "' is not a Java
Project.");
+ return;
+ }
+ if (configName.length() == 0) {
+ setErrorMessage("Smooks Configuration not specified.");
+ return;
+ }
+ } catch (CoreException e) {
+ setErrorMessage("Unexpected Validation Error: " + e.getMessage());
+ }
+
+ if(!launchMetaData.isValidSmooksConfig()) {
+ setErrorMessage("The selected Smooks configuration is not valid. Must be a valid
Smooks configuration, with a valid configured input.");
+ }
+ }
+
+ private IResource getSmooksConfig() {
+ String projectName = fProjText.getText();
+ String configName = fConfigurationText.getText();
+
+ return getSmooksConfig(projectName, configName);
+ }
+
+ public static IResource getSmooksConfig(ILaunchConfiguration launchConfig) {
+ try {
+ String projectName =
launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
""); //$NON-NLS-1$;
+ String configName =
launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
""); //$NON-NLS-1$;
+
+ return getSmooksConfig(projectName, configName);
+ } catch (CoreException e) {
+ return null;
+ }
+ }
+
+ private static IResource getSmooksConfig(String projectName, String configName) {
+ if(projectName != null && !projectName.trim().equals("") &&
configName != null && !configName.trim().equals("")) {
+ IProject project = getWorkspaceRoot().getProject(projectName);
+ if(assertProjectOK(project)) {
+ return project.findMember(configName);
+ }
+ }
+
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
+ */
+ public String getName() {
+ return "Run";
+ }
+
+ private void setButtonGridData(Button button) {
+ GridData gridData= new GridData();
+ button.setLayoutData(gridData);
+ }
+
+ private static boolean assertProjectOK(IProject project) {
+ return (project != null && project.exists() && project.isAccessible()
&& !project.isHidden());
+ }
+}
+
+