Package: AcceleoJavaArgumentsTab

AcceleoJavaArgumentsTab

nameinstructionbranchcomplexitylinemethod
AcceleoJavaArgumentsTab()
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%
createControl(Composite)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
updateArguments(ILaunchConfigurationWorkingCopy, String, String, String)
M: 145 C: 0
0%
M: 20 C: 0
0%
M: 11 C: 0
0%
M: 37 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 java.util.StringTokenizer;
14:
15: import org.eclipse.core.resources.ResourcesPlugin;
16: import org.eclipse.core.runtime.IPath;
17: import org.eclipse.core.runtime.Path;
18: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19: import org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab;
20: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
21: import org.eclipse.swt.widgets.Composite;
22:
23: /**
24: * A launch configuration javaArgumentsTab that displays program arguments, VM arguments, and working
25: * directory launch configuration attributes.
26: * <p>
27: * This class may be instantiated.
28: *
29: * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
30: */
31: public class AcceleoJavaArgumentsTab extends JavaArgumentsTab {
32:
33:         /**
34:          * {@inheritDoc}
35:          *
36:          * @see org.eclipse.jdt.debug.ui.launchConfigurations.JavaArgumentsTab#createControl(org.eclipse.swt.widgets.Composite)
37:          */
38:         @Override
39:         public void createControl(Composite parent) {
40:                 super.createControl(parent);
41:                 fPrgmArgumentsText.setEditable(false);
42:         }
43:
44:         /**
45:          * Updates the program arguments with a model path, a target folder path, and other Acceleo arguments.
46:          *
47:          * @param config
48:          * is an editable copy of the current launch configuration
49:          * @param model
50:          * is the model path, relative to the workspace
51:          * @param target
52:          * is the target folder path, relative to the workspace
53:          * @param args
54:          * are the Acceleo application arguments (properties)
55:          */
56:         public void updateArguments(ILaunchConfigurationWorkingCopy config, String model, String target,
57:                         String args) {
58:                 IPath modelPath;
59:•                if (model != null) {
60:                         modelPath = new Path(model);
61:                 } else {
62:                         modelPath = new Path(""); //$NON-NLS-1$
63:                 }
64:•                if (modelPath.segmentCount() > 1) {
65:                         modelPath = ResourcesPlugin.getWorkspace().getRoot().getFile(modelPath).getLocation();
66:                 }
67:•                if (modelPath == null) {
68:                         modelPath = new Path(""); //$NON-NLS-1$
69:                 }
70:                 IPath targetPath;
71:•                if (target != null) {
72:                         targetPath = new Path(target);
73:                 } else {
74:                         targetPath = new Path(""); //$NON-NLS-1$
75:                 }
76:•                if (targetPath.segmentCount() == 1) {
77:                         targetPath = ResourcesPlugin.getWorkspace().getRoot().getProject(targetPath.lastSegment())
78:                                         .getLocation();
79:•                } else if (targetPath.segmentCount() > 1) {
80:                         targetPath = ResourcesPlugin.getWorkspace().getRoot().getFolder(targetPath).getLocation();
81:                 }
82:•                if (targetPath == null) {
83:                         targetPath = new Path(""); //$NON-NLS-1$
84:                 }
85:                 StringBuffer newBuffer = new StringBuffer();
86:                 newBuffer.append('"');
87:                 newBuffer.append(modelPath.toString());
88:                 newBuffer.append("\" \""); //$NON-NLS-1$
89:                 newBuffer.append(targetPath.toString());
90:                 newBuffer.append('"');
91:•                if (args.length() > 0) {
92:                         StringTokenizer st = new StringTokenizer(args, "\n"); //$NON-NLS-1$
93:•                        while (st.hasMoreTokens()) {
94:                                 String token = st.nextToken().trim();
95:                                 newBuffer.append(" \""); //$NON-NLS-1$
96:                                 newBuffer.append(token);
97:                                 newBuffer.append('"');
98:                         }
99:                 }
100:                 String newText = newBuffer.toString();
101:•                if (!newText.equals(fPrgmArgumentsText.getText())) {
102:                         fPrgmArgumentsText.setText(newText);
103:                         config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, newText);
104:                 }
105:         }
106:
107: }