Skip to main content
summaryrefslogtreecommitdiffstats
blob: 71f4b53a1a2eca856e4ad5ca98ac49cf57826200 (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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*******************************************************************************
 * Copyright (c) 2007, 2010 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.frameworkadmin;

import java.net.URI;
import org.eclipse.core.runtime.URIUtil;
import org.osgi.framework.Version;

/**
 * This object represents information of a bundle. 
 * @since 2.0
 */
public class BundleInfo {
	public static final String EMPTY_VERSION = "0.0.0"; //$NON-NLS-1$
	public static final int NO_LEVEL = -1;
	public static final int NO_BUNDLEID = -1;

	private String symbolicName = null;
	private String version = EMPTY_VERSION;
	private URI baseLocation = null;
	private URI location = null;
	private long bundleId = NO_BUNDLEID;

	private boolean markedAsStarted = false;
	private int startLevel = NO_LEVEL;
	private boolean resolved = false;

	private String manifest = null;
	private String fragmentHost = null;

	/**
	 * Create a new BundleInfo object
	 */
	public BundleInfo() {
	}

	/**
	 * Create a new BundleInfo object
	 * @param location - the location of the bundle
	 */
	public BundleInfo(URI location) {
		this.location = location;
	}

	/**
	 * Create a new BundleInfo object
	 * @param location - the location of the bundle
	 * @param startLevel - the start to be used or {@link BundleInfo#NO_LEVEL}
	 * @param started - whether or not the bundle should be started
	 */
	public BundleInfo(URI location, int startLevel, boolean started) {
		this.location = location;
		this.startLevel = startLevel < 0 ? NO_LEVEL : startLevel;
		this.markedAsStarted = started;
	}

	/**
	 * Create a new BundleInfo object
	 * @param symbolic  The Bundle-SymbolicName name for this bundle
	 * @param version - The version for this bundle, this must be a valid {@link Version} string, if null is passed {@link #EMPTY_VERSION} will be used instead
	 * @param location - the location of the bundle
	 * @param startLevel - the start level of the bundle or {@link BundleInfo#NO_LEVEL}
	 * @param started - whether or not the bundle should be started
	 */
	public BundleInfo(String symbolic, String version, URI location, int startLevel, boolean started) {
		this.symbolicName = symbolic;
		this.version = version != null ? version : EMPTY_VERSION;
		this.location = location;
		this.markedAsStarted = started;
		this.startLevel = startLevel < 0 ? NO_LEVEL : startLevel;
	}

	/**
	 * Get the bundle id
	 * @return the bundle id or {@link #NO_BUNDLEID}
	 */
	public long getBundleId() {
		return bundleId;
	}

	/**
	 * The base location
	 * An absolute URI which may be used to resolve relative {@link #getLocation()} URIs
	 * @return absolute URI or null if not set
	 */
	public URI getBaseLocation() {
		return baseLocation;
	}

	/**
	 * The location of this bundle.
	 * A location is required if this bundle will be persisted into a configuration file
	 * @return URI location or null if not set
	 */
	public URI getLocation() {
		return location;
	}

	/**
	 * The manifest for this bundle
	 * @return the manifest or null if not set
	 */
	public String getManifest() {
		return manifest;
	}

	/**
	 * The start level for this bundle
	 * @return the start level or {@link #NO_LEVEL}
	 */
	public int getStartLevel() {
		return startLevel;
	}

	/**
	 * The Bundle-SymbolicName for this bundle.
	 * A symbolic name is required if this bundle will be persisted into a configuration file
	 * @return the symbolic name or null if not set
	 */
	public String getSymbolicName() {
		return symbolicName;
	}

	/**
	 * Return the version
	 * @return an {@link Version} string, or "0.0.0" if not set 
	 */
	public String getVersion() {
		if (version == null)
			return EMPTY_VERSION;
		return version;
	}

	/**
	 * Return the host if this bundle is a fragment
	 * @return the host, or null if this is not a fragment
	 */
	public String getFragmentHost() {
		return fragmentHost;
	}

	/**
	 * Whether or not this bundle is marked to be started
	 * Default is false
	 * @return boolean
	 */
	public boolean isMarkedAsStarted() {
		return markedAsStarted;
	}

	/**
	 * Whether or not this bundle is resolved
	 * Default is false
	 * @return boolean
	 */
	public boolean isResolved() {
		return resolved;
	}

	/**
	 * Set the bundle id
	 * @param bundleId
	 */
	public void setBundleId(long bundleId) {
		this.bundleId = bundleId;
	}

	/**
	 * Set a base location against which relative {@link #getLocation()} URIs may be resolved
	 * @param baseLocation - an absolute URI
	 */
	public void setBaseLocation(URI baseLocation) {
		this.baseLocation = baseLocation;
	}

	/**
	 * Set the location for this bundle.
	 * @param location
	 */
	public void setLocation(URI location) {
		this.location = location;
	}

	/**
	 * Set the manifest for this bundle
	 * @param manifest
	 */
	public void setManifest(String manifest) {
		this.manifest = manifest;
	}

	/**
	 * Set whether or not this bundle should be started
	 * @param markedAsStarted
	 */
	public void setMarkedAsStarted(boolean markedAsStarted) {
		this.markedAsStarted = markedAsStarted;
	}

	/** 
	 * Set whether or not the bundle is resolved
	 * @param resolved
	 */
	public void setResolved(boolean resolved) {
		this.resolved = resolved;
	}

	/**
	 * Set the start level.
	 * @param level if a value < 0 is passed, the start level will be set to {@link #NO_LEVEL}
	 */
	public void setStartLevel(int level) {
		this.startLevel = level < 0 ? NO_LEVEL : level;
	}

	/**
	 * Set the Bundle-SymbolicName
	 * @param symbolicName
	 */
	public void setSymbolicName(String symbolicName) {
		this.symbolicName = symbolicName;
	}

	/**
	 * Set the version, should be a valid {@link Version} string
	 * @param value
	 */
	public void setVersion(String value) {
		if (value == null)
			this.version = EMPTY_VERSION;
		else
			this.version = value;
	}

	/**
	 * Set the host if this bundle is a fragment
	 * @param fragmentHost
	 */
	public void setFragmentHost(String fragmentHost) {
		this.fragmentHost = fragmentHost;
	}

	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("BundleInfo("); //$NON-NLS-1$
		if (symbolicName != null)
			buffer.append(symbolicName);
		buffer.append(", "); //$NON-NLS-1$
		buffer.append(version);

		if (fragmentHost != null) {
			buffer.append(", fragmentHost="); //$NON-NLS-1$
			buffer.append(fragmentHost);
		}

		if (baseLocation != null) {
			buffer.append(", baseLocation="); //$NON-NLS-1$
			buffer.append(baseLocation);
		}
		buffer.append(", location="); //$NON-NLS-1$
		buffer.append(location);
		buffer.append(", startLevel="); //$NON-NLS-1$
		buffer.append(startLevel);
		buffer.append(", toBeStarted="); //$NON-NLS-1$
		buffer.append(markedAsStarted);
		buffer.append(", resolved="); //$NON-NLS-1$
		buffer.append(resolved);
		buffer.append(", id="); //$NON-NLS-1$
		buffer.append(this.bundleId);//		buffer.append(',').append(manifest == null ? "no manifest" : "manifest available");
		buffer.append(',').append(manifest == null ? "no manifest" : "manifest available"); //$NON-NLS-1$ //$NON-NLS-2$
		buffer.append(')');
		return buffer.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((symbolicName == null) ? 0 : symbolicName.hashCode());
		result = prime * result + version.hashCode();
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;

		if (obj == null)
			return false;

		if (getClass() != obj.getClass())
			return false;

		BundleInfo other = (BundleInfo) obj;
		if (symbolicName == null) {
			if (other.symbolicName != null)
				return false;
		} else if (!symbolicName.equals(other.symbolicName))
			return false;

		if (!version.equals(other.getVersion()))
			return false;

		if (location == null || other.location == null)
			return true;

		//compare absolute location URIs
		URI absoluteLocation = null;
		if (location.isAbsolute() || baseLocation == null)
			absoluteLocation = location;
		else
			absoluteLocation = URIUtil.append(baseLocation, URIUtil.toUnencodedString(location));

		URI otherAbsoluteLocation = null;
		if (other.location.isAbsolute() || other.baseLocation == null)
			otherAbsoluteLocation = other.location;
		else
			otherAbsoluteLocation = URIUtil.append(other.baseLocation, URIUtil.toUnencodedString(other.location));
		return URIUtil.sameURI(absoluteLocation, otherAbsoluteLocation);
	}
}

Back to the top