View | Details | Raw Unified | Return to bug 276326 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/target/AbstractBundleContainer.java (-2 / +1 lines)
Lines 163-170 Link Here
163
	protected abstract IResolvedBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException;
163
	protected abstract IResolvedBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException;
164
164
165
	/**
165
	/**
166
	 * Collects all of the features in this container.  May return an empty array if {@link #resolveBundles(ITargetDefinition, IProgressMonitor)}
166
	 * Collects all of the features in this container
167
	 * has not been called previously.
168
	 * <p>
167
	 * <p>
169
	 * Subclasses must implement this method.
168
	 * Subclasses must implement this method.
170
	 * </p><p>
169
	 * </p><p>
(-)src/org/eclipse/pde/internal/core/target/AbstractTargetHandle.java (-3 lines)
Lines 158-166 Link Here
158
	 */
158
	 */
159
	static IProfileRegistry getProfileRegistry() {
159
	static IProfileRegistry getProfileRegistry() {
160
		IProvisioningAgent agent = (IProvisioningAgent) PDECore.getDefault().acquireService(IProvisioningAgent.SERVICE_NAME);
160
		IProvisioningAgent agent = (IProvisioningAgent) PDECore.getDefault().acquireService(IProvisioningAgent.SERVICE_NAME);
161
		if (agent == null) {
162
			return null;
163
		}
164
		return (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
161
		return (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
165
	}
162
	}
166
163
(-)src/org/eclipse/pde/internal/core/target/IUBundleContainer.java (-181 / +91 lines)
Lines 190-300 Link Here
190
	 * @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#resolveBundles(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition, org.eclipse.core.runtime.IProgressMonitor)
190
	 * @see org.eclipse.pde.internal.core.target.impl.AbstractBundleContainer#resolveBundles(org.eclipse.pde.internal.core.target.provisional.ITargetDefinition, org.eclipse.core.runtime.IProgressMonitor)
191
	 */
191
	 */
192
	protected IResolvedBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
192
	protected IResolvedBundle[] resolveBundles(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
193
		// Resolving may change the included features, clear the cached values
193
		fFeatures = null; // Resolving may change the included features
194
		fFeatures = null;
194
		if (fIncludeAllRequired) {
195
195
			return resolveWithPlanner(definition, monitor);
196
		SubMonitor subMon = SubMonitor.convert(monitor, 100);
197
198
		// Attempt to restore from the profile first, as it is local and faster
199
		IResolvedBundle[] result = resolveWithProfile(definition, subMon.newChild(25));
200
		if (result != null) {
201
			subMon.done();
202
			return result;
203
		}
204
205
		// Unable to load from profile, resolve normally
206
		try {
207
			if (fIncludeAllRequired) {
208
				result = resolveWithPlanner(definition, subMon.newChild(75));
209
			} else {
210
				result = resolveWithSlicer(definition, subMon.newChild(75));
211
			}
212
			// If there is a problem generating the profile, delete it so it doesn't get used by #resolveWithProfile()
213
			if (result == null || result.length == 0 || subMon.isCanceled()) {
214
				AbstractTargetHandle handle = ((AbstractTargetHandle) definition.getHandle());
215
				handle.deleteProfile();
216
			}
217
			return result;
218
		} catch (CoreException e) {
219
			AbstractTargetHandle handle = ((AbstractTargetHandle) definition.getHandle());
220
			handle.deleteProfile();
221
			throw e;
222
		}
223
224
	}
225
226
	/**
227
	 * Used to resolve the contents of this container if the container has been resolved and saved to a profile file.  If the
228
	 * profile contains the correct bundles, there is no need to do a full resolve.  If this method has a problem (missing
229
	 * file, unable to compute all dependent bundles), this method will return <code>null</code> and the caller should 
230
	 * use {@link #resolveWithPlanner(ITargetDefinition, IProgressMonitor)} or {@link #resolveWithSlicer(ITargetDefinition, IProgressMonitor)} 
231
	 * to do a full resolve.
232
	 * 
233
	 * @param definition definition being resolved
234
	 * @param monitor for reporting progress
235
	 * @return set of bundles included in this container or <code>null</code> if the profile is out of date
236
	 * @throws CoreException if an unexpected problem occurs trying to read from the profile
237
	 */
238
	private IResolvedBundle[] resolveWithProfile(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
239
		IProfile profile = ((TargetDefinition) definition).getProfile();
240
		if (profile == null) {
241
			return null;
242
		}
243
244
		SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.IUBundleContainer_LoadingFromProfileJob, 20);
245
246
		// resolve IUs (similar to #getInstallableUnits but only checks the profile, no remote repositories
247
		if (fUnits == null) {
248
			fUnits = new IInstallableUnit[fIds.length];
249
			for (int i = 0; i < fIds.length; i++) {
250
				IQuery query = QueryUtil.createIUQuery(fIds[i], fVersions[i]);
251
				IQueryResult queryResult = profile.query(query, null);
252
				if (queryResult.isEmpty()) {
253
					// Missing a root unit in the profile
254
					fUnits = null;
255
					return null;
256
				}
257
				fUnits[i] = (IInstallableUnit) queryResult.iterator().next();
258
			}
259
		}
260
		IInstallableUnit[] units = fUnits;
261
262
		// slice IUs and all prerequisites
263
		PermissiveSlicer slicer = new PermissiveSlicer(profile, new Properties(), true, false, true, false, false);
264
		IQueryable slice = slicer.slice(units, new SubProgressMonitor(subMonitor, 10));
265
266
		// query for bundles
267
		Map bundles = generateResolvedBundles(slice, getBundlePool(profile), false);
268
269
		// If there are no resolved bundles from the profile, or a backing file was missing from the repository, do a normal resolve
270
		if (bundles == null || bundles.isEmpty()) {
271
			subMonitor.done();
272
			return null;
273
		}
274
275
		if (subMonitor.isCanceled()) {
276
			return null;
277
		}
278
279
		// Cache the feature list
280
		queryForFeatures(slice);
281
282
		if (subMonitor.isCanceled()) {
283
			return null;
284
		}
285
286
		removeDuplicateBundles(definition, bundles);
287
288
		// If there are no resolved bundles from the profile, do a normal resolve
289
		if (bundles.isEmpty()) {
290
			subMonitor.done();
291
			return null;
292
		}
196
		}
293
197
		return resolveWithSlicer(definition, monitor);
294
		subMonitor.worked(10);
295
		subMonitor.done();
296
297
		return (ResolvedBundle[]) bundles.values().toArray(new ResolvedBundle[bundles.size()]);
298
	}
198
	}
