diff options
author | Christopher Gerking | 2018-08-22 10:44:34 +0000 |
---|---|---|
committer | Ed Willink | 2019-02-27 09:54:25 +0000 |
commit | a6dd5b0cd7cb4895922bd5d1251a9cf6b989c269 (patch) | |
tree | 760fa31e676216a1f38c5f59dffde11979edc22d | |
parent | f9beafc7daf83facad76f30c4b9f6069074b74a3 (diff) | |
download | org.eclipse.qvto-a6dd5b0cd7cb4895922bd5d1251a9cf6b989c269.tar.gz org.eclipse.qvto-a6dd5b0cd7cb4895922bd5d1251a9cf6b989c269.tar.xz org.eclipse.qvto-a6dd5b0cd7cb4895922bd5d1251a9cf6b989c269.zip |
[537609] Ensure proper IProcess termination, deprecating ShallowProcess
15 files changed, 509 insertions, 567 deletions
diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/Messages.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/Messages.java index 1b0c74e90..43ea58edb 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/Messages.java +++ b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/Messages.java @@ -1,38 +1,39 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.common; import org.eclipse.osgi.util.NLS; public class Messages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.m2m.internal.qvt.oml.common.messages"; //$NON-NLS-1$ + private static final String BUNDLE_NAME = "org.eclipse.m2m.internal.qvt.oml.common.messages"; //$NON-NLS-1$ - private Messages() { - } + private Messages() { + } - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - public static String FileUtil_CannotDelete; - public static String ShallowProcess_Label; - public static String ShallowProcess_LabelTransform; - public static String ShallowProcess_InvalidState; - - public static String TransformationRegistry_MissingMetamodelAttr; - public static String TransformationRegistry_MissingMetaclassAttr; - public static String TransformationRegistry_UnknownMetamodel; - public static String TransformationRegistry_NoElements; - - public static String InvalidFilePath; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + public static String FileUtil_CannotDelete; + public static String IProcess_Label; + public static String IProcess_LabelTransform; + public static String IProcess_InvalidState; + + public static String TransformationRegistry_MissingMetamodelAttr; + public static String TransformationRegistry_MissingMetaclassAttr; + public static String TransformationRegistry_UnknownMetamodel; + public static String TransformationRegistry_NoElements; + + public static String InvalidFilePath; } diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/BaseProcess.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/BaseProcess.java index 4085e3292..d69004265 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/BaseProcess.java +++ b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/BaseProcess.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.common.launch; @@ -15,22 +16,23 @@ import org.eclipse.core.runtime.PlatformObject; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IStreamsProxy; +@Deprecated public abstract class BaseProcess extends PlatformObject implements IProcess { - + public static interface IRunnable { - - public void run() throws Exception; - - } - + + public void run() throws Exception; + + } + public void setStreamsProxy(IStreamsProxy streamsProxy) { myStreamsProxy = streamsProxy; } - - public IStreamsProxy getStreamsProxy() { - return myStreamsProxy; - } - - private IStreamsProxy myStreamsProxy; - + + public IStreamsProxy getStreamsProxy() { + return myStreamsProxy; + } + + private IStreamsProxy myStreamsProxy; + } diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ProcessJob.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ProcessJob.java index fcbc758a3..3ff71638f 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ProcessJob.java +++ b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ProcessJob.java @@ -1,10 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 + *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.common.launch; import org.eclipse.core.resources.WorkspaceJob; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.IProcess; @@ -23,6 +39,15 @@ public abstract class ProcessJob extends WorkspaceJob implements IProcess { this.launch = launch; this.proxy = proxy; + + addJobChangeListener(new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + if (DebugPlugin.getDefault() != null) { + DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(ProcessJob.this, DebugEvent.TERMINATE)}); + } + } + }); } public boolean canTerminate() { @@ -33,7 +58,7 @@ public abstract class ProcessJob extends WorkspaceJob implements IProcess { return getResult() != null; } - public void terminate() throws DebugException { + public void terminate() { cancel(); } @@ -49,8 +74,8 @@ public abstract class ProcessJob extends WorkspaceJob implements IProcess { } return transformationURI != null - ? NLS.bind(Messages.ShallowProcess_LabelTransform, transformationURI) - : Messages.ShallowProcess_Label; + ? NLS.bind(Messages.IProcess_LabelTransform, transformationURI) + : Messages.IProcess_Label; } public ILaunch getLaunch() { @@ -69,7 +94,7 @@ public abstract class ProcessJob extends WorkspaceJob implements IProcess { public int getExitValue() throws DebugException { if(!isTerminated()) { - throw new DebugException(new Status(IStatus.ERROR, CommonPlugin.ID, 1, Messages.ShallowProcess_InvalidState, null)); + throw new DebugException(new Status(IStatus.ERROR, CommonPlugin.ID, 1, Messages.IProcess_InvalidState, null)); } return getResult().getSeverity(); diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/SafeRunner.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/SafeRunner.java index b6a7b3ddc..e5c764985 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/SafeRunner.java +++ b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/SafeRunner.java @@ -1,38 +1,39 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.common.launch; import org.eclipse.m2m.internal.qvt.oml.common.launch.BaseProcess.IRunnable; - +@Deprecated public class SafeRunner { - public static interface IRunner { - public void run(BaseProcess.IRunnable r) throws Exception; - } - - public static BaseProcess.IRunnable getSafeRunnable(final BaseProcess.IRunnable r) { - final IRunner runner = SameThreadRunner.INSTANCE; - return new BaseProcess.IRunnable() { - public void run() throws Exception { - runner.run(r); - } - }; - } + public static interface IRunner { + public void run(BaseProcess.IRunnable r) throws Exception; + } + + public static BaseProcess.IRunnable getSafeRunnable(final BaseProcess.IRunnable r) { + final IRunner runner = SameThreadRunner.INSTANCE; + return new BaseProcess.IRunnable() { + public void run() throws Exception { + runner.run(r); + } + }; + } + + static class SameThreadRunner implements IRunner { + public void run(IRunnable r) throws Exception { + r.run(); + } - static class SameThreadRunner implements IRunner { - public void run(IRunnable r) throws Exception { - r.run(); - } - - static IRunner INSTANCE = new SameThreadRunner(); - } + static IRunner INSTANCE = new SameThreadRunner(); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ShallowProcess.java b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ShallowProcess.java index d2dd865f6..3555cb14d 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ShallowProcess.java +++ b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/launch/ShallowProcess.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.common.launch; @@ -25,34 +26,35 @@ import org.eclipse.m2m.internal.qvt.oml.common.Messages; import org.eclipse.osgi.util.NLS; +@Deprecated public class ShallowProcess extends BaseProcess { public ShallowProcess(ILaunch launch, IRunnable r) { - myLaunch = launch; - myRunnable = r; - } - - public void run() throws Exception { - run(null); - } - - public void run(IDebugTarget debugTarget) throws Exception { - myLaunch.addProcess(this); - try { - if(debugTarget != null) { - myLaunch.addDebugTarget(debugTarget); - } - myRunnable.run(); - } - finally { - myRunnable = null; - if (DebugPlugin.getDefault() != null) { - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)}); - } - } - } - - public String getLabel() { + myLaunch = launch; + myRunnable = r; + } + + public void run() throws Exception { + run(null); + } + + public void run(IDebugTarget debugTarget) throws Exception { + myLaunch.addProcess(this); + try { + if(debugTarget != null) { + myLaunch.addDebugTarget(debugTarget); + } + myRunnable.run(); + } + finally { + myRunnable = null; + if (DebugPlugin.getDefault() != null) { + DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)}); + } + } + } + + public String getLabel() { String transformationURI = null; ILaunchConfiguration configuration = myLaunch.getLaunchConfiguration(); if(configuration != null) { @@ -62,42 +64,42 @@ public class ShallowProcess extends BaseProcess { CommonPlugin.log(e.getStatus()); } } - - return transformationURI != null - ? NLS.bind(Messages.ShallowProcess_LabelTransform, transformationURI) - : Messages.ShallowProcess_Label; - } - - public ILaunch getLaunch() { - return myLaunch; - } - - public void setAttribute(String key, String value) { - } - - public String getAttribute(String key) { - return null; - } - - public int getExitValue() throws DebugException { - if(!isTerminated()) { - throw new DebugException(new Status(IStatus.ERROR, CommonPlugin.ID, 1, Messages.ShallowProcess_InvalidState, null)); - } - - return 0; - } - - public boolean canTerminate() { - return !isTerminated(); - } - - public boolean isTerminated() { - return myRunnable == null; - } - - public void terminate() throws DebugException { - } - - private final ILaunch myLaunch; - private IRunnable myRunnable; + + return transformationURI != null + ? NLS.bind(Messages.IProcess_LabelTransform, transformationURI) + : Messages.IProcess_Label; + } + + public ILaunch getLaunch() { + return myLaunch; + } + + public void setAttribute(String key, String value) { + } + + public String getAttribute(String key) { + return null; + } + + public int getExitValue() throws DebugException { + if(!isTerminated()) { + throw new DebugException(new Status(IStatus.ERROR, CommonPlugin.ID, 1, Messages.IProcess_InvalidState, null)); + } + + return 0; + } + + public boolean canTerminate() { + return !isTerminated(); + } + + public boolean isTerminated() { + return myRunnable == null; + } + + public void terminate() throws DebugException { + } + + private final ILaunch myLaunch; + private IRunnable myRunnable; } diff --git a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/messages.properties b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/messages.properties index ce9c9e2b6..a33e19fa8 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/messages.properties +++ b/plugins/org.eclipse.m2m.qvt.oml.common/src/org/eclipse/m2m/internal/qvt/oml/common/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007, 2014 Borland Software Corporation and others. +# Copyright (c) 2007, 2019 Borland Software Corporation and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v2.0 @@ -8,12 +8,13 @@ # # Contributors: # Borland Software Corporation - initial API and implementation +# Christopher Gerking - bug 537609 ############################################################################### FileUtil_CannotDelete=Cannot delete ''{0}'' -ShallowProcess_Label=QVTO Process -ShallowProcess_LabelTransform=execute ''{0}'' -ShallowProcess_InvalidState=Invalid state +IProcess_Label=QVTO Process +IProcess_LabelTransform=execute ''{0}'' +IProcess_InvalidState=Invalid state TransformationRegistry_MissingMetamodelAttr=Missing metamodel attribute: {0} TransformationRegistry_MissingMetaclassAttr=Missing metaclass attribute: {0} diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/InMemoryQvtLaunchConfigurationDelegate.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/InMemoryQvtLaunchConfigurationDelegate.java index 5e63fa759..1ced7f4c5 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/InMemoryQvtLaunchConfigurationDelegate.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/InMemoryQvtLaunchConfigurationDelegate.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.runtime.launch; @@ -16,18 +17,15 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.IStatusHandler; -import org.eclipse.m2m.internal.qvt.oml.QvtPlugin; import org.eclipse.m2m.internal.qvt.oml.common.MDAConstants; import org.eclipse.m2m.internal.qvt.oml.common.MdaException; import org.eclipse.m2m.internal.qvt.oml.common.launch.EmptyDebugTarget; import org.eclipse.m2m.internal.qvt.oml.common.launch.IQvtLaunchConstants; -import org.eclipse.m2m.internal.qvt.oml.common.launch.ShallowProcess; +import org.eclipse.m2m.internal.qvt.oml.common.launch.ProcessJob; import org.eclipse.m2m.internal.qvt.oml.common.launch.StreamsProxy; import org.eclipse.m2m.internal.qvt.oml.emf.util.EmfUtil; import org.eclipse.m2m.internal.qvt.oml.evaluator.QvtInterruptedExecutionException; @@ -42,143 +40,91 @@ import org.eclipse.osgi.util.NLS; public class InMemoryQvtLaunchConfigurationDelegate extends QvtLaunchConfigurationDelegateBase { - - public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.m2m.qvt.oml.InMemoryQvtTransformation"; //$NON-NLS-1$ - - /** - * A handler for transformation job-done-status can be registered, taking argument as - * array of Object[] { Job, Runnable }, where <code>Runnable</code> element is optional - * and may execute a UI feedback on the job done event. - * - * @see IStatusHandler - */ - public static final IStatus statusJobDone = new Status(IStatus.INFO, QvtRuntimePlugin.ID, 200, "", null); //$NON-NLS-1$ - - - public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch, final IProgressMonitor monitor) throws CoreException { - String moduleUri = QvtLaunchUtil.getTransformationURI(configuration); - final QvtTransformation qvtTransformation; + + public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.m2m.qvt.oml.InMemoryQvtTransformation"; //$NON-NLS-1$ + + /** + * A handler for transformation job-done-status can be registered, taking argument as + * array of Object[] { Job, Runnable }, where <code>Runnable</code> element is optional + * and may execute a UI feedback on the job done event. + * + * @see IStatusHandler + */ + public static final IStatus statusJobDone = new Status(IStatus.INFO, QvtRuntimePlugin.ID, 200, "", null); //$NON-NLS-1$ + + + public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch, final IProgressMonitor monitor) throws CoreException { + String moduleUri = QvtLaunchUtil.getTransformationURI(configuration); + final QvtTransformation qvtTransformation; try { qvtTransformation = new QvtInterpretedTransformation(TransformationUtil.getQvtModule(EmfUtil.makeUri(moduleUri))); } catch (MdaException e) { throw new IllegalArgumentException(NLS.bind(Messages.QvtBuilderLaunchTab_TransformationNotFound, moduleUri)); } - final Runnable doneAction = (Runnable) configuration.getAttributes().get(IQvtLaunchConstants.DONE_ACTION); - final IProgressMonitor configMonitor = (IProgressMonitor) configuration.getAttributes().get(IQvtLaunchConstants.MONITOR); - final IProgressMonitor actualMonitor = configMonitor != null ? configMonitor : monitor; - - final StreamsProxy streamsProxy = new StreamsProxy(); - - ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { - - public void run() throws Exception { - try { - IStatus status = QvtLaunchConfigurationDelegateBase.validate(qvtTransformation, configuration); - if (status.getSeverity() > IStatus.WARNING) { - throw new CoreException(status); - } - - ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(streamsProxy.getOutputWriter()), actualMonitor); - - QvtLaunchUtil.doLaunch(qvtTransformation, configuration, context); - } - finally { - qvtTransformation.cleanup(); - } - } - }; - - r = getSafeRunnable(qvtTransformation, r); - - ShallowProcess process = new ShallowProcess(launch, r); - process.setStreamsProxy(streamsProxy); - final EmptyDebugTarget debugTarget = new EmptyDebugTarget(launch, process, QvtRuntimePlugin.ID, MDAConstants.QVTO_LAUNCH_CONFIGURATION_NAME); - - boolean isLaunchInBackground = true; - try { - isLaunchInBackground = !Boolean.FALSE.toString().equals(configuration.getAttribute(IQvtLaunchConstants.LAUNCH_IN_BACKGROUND, (String) null)); - } catch (Exception e) { - } - - if (isLaunchInBackground) { - Job job = createTransformationJob(qvtTransformation, process, debugTarget, doneAction, actualMonitor); - job.schedule(); - } - else { - actualMonitor.beginTask(NLS.bind(Messages.InMemoryQvtLaunchConfigurationDelegate_RunningTaskName, TransformationUtil.getTransformationFqn(qvtTransformation)), - IProgressMonitor.UNKNOWN); - try { - process.run(debugTarget); - - IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(statusJobDone); - if(statusHandler != null) { - Object[] handlerArgs = new Object[] { this, doneAction }; - Object resolution = statusHandler.handleStatus(statusJobDone, handlerArgs); - assert resolution != null : "Invalid job done status resolution"; //$NON-NLS-1$ - } - } catch (CoreException e) { - throw e; - } catch (Exception e) { - String reason = e instanceof QvtInterruptedExecutionException ? "interrupted." : "failed."; //$NON-NLS-1$ //$NON-NLS-2$ - throw new CoreException( - MiscUtil.makeErrorStatus("Transformation '" + TransformationUtil.getTransformationFqn(qvtTransformation) + "' " + reason, e)); //$NON-NLS-1$ //$NON-NLS-2$ - } finally { - actualMonitor.done(); + final Runnable doneAction = (Runnable) configuration.getAttributes().get(IQvtLaunchConstants.DONE_ACTION); + final IProgressMonitor configMonitor = (IProgressMonitor) configuration.getAttributes().get(IQvtLaunchConstants.MONITOR); + final IProgressMonitor actualMonitor = configMonitor != null ? configMonitor : monitor; - try { - launch.terminate(); - } catch (DebugException e) { - QvtPlugin.getDefault().log(e.getStatus()); - } - } - } - } + final StreamsProxy streamsProxy = new StreamsProxy(); + + ProcessJob processJob = new ProcessJob(Messages.InMemoryQvtLaunchConfigurationDelegate_TransformationJobName, launch, streamsProxy) { - private Job createTransformationJob(final QvtTransformation transformation, final ShallowProcess process, final EmptyDebugTarget debugTarget, - final Runnable doneAction, final IProgressMonitor monitor) { - Job job = new Job(Messages.InMemoryQvtLaunchConfigurationDelegate_TransformationJobName) { - @Override - protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask(NLS.bind(Messages.InMemoryQvtLaunchConfigurationDelegate_RunningTaskName, TransformationUtil.getTransformationFqn(transformation)), + public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { + + monitor.beginTask(NLS.bind(Messages.InMemoryQvtLaunchConfigurationDelegate_RunningTaskName, TransformationUtil.getTransformationFqn(qvtTransformation)), IProgressMonitor.UNKNOWN); try { - process.run(debugTarget); - + IStatus status = QvtLaunchConfigurationDelegateBase.validate(qvtTransformation, configuration); + if (status.getSeverity() > IStatus.WARNING) { + throw new CoreException(status); + } + + ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(streamsProxy.getOutputWriter()), actualMonitor); + + QvtLaunchUtil.doLaunch(qvtTransformation, configuration, context); + IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(statusJobDone); if(statusHandler != null) { Object[] handlerArgs = new Object[] { this, doneAction }; Object resolution = statusHandler.handleStatus(statusJobDone, handlerArgs); assert resolution != null : "Invalid job done status resolution"; //$NON-NLS-1$ } + } catch (CoreException e) { + throw e; } catch (Exception e) { String reason = e instanceof QvtInterruptedExecutionException ? "interrupted." : "failed."; //$NON-NLS-1$ //$NON-NLS-2$ - return MiscUtil.makeErrorStatus("Transformation '" + TransformationUtil.getTransformationFqn(transformation) + "' " + reason, e); //$NON-NLS-1$ //$NON-NLS-2$ + throw new CoreException(MiscUtil.makeErrorStatus("Transformation '" + TransformationUtil.getTransformationFqn(qvtTransformation) + "' " + reason, e)); //$NON-NLS-1$ //$NON-NLS-2$ } finally { monitor.done(); - try { - process.getLaunch().terminate(); - } catch (DebugException e) { - QvtPlugin.getDefault().log(e.getStatus()); - } + qvtTransformation.cleanup(); } return Status.OK_STATUS; } - - protected void canceling() { - monitor.setCanceled(true); - } - }; - job.setUser(true); - return job; + + launch.addProcess(processJob); + + final EmptyDebugTarget debugTarget = new EmptyDebugTarget(launch, processJob, QvtRuntimePlugin.ID, MDAConstants.QVTO_LAUNCH_CONFIGURATION_NAME); + + launch.addDebugTarget(debugTarget); + + boolean isLaunchInBackground = true; + try { + isLaunchInBackground = !Boolean.FALSE.toString().equals(configuration.getAttribute(IQvtLaunchConstants.LAUNCH_IN_BACKGROUND, (String) null)); + } catch (Exception e) { + } + + processJob.setUser(!isLaunchInBackground); + + processJob.schedule(); } - - @Override + + @Override protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode) throws CoreException { - return new IProject[0]; - } + return new IProject[0]; + } } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtBuilderLaunchConfigurationDelegate.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtBuilderLaunchConfigurationDelegate.java index 6d92f9e54..76861e13a 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtBuilderLaunchConfigurationDelegate.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtBuilderLaunchConfigurationDelegate.java @@ -1,13 +1,14 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.runtime.launch; @@ -25,6 +26,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.core.variables.IDynamicVariable; import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunch; @@ -32,8 +34,7 @@ import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; import org.eclipse.emf.common.util.URI; import org.eclipse.m2m.internal.qvt.oml.common.MdaException; -import org.eclipse.m2m.internal.qvt.oml.common.launch.BaseProcess; -import org.eclipse.m2m.internal.qvt.oml.common.launch.ShallowProcess; +import org.eclipse.m2m.internal.qvt.oml.common.launch.ProcessJob; import org.eclipse.m2m.internal.qvt.oml.common.launch.StreamsProxy; import org.eclipse.m2m.internal.qvt.oml.common.launch.TargetUriData; import org.eclipse.m2m.internal.qvt.oml.emf.util.EmfUtil; @@ -44,7 +45,6 @@ import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtModule; import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation.TransformationParameter; import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation.TransformationParameter.DirectionKind; import org.eclipse.m2m.internal.qvt.oml.runtime.project.TransformationUtil; -import org.eclipse.m2m.internal.qvt.oml.runtime.util.MiscUtil; import org.eclipse.m2m.qvt.oml.ExecutionContext; import org.eclipse.m2m.qvt.oml.util.WriterLog; import org.eclipse.osgi.util.NLS; @@ -52,137 +52,134 @@ import org.eclipse.osgi.util.NLS; public class QvtBuilderLaunchConfigurationDelegate extends LaunchConfigurationDelegate { public static final String QVTO_BUILDER_MARKER = "org.eclipse.m2m.qvt.oml.runtime.qvtBuilderMarker"; //$NON-NLS-1$ - - public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch, final IProgressMonitor monitor) throws CoreException { - - try { - final String buildType = getVariableValue("build_type"); //$NON-NLS-1$ - IPath path = new Path(getVariableValue("build_project")); //$NON-NLS-1$ - final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment()); - - StreamsProxy streamsProxy = new StreamsProxy(); - final PrintWriter printWriter = new PrintWriter(streamsProxy.getOutputWriter()); - - ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { - public void run() throws Exception { - if(BUILD_TYPE_CLEAN.equals(buildType)) { - clean(project, configuration); - } - else { - build(project, configuration, printWriter, monitor); - } - } - }; - - ShallowProcess shallowProcess = new ShallowProcess(launch, r); - shallowProcess.setStreamsProxy(streamsProxy); - shallowProcess.run(); - } - catch(Exception e) { - throw new CoreException(MiscUtil.makeErrorStatus(org.eclipse.m2m.internal.qvt.oml.emf.util.StatusUtil.getExceptionMessages(e), e)); - } - } - - private void build(final IProject project, final ILaunchConfiguration configuration, final PrintWriter printWriter, - final IProgressMonitor monitor) throws Exception { - - String moduleUri = QvtLaunchUtil.getTransformationURI(configuration); - final QvtInterpretedTransformation transformation; + + public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch, final IProgressMonitor monitor) throws CoreException { + + final String buildType = getVariableValue("build_type"); //$NON-NLS-1$ + IPath path = new Path(getVariableValue("build_project")); //$NON-NLS-1$ + final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment()); + + StreamsProxy streamsProxy = new StreamsProxy(); + final PrintWriter printWriter = new PrintWriter(streamsProxy.getOutputWriter()); + + ProcessJob processJob = new ProcessJob(buildType + " " + project.getName(), launch, streamsProxy) { + + @Override + public IStatus runInWorkspace(IProgressMonitor jobMonitor) throws CoreException { + try { + if(BUILD_TYPE_CLEAN.equals(buildType)) { + clean(project, configuration); + } + else { + build(project, configuration, printWriter, jobMonitor); + } + } + catch (MdaException e) { + throw new CoreException(e.getStatus()); + } + + return Status.OK_STATUS; + } + }; + + launch.addProcess(processJob); + + processJob.schedule(); + } + + private void build(final IProject project, final ILaunchConfiguration configuration, final PrintWriter printWriter, + final IProgressMonitor monitor) throws CoreException, MdaException { + + String moduleUri = QvtLaunchUtil.getTransformationURI(configuration); + final QvtInterpretedTransformation transformation; try { QvtModule qvtModule = TransformationUtil.getQvtModule(EmfUtil.makeUri(moduleUri)); transformation = new QvtInterpretedTransformation(qvtModule); } catch (MdaException e) { - createMarker(project, NLS.bind(Messages.QvtBuilderLaunchTab_TransformationNotFound, moduleUri)); - return; + createMarker(project, NLS.bind(Messages.QvtBuilderLaunchTab_TransformationNotFound, moduleUri)); + return; } - - BaseProcess.IRunnable r = new BaseProcess.IRunnable() { - public void run() throws Exception { - try { - IStatus status = QvtLaunchConfigurationDelegateBase.validate(transformation, configuration); - if(status.getSeverity() > IStatus.WARNING) { - createMarker(project, status.getMessage()); - return; - } - - ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(printWriter), monitor); - - QvtLaunchUtil.doLaunch(transformation, configuration, context); - } - finally { - transformation.cleanup(); - } - } - }; - - r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transformation, r); - r.run(); - } - - private void clean(IProject project, ILaunchConfiguration configuration) throws Exception { - String moduleUri = QvtLaunchUtil.getTransformationURI(configuration); - final QvtInterpretedTransformation transformation; + + try { + IStatus status = QvtLaunchConfigurationDelegateBase.validate(transformation, configuration); + if(status.getSeverity() > IStatus.WARNING) { + createMarker(project, status.getMessage()); + return; + } + + ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(printWriter), monitor); + + QvtLaunchUtil.doLaunch(transformation, configuration, context); + } + finally { + transformation.cleanup(); + } + } + + private void clean(IProject project, ILaunchConfiguration configuration) throws CoreException, MdaException { + String moduleUri = QvtLaunchUtil.getTransformationURI(configuration); + final QvtInterpretedTransformation transformation; try { transformation = new QvtInterpretedTransformation(TransformationUtil.getQvtModule(EmfUtil.makeUri(moduleUri))); } catch (MdaException e) { - createMarker(project, NLS.bind(Messages.QvtBuilderLaunchTab_TransformationNotFound, moduleUri)); - return; + createMarker(project, NLS.bind(Messages.QvtBuilderLaunchTab_TransformationNotFound, moduleUri)); + return; + } + + List<TransformationParameter> transfParams = transformation.getParameters(); + List<TargetUriData> targetUris = QvtLaunchUtil.getTargetUris(configuration); + for (int i = 0, n = targetUris.size(); i < n; ++i) { + if (transfParams.size() > i && transfParams.get(i).getDirectionKind() == DirectionKind.OUT) { + URI outUri = URI.createURI(targetUris.get(i).getUriString()); + if (outUri != null) { + IFile file = URIUtils.getFile(outUri); + if (file != null) { + file.delete(true, true, null); + } + } + } } - - List<TransformationParameter> transfParams = transformation.getParameters(); - List<TargetUriData> targetUris = QvtLaunchUtil.getTargetUris(configuration); - for (int i = 0, n = targetUris.size(); i < n; ++i) { - if (transfParams.size() > i && transfParams.get(i).getDirectionKind() == DirectionKind.OUT) { - URI outUri = URI.createURI(targetUris.get(i).getUriString()); - if (outUri != null) { - IFile file = URIUtils.getFile(outUri); - if (file != null) { - file.delete(true, true, null); - } - } - } - } - - String traceFile = QvtLaunchUtil.getTraceFileURI(configuration); - if (traceFile != null) { - URI traceUri = URI.createPlatformResourceURI(traceFile, false); - if (traceUri != null) { - IFile file = URIUtils.getFile(traceUri); - if (file != null) { - file.delete(true, true, null); - } - } - } - } + + String traceFile = QvtLaunchUtil.getTraceFileURI(configuration); + if (traceFile != null) { + URI traceUri = URI.createPlatformResourceURI(traceFile, false); + if (traceUri != null) { + IFile file = URIUtils.getFile(traceUri); + if (file != null) { + file.delete(true, true, null); + } + } + } + } private void createMarker(IProject project, String message) { - if(project == null) { - return; - } - - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(IMarker.MESSAGE, message); - attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); - try { - IMarker marker = project.createMarker(QVTO_BUILDER_MARKER); - marker.setAttributes(attributes); - } - catch (CoreException e) { - Logger.getLogger().log(Logger.SEVERE, "Failed to create marker on " + project, e); //$NON-NLS-1$ - } + if(project == null) { + return; + } + + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(IMarker.MESSAGE, message); + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + try { + IMarker marker = project.createMarker(QVTO_BUILDER_MARKER); + marker.setAttributes(attributes); + } + catch (CoreException e) { + Logger.getLogger().log(Logger.SEVERE, "Failed to create marker on " + project, e); //$NON-NLS-1$ + } } - + private String getVariableValue(String variableName) throws CoreException { - IDynamicVariable dynamicVar = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable(variableName); - return dynamicVar.getValue(null); + IDynamicVariable dynamicVar = VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable(variableName); + return dynamicVar.getValue(null); } - /** - * Copied from org.eclipse.ui.externaltools.internal.model.IExternalToolConstants - * - * Looks like it's never evolved to API (see: http://dev.eclipse.org/newslists/news.eclipse.platform/msg38656.html) - * - */ + /** + * Copied from org.eclipse.ui.externaltools.internal.model.IExternalToolConstants + * + * Looks like it's never evolved to API (see: http://dev.eclipse.org/newslists/news.eclipse.platform/msg38656.html) + * + */ // ------- Build Types ------- /** @@ -202,7 +199,7 @@ public class QvtBuilderLaunchConfigurationDelegate extends LaunchConfigurationDe * the external tool running as a builder (value <code>auto</code>). */ public static final String BUILD_TYPE_AUTO = "auto"; //$NON-NLS-1$ - + /** * Build type indicating a clean project build request for * the external tool running as a builder (value <code>clean</code>). diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegate.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegate.java index 059cb0f03..b40ea66b5 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegate.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegate.java @@ -1,14 +1,14 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 Borland Software Corporation and others. - * + * Copyright (c) 2007, 2019 Borland Software Corporation and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html - * + * * Contributors: * Borland Software Corporation - initial API and implementation - * Christopher Gerking - bug 431082 + * Christopher Gerking - bugs 431082, 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.runtime.launch; @@ -16,7 +16,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; @@ -34,87 +33,83 @@ import org.eclipse.m2m.qvt.oml.util.WriterLog; public class QvtLaunchConfigurationDelegate extends QvtLaunchConfigurationDelegateBase { - public static final String LAUNCH_CONFIGURATION_TYPE_ID = QvtPlugin.ID + ".QvtTransformation"; //$NON-NLS-1$ + public static final String LAUNCH_CONFIGURATION_TYPE_ID = QvtPlugin.ID + ".QvtTransformation"; //$NON-NLS-1$ public QvtLaunchConfigurationDelegate() { } - - // FIXME - do refactoring of this area + + // FIXME - do refactoring of this area public void launch(final ILaunchConfiguration configuration, String mode, final ILaunch launch, final IProgressMonitor launchMonitor) throws CoreException { - - final QvtTransformation qvtTransformation = new QvtInterpretedTransformation(getQvtModule(configuration)); - - final StreamsProxy streamsProxy = new StreamsProxy(); - - ProcessJob processJob = new ProcessJob(Messages.InMemoryQvtLaunchConfigurationDelegate_TransformationJobName, launch, streamsProxy) { - + + final QvtTransformation qvtTransformation = new QvtInterpretedTransformation(getQvtModule(configuration)); + + final StreamsProxy streamsProxy = new StreamsProxy(); + + ProcessJob processJob = new ProcessJob(Messages.InMemoryQvtLaunchConfigurationDelegate_TransformationJobName, launch, streamsProxy) { + @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { + public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { try { - IStatus status = QvtLaunchConfigurationDelegateBase.validate(qvtTransformation, configuration); - if(status.getSeverity() > IStatus.WARNING) { - return status; - } - - ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(streamsProxy.getOutputWriter()), monitor); - - QvtLaunchUtil.doLaunch(qvtTransformation, configuration, context); - - return Status.OK_STATUS; - } + IStatus status = QvtLaunchConfigurationDelegateBase.validate(qvtTransformation, configuration); + if(status.getSeverity() > IStatus.WARNING) { + return status; + } + + ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(streamsProxy.getOutputWriter()), monitor); + + QvtLaunchUtil.doLaunch(qvtTransformation, configuration, context); + + return Status.OK_STATUS; + } catch (QvtRuntimeException e) { // QVT runtime exception are legal QVT transformation level errors - return BasicDiagnostic.toIStatus(e.getDiagnostic()); - } - catch (Exception e) { + return BasicDiagnostic.toIStatus(e.getDiagnostic()); + } + catch (Exception e) { IStatus actualStatus = new Status(IStatus.ERROR, QvtRuntimePlugin.ID, QvtRuntimePlugin.LAUNCH_ERROR_STATUS.getCode(), e.getMessage(), e.getMessage() == null ? e : null); - + IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(QvtRuntimePlugin.LAUNCH_ERROR_STATUS); - - if(statusHandler != null) { + + if(statusHandler != null) { try { statusHandler.handleStatus(actualStatus, configuration); } catch (CoreException coreExc) { actualStatus = coreExc.getStatus(); QvtPlugin.getDefault().log(actualStatus); } - } - + } + QvtPlugin.error(Messages.InMemoryQvtLaunchConfigurationDelegate_TransformationJobName, e); - + throw new CoreException(actualStatus); } finally { qvtTransformation.cleanup(); - - if (DebugPlugin.getDefault() != null) { - DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)}); - } } } }; - + launch.addProcess(processJob); - + processJob.schedule(); } - - -// FIXME - do we need such an annoying generic check ? -// Useless anyway without overriding -// org.eclipse.debug.core.model.LaunchConfigurationDelegate.getProjectsForProblemSearch(ILaunchConfiguration, String) -// @Override -// protected boolean existsProblems(IProject proj) throws CoreException { -// IMarker[] markers = proj.findMarkers(QVTOProjectPlugin.PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); -// for (int i = 0; i < markers.length; i++) { -// if (isLaunchProblem(markers[i])) { -// return true; -// } -// } -// -// return false; -// } + + + // FIXME - do we need such an annoying generic check ? + // Useless anyway without overriding + // org.eclipse.debug.core.model.LaunchConfigurationDelegate.getProjectsForProblemSearch(ILaunchConfiguration, String) + // @Override + // protected boolean existsProblems(IProject proj) throws CoreException { + // IMarker[] markers = proj.findMarkers(QVTOProjectPlugin.PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); + // for (int i = 0; i < markers.length; i++) { + // if (isLaunchProblem(markers[i])) { + // return true; + // } + // } + // + // return false; + // } } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegateBase.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegateBase.java index 19a0fd4a6..8ef8e3166 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegateBase.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchConfigurationDelegateBase.java @@ -8,6 +8,7 @@ * * Contributors: * Borland Software Corporation - initial API and implementation + * Christopher Gerking - bug 537609 *******************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.runtime.launch; @@ -83,6 +84,7 @@ public abstract class QvtLaunchConfigurationDelegateBase extends LaunchConfigura } } + @Deprecated public static BaseProcess.IRunnable getSafeRunnable(QvtTransformation transformation, IRunnable r) throws CoreException { return SafeRunner.getSafeRunnable(r); } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchUtil.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchUtil.java index 76d92fb24..c6eb04516 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchUtil.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/internal/qvt/oml/runtime/launch/QvtLaunchUtil.java @@ -199,7 +199,7 @@ public class QvtLaunchUtil { return name + index; } - public static void doLaunch(QvtTransformation transformation, ILaunchConfiguration configuration, ExecutionContext context) throws Exception { + public static void doLaunch(QvtTransformation transformation, ILaunchConfiguration configuration, ExecutionContext context) throws CoreException, MdaException { List<TargetUriData> targetUris = getTargetUris(configuration); List<URI> paramUris = new ArrayList<URI>(targetUris.size()); diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/qvt/oml/runtime/util/QvtoTransformationHelper.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/qvt/oml/runtime/util/QvtoTransformationHelper.java index f80c25ae6..43bd81222 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/qvt/oml/runtime/util/QvtoTransformationHelper.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src/org/eclipse/m2m/qvt/oml/runtime/util/QvtoTransformationHelper.java @@ -126,8 +126,8 @@ public class QvtoTransformationHelper { //options.setMetamodelResourceSet(wrappedMetamodelResourceSet); transf.setQvtCompilerOptions(options); - ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { - public void run() throws Exception { +// ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { +// public void run() throws Exception { List<ModelContent> inModels = new ArrayList<ModelContent>(inObjects.size()); for (EObject inObj : inObjects) { inModels.add(new ModelContent(Collections.singletonList(inObj))); @@ -136,12 +136,12 @@ public class QvtoTransformationHelper { outExtents, outMainParams, outTraces, outConsole); transf.cleanup(); - } - - }; +// } +// +// }; - r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transf, r); - r.run(); +// r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transf, r); +// r.run(); final List<ModelExtent> extents = new ArrayList<ModelExtent>(); for (ModelExtentContents nextExtent : outExtents) { @@ -176,9 +176,9 @@ public class QvtoTransformationHelper { catch (MdaException e) { throw new CoreException(e.getStatus() != null ? e.getStatus() : new Status(IStatus.ERROR, QvtRuntimePlugin.ID, e.getMessage())); } - catch (CoreException e) { - throw e; - } +// catch (CoreException e) { +// throw e; +// } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, QvtRuntimePlugin.ID, e.getMessage())); } diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/AbstractApplyTransformationTask.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/AbstractApplyTransformationTask.java index f258d81fe..360fce245 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/AbstractApplyTransformationTask.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/AbstractApplyTransformationTask.java @@ -185,8 +185,8 @@ public abstract class AbstractApplyTransformationTask extends Task { final List<URI> outUris = new ArrayList<URI>(); final QvtTransformation transformation = getTransformationObject(); try { - ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { - public void run() throws Exception { +// ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { +// public void run() throws Exception { try { Iterator<TargetUriData> itrTargetData = targetUris.iterator(); for (TransformationParameter transfParam : transformation.getParameters()) { @@ -215,12 +215,12 @@ public abstract class AbstractApplyTransformationTask extends Task { finally { transformation.cleanup(); } - } - }; +// } +// }; - r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transformation, r); +// r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transformation, r); - r.run(); +// r.run(); if (getProject() != null && getResultUriProperty() != null) { int index = 1; diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/QvtoAntTransformationTask.java b/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/QvtoAntTransformationTask.java index 1dfa35046..6cac0919c 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/QvtoAntTransformationTask.java +++ b/plugins/org.eclipse.m2m.qvt.oml.runtime/src_ant/org/eclipse/m2m/internal/qvt/oml/runtime/ant/QvtoAntTransformationTask.java @@ -319,8 +319,8 @@ public class QvtoAntTransformationTask extends Task { final QvtTransformation transformation = getTransformationObject(); try { - ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { - public void run() throws Exception { +// ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { +// public void run() throws Exception { try { URI traceUri = getTraceUri(QvtoAntTransformationTask.this); boolean useTrace = myTrace == null ? false : myTrace.isGenerate(); @@ -349,12 +349,12 @@ public class QvtoAntTransformationTask extends Task { finally { transformation.cleanup(); } - } +// } +// +// }; - }; - - r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transformation, r); - r.run(); +// r = QvtLaunchConfigurationDelegateBase.getSafeRunnable(transformation, r); +// r.run(); } catch (Exception e) { if(e instanceof RuntimeException && e instanceof QvtRuntimeException == false) { diff --git a/plugins/org.eclipse.m2m.qvt.oml.tools.coverage.ui/src/org/eclipse/m2m/internal/qvt/oml/tools/coverage/ui/launching/QvtLaunchConfigurationCoverageDelegate.java b/plugins/org.eclipse.m2m.qvt.oml.tools.coverage.ui/src/org/eclipse/m2m/internal/qvt/oml/tools/coverage/ui/launching/QvtLaunchConfigurationCoverageDelegate.java index 93d670235..40452fa42 100644 --- a/plugins/org.eclipse.m2m.qvt.oml.tools.coverage.ui/src/org/eclipse/m2m/internal/qvt/oml/tools/coverage/ui/launching/QvtLaunchConfigurationCoverageDelegate.java +++ b/plugins/org.eclipse.m2m.qvt.oml.tools.coverage.ui/src/org/eclipse/m2m/internal/qvt/oml/tools/coverage/ui/launching/QvtLaunchConfigurationCoverageDelegate.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014,2018 ASML Netherlands B.V. and others. + * Copyright (c) 2014, 2019 ASML Netherlands B.V. and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 @@ -8,7 +8,7 @@ * * Contributors: * ASML Netherlands B.V. - Initial API and implementation - * + * Christopher Gerking - bug 537609 *****************************************************************************/ package org.eclipse.m2m.internal.qvt.oml.tools.coverage.ui.launching; @@ -18,13 +18,13 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.IStatusHandler; +import org.eclipse.emf.common.util.BasicDiagnostic; import org.eclipse.m2m.internal.qvt.oml.QvtPlugin; -import org.eclipse.m2m.internal.qvt.oml.common.launch.ShallowProcess; +import org.eclipse.m2m.internal.qvt.oml.common.launch.ProcessJob; import org.eclipse.m2m.internal.qvt.oml.common.launch.StreamsProxy; import org.eclipse.m2m.internal.qvt.oml.evaluator.QVTEvaluationOptions; import org.eclipse.m2m.internal.qvt.oml.evaluator.QvtGenericVisitorDecorator; @@ -43,111 +43,81 @@ import org.eclipse.m2m.qvt.oml.util.WriterLog; @SuppressWarnings("restriction") public class QvtLaunchConfigurationCoverageDelegate extends QvtLaunchConfigurationDelegateBase { - public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.m2m.qvt.oml.QvtTransformation"; //$NON-NLS-1$ - - public QvtLaunchConfigurationCoverageDelegate() { - } - - // FIXME - do refactoring of this area - @Override - public void launch(final ILaunchConfiguration configuration, String mode, final ILaunch launch, - final IProgressMonitor monitor) throws CoreException { - - try { - final QvtTransformation qvtTransformation = new QvtInterpretedTransformation(getQvtModule(configuration)); - - final StreamsProxy streamsProxy = new StreamsProxy(); - - ShallowProcess.IRunnable r = new ShallowProcess.IRunnable() { - - @Override - public void run() throws Exception { - IStatus status = QvtLaunchConfigurationDelegateBase.validate(qvtTransformation, configuration); - if (status.getSeverity() > IStatus.WARNING) { - throw new CoreException(status); - } - - ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(streamsProxy.getOutputWriter()), monitor); - - // Install the decorators for collecting coverage data - ArrayList<Class<? extends QvtGenericVisitorDecorator>> decorators = new ArrayList<Class<? extends QvtGenericVisitorDecorator>>(); - decorators.add(QVTOCoverageDecorator.class); - context.getSessionData().setValue(QVTEvaluationOptions.VISITOR_DECORATORS, decorators); - - // Create coverage data private for this run - CoverageData data = new CoverageData(); - context.getSessionData().setValue(QVTOCoverageDecorator.COVERAGE_DATA, data); - - QvtLaunchUtil.doLaunch(qvtTransformation, configuration, context); - - qvtTransformation.cleanup(); - - // Activate the coverage view - CoveragePlugin.getDefault().showCoverageView(data); - } - }; - - r = getSafeRunnable(qvtTransformation, r); - final ShallowProcess process = new ShallowProcess(launch, r) { - boolean isTerminated = false; - - @Override - public void terminate() throws DebugException { - monitor.setCanceled(true); - isTerminated = true; - super.terminate(); - } - - @Override - public boolean isTerminated() { - return isTerminated || super.isTerminated(); - } - - @Override - public boolean canTerminate() { - return !isTerminated(); - } - }; - - process.setStreamsProxy(streamsProxy); - - Thread processThread = new Thread(new Runnable() { - @Override - public void run() { - try { - process.run(); - } catch (Exception e) { - if (e instanceof QvtRuntimeException == false) { - // QVT runtime exception are legal QVT transformation level errors - - IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(QvtRuntimePlugin.LAUNCH_ERROR_STATUS); - if(statusHandler != null) { - IStatus actualStatus = new Status(IStatus.ERROR, QvtRuntimePlugin.ID, - QvtRuntimePlugin.LAUNCH_ERROR_STATUS.getCode(), e.getMessage(), - e.getMessage() == null ? e : null); - try { - statusHandler.handleStatus(actualStatus, configuration); - } catch (CoreException coreExc) { - QvtPlugin.getDefault().log(coreExc.getStatus()); - } - } - - QvtPlugin.error(e); - } - } - - try { - launch.terminate(); - } catch (DebugException e) { - QvtPlugin.getDefault().log(e.getStatus()); - } - } - }, "QVT Run"); //$NON-NLS-1$ - - processThread.start(); - } catch (Exception e) { - throw new CoreException(org.eclipse.m2m.internal.qvt.oml.runtime.util.MiscUtil.makeErrorStatus(e)); - } - } + public static final String LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.m2m.qvt.oml.QvtTransformation"; //$NON-NLS-1$ + + public QvtLaunchConfigurationCoverageDelegate() { + } + + // FIXME - do refactoring of this area + @Override + public void launch(final ILaunchConfiguration configuration, String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException { + + final QvtTransformation qvtTransformation = new QvtInterpretedTransformation(getQvtModule(configuration)); + + final StreamsProxy streamsProxy = new StreamsProxy(); + + ProcessJob processJob = new ProcessJob("QVT Run", launch, streamsProxy) { //$NON-NLS-1$ + + @Override + public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { + try { + IStatus status = QvtLaunchConfigurationDelegateBase.validate(qvtTransformation, configuration); + if (status.getSeverity() > IStatus.WARNING) { + throw new CoreException(status); + } + + ExecutionContext context = QvtLaunchUtil.createContext(configuration, new WriterLog(streamsProxy.getOutputWriter()), monitor); + + // Install the decorators for collecting coverage data + ArrayList<Class<? extends QvtGenericVisitorDecorator>> decorators = new ArrayList<Class<? extends QvtGenericVisitorDecorator>>(); + decorators.add(QVTOCoverageDecorator.class); + context.getSessionData().setValue(QVTEvaluationOptions.VISITOR_DECORATORS, decorators); + + // Create coverage data private for this run + CoverageData data = new CoverageData(); + context.getSessionData().setValue(QVTOCoverageDecorator.COVERAGE_DATA, data); + + QvtLaunchUtil.doLaunch(qvtTransformation, configuration, context); + + qvtTransformation.cleanup(); + + // Activate the coverage view + CoveragePlugin.getDefault().showCoverageView(data); + + return Status.OK_STATUS; + } + catch (QvtRuntimeException e) { + // QVT runtime exception are legal QVT transformation level errors + return BasicDiagnostic.toIStatus(e.getDiagnostic()); + } + catch (Exception e) { + IStatus actualStatus = new Status(IStatus.ERROR, QvtRuntimePlugin.ID, + QvtRuntimePlugin.LAUNCH_ERROR_STATUS.getCode(), e.getMessage(), + e.getMessage() == null ? e : null); + + IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(QvtRuntimePlugin.LAUNCH_ERROR_STATUS); + + if(statusHandler != null) { + try { + statusHandler.handleStatus(actualStatus, configuration); + } catch (CoreException coreExc) { + actualStatus = coreExc.getStatus(); + QvtPlugin.getDefault().log(actualStatus); + } + } + + QvtPlugin.error(e); + + throw new CoreException(actualStatus); + } + finally { + qvtTransformation.cleanup(); + } + } + }; + + launch.addProcess(processJob); + processJob.schedule(); + } } |