Author: tfennelly
Date: 2009-11-27 16:34:25 -0500 (Fri, 27 Nov 2009)
New Revision: 18895
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF
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/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-5285
Launch Configuration Delegate using stale into from Launch Config
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-27
17:26:32 UTC (rev 18894)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/META-INF/MANIFEST.MF 2009-11-27
21:34:25 UTC (rev 18895)
@@ -36,7 +36,8 @@
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"
+ org.eclipse.ui.console;bundle-version="3.4.0",
+ org.jboss.tools.common.model.ui;bundle-version="2.0.0"
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
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-27
17:26:32 UTC (rev 18894)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchConfigurationDelegate.java 2009-11-27
21:34:25 UTC (rev 18895)
@@ -28,7 +28,7 @@
import java.util.Arrays;
import java.util.List;
-import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -38,41 +38,58 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.jdt.junit.launcher.JUnitLaunchConfigurationDelegate;
import org.eclipse.jdt.launching.ExecutionArguments;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IVMRunner;
import org.eclipse.jdt.launching.VMRunnerConfiguration;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
import org.jboss.tools.smooks.core.SmooksInputType;
/**
+ * Smooks Launch Configuration Delegate.
+ *
* @author <a
href="mailto:tom.fennelly@jboss.com">tom.fennelly@jboss.com</a>
*/
public class SmooksLaunchConfigurationDelegate extends JUnitLaunchConfigurationDelegate
{
private static final String PLUGIN_ID =
"org.jboss.tools.smooks.ui.smooksLauncher";
- 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);
+ IProject project = getJavaProject(launchConfig).getProject();
+ final String smooksConfigName =
launchConfig.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
"");
+ final SmooksLaunchMetadata launchMetadata = new SmooksLaunchMetadata();
+
+ launchMetadata.setSmooksConfig(project.findMember(smooksConfigName));
- // 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, "");
+ if(launchMetadata.isValidSmooksConfig()) {
+ IVMRunner runner= getVMRunner(launchConfig, mode);
+ VMRunnerConfiguration runConfig = buildRunnerConfig(launchConfig);
+
+ // check for cancellation
+ if (monitor.isCanceled()) {
+ return;
+ }
- runConfig.setProgramArguments(new String[]
{smooksConfig.getRawLocation().toOSString(), inputType, inputPath, nodeTypes});
+ 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()));
+ }
+ });
}
}
@@ -148,7 +165,7 @@
}
}
} catch (IOException e) {
- new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, "Error
copying SmooksLauncher to classpath.", e));
+ new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Error
copying SmooksLauncher to classpath.", e));
}
}
}
Modified:
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-27
17:26:32 UTC (rev 18894)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLaunchMetadata.java 2009-11-27
21:34:25 UTC (rev 18895)
@@ -49,6 +49,7 @@
public class SmooksLaunchMetadata {
private Smooks inputParamExtractor;
+ private boolean isSmooksConfig;
private boolean isValidSmooksConfig;
private File configFile;
private String inputType;
@@ -57,11 +58,16 @@
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;
}
@@ -72,17 +78,19 @@
}
if(configFile == null) {
- return "Smooks configuration file not configured.";
+ 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 file 'Input' task is not
configured with a sample input file. Please configure the 'Input' task in the
Process flow.";
+ 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 file 'Input' task is configured
with a sample input file, but the file cannot be found. Please reconfigure the
'Input' task in the Process flow.";
+ 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 file '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 "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 "";
@@ -158,6 +166,7 @@
}
private void reset() {
+ isSmooksConfig = false;
isValidSmooksConfig = false;
configFile = null;
inputType = null;
@@ -165,6 +174,13 @@
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 {
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-27
17:26:32 UTC (rev 18894)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksLauncher.java 2009-11-27
21:34:25 UTC (rev 18895)
@@ -19,9 +19,12 @@
*/
package org.jboss.tools.smooks.launch;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.Map.Entry;
@@ -32,6 +35,7 @@
import org.jboss.tools.smooks.core.SmooksInputType;
import org.milyn.Smooks;
import org.milyn.payload.JavaResult;
+import org.milyn.payload.StringResult;
import org.xml.sax.SAXException;
import com.thoughtworks.xstream.XStream;
@@ -67,18 +71,26 @@
JavaResult javaResult = new JavaResult();
if(processNodeTypes.contains(ProcessNodeType.TEMPLATING)) {
- smooks.filterSource(new StreamSource(new FileInputStream(input)), new
StreamResult(System.out), javaResult);
+ StringResult stringResult = new StringResult();
+
+ smooks.filterSource(new StreamSource(new FileInputStream(input)), stringResult,
javaResult);
+ System.out.println("[StreamResult ...]\n");
+ System.out.println(" |--");
+ System.out.println(indent(stringResult.toString()));
+ System.out.println(" |--\n");
} 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("=============================================");
- }
+ }
+
+ Set<Entry<String, Object>> bindings =
javaResult.getResultMap().entrySet();
+ if(!bindings.isEmpty()) {
+ System.out.println("[JavaResult Objects (XML Serialized)...]");
+
+ for(Entry<String, Object> binding : bindings) {
+ System.out.println("\n" + binding.getKey() + ":");
+ System.out.println(" |--");
+ System.out.println(indent((new XStream()).toXML(binding.getValue())));
+ System.out.println(" |--");
}
}
@@ -107,4 +119,20 @@
return nodeTypes;
}
+
+ private static String indent(String in) throws IOException {
+ BufferedReader lineReader = new BufferedReader(new StringReader(in));
+ StringBuilder indentBuf = new StringBuilder();
+
+ String line = lineReader.readLine();
+ while(line != null) {
+ indentBuf.append(" |").append(line);
+ line = lineReader.readLine();
+ if(line != null) {
+ indentBuf.append('\n');
+ }
+ }
+
+ return indentBuf.toString();
+ }
}
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-27
17:26:32 UTC (rev 18894)
+++
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/launch/SmooksRunTab.java 2009-11-27
21:34:25 UTC (rev 18895)
@@ -173,8 +173,6 @@
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();
@@ -218,15 +216,6 @@
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$
- }
}
/*