299
199
300
	/**
200
	/**
Lines 309-319 Link Here
309
	 */
209
	 */
310
	private IResolvedBundle[] resolveWithPlanner(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
210
	private IResolvedBundle[] resolveWithPlanner(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
311
		SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
211
		SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
312
		subMonitor.beginTask(Messages.IUBundleContainer_0, 200);
212
		subMonitor.beginTask(Messages.IUBundleContainer_0, 210);
313
213
314
		// retrieve profile
214
		// retrieve profile
315
		IProfile profile = ((TargetDefinition) definition).getProfile();
215
		IProfile profile = ((TargetDefinition) definition).getProfile();
316
		profile.getTimestamp();
317
		subMonitor.worked(10);
216
		subMonitor.worked(10);
318
217
319
		if (subMonitor.isCanceled()) {
218
		if (subMonitor.isCanceled()) {
Lines 344-350 Link Here
344
			return new IResolvedBundle[0];
243
			return new IResolvedBundle[0];
345
		}
244
		}
346
245
347
		IProvisioningPlan plan = planner.getProvisioningPlan(request, context, new SubProgressMonitor(subMonitor, 20));
246
		IProvisioningPlan plan = planner.getProvisioningPlan(request, context, new SubProgressMonitor(subMonitor, 10));
348
		IStatus status = plan.getStatus();
247
		IStatus status = plan.getStatus();
349
		if (!status.isOK()) {
248
		if (!status.isOK()) {
350
			throw new CoreException(status);
249
			throw new CoreException(status);
Lines 383-388 Link Here
383
			return new IResolvedBundle[0];
282
			return new IResolvedBundle[0];
384
		}
283
		}
385
284
285
		// query for bundles
286
		OSGiBundleQuery query = new OSGiBundleQuery();
287
		IQueryResult queryResult = slice.query(query, new SubProgressMonitor(subMonitor, 10));
288
289
		if (subMonitor.isCanceled()) {
290
			return new IResolvedBundle[0];
291
		}
292
386
		// Cache the feature list
293
		// Cache the feature list
387
		queryForFeatures(slice);
294
		queryForFeatures(slice);
388
295
Lines 390-404 Link Here
390
			return new IResolvedBundle[0];
297
			return new IResolvedBundle[0];
391
		}
298
		}
