Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ece7e58484be8f4f9a859d0db9e99466e1d58ffb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*******************************************************************************
 *  Copyright (c) 2007, 2019 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.provisional.frameworkadmin;

import java.io.File;
import java.util.*;

/**
 * This object is instantiated by {@link Manipulator#getLauncherData()}; The
 * class that keeps some parameters of the {@link Manipulator} created this
 * object. The manipulating of the parameters will affect the
 * {@link Manipulator}.
 * 
 * 
 * @see Manipulator
 */
public class LauncherData {
	private File fwPersistentDataLocation = null;
	private File jvm = null;
	private List<String> jvmArgs = new LinkedList<>();
	private List<String> programArgs = new LinkedList<>();

	private boolean clean;
	private File fwConfigLocation;
	private File home = null;
	private File fwJar = null;

	private File launcher = null;
	private File launcherConfigLocation = null;

	private String fwName;
	private String fwVersion;
	private String launcherName;
	private String launcherVersion;
	private String os;

	public LauncherData(String fwName, String fwVersion, String launcherName, String launcherVersion) {
		this.fwName = fwName;
		this.fwVersion = fwVersion;
		this.launcherName = launcherName;
		this.launcherVersion = launcherVersion;
		this.initialize();
	}

	public void addJvmArg(String arg) {
		if (arg == null)
			return;
		jvmArgs.add(arg);
	}

	public void addProgramArg(String arg) {
		if (arg == null)
			return;
		programArgs.add(arg);
	}

	public File getFwConfigLocation() {
		return fwConfigLocation;
	}

	public File getFwJar() {
		return fwJar;
	}

	public String getFwName() {
		return fwName;
	}

	public File getFwPersistentDataLocation() {
		return fwPersistentDataLocation;
	}

	public String getFwVersion() {
		return fwVersion;
	}

	public File getHome() {
		return home;
	}

	public File getJvm() {
		return jvm;
	}

	public String[] getJvmArgs() {
		String[] args = new String[jvmArgs.size()];
		jvmArgs.toArray(args);
		return args;
	}

	public File getLauncher() {
		return launcher;
	}

	public File getLauncherConfigLocation() {
		return launcherConfigLocation;
	}

	public String getLauncherName() {
		return launcherName;
	}

	public String getLauncherVersion() {
		return launcherVersion;
	}

	public String[] getProgramArgs() {
		String[] args = new String[programArgs.size()];
		programArgs.toArray(args);
		return args;
	}

	public void initialize() {
		fwPersistentDataLocation = null;
		jvm = null;
		jvmArgs.clear();
		programArgs.clear();
		clean = false;
		fwConfigLocation = null;
		fwJar = null;
		launcher = null;
	}

	public boolean isClean() {
		return clean;
	}

	public void removeJvmArg(String arg) {
		jvmArgs.remove(arg);
	}

	public void removeProgramArg(String arg) {
		// We want to handle program args as key/value pairs subsequently
		// a key MUST start with a "-", all other args are ignored. For
		// backwards compatibility we remove all program args until the
		// next program arg key
		// (see bug 253862)
		if (!arg.startsWith("-")) //$NON-NLS-1$
			return;

		int index = programArgs.indexOf(arg);
		if (index == -1)
			return;

		programArgs.remove(index);
		while (index < programArgs.size()) {
			String next = programArgs.get(index);
			if (next.charAt(0) == '-')
				return;
			programArgs.remove(index);
		}
	}

	public void setFwConfigLocation(File fwConfigLocation) {
		this.fwConfigLocation = fwConfigLocation;
	}

	public void setFwJar(File fwJar) {
		this.fwJar = fwJar;
	}

	public void setFwPersistentDataLocation(File fwPersistentDataLocation, boolean clean) {
		this.fwPersistentDataLocation = fwPersistentDataLocation;
		this.clean = clean;
	}

	public void setHome(File home) {
		this.home = home;
	}

	public void setJvm(File file) {
		this.jvm = file;
		if (file == null)
			removeProgramArg("-vm"); //$NON-NLS-1$
	}

	public void setJvmArgs(String[] args) {
		if (args == null || args.length == 0) {
			jvmArgs.clear();
			return;
		}
		for (String arg : args)
			this.addJvmArg(arg);
	}

	public void setLauncher(File launcherFile) {
		launcher = launcherFile;
	}

	public void setLauncherConfigLocation(File launcherConfigLocation) {
		this.launcherConfigLocation = launcherConfigLocation;
	}

	public void setOS(String os) {
		this.os = os;
	}

	public String getOS() {
		return os;
	}

	public void setProgramArgs(String[] args) {
		if (args == null || args.length == 0) {
			programArgs.clear();
			return;
		}
		for (String arg : args)
			this.addProgramArg(arg);
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Class:" + this.getClass().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("fwName=" + this.fwName + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("fwVersion=" + this.fwVersion + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("launcherName=" + this.launcherName + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("launcherVersion=" + this.launcherVersion + "\n"); //$NON-NLS-1$ //$NON-NLS-2$

		sb.append("jvm=" + this.jvm + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		if (this.jvmArgs.size() == 0)
			sb.append("jvmArgs = null\n"); //$NON-NLS-1$
		else {
			sb.append("jvmArgs=\n"); //$NON-NLS-1$
			int i = 0;
			for (Iterator<String> iterator = jvmArgs.iterator(); iterator.hasNext(); iterator.next())
				sb.append("\tjvmArgs[" + i++ + "]=" + iterator + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

		}
		if (this.programArgs.size() == 0)
			sb.append("programArgs = null\n"); //$NON-NLS-1$
		else {
			sb.append("programArgs=\n"); //$NON-NLS-1$
			int i = 0;
			for (Iterator<String> iterator = programArgs.iterator(); iterator.hasNext(); iterator.next())
				sb.append("\tprogramArgs[" + i++ + "]=" + iterator + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		}
		sb.append("fwConfigLocation=" + this.fwConfigLocation + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("fwJar=" + this.fwJar + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("fwPersistentDataLocation=" + this.fwPersistentDataLocation + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("home=" + this.home + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("launcher=" + this.launcher + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("launcherConfigLocation=" + this.launcherConfigLocation + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
		sb.append("clean=" + this.isClean() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$

		return sb.toString();
	}
}

Back to the top