Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 353056 | Differences between
and this patch

Collapse All | Expand All

(-)a/valgrind/org.eclipse.linuxtools.valgrind.core/plugin.xml (+1 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
2
<?eclipse version="3.4"?>
3
<plugin>
3
<plugin>
4
   <extension-point id="valgrindLocation" name="valgrindLocation" schema="schema/valgrindLocation.exsd"/>
4
   <extension
5
   <extension
5
         point="org.eclipse.ui.preferencePages">
6
         point="org.eclipse.ui.preferencePages">
6
      <page
7
      <page
(-)a/valgrind/org.eclipse.linuxtools.valgrind.core/schema/valgrindLocation.exsd (+71 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.linuxtools.valgrind.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.eclipse.linuxtools.valgrind.core" id="valgrindLocation" name="valgrindLocation"/>
7
      </appinfo>
8
      <documentation>
9
         Sets the Valgrition binary location to be used by valgrind plugins
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="valgrindLocation"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="valgrindLocation">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  Location class. Must implement IValgrindLocation.
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java" basedOn=":org.eclipse.linuxtools.valgrind.core.IValgrindLocation"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="priority" type="string" use="default" value="0">
63
            <annotation>
64
               <documentation>
65
                  Priority for this location. If there are other plugins adding ValgrindLocations the location with higher property will be used.
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
</schema>
(-)a/valgrind/org.eclipse.linuxtools.valgrind.core/src/org/eclipse/linuxtools/internal/valgrind/core/ValgrindCommand.java (-14 / +68 lines)
Lines 17-46 import java.io.InputStream; Link Here
17
import org.eclipse.cdt.utils.pty.PTY;
17
import org.eclipse.cdt.utils.pty.PTY;
18
import org.eclipse.cdt.utils.spawner.ProcessFactory;
18
import org.eclipse.cdt.utils.spawner.ProcessFactory;
19
19
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IExtensionPoint;
23
import org.eclipse.core.runtime.Platform;
24
25
import org.eclipse.debug.core.ILaunchConfiguration;
26
27
import org.eclipse.linuxtools.valgrind.core.IValgrindLocation;
28
20
public class ValgrindCommand {
29
public class ValgrindCommand {
21
	protected static final String WHICH_CMD = "which"; //$NON-NLS-1$
30
	protected static final String WHICH_CMD = "which"; //$NON-NLS-1$
22
	protected static final String VALGRIND_CMD = "valgrind"; //$NON-NLS-1$
31
	protected static final String VALGRIND_CMD = "valgrind"; //$NON-NLS-1$
32
	protected static final String EXTENSION_POINT_PRIORITY = "priority"; //$NON-NLS-1$
33
	protected static final String EXTENSION_POINT_CLASS = "class"; //$NON-NLS-1$
34
	protected static final String EXTENSION_POINT_ID = "valgrindLocation"; //$NON-NLS-1$
23
35
24
	protected Process process;
36
	protected Process process;
25
	protected String[] args;
37
	protected String[] args;
38
	protected ILaunchConfiguration config;
39
40
	public ValgrindCommand (ILaunchConfiguration config) {
41
		this.config = config;
42
	}
43
44
	public ValgrindCommand () {
45
		this(null);
46
	}
47
48
	private IConfigurationElement getHighestPriority(IConfigurationElement[] elements) {
49
		if (elements.length == 0)
50
			return null;
51
52
		int priority = Integer.parseInt(elements[0].getAttribute(EXTENSION_POINT_PRIORITY));
53
		IConfigurationElement highest = elements[0];
54
		for (int i = 1; i < elements.length; i++) {
55
			int priority2 = Integer.parseInt(elements[i].getAttribute(EXTENSION_POINT_PRIORITY));
56
			if (priority2 > priority) {
57
				priority = priority2;
58
				highest = elements[i];
59
			}
60
		}
61
		return highest;
62
	}
63
64
	private String getExtensionPointLocation() {
65
		IExtensionPoint ep = Platform.getExtensionRegistry().
66
					getExtensionPoint(PluginConstants.CORE_PLUGIN_ID, EXTENSION_POINT_ID);
67
		if (ep == null)
68
			return null;
69
70
		IConfigurationElement element = getHighestPriority(ep.getConfigurationElements());
71
		if (element == null)
72
			return null;
73
74
		try {
75
			return ((IValgrindLocation)element.createExecutableExtension(EXTENSION_POINT_CLASS)).getValgrindLocation(config);
76
		} catch (CoreException e) {
77
			return null;
78
		}
79
	}
26
80
27
	public String whichValgrind() throws IOException {
81
	public String whichValgrind() throws IOException {
28
		String ret;
82
		// Valgrind binary location set in extension point overrides every other definition
29
		
83
		String valgrindExtensionPointLocation = getExtensionPointLocation();
84
		if (valgrindExtensionPointLocation != null)
85
			return valgrindExtensionPointLocation;
86
30
		// Valgrind binary location in preferences overrides default location
87
		// Valgrind binary location in preferences overrides default location
31
		String valgrindPreferedPath = ValgrindPlugin.getDefault().getPreferenceStore().getString(ValgrindPreferencePage.VALGRIND_PATH);
88
		String valgrindPreferedPath = ValgrindPlugin.getDefault().getPreferenceStore().getString(ValgrindPreferencePage.VALGRIND_PATH);
32
		if (valgrindPreferedPath.equals("")) { //$NON-NLS-1$
89
		if (!valgrindPreferedPath.equals(""))
33
			// No preference, check Valgrind exists in the user's PATH
90
			return valgrindPreferedPath;
34
			StringBuffer out = new StringBuffer();
91
35
			Process p = Runtime.getRuntime().exec(WHICH_CMD + " " + VALGRIND_CMD); //$NON-NLS-1$
92
		// No preference, check Valgrind exists in the user's PATH
36
			// Throws IOException if which command is unsuccessful
93
		StringBuffer out = new StringBuffer();
37
			readIntoBuffer(out, p);
94
		Process p = Runtime.getRuntime().exec(WHICH_CMD + " " + VALGRIND_CMD); //$NON-NLS-1$
38
			ret = out.toString().trim();
95
		// Throws IOException if which command is unsuccessful
39
		}
96
		readIntoBuffer(out, p);
40
		else {
97
		return out.toString().trim();
41
			ret = valgrindPreferedPath;
42
		}
43
		return ret;
44
	}
98
	}
45
	
99
	
46
	/**
100
	/**
(-)a/valgrind/org.eclipse.linuxtools.valgrind.core/src/org/eclipse/linuxtools/valgrind/core/IValgrindLocation.java (+18 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM, Inc.
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
 *    Otavio Pontes <obusatto@br.ibm.com> - initial API
10
 *******************************************************************************/
11
package org.eclipse.linuxtools.valgrind.core;
12
13
import org.eclipse.debug.core.ILaunchConfiguration;
14
15
public interface IValgrindLocation {
16
17
	public abstract String getValgrindLocation(ILaunchConfiguration configuration);
18
}
(-)a/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchConfigurationDelegate.java (-9 / +23 lines)
Lines 80-85 public class ValgrindLaunchConfigurationDelegate extends AbstractCLaunchDelegate Link Here
80
	protected ILaunch launch;
80
	protected ILaunch launch;
81
	protected IProcess process;
81
	protected IProcess process;
82
	protected String launchStr;
82
	protected String launchStr;
83
	protected IPath valgrindLocation;
83
	protected Version valgrindVersion; // null if not used
84
	protected Version valgrindVersion; // null if not used
84
85
85
	public void launch(ILaunchConfiguration config, String mode,
86
	public void launch(ILaunchConfiguration config, String mode,
Lines 97-103 public class ValgrindLaunchConfigurationDelegate extends AbstractCLaunchDelegate Link Here
97
		this.config = config;
98
		this.config = config;
98
		this.launch	= launch;
99
		this.launch	= launch;
99
		try {
100
		try {
100
			command = getValgrindCommand();
101
			command = getValgrindCommand(config);
101
102
102
			// remove any output from previous run
103
			// remove any output from previous run
103
			ValgrindUIPlugin.getDefault().resetView();
104
			ValgrindUIPlugin.getDefault().resetView();
Lines 105-114 public class ValgrindLaunchConfigurationDelegate extends AbstractCLaunchDelegate Link Here
105
			getPlugin().setCurrentLaunchConfiguration(null);
106
			getPlugin().setCurrentLaunchConfiguration(null);
106
			getPlugin().setCurrentLaunch(null);
107
			getPlugin().setCurrentLaunch(null);
107
			
108
			
108
			// find Valgrind binary if not already done
109
			findValgrindLocation();
109
			IPath valgrindLocation = getPlugin().getValgrindLocation();
110
			findValgrindVersion();
110
			// also ensure Valgrind version is usable
111
			valgrindVersion = getPlugin().getValgrindVersion();
112
111
113
			monitor.worked(1);
112
			monitor.worked(1);
114
			IPath exePath = CDebugUtils.verifyProgramPath(config);
113
			IPath exePath = CDebugUtils.verifyProgramPath(config);
Lines 196-201 public class ValgrindLaunchConfigurationDelegate extends AbstractCLaunchDelegate Link Here
196
		}
195
		}
197
	}
196
	}
198
197
198
	protected ValgrindCommand getValgrindCommand(ILaunchConfiguration config ) {
199
		return new ValgrindCommand(config);
200
	}
201
202
	private void findValgrindLocation() throws CoreException {
203
		if (command == null)
204
			return;
205
		valgrindLocation = ValgrindLaunchPlugin.getValgrindLocation(command);
206
	}
207
208
	private void findValgrindVersion() throws CoreException {
209
		if (command == null)
210
			return;
211
212
		if (valgrindLocation == null)
213
			findValgrindLocation();
214
		valgrindVersion = ValgrindLaunchPlugin.getValgrindVersion(command, valgrindLocation);
215
	}
216
199
	protected IValgrindMessage[] parseLogs(IPath outputPath) throws IOException, CoreException {
217
	protected IValgrindMessage[] parseLogs(IPath outputPath) throws IOException, CoreException {
200
		List<IValgrindMessage> messages = new ArrayList<IValgrindMessage>();
218
		List<IValgrindMessage> messages = new ArrayList<IValgrindMessage>();
201
		
219
		
Lines 267-276 public class ValgrindLaunchConfigurationDelegate extends AbstractCLaunchDelegate Link Here
267
		return DebugPlugin.newProcess(launch, systemProcess, renderProcessLabel(programName));
285
		return DebugPlugin.newProcess(launch, systemProcess, renderProcessLabel(programName));
268
	}
286
	}
269
287
270
	protected ValgrindCommand getValgrindCommand() {
271
		return getPlugin().getValgrindCommand();
272
	}
273
274
	protected ValgrindLaunchPlugin getPlugin() {
288
	protected ValgrindLaunchPlugin getPlugin() {
275
		return ValgrindLaunchPlugin.getDefault();
289
		return ValgrindLaunchPlugin.getDefault();
276
	}
290
	}
(-)a/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchPlugin.java (-65 / +22 lines)
Lines 42-48 import org.eclipse.ui.plugin.AbstractUIPlugin; Link Here
42
import org.osgi.framework.BundleContext;
42
import org.osgi.framework.BundleContext;
43
import org.osgi.framework.Version;
43
import org.osgi.framework.Version;
44
44
45
public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyChangeListener {
45
public class ValgrindLaunchPlugin extends AbstractUIPlugin {
46
46
47
	// The plug-in ID
47
	// The plug-in ID
48
	public static final String PLUGIN_ID = PluginConstants.LAUNCH_PLUGIN_ID;
48
	public static final String PLUGIN_ID = PluginConstants.LAUNCH_PLUGIN_ID;
Lines 72-80 public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyC Link Here
72
	
72
	
73
	protected HashMap<String, IConfigurationElement> toolMap;
73
	protected HashMap<String, IConfigurationElement> toolMap;
74
	
74
	
75
	private ValgrindCommand valgrindCommand;
76
	private IPath valgrindLocation;
77
	private Version valgrindVersion;
78
	private ILaunchConfiguration config;
75
	private ILaunchConfiguration config;
79
	private ILaunch launch;
76
	private ILaunch launch;
80
77
Lines 94-102 public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyC Link Here
94
	public void start(BundleContext context) throws Exception {
91
	public void start(BundleContext context) throws Exception {
95
		super.start(context);
92
		super.start(context);
96
		plugin = this;
93
		plugin = this;
97
		
98
		// Register as listener for changes to the property page
99
		ValgrindPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
100
	}
94
	}
101
95
102
	/*
96
	/*
Lines 117-153 public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyC Link Here
117
		return plugin;
111
		return plugin;
118
	}
112
	}
119
113
120
	public IPath getValgrindLocation() throws CoreException {
114
	public static IPath getValgrindLocation() throws CoreException {
121
		if (valgrindLocation == null) {
115
		return getValgrindLocation(new ValgrindCommand());
122
			findValgrindLocation();
123
		}
124
		
125
		return valgrindLocation;
126
	}
127
	
128
	public void setValgrindLocation(IPath valgrindLocation) {
129
		this.valgrindLocation = valgrindLocation;
130
	}
116
	}
131
	
117
132
	public Version getValgrindVersion() throws CoreException {
118
	public static IPath getValgrindLocation(ValgrindCommand command) throws CoreException {
133
		if (valgrindVersion == null) {
119
		if (command.isEnabled()) {
134
			findValgrindVersion();
135
		}
136
		// check for minimum supported version
137
		if (valgrindVersion.compareTo(MIN_VER) < 0) {
138
			throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(Messages.getString("ValgrindLaunchPlugin.Error_min_version"), valgrindVersion.toString(), MIN_VER.toString()))); //$NON-NLS-1$
139
		}
140
		return valgrindVersion;
141
	}
142
	
143
	public void setValgrindVersion(Version valgrindVersion) {
144
		this.valgrindVersion = valgrindVersion;
145
	}
146
	
147
	private void findValgrindLocation() throws CoreException {
148
		if (getValgrindCommand().isEnabled()) {
149
			try {
120
			try {
150
				valgrindLocation = Path.fromOSString(getValgrindCommand().whichValgrind());
121
				return Path.fromOSString(command.whichValgrind());
151
			} catch (IOException e) {
122
			} catch (IOException e) {
152
				IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, Messages.getString("ValgrindLaunchPlugin.Please_ensure_Valgrind"), e); //$NON-NLS-1$
123
				IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, Messages.getString("ValgrindLaunchPlugin.Please_ensure_Valgrind"), e); //$NON-NLS-1$
153
				throw new CoreException(status);
124
				throw new CoreException(status);
Lines 158-171 public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyC Link Here
158
			throw new CoreException(status);
129
			throw new CoreException(status);
159
		}
130
		}
160
	}
131
	}
161
	
132
162
	private void findValgrindVersion() throws CoreException {
133
	public static Version getValgrindVersion(ValgrindCommand command, IPath valgrindLocation) throws CoreException {
134
		Version valgrindVersion = null;
163
		try {
135
		try {
164
			if (valgrindLocation == null) {
136
			String verString = command.whichVersion(valgrindLocation.toOSString());
165
				findValgrindLocation();
166
			}
167
			
168
			String verString = getValgrindCommand().whichVersion(valgrindLocation.toOSString());
169
			verString = verString.replace(VERSION_PREFIX, ""); //$NON-NLS-1$
137
			verString = verString.replace(VERSION_PREFIX, ""); //$NON-NLS-1$
170
			if (verString.indexOf(VERSION_DELIMITER) > 0) {
138
			if (verString.indexOf(VERSION_DELIMITER) > 0) {
171
				verString = verString.substring(0, verString.indexOf(VERSION_DELIMITER));
139
				verString = verString.substring(0, verString.indexOf(VERSION_DELIMITER));
Lines 180-198 public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyC Link Here
180
			IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(Messages.getString("ValgrindLaunchPlugin.Couldn't_determine_version"), valgrindLocation), e); //$NON-NLS-1$
148
			IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(Messages.getString("ValgrindLaunchPlugin.Couldn't_determine_version"), valgrindLocation), e); //$NON-NLS-1$
181
			throw new CoreException(status);
149
			throw new CoreException(status);
182
		}
150
		}
183
	}
151
184
	
152
		// check for minimum supported version
185
	public void setValgrindCommand(ValgrindCommand command) {
153
		if (valgrindVersion.compareTo(MIN_VER) < 0) {
186
		valgrindCommand = command;
154
			throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, NLS.bind(Messages.getString("ValgrindLaunchPlugin.Error_min_version"), valgrindVersion.toString(), MIN_VER.toString()))); //$NON-NLS-1$
187
	}
188
	
189
	protected ValgrindCommand getValgrindCommand() {
190
		if (valgrindCommand == null) {
191
			valgrindCommand = new ValgrindCommand();
192
		}
155
		}
193
		return valgrindCommand;
156
		return valgrindVersion;
194
	}
157
	}
195
	
158
159
	public static Version getValgrindVersion() throws CoreException {
160
		ValgrindCommand command = new ValgrindCommand();
161
		return getValgrindVersion(command, getValgrindLocation(command));
162
	}
163
196
	public String[] getRegisteredToolIDs() {
164
	public String[] getRegisteredToolIDs() {
197
		Set<String> ids = getToolMap().keySet();
165
		Set<String> ids = getToolMap().keySet();
198
		return ids.toArray(new String[ids.size()]);
166
		return ids.toArray(new String[ids.size()]);
Lines 319-333 public class ValgrindLaunchPlugin extends AbstractUIPlugin implements IPropertyC Link Here
319
		}
287
		}
320
		return toolMap;
288
		return toolMap;
321
	}
289
	}
322
323
	public void propertyChange(PropertyChangeEvent event) {
324
		String prop = event.getProperty();
325
		if (prop.equals(ValgrindPreferencePage.VALGRIND_PATH)
326
				|| prop.equals(ValgrindPreferencePage.VALGRIND_ENABLE)) {
327
			// Reset Valgrind location and version
328
			valgrindLocation = null;
329
			valgrindVersion = null;
330
		}
331
	}
332
	
333
}
290
}
(-)a/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindOptionsTab.java (-11 / +13 lines)
Lines 24-29 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; Link Here
24
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
24
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
25
import org.eclipse.jface.dialogs.IDialogConstants;
25
import org.eclipse.jface.dialogs.IDialogConstants;
26
import org.eclipse.linuxtools.internal.valgrind.core.LaunchConfigurationConstants;
26
import org.eclipse.linuxtools.internal.valgrind.core.LaunchConfigurationConstants;
27
import org.eclipse.linuxtools.internal.valgrind.core.ValgrindCommand;
27
import org.eclipse.linuxtools.valgrind.launch.IValgrindToolPage;
28
import org.eclipse.linuxtools.valgrind.launch.IValgrindToolPage;
28
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.SWT;
Lines 93-115 public class ValgrindOptionsTab extends AbstractLaunchConfigurationTab { Link Here
93
	protected Exception ex;
94
	protected Exception ex;
94
	
95
	
95
	private Version valgrindVersion;
96
	private Version valgrindVersion;
97
	private boolean checkVersion;
96
	
98
	
97
	public ValgrindOptionsTab() {
99
	public ValgrindOptionsTab() {
98
		this(true);
100
		this(true);
99
	}
101
	}
100
	
102
	
101
	public ValgrindOptionsTab(boolean checkVersion) {
103
	public ValgrindOptionsTab(boolean checkVersion) {
102
		if (checkVersion) {
104
		this.checkVersion = checkVersion;
103
			try {
104
				valgrindVersion = getPlugin().getValgrindVersion();
105
			} catch (CoreException e) {
106
				ex = e;
107
			}
108
		}
109
		else {
110
			// Do not check version
111
			valgrindVersion = null;
112
		}
113
	}	
105
	}	
114
106
115
	protected SelectionListener selectListener = new SelectionAdapter() {
107
	protected SelectionListener selectListener = new SelectionAdapter() {
Lines 469-474 public class ValgrindOptionsTab extends AbstractLaunchConfigurationTab { Link Here
469
		launchConfigurationWorkingCopy = null;
461
		launchConfigurationWorkingCopy = null;
470
462
471
		try {
463
		try {
464
			if (checkVersion) {
465
				ValgrindCommand command = getValgrindCommand(configuration);
466
				IPath valgrindLocation = ValgrindLaunchPlugin.getValgrindLocation(command);
467
				valgrindVersion = ValgrindLaunchPlugin.getValgrindVersion(command, valgrindLocation);
468
			}
469
472
			tool = configuration.getAttribute(LaunchConfigurationConstants.ATTR_TOOL, LaunchConfigurationConstants.DEFAULT_TOOL);
470
			tool = configuration.getAttribute(LaunchConfigurationConstants.ATTR_TOOL, LaunchConfigurationConstants.DEFAULT_TOOL);
473
			int select = -1;
471
			int select = -1;
474
			for (int i = 0; i < tools.length && select < 0; i++) {
472
			for (int i = 0; i < tools.length && select < 0; i++) {
Lines 510-515 public class ValgrindOptionsTab extends AbstractLaunchConfigurationTab { Link Here
510
		isInitializing = false;
508
		isInitializing = false;
511
	}
509
	}
512
510
511
	protected ValgrindCommand getValgrindCommand(ILaunchConfiguration configuration) {
512
		return new ValgrindCommand(configuration);
513
	}
514
513
	@Override
515
	@Override
514
	public boolean isValid(ILaunchConfiguration launchConfig) {
516
	public boolean isValid(ILaunchConfiguration launchConfig) {
515
		setErrorMessage(null);
517
		setErrorMessage(null);
(-)a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/LocationPreferenceTest.java (-4 / +3 lines)
Lines 22-28 import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchPlugin; Link Here
22
22
23
public class LocationPreferenceTest extends TestCase {
23
public class LocationPreferenceTest extends TestCase {
24
24
25
	private ValgrindCommand command = new ValgrindCommand() {
25
	private ValgrindCommand command = new ValgrindCommand(null) {
26
		protected void readIntoBuffer(StringBuffer out, Process p) throws IOException {
26
		protected void readIntoBuffer(StringBuffer out, Process p) throws IOException {
27
			// Simulate not finding Valgrind in the user's PATH
27
			// Simulate not finding Valgrind in the user's PATH
28
			throw new IOException();
28
			throw new IOException();
Lines 36-44 public class LocationPreferenceTest extends TestCase { Link Here
36
	public void testManualLocationNoPATH() throws Exception {
36
	public void testManualLocationNoPATH() throws Exception {
37
		// Set a preference for a manual location
37
		// Set a preference for a manual location
38
		ValgrindPlugin.getDefault().getPreferenceStore().setValue(ValgrindPreferencePage.VALGRIND_PATH, "/path/to/valgrind");
38
		ValgrindPlugin.getDefault().getPreferenceStore().setValue(ValgrindPreferencePage.VALGRIND_PATH, "/path/to/valgrind");
39
		
39
		ValgrindPlugin.getDefault().getPreferenceStore().setValue(ValgrindPreferencePage.VALGRIND_ENABLE, true);
40
		ValgrindLaunchPlugin.getDefault().setValgrindCommand(command);
40
41
		
42
		ValgrindLaunchPlugin.getDefault().getValgrindLocation();
41
		ValgrindLaunchPlugin.getDefault().getValgrindLocation();
43
	}
42
	}
44
}
43
}
(-)a/valgrind/org.eclipse.linuxtools.valgrind.memcheck.tests/src/org/eclipse/linuxtools/internal/valgrind/memcheck/tests/MinVersionTest.java (-21 / +28 lines)
Lines 10-64 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.linuxtools.internal.valgrind.memcheck.tests;
11
package org.eclipse.linuxtools.internal.valgrind.memcheck.tests;
12
12
13
import java.io.IOException;
14
13
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.debug.core.ILaunchConfiguration;
15
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
16
import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindLaunchPlugin;
18
import org.eclipse.linuxtools.internal.valgrind.core.ValgrindCommand;
17
import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindOptionsTab;
19
import org.eclipse.linuxtools.internal.valgrind.launch.ValgrindOptionsTab;
20
import org.eclipse.linuxtools.internal.valgrind.tests.ValgrindStubCommand;
21
import org.eclipse.linuxtools.internal.valgrind.tests.ValgrindTestLaunchDelegate;
18
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Display;
20
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.Shell;
21
import org.osgi.framework.Version;
22
25
23
public class MinVersionTest extends AbstractMemcheckTest {
26
public class MinVersionTest extends AbstractMemcheckTest {
24
	private static final Version VER_3_2_1 = new Version(3, 2, 1);
27
	private static ValgrindTestLaunchDelegate delegate_3_2_1 = new ValgrindTestLaunchDelegate() {
25
	private Version verSave;
28
		@Override
29
		protected ValgrindCommand getValgrindCommand(ILaunchConfiguration config) {
30
			return new ValgrindStubCommand() {
31
				@Override
32
				public String whichVersion(String whichValgrind) throws IOException {
33
					return "valgrind-3.2.1"; //$NON-NLS-1$
34
				}
35
			};
36
		}
37
	};
26
	
38
	
27
	@Override
39
	@Override
28
	protected void setUp() throws Exception {
40
	protected void setUp() throws Exception {
29
		super.setUp();
41
		super.setUp();
30
		proj = createProjectAndBuild("basicTest"); //$NON-NLS-1$
42
		proj = createProjectAndBuild("basicTest"); //$NON-NLS-1$
31
		
32
		saveVersion();
33
	}
43
	}
34
44
35
	private void saveVersion() throws CoreException {
36
		verSave = ValgrindLaunchPlugin.getDefault().getValgrindVersion();
37
		ValgrindLaunchPlugin.getDefault().setValgrindVersion(VER_3_2_1);
38
	}
39
	
40
	@Override
45
	@Override
41
	protected void tearDown() throws Exception {
46
	protected void tearDown() throws Exception {
42
		restoreVersion();
43
		
44
		deleteProject(proj);
47
		deleteProject(proj);
45
		super.tearDown();
48
		super.tearDown();
46
	}
49
	}
47
50
48
	private void restoreVersion() {
49
		ValgrindLaunchPlugin.getDefault().setValgrindVersion(verSave);
50
	}
51
		
52
	public void testLaunchBadVersion() throws Exception {
51
	public void testLaunchBadVersion() throws Exception {
53
		// Put this back so we can make a valid config
52
		// Put this back so we can make a valid config
54
		restoreVersion();
55
		ILaunchConfiguration config = createConfiguration(proj.getProject());
53
		ILaunchConfiguration config = createConfiguration(proj.getProject());
56
		// For some reason we downgraded
54
		// For some reason we downgraded
57
		saveVersion();
58
		
55
		
59
		CoreException ce = null;		
56
		CoreException ce = null;		
60
		try {
57
		try {
61
			doLaunch(config, "testDefaults"); //$NON-NLS-1$
58
			doLaunch(config, "testDefaults", delegate_3_2_1); //$NON-NLS-1$
62
		} catch (CoreException e) {
59
		} catch (CoreException e) {
63
			ce = e;
60
			ce = e;
64
		}
61
		}
Lines 69-75 public class MinVersionTest extends AbstractMemcheckTest { Link Here
69
	public void testTabsBadVersion() throws Exception {
66
	public void testTabsBadVersion() throws Exception {
70
		Shell testShell = new Shell(Display.getDefault());
67
		Shell testShell = new Shell(Display.getDefault());
71
		testShell.setLayout(new GridLayout());
68
		testShell.setLayout(new GridLayout());
72
		ValgrindOptionsTab tab = new ValgrindOptionsTab();
69
		ValgrindOptionsTab tab = new ValgrindOptionsTab() {
70
			@Override
71
			protected ValgrindCommand getValgrindCommand(ILaunchConfiguration config) {
72
				return new ValgrindStubCommand() {
73
					@Override
74
					public String whichVersion(String whichValgrind) throws IOException {
75
						return "valgrind-3.2.1"; //$NON-NLS-1$
76
					}
77
				};
78
			}
79
		};
73
		
80
		
74
		ILaunchConfiguration config = getLaunchConfigType().newInstance(null, getLaunchManager()
81
		ILaunchConfiguration config = getLaunchConfigType().newInstance(null, getLaunchManager()
75
				.generateLaunchConfigurationName(
82
				.generateLaunchConfigurationName(
(-)a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/AbstractValgrindTest.java (-8 / +9 lines)
Lines 65-74 public abstract class AbstractValgrindTest extends AbstractTest { Link Here
65
	@Override
65
	@Override
66
	protected void setUp() throws Exception {
66
	protected void setUp() throws Exception {
67
		launches = new ArrayList<ILaunch>();
67
		launches = new ArrayList<ILaunch>();
68
		
69
		// Substitute Valgrind command line interaction
70
		ValgrindLaunchPlugin.getDefault().setValgrindCommand(getValgrindCommand());
71
		
72
		super.setUp();
68
		super.setUp();
73
	}
69
	}
74
70
Lines 86-92 public abstract class AbstractValgrindTest extends AbstractTest { Link Here
86
		return getLaunchManager().getLaunchConfigurationType(ValgrindLaunchPlugin.LAUNCH_ID);
82
		return getLaunchManager().getLaunchConfigurationType(ValgrindLaunchPlugin.LAUNCH_ID);
87
	}
83
	}
88
84
89
	protected ILaunch doLaunch(ILaunchConfiguration config, String testName) throws Exception {
85
	protected ILaunch doLaunch(ILaunchConfiguration config, String testName, ValgrindTestLaunchDelegate delegate) throws Exception {
90
		ILaunch launch;
86
		ILaunch launch;
91
		IPath pathToFiles = getPathToFiles(testName);
87
		IPath pathToFiles = getPathToFiles(testName);
92
		
88
		
Lines 98-104 public abstract class AbstractValgrindTest extends AbstractTest { Link Here
98
		wc.setAttribute(LaunchConfigurationConstants.ATTR_INTERNAL_OUTPUT_DIR, pathToFiles.toOSString());
94
		wc.setAttribute(LaunchConfigurationConstants.ATTR_INTERNAL_OUTPUT_DIR, pathToFiles.toOSString());
99
		wc.doSave();
95
		wc.doSave();
100
96
101
		ValgrindTestLaunchDelegate delegate = new ValgrindTestLaunchDelegate();
97
		if (delegate == null)
98
			delegate = new ValgrindTestLaunchDelegate();
102
		launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
99
		launch = new Launch(config, ILaunchManager.PROFILE_MODE, null);
103
		
100
		
104
		DebugPlugin.getDefault().getLaunchManager().addLaunch(launch);
101
		DebugPlugin.getDefault().getLaunchManager().addLaunch(launch);
Lines 111-116 public abstract class AbstractValgrindTest extends AbstractTest { Link Here
111
		return launch;
108
		return launch;
112
	}
109
	}
113
110
111
	protected ILaunch doLaunch(ILaunchConfiguration config, String testName) throws Exception {
112
		return doLaunch(config, testName);
113
	}
114
114
	protected IPath getPathToFiles(String testName) throws URISyntaxException,
115
	protected IPath getPathToFiles(String testName) throws URISyntaxException,
115
			IOException {
116
			IOException {
116
		URL location = FileLocator.find(getBundle(), new Path("valgrindFiles"), null); //$NON-NLS-1$
117
		URL location = FileLocator.find(getBundle(), new Path("valgrindFiles"), null); //$NON-NLS-1$
Lines 195-202 public abstract class AbstractValgrindTest extends AbstractTest { Link Here
195
			return new ValgrindStubCommand();
196
			return new ValgrindStubCommand();
196
		}
197
		}
197
		else {
198
		else {
198
			return new ValgrindCommand();
199
			return new ValgrindCommand(null);
199
		}
200
		}
200
	}
201
	}
201
202
202
}
203
}
(-)a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindStubCommand.java (+3 lines)
Lines 19-24 public class ValgrindStubCommand extends ValgrindCommand { Link Here
19
	protected static final String VERSION_FILE = ".version"; //$NON-NLS-1$
19
	protected static final String VERSION_FILE = ".version"; //$NON-NLS-1$
20
	
20
	
21
	protected int exitcode;
21
	protected int exitcode;
22
	public ValgrindStubCommand() {
23
		super(null);
24
	}
22
	
25
	
23
	@Override
26
	@Override
24
	public String whichValgrind() throws IOException {
27
	public String whichValgrind() throws IOException {
(-)a/valgrind/org.eclipse.linuxtools.valgrind.tests/src/org/eclipse/linuxtools/internal/valgrind/tests/ValgrindTestLaunchDelegate.java (-3 / +2 lines)
Lines 25-36 public class ValgrindTestLaunchDelegate extends ValgrindLaunchConfigurationDeleg Link Here
25
	protected static final String ERROR_CODE_FILE = ".errorCode"; //$NON-NLS-1$
25
	protected static final String ERROR_CODE_FILE = ".errorCode"; //$NON-NLS-1$
26
	
26
	
27
	@Override
27
	@Override
28
	protected ValgrindCommand getValgrindCommand() {
28
	protected ValgrindCommand getValgrindCommand(ILaunchConfiguration config) {
29
		if (!ValgrindTestsPlugin.RUN_VALGRIND) {
29
		if (!ValgrindTestsPlugin.RUN_VALGRIND) {
30
			return new ValgrindStubCommand();
30
			return new ValgrindStubCommand();
31
		}
31
		}
32
		else {
32
		else {
33
			return super.getValgrindCommand();
33
			return super.getValgrindCommand(config);
34
		}
34
		}
35
	}
35
	}
36
36
37
- 

Return to bug 353056