392
299
393
		// query for bundles
300
		Map bundles = new LinkedHashMap();
394
		Map bundles = generateResolvedBundles(slice, getBundlePool(profile), true);
301
		IFileArtifactRepository repo = getBundlePool(profile);
302
		for (Iterator iterator = queryResult.iterator(); iterator.hasNext();) {
303
			IInstallableUnit unit = (IInstallableUnit) iterator.next();
304
			Collection/*<IArtifactKey*/artifacts = unit.getArtifacts();
305
			for (Iterator iterator2 = artifacts.iterator(); iterator2.hasNext();) {
306
				File file = repo.getArtifactFile((IArtifactKey) iterator2.next());
307
				if (file == null) {
308
					// TODO: missing bundle
309
				} else {
310
					IResolvedBundle bundle = generateBundle(file);
311
					if (bundle != null) {
312
						bundles.put(bundle.getBundleInfo(), bundle);
313
					}
314
				}
315
			}
316
		}
395
317
396
		if (subMonitor.isCanceled()) {
318
		if (subMonitor.isCanceled()) {
397
			return new IResolvedBundle[0];
319
			return new IResolvedBundle[0];
398
		}
320
		}
399
321
400
		removeDuplicateBundles(definition, bundles);
322
		// remove all bundles from previous IU containers (so we don't get duplicates from multi-locations
401
323
		IBundleContainer[] containers = definition.getBundleContainers();
324
		for (int i = 0; i < containers.length; i++) {
325
			IBundleContainer container = containers[i];
326
			if (container == this) {
327
				break;
328
			}
329
			if (container instanceof IUBundleContainer) {
330
				IUBundleContainer bc = (IUBundleContainer) container;
331
				IResolvedBundle[] included = bc.getBundles();
332
				if (included != null) {
333
					for (int j = 0; j < included.length; j++) {
334
						bundles.remove(included[j].getBundleInfo());
335
					}
336
				}
337
			}
338
		}
402
		subMonitor.worked(10);
339
		subMonitor.worked(10);
403
		subMonitor.done();
340
		subMonitor.done();
404
		return (ResolvedBundle[]) bundles.values().toArray(new ResolvedBundle[bundles.size()]);
341
		return (ResolvedBundle[]) bundles.values().toArray(new ResolvedBundle[bundles.size()]);
Lines 416-422 Link Here
416
	 */
353
	 */
417
	private IResolvedBundle[] resolveWithSlicer(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
354
	private IResolvedBundle[] resolveWithSlicer(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
418
		SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
355
		SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
419
		subMonitor.beginTask(Messages.IUBundleContainer_0, 180);
356
		subMonitor.beginTask(Messages.IUBundleContainer_0, 200);
420
357
421
		// retrieve profile
358
		// retrieve profile
422
		IProfile profile = ((TargetDefinition) definition).getProfile();
359
		IProfile profile = ((TargetDefinition) definition).getProfile();
Lines 522-527 Link Here
522
			return new IResolvedBundle[0];
459
			return new IResolvedBundle[0];
523
		}
460
		}
524
461
462
		// query for bundles
463
		queryResult = slice.query(new OSGiBundleQuery(), new SubProgressMonitor(subMonitor, 10));
