Package: AcceleoLaunchDelegateStandalone$1

AcceleoLaunchDelegateStandalone$1

nameinstructionbranchcomplexitylinemethod
run(IProgressMonitor)
M: 26 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
{...}
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2012 Obeo.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * Obeo - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.acceleo.internal.ide.ui.launching;
12:
13: import org.eclipse.acceleo.ide.ui.AcceleoUIActivator;
14: import org.eclipse.core.resources.IContainer;
15: import org.eclipse.core.resources.IResource;
16: import org.eclipse.core.resources.IWorkspaceRunnable;
17: import org.eclipse.core.resources.ResourcesPlugin;
18: import org.eclipse.core.runtime.CoreException;
19: import org.eclipse.core.runtime.IPath;
20: import org.eclipse.core.runtime.IProgressMonitor;
21: import org.eclipse.core.runtime.Path;
22: import org.eclipse.debug.core.ILaunch;
23: import org.eclipse.debug.core.ILaunchConfiguration;
24:
25: /**
26: * To launch an Acceleo application in a Java standalone way.
27: *
28: * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
29: */
30: public class AcceleoLaunchDelegateStandalone extends org.eclipse.jdt.launching.JavaLaunchDelegate {
31:
32:         /**
33:          * {@inheritDoc}
34:          *
35:          * @see org.eclipse.jdt.launching.JavaLaunchDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration,
36:          * java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
37:          */
38:         @Override
39:         public void launch(final ILaunchConfiguration configuration, String mode, final ILaunch launch,
40:                         IProgressMonitor monitor) throws CoreException {
41:                 super.launch(configuration, mode, launch, monitor);
42:                 String target = getTargetPath(configuration);
43:                 if (target.length() > 0) {
44:                         IPath targetPath = new Path(target);
45:                         final IContainer container;
46:                         if (targetPath.segmentCount() == 1) {
47:                                 container = ResourcesPlugin.getWorkspace().getRoot().getProject(targetPath.lastSegment());
48:                         } else if (targetPath.segmentCount() > 1) {
49:                                 container = ResourcesPlugin.getWorkspace().getRoot().getFolder(targetPath);
50:                         } else {
51:                                 container = null;
52:                         }
53:                         if (container != null) {
54:                                 IWorkspaceRunnable operation = new IWorkspaceRunnable() {
55:                                         public void run(final IProgressMonitor progressMonitor) throws CoreException {
56:                                                 try {
57:•                                                        while (!launch.isTerminated() && !progressMonitor.isCanceled()) {
58:                                                                 Thread.sleep(100);
59:                                                         }
60:                                                 } catch (InterruptedException e) {
61:                                                         AcceleoUIActivator.log(e, true);
62:                                                 }
63:•                                                if (container.getProject() != null) {
64:                                                         container.getProject().refreshLocal(IResource.DEPTH_INFINITE, progressMonitor);
65:                                                 }
66:                                         }
67:                                 };
68:                                 ResourcesPlugin.getWorkspace().run(operation, monitor);
69:                         }
70:                 }
71:         }
72:
73:         /**
74:          * Returns the target folder specified by the given launch configuration, or an empty string if none.
75:          *
76:          * @param configuration
77:          * launch configuration
78:          * @return the target folder or an empty string
79:          */
80:         protected String getTargetPath(final ILaunchConfiguration configuration) {
81:                 String target = ""; //$NON-NLS-1$
82:                 try {
83:                         target = configuration.getAttribute(IAcceleoLaunchConfigurationConstants.ATTR_TARGET_PATH, ""); //$NON-NLS-1$
84:                 } catch (CoreException e) {
85:                         target = ""; //$NON-NLS-1$
86:                         AcceleoUIActivator.getDefault().getLog().log(e.getStatus());
87:                 }
88:                 return target;
89:         }
90:
91: }