summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhubner2009-04-29 06:38:08 (EDT)
committerdhubner2009-04-29 06:38:08 (EDT)
commit5ac4f62efe494ff177a380bb2632e7a0e7e93211 (patch)
treed4675936d1e79cb30cc2ae6a316f51277dfb668a
parent6ef7107dbc3cae3c0342a2a5f9802252fc6cd41e (diff)
downloadorg.eclipse.mwe-5ac4f62efe494ff177a380bb2632e7a0e7e93211.zip
org.eclipse.mwe-5ac4f62efe494ff177a380bb2632e7a0e7e93211.tar.gz
org.eclipse.mwe-5ac4f62efe494ff177a380bb2632e7a0e7e93211.tar.bz2
patches for #274171 and #274265
-rw-r--r--plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java178
1 files changed, 84 insertions, 94 deletions
diff --git a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java
index 79e78e8..9c6a228 100644
--- a/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java
+++ b/plugins/org.eclipse.emf.mwe.core/src/org/eclipse/emf/mwe/core/WorkflowRunner.java
@@ -103,18 +103,14 @@ public class WorkflowRunner {
.withArgName("className,moreArgs")
.withDescription(
"the name of a class that implements ProgressMonitor. More arguments can be appended that will be injected to the monitor,"
- + " if it has a init(String[] args) method.")
- .withLongOpt("monitorClass").withValueSeparator(',')
- .create(MONITOR));
-
- options.addOption(OptionBuilder.withLongOpt("ant").withDescription(
- "must be set when using in Ant context").create(ANT));
-
- final Option paramOption = OptionBuilder
- .withArgName("key=value")
- .withDescription(
- "external property that is handled as workflow property")
- .hasArgs().create(PARAM);
+ + " if it has a init(String[] args) method.").withLongOpt("monitorClass")
+ .withValueSeparator(',').create(MONITOR));
+
+ options.addOption(OptionBuilder.withLongOpt("ant").withDescription("must be set when using in Ant context")
+ .create(ANT));
+
+ final Option paramOption = OptionBuilder.withArgName("key=value").withDescription(
+ "external property that is handled as workflow property").hasArgs().create(PARAM);
paramOption.setLongOpt("param");
options.addOption(paramOption);
@@ -131,9 +127,9 @@ public class WorkflowRunner {
CommandLine line = null;
try {
line = parser.parse(options, args);
- } catch (final ParseException exp) {
- System.err.println("Parsing arguments failed. Reason: "
- + exp.getMessage());
+ }
+ catch (final ParseException exp) {
+ System.err.println("Parsing arguments failed. Reason: " + exp.getMessage());
wrongCall(options);
return;
}
@@ -149,49 +145,49 @@ public class WorkflowRunner {
final List<String> unprocessedArgs = new ArrayList<String>();
for (int i = 0; i < args.length; i++) {
final String arg = args[i];
- if (arg.equals("-" + CMDL)
- || arg.equals("--cmdLineProcessor")) {
+ if (arg.equals("-" + CMDL) || arg.equals("--cmdLineProcessor")) {
i++; // ignore this and next element
- } else if (arg.equals("-" + MONITOR)
- || arg.equals("--monitorClass")) {
+ }
+ else if (arg.equals("-" + MONITOR) || arg.equals("--monitorClass")) {
// i++; // ignore this and next element
i = i + monitorOptValues.length;
- } else if (arg.endsWith(".oaw")) {
+ }
+ else if (arg.endsWith(".oaw")) {
if (wfFile != null) {
System.err.println("Workflowfile already defined!");
System.exit(1);
}
wfFile = arg;
; // continue the loop (will be handled later)
- } else {
+ }
+ else {
unprocessedArgs.add(arg);
}
}
- final Class<?> cmdLineProcessor = ResourceLoaderFactory
- .createResourceLoader().loadClass(
- line.getOptionValue(CMDL));
+ final Class<?> cmdLineProcessor = ResourceLoaderFactory.createResourceLoader().loadClass(
+ line.getOptionValue(CMDL));
if (cmdLineProcessor == null) {
- System.err.println("cannot find class '"
- + line.getOptionValue(CMDL)
+ System.err.println("cannot find class '" + line.getOptionValue(CMDL)
+ "' for command line processing.");
System.exit(1);
}
- final Method method = cmdLineProcessor.getMethod("processCmdLine",
- String[].class, Map.class, WorkflowContext.class);
- method.invoke(cmdLineProcessor.newInstance(), unprocessedArgs
- .toArray(new String[0]), params, runner.getContext());
- } catch (final Exception e) {
+ final Method method = cmdLineProcessor.getMethod("processCmdLine", String[].class, Map.class,
+ WorkflowContext.class);
+ method.invoke(cmdLineProcessor.newInstance(), unprocessedArgs.toArray(new String[0]), params, runner
+ .getContext());
+ }
+ catch (final Exception e) {
e.printStackTrace();
System.exit(1);
}
- } else {
+ }
+ else {
params = resolveParams(line.getOptionValues(PARAM));
wfFile = line.getArgs()[0];
}
- if ((wfFile == null)
- || !(wfFile.endsWith(".oaw") || wfFile.endsWith(".mwe"))) {
+ if ((wfFile == null) || !(wfFile.endsWith(".oaw") || wfFile.endsWith(".mwe"))) {
wrongCall(options);
}
@@ -199,19 +195,17 @@ public class WorkflowRunner {
if (monitorOptValues != null) {
try {
- final Class<?> clazz = ResourceLoaderFactory
- .createResourceLoader().loadClass(monitorOptValues[0]);
+ final Class<?> clazz = ResourceLoaderFactory.createResourceLoader().loadClass(monitorOptValues[0]);
if (clazz == null) {
- throw new ClassNotFoundException("Didn't find class "
- + monitorOptValues[0]);
+ throw new ClassNotFoundException("Didn't find class " + monitorOptValues[0]);
}
monitor = (ProgressMonitor) clazz.newInstance();
- final Method method = monitor.getClass().getMethod("init",
- new Class[] { String[].class });
+ final Method method = monitor.getClass().getMethod("init", new Class[] { String[].class });
if (method != null) {
method.invoke(monitor, new Object[] { monitorOptValues });
}
- } catch (final Exception e) {
+ }
+ catch (final Exception e) {
logger.error(e.getMessage(), e);
if (line.hasOption(ANT)) {
System.exit(1);
@@ -235,8 +229,7 @@ public class WorkflowRunner {
} while ((wfUrl == null) && (index >= 0));
if (wfUrl == null) {
- runner.logger.error("can't find the workflow file '"
- + line.getArgs()[0] + "' in the current class path");
+ runner.logger.error("can't find the workflow file '" + line.getArgs()[0] + "' in the current class path");
if (line.hasOption(ANT)) {
System.exit(1);
}
@@ -266,8 +259,7 @@ public class WorkflowRunner {
for (final String element : args) {
final String[] string = element.split("=", 2);
if (string.length != 2) {
- throw new IllegalArgumentException(
- "wrong param syntax (-pkey=value). was : " + element);
+ throw new IllegalArgumentException("wrong param syntax (-pkey=value). was : " + element);
}
params.put(string[0], string[1]);
}
@@ -281,10 +273,8 @@ public class WorkflowRunner {
*/
private static void wrongCall(final Options options) {
final HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("java " + WorkflowRunner.class.getName()
- + " some_workflow_file.mwe [options]\nor\njava "
- + WorkflowRunner.class.getName()
- + " some_workflow_file.oaw [options]\n", options);
+ formatter.printHelp("java " + WorkflowRunner.class.getName() + " some_workflow_file.mwe [options]\nor\njava "
+ + WorkflowRunner.class.getName() + " some_workflow_file.oaw [options]\n", options);
System.exit(0);
}
@@ -294,10 +284,8 @@ public class WorkflowRunner {
* @param logger
* @param params
*/
- public boolean run(final String workFlowFile,
- final ProgressMonitor theMonitor,
- final Map<String, String> theParams,
- final Map<String, ?> externalSlotContents) {
+ public boolean run(final String workFlowFile, final ProgressMonitor theMonitor,
+ final Map<String, String> theParams, final Map<String, ?> externalSlotContents) {
final boolean configOK = prepare(workFlowFile, theMonitor, theParams);
final Issues issues = new IssuesImpl();
if (configOK) {
@@ -306,8 +294,7 @@ public class WorkflowRunner {
return false;
}
- public boolean prepare(final String workFlowFile,
- final ProgressMonitor theMonitor,
+ public boolean prepare(final String workFlowFile, final ProgressMonitor theMonitor,
final Map<String, String> theParams) {
if (workFlowFile == null) {
throw new NullPointerException("workflowFile is null");
@@ -315,17 +302,16 @@ public class WorkflowRunner {
if (theMonitor == null) {
monitor = new NullProgressMonitor();
- } else {
+ }
+ else {
monitor = theMonitor;
}
params = theParams;
- logger
- .info("--------------------------------------------------------------------------------------");
+ logger.info("--------------------------------------------------------------------------------------");
logger.info("EMF Modeling Workflow Engine " + getVersion());
logger.info("(c) 2005-2009 openarchitectureware.org and contributors");
- logger
- .info("--------------------------------------------------------------------------------------");
+ logger.info("--------------------------------------------------------------------------------------");
logger.info("running workflow: " + workFlowFile);
logger.info("");
@@ -342,9 +328,9 @@ public class WorkflowRunner {
// a configuration problem.
// Detect this very special case
try {
- workflow = factory.parseInitAndCreate(workFlowFile, params,
- getConverters(), issues);
- } catch (final IllegalArgumentException illegalArg) {
+ workflow = factory.parseInitAndCreate(workFlowFile, params, getConverters(), issues);
+ }
+ catch (final IllegalArgumentException illegalArg) {
if (illegalArg.getMessage().startsWith("Couldn't load file")) {
throw new ConfigurationException(illegalArg.getMessage());
}
@@ -352,8 +338,7 @@ public class WorkflowRunner {
}
logIssues(logger, issues);
if (issues.hasErrors()) {
- logger
- .error("Workflow interrupted because of configuration errors.");
+ logger.error("Workflow interrupted because of configuration errors.");
return false;
}
if (workflow != null) {
@@ -361,11 +346,11 @@ public class WorkflowRunner {
}
logIssues(logger, issues);
if (issues.hasErrors()) {
- logger
- .error("Workflow interrupted because of configuration errors.");
+ logger.error("Workflow interrupted because of configuration errors.");
return false;
}
- } catch (final ConfigurationException ex) {
+ }
+ catch (final ConfigurationException ex) {
logger.fatal(ex.getMessage(), ex);
logIssues(logger, issues);
return false;
@@ -385,12 +370,12 @@ public class WorkflowRunner {
@SuppressWarnings("unchecked")
private Map<Class<?>, Converter> getConverters() {
Map<Class<?>, Converter> result = getCustomConverters();
- final Map<Class<?>, Converter> defaults = WorkflowFactory
- .getDefaultConverter();
+ final Map<Class<?>, Converter> defaults = WorkflowFactory.getDefaultConverter();
if (result == null) {
// go with the default values
result = defaults;
- } else {
+ }
+ else {
// add default Converter implementations if we don't have a custom
// implementation yet
for (final Map.Entry<Class<?>, Converter> record : defaults.entrySet()) {
@@ -418,8 +403,7 @@ public class WorkflowRunner {
return null;
}
- public boolean executeWorkflow(final Map<?, ?> externalSlotContents,
- final Issues issues) {
+ public boolean executeWorkflow(final Map<?, ?> externalSlotContents, final Issues issues) {
try {
wfContext = new WorkflowContextDefaultImpl();
addExternalSlotContents(externalSlotContents);
@@ -433,13 +417,16 @@ public class WorkflowRunner {
return false;
}
return true;
- } catch (final Exception e) {
+ }
+ catch (final Exception e) {
if (e.getClass().getName().indexOf("Interrupt") > -1) {
logger.error("Workflow interrupted. Reason: " + e.getMessage());
- } else {
+ }
+ else {
logger.error(e.getMessage(), e);
}
- } finally {
+ }
+ finally {
logIssues(logger, issues);
}
return false;
@@ -486,28 +473,31 @@ public class WorkflowRunner {
String version = null;
+ // FIXME find a proper way to resolve the version
// get all META-INF/MANIFEST.MF found in the classpath
try {
- final Manifest manifest = new Manifest(ResourceLoaderFactory
- .createResourceLoader().getResource("META-INF/MANIFEST.MF")
- .openStream());
+ final Manifest manifest = new Manifest(ResourceLoaderFactory.createResourceLoader().getResource(
+ "META-INF/MANIFEST.MF").openStream());
// identify the manifest from core.workflow plugin
- final String bundleName = manifest.getMainAttributes().getValue(
- "Bundle-SymbolicName");
- if (bundleName.startsWith("org.eclipse.emf.mwe.core")) {
- // Read bundle version an split it.
- // Original value : "4.1.1.200609291913"
- // Resulting value : "4.1.1, Build 200609291913"
- version = manifest.getMainAttributes().getValue(
- "Bundle-Version");
- final int lastPoint = version.lastIndexOf('.');
- version = version.substring(0, lastPoint) + ", Build "
- + version.substring(lastPoint + 1);
- return version;
+ final String bundleName = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
+ if (bundleName != null) {
+ if (bundleName.startsWith("org.eclipse.emf.mwe.core")) {
+
+ // Read bundle version an split it.
+ // Original value : "4.1.1.200609291913"
+ // Resulting value : "4.1.1, Build 200609291913"
+ version = manifest.getMainAttributes().getValue("Bundle-Version");
+ final int lastPoint = version.lastIndexOf('.');
+ version = version.substring(0, lastPoint) + ", Build " + version.substring(lastPoint + 1);
+ return version;
+ }
}
- } catch (final IOException e) {
- logger
- .debug("Failed to read Manifest file. Unable to retrieve version");
+ else {
+ logger.warn("Manifest does not contains 'Bundle-SymbolicName' attribute");
+ }
+ }
+ catch (final IOException e) {
+ logger.debug("Failed to read Manifest file. Unable to retrieve version");
}
// build version not detected from manifest, fallback
// this will only occur in developer's workbench