464
465
		if (subMonitor.isCanceled()) {
466
			return new IResolvedBundle[0];
467
		}
468
525
		// Cache the feature list
469
		// Cache the feature list
526
		queryForFeatures(slice);
470
		queryForFeatures(slice);
527
471
Lines 529-543 Link Here
529
			return new IResolvedBundle[0];
473
			return new IResolvedBundle[0];
530
		}
474
		}
531
475
532
		// query for bundles
476
		Map bundles = new LinkedHashMap();
533
		Map bundles = generateResolvedBundles(slice, getBundlePool(profile), true);
477
		IFileArtifactRepository repo = getBundlePool(profile);
478
		Iterator iterator = queryResult.iterator();
479
		while (iterator.hasNext()) {
480
			IInstallableUnit unit = (IInstallableUnit) iterator.next();
481
			Collection/*<IArtifactKey>*/artifacts = unit.getArtifacts();
482
			for (Iterator iterator2 = artifacts.iterator(); iterator2.hasNext();) {
483
				File file = repo.getArtifactFile((IArtifactKey) iterator2.next());
484
				if (file == null) {
485
					// TODO: missing bundle
486
				} else {
487
					IResolvedBundle bundle = generateBundle(file);
488
					if (bundle != null) {
489
						bundles.put(bundle.getBundleInfo(), bundle);
490
					}
491
				}
492
			}
493
		}
534
494
535
		if (subMonitor.isCanceled()) {
495
		if (subMonitor.isCanceled()) {
536
			return new IResolvedBundle[0];
496
			return new IResolvedBundle[0];
537
		}
497
		}
538
498
539
		removeDuplicateBundles(definition, bundles);
499
		// remove all bundles from previous IU containers (so we don't get duplicates from multi-locations
540
500
		IBundleContainer[] containers = definition.getBundleContainers();
501
		for (int i = 0; i < containers.length; i++) {
502
			IBundleContainer container = containers[i];
503
			if (container == this) {
504
				break;
505
			}
506
			if (container instanceof IUBundleContainer) {
507
				IUBundleContainer bc = (IUBundleContainer) container;
508
				IResolvedBundle[] included = bc.getBundles();
509
				if (included != null) {
510
					for (int j = 0; j < included.length; j++) {
511
						bundles.remove(included[j].getBundleInfo());
512
					}
513
				}
514
			}
515
		}
541
		subMonitor.worked(10);
516
		subMonitor.worked(10);
542
		subMonitor.done();
517
		subMonitor.done();
543
		return (ResolvedBundle[]) bundles.values().toArray(new ResolvedBundle[bundles.size()]);
518
		return (ResolvedBundle[]) bundles.values().toArray(new ResolvedBundle[bundles.size()]);
Lines 608-678 Link Here
608
	}
583
	}
609
584
610
	/**
585
	/**
611
	 * Checks all other bundle containers in the given target and removes any bundles provided by them from
612
	 * the map.  This prevents targets containing more than one IUBundleContainer from having duplicate bundles.
613
	 * 
614
	 * @param definition target definition to look for other containers in
615
	 * @param bundles collection of bundles arranged by mapping BundleInfo to IResolvedBundle
616
	 */
617
	private void removeDuplicateBundles(ITargetDefinition definition, Map bundles) {
618
		// remove all bundles from previous IU containers (so we don't get duplicates from multi-locations
619
		IBundleContainer[] containers = definition.getBundleContainers();
620
		for (int i = 0; i < containers.length; i++) {
621
			IBundleContainer container = containers[i];
622
			if (container == this) {
623
				break;
624
			}
625
			if (container instanceof IUBundleContainer) {
626
				IUBundleContainer bc = (IUBundleContainer) container;
627
				IResolvedBundle[] included = bc.getBundles();
628
				if (included != null) {
629
					for (int j = 0; j < included.length; j++) {
630
						bundles.remove(included[j].getBundleInfo());
631
					}
632
				}
633
			}
634
		}
635
	}
