Package: AcceleoLaunchDelegate

AcceleoLaunchDelegate

nameinstructionbranchcomplexitylinemethod
AcceleoLaunchDelegate()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getLaunchingStrategy(ILaunchConfiguration)
M: 18 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getLaunchingStrategy(String)
M: 88 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 25 C: 0
0%
M: 1 C: 0
0%
launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
M: 29 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2014 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.acceleo.ide.ui.launching.strategy.IAcceleoLaunchingStrategy;
15: import org.eclipse.acceleo.internal.ide.ui.launching.strategy.AcceleoJavaLaunchingStrategy;
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.core.runtime.IConfigurationElement;
18: import org.eclipse.core.runtime.IExtension;
19: import org.eclipse.core.runtime.IExtensionPoint;
20: import org.eclipse.core.runtime.IExtensionRegistry;
21: import org.eclipse.core.runtime.IProgressMonitor;
22: import org.eclipse.core.runtime.Platform;
23: import org.eclipse.debug.core.ILaunch;
24: import org.eclipse.debug.core.ILaunchConfiguration;
25: import org.osgi.framework.Bundle;
26:
27: /**
28: * To launch an Acceleo application in a Java standalone way, or in a full Eclipse way. This last way is
29: * currently required for debugging an Acceleo file. You can also debug an Acceleo application by launching it
30: * in a Java standalone way, but you will debug the Acceleo Java sources...
31: *
32: * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
33: */
34: public class AcceleoLaunchDelegate extends AcceleoLaunchDelegateStandalone {
35:
36:         /**
37:          * {@inheritDoc}
38:          *
39:          * @see org.eclipse.jdt.launching.JavaLaunchDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration,
40:          * java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
41:          */
42:         @Override
43:         public void launch(final ILaunchConfiguration configuration, String mode, ILaunch launch,
44:                         IProgressMonitor monitor) throws CoreException {
45:                 try {
46:                         IAcceleoLaunchingStrategy strategy = getLaunchingStrategy(configuration);
47:•                        if (strategy instanceof AcceleoJavaLaunchingStrategy) {
48:                                 super.launch(configuration, mode, launch, monitor);
49:•                        } else if (strategy != null) {
50:                                 // Launches the given configuration in the current Eclipse thread.
51:                                 strategy.launch(configuration, mode, launch, monitor);
52:                         }
53:                 } finally {
54:•                        if (!launch.isTerminated()) {
55:                                 launch.terminate();
56:                         }
57:                 }
58:         }
59:
60:         /**
61:          * Returns the launching strategy specified by the given launch configuration, or <code>null</code> if
62:          * none.
63:          *
64:          * @param configuration
65:          * launch configuration
66:          * @return the launching strategy, or null if none
67:          */
68:         private IAcceleoLaunchingStrategy getLaunchingStrategy(final ILaunchConfiguration configuration) {
69:                 String description;
70:                 try {
71:                         description = configuration.getAttribute(
72:                                         IAcceleoLaunchConfigurationConstants.ATTR_LAUNCHING_STRATEGY_DESCRIPTION, ""); //$NON-NLS-1$
73:                 } catch (CoreException e) {
74:                         description = ""; //$NON-NLS-1$
75:                         AcceleoUIActivator.getDefault().getLog().log(e.getStatus());
76:                 }
77:                 return getLaunchingStrategy(description);
78:         }
79:
80:         /**
81:          * Gets the launching strategy that matches the given description. It is used to define a specific way of
82:          * launching an Acceleo generation.
83:          *
84:          * @param launchingID
85:          * is the description of the strategy to get in the current Eclipse instance
86:          * @return the launching strategy that matches the given description, or null if it doesn't exist
87:          */
88:         @SuppressWarnings("unchecked")
89:         private IAcceleoLaunchingStrategy getLaunchingStrategy(String launchingID) {
90:                 IExtensionRegistry registry = Platform.getExtensionRegistry();
91:                 IExtensionPoint extensionPoint = registry
92:                                 .getExtensionPoint(IAcceleoLaunchingStrategy.LAUNCHING_STRATEGY_EXTENSION_ID);
93:•                if (extensionPoint != null && extensionPoint.getExtensions().length > 0) {
94:                         IExtension[] extensions = extensionPoint.getExtensions();
95:•                        for (int i = 0; i < extensions.length; i++) {
96:                                 IExtension extension = extensions[i];
97:                                 IConfigurationElement[] members = extension.getConfigurationElements();
98:•                                for (int j = 0; j < members.length; j++) {
99:                                         IConfigurationElement member = members[j];
100:                                         String description = member.getAttribute("description"); //$NON-NLS-1$
101:                                         String strategyClass = member.getAttribute("class"); //$NON-NLS-1$
102:•                                        if (strategyClass != null && description != null && launchingID != null
103:•                                                        && launchingID.startsWith(description)) {
104:                                                 try {
105:                                                         Bundle bundle = Platform.getBundle(member.getNamespaceIdentifier());
106:                                                         @SuppressWarnings("cast")
107:                                                         Class<IAcceleoLaunchingStrategy> c = (Class<IAcceleoLaunchingStrategy>)bundle
108:                                                                         .loadClass(strategyClass);
109:                                                         return c.newInstance();
110:                                                 } catch (ClassNotFoundException e) {
111:                                                         AcceleoUIActivator.log(e, true);
112:                                                 } catch (InstantiationException e) {
113:                                                         AcceleoUIActivator.log(e, true);
114:                                                 } catch (IllegalAccessException e) {
115:                                                         AcceleoUIActivator.log(e, true);
116:                                                 }
117:                                         }
118:                                 }
119:                         }
120:                 }
121:                 return null;
122:         }
123:
124: }