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 253862
Collapse All | Expand All

(-)src/org/eclipse/equinox/frameworkadmin/tests/AllTests.java (+1 lines)
Lines 36-41 Link Here
36
		suite.addTestSuite(TestRunningInstance.class);
36
		suite.addTestSuite(TestRunningInstance.class);
37
		suite.addTestSuite(ManipulatorTests.class);
37
		suite.addTestSuite(ManipulatorTests.class);
38
		suite.addTestSuite(UtilsTest.class);
38
		suite.addTestSuite(UtilsTest.class);
39
		suite.addTestSuite(LauncherDataTest.class);
39
		return suite;
40
		return suite;
40
	}
41
	}
41
42
(-)src/org/eclipse/equinox/frameworkadmin/tests/LauncherDataTest.java (+93 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 IBM Corporation and others.
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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.frameworkadmin.tests;
12
13
import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData;
14
15
import junit.framework.TestCase;
16
17
/**
18
 * @since 1.0
19
 */
20
public class LauncherDataTest extends TestCase {
21
22
	/*
23
	 * Constructor for the class.
24
	 */
25
	public LauncherDataTest(String name) {
26
		super(name);
27
	}
28
29
	public void testRemoveProgramArg() {
30
		LauncherData data = new LauncherData("equinox", "1.0", "eclipse", "1.0");
31
		data.setProgramArgs(new String[] {"-console", "-startup", "foo"});
32
		data.removeProgramArg("-startup");
33
		assertEquals("1.0", new String[] {"-console"}, data.getProgramArgs());
34
35
		data.setProgramArgs(null);
36
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "-bar"});
37
		data.removeProgramArg("-startup");
38
		assertEquals("2.0", new String[] {"-console", "-bar"}, data.getProgramArgs());
39
40
		data.setProgramArgs(null);
41
		data.setProgramArgs(new String[] {"-startup", "foo"});
42
		data.removeProgramArg("-startup");
43
		assertEquals("3.0", new String[0], data.getProgramArgs());
44
45
		data.setProgramArgs(null);
46
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar"});
47
		data.removeProgramArg("-startup");
48
		assertEquals("4.0", new String[] {"-console"}, data.getProgramArgs());
49
50
		data.setProgramArgs(null);
51
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"});
52
		data.removeProgramArg("-startup");
53
		assertEquals("5.0", new String[] {"-console", "-xxx"}, data.getProgramArgs());
54
55
		// arg which doesn't start with a dash - dont' consume anything but that specific arg
56
		data.setProgramArgs(null);
57
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"});
58
		data.removeProgramArg("foo");
59
		assertEquals("6.0", new String[] {"-console", "-startup", "bar", "-xxx"}, data.getProgramArgs());
60
61
		// non-matching arg
62
		data.setProgramArgs(null);
63
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"});
64
		data.removeProgramArg("zzz");
65
		assertEquals("7.0", new String[] {"-console", "-startup", "foo", "bar", "-xxx"}, data.getProgramArgs());
66
67
		// empty string
68
		data.setProgramArgs(null);
69
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"});
70
		data.removeProgramArg("");
71
		assertEquals("8.0", new String[] {"-console", "-startup", "foo", "bar", "-xxx"}, data.getProgramArgs());
72
73
		// just whitespace
74
		data.setProgramArgs(null);
75
		data.setProgramArgs(new String[] {"-console", "-startup", "foo", "bar", "-xxx"});
76
		data.removeProgramArg(" ");
77
		assertEquals("9.0", new String[] {"-console", "-startup", "foo", "bar", "-xxx"}, data.getProgramArgs());
78
79
	}
80
81
	/*
82
	 * Compare the give 2 arrays and assert whether or not they should be considered equal.
83
	 */
84
	public static void assertEquals(String message, String[] one, String[] two) {
85
		if (one == null)
86
			assertNull(message, two);
87
		if (two == null)
88
			fail(message);
89
		assertEquals(message, one.length, two.length);
90
		for (int i = 0; i < one.length; i++)
91
			assertEquals(message, one[i], two[i]);
92
	}
93
}
(-)src/org/eclipse/equinox/internal/provisional/frameworkadmin/LauncherData.java (-1 / +15 lines)
Lines 138-144 Link Here
138
	}
138
	}
139
139
140
	public void removeProgramArg(String arg) {
140
	public void removeProgramArg(String arg) {
141
		programArgs.remove(arg);
141
		int index = programArgs.indexOf(arg);
142
		if (index == -1)
143
			return;
144
		programArgs.remove(index);
145
		// if the user wants us to remove an arg that starts with
146
		// a dash, then consume all args up to the next dash-prefixed
147
		// arg (see bug 253862)
148
		if (arg.charAt(0) != '-')
149
			return;
150
		while (index < programArgs.size()) {
151
			String next = (String) programArgs.get(index);
152
			if (next.charAt(0) == '-')
153
				return;
154
			programArgs.remove(index);
155
		}
142
	}
156
	}
143
157
144
	public void setFwConfigLocation(File fwConfigLocation) {
158
	public void setFwConfigLocation(File fwConfigLocation) {

Return to bug 253862