636
637
	/**
638
	 * Collects all available installable units from the given source that represent OSGI
639
	 * bundles.  A IResolvedBundle is created for each and a map containing all results
640
	 * mapping BundleInfo to IResolvedBundle is returned.
641
	 * <p>
642
	 * If there is an artifact missing for a unit it will either be ignored (not added to the returned map),
643
	 * or <code>null</code> will be returned depending on the ignoreMissingFiles parameter. 
644
	 * </p>
645
	 * @param source A queryable profile or slice that the bundle units will be obtained from
646
	 * @param ignoreMissingFiles if <code>true</code> ius that have missing artifacts will be ignored and not added to the map, if <code>false</code>, <code>null</code> will be returned
647
	 * @return map of BundleInfo to IResolvedBundle or <code>null</code> if a missing file is found and not ignored
648
	 * @throws CoreException
649
	 */
650
	private Map generateResolvedBundles(IQueryable source, IFileArtifactRepository repo, boolean ignoreMissingFiles) throws CoreException {
651
		OSGiBundleQuery query = new OSGiBundleQuery();
652
		IQueryResult queryResult = source.query(query, null);
653
		Map bundles = new LinkedHashMap();
654
		for (Iterator iterator = queryResult.iterator(); iterator.hasNext();) {
655
			IInstallableUnit unit = (IInstallableUnit) iterator.next();
656
			Collection artifacts = unit.getArtifacts();
657
			for (Iterator iterator2 = artifacts.iterator(); iterator2.hasNext();) {
658
				File file = repo.getArtifactFile((IArtifactKey) iterator2.next());
659
				if (file == null) {
660
					// Missing file
661
					if (!ignoreMissingFiles) {
662
						return null;
663
					}
664
				} else {
665
					IResolvedBundle bundle = generateBundle(file);
666
					if (bundle != null) {
667
						bundles.put(bundle.getBundleInfo(), bundle);
668
					}
669
				}
670
			}
671
		}
672
		return bundles;
673
	}
674
675
	/**
676
	 * Returns the metadata repository with the given URI.
586
	 * Returns the metadata repository with the given URI.
677
	 * 
587
	 * 
678
	 * @param uri location
588
	 * @param uri location
(-)src/org/eclipse/pde/internal/core/target/Messages.java (-1 lines)
Lines 39-45 Link Here
39
	public static String IUBundleContainer_5;
39
	public static String IUBundleContainer_5;
40
	public static String IUBundleContainer_6;
40
	public static String IUBundleContainer_6;
41
	public static String IUBundleContainer_7;
41
	public static String IUBundleContainer_7;
42
	public static String IUBundleContainer_LoadingFromProfileJob;
43
	public static String IUBundleContainer_ProblemsLoadingRepositories;
42
	public static String IUBundleContainer_ProblemsLoadingRepositories;
44
	public static String LoadTargetDefinitionJob_0;
43
	public static String LoadTargetDefinitionJob_0;
45
	public static String LoadTargetDefinitionJob_1;
44
	public static String LoadTargetDefinitionJob_1;
(-)src/org/eclipse/pde/internal/core/target/Messages.properties (-1 lines)
Lines 31-37 Link Here
31
IUBundleContainer_5=Provisioning planner not found
31
IUBundleContainer_5=Provisioning planner not found
32
IUBundleContainer_6=Target provisioning skipped install plan.
32
IUBundleContainer_6=Target provisioning skipped install plan.
33
IUBundleContainer_7=Provisioning agent not found
33
IUBundleContainer_7=Provisioning agent not found
34
IUBundleContainer_LoadingFromProfileJob=Loading target information from profile
35
IUBundleContainer_ProblemsLoadingRepositories=Problems loading repositories
34
IUBundleContainer_ProblemsLoadingRepositories=Problems loading repositories
36
LoadTargetDefinitionJob_0=Load Target Platform
35
LoadTargetDefinitionJob_0=Load Target Platform
37
LoadTargetDefinitionJob_1=Unable to resolve plug-ins in target definition
36
LoadTargetDefinitionJob_1=Unable to resolve plug-ins in target definition

Return to bug 276326