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 207802 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties (+2 lines)
Lines 26-29 Link Here
26
repoMan_internalError=Internal error.
26
repoMan_internalError=Internal error.
27
repoMan_notExists=No repository found at {0}.
27
repoMan_notExists=No repository found at {0}.
28
repoMan_unknownType=Unknown repository type at {0}.
28
repoMan_unknownType=Unknown repository type at {0}.
29
30
download_thread_interrupted=Download thread {0} was interrupted, incomplete artifact retrieval.
29
	
31
	
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java (+2 lines)
Lines 42-45 Link Here
42
	public static String io_incompatibleVersion;
42
	public static String io_incompatibleVersion;
43
	public static String mirroring;
43
	public static String mirroring;
44
44
45
	public static String download_thread_interrupted;
46
45
}
47
}
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 12-17 Link Here
12
 org.eclipse.equinox.p2.artifact.repository.processing,
12
 org.eclipse.equinox.p2.artifact.repository.processing,
13
 org.eclipse.equinox.spi.p2.artifact.repository
13
 org.eclipse.equinox.spi.p2.artifact.repository
14
Import-Package: javax.xml.parsers,
14
Import-Package: javax.xml.parsers,
15
 org.eclipse.core.runtime.jobs,
15
 org.eclipse.core.runtime.preferences;resolution:=optional,
16
 org.eclipse.core.runtime.preferences;resolution:=optional,
16
 org.eclipse.equinox.app;version="1.0.0",
17
 org.eclipse.equinox.app;version="1.0.0",
17
 org.eclipse.equinox.internal.p2.core.helpers,
18
 org.eclipse.equinox.internal.p2.core.helpers,
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java (-13 / +46 lines)
Lines 24-29 Link Here
24
import org.eclipse.equinox.p2.core.ProvisionException;
24
import org.eclipse.equinox.p2.core.ProvisionException;
25
import org.eclipse.equinox.p2.metadata.IArtifactKey;
25
import org.eclipse.equinox.p2.metadata.IArtifactKey;
26
import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository;
26
import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository;
27
import org.eclipse.osgi.util.NLS;
27
28
28
public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository {
29
public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository {
29
30
Lines 379-385 Link Here
379
		return super.getAdapter(adapter);
380
		return super.getAdapter(adapter);
380
	}
381
	}
381
382
382
	private IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) {
383
	IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) {
383
		request.setSourceRepository(this);
384
		request.setSourceRepository(this);
384
		request.perform(monitor);
385
		request.perform(monitor);
385
		return request.getResult();
386
		return request.getResult();
Lines 429-448 Link Here
429
	}
430
	}
430
431
431
	public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
432
	public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
432
		SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length);
433
		final MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null);
433
		try {
434
		LinkedList requestsPending = new LinkedList(Arrays.asList(requests));
434
			MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null);
435
435
			for (int i = 0; i < requests.length; i++) {
436
		// TODO : Determine number of threads to use from a property
436
				if (monitor.isCanceled())
437
		int numberOfJobs = Math.min(requests.length, 4); // magic number
437
					return Status.CANCEL_STATUS;
438
		if (numberOfJobs <= 1) {
438
				IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1));
439
			SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length);
439
				if (!result.isOK())
440
			try {
440
					overallStatus.add(result);
441
				for (int i = 0; i < requests.length; i++) {
442
					if (monitor.isCanceled())
443
						return Status.CANCEL_STATUS;
444
					IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1));
445
					if (!result.isOK())
446
						overallStatus.add(result);
447
				}
448
			} finally {
449
				subMonitor.done();
450
			}
451
		} else {
452
			// initialize the various jobs needed to process the get artifact requests
453
			monitor.beginTask("Download " + requests.length + " artifacts", requests.length);
454
			try {
455
				SimpleArtifactRepositoryDownloadJob jobs[] = new SimpleArtifactRepositoryDownloadJob[numberOfJobs];
456
				for (int i = 0; i < numberOfJobs; i++) {
457
					jobs[i] = new SimpleArtifactRepositoryDownloadJob("downloadjob-" + i);
458
					jobs[i].initialize(this, requestsPending, monitor, overallStatus);
459
				}
460
				// schedule the various jobs
461
				for (int i = 0; i < numberOfJobs; i++) {
462
					jobs[i].schedule();
463
				}
464
				// wait for all the jobs to complete
465
				for (int i = 0; i < numberOfJobs; i++) {
466
					try {
467
						jobs[i].join();
468
					} catch (InterruptedException e) {
469
						synchronized (overallStatus) {
470
							overallStatus.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.download_thread_interrupted, jobs[i].getName())));
471
						}
472
					}
473
				}
474
			} finally {
475
				monitor.done();
441
			}
476
			}
442
			return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus);
443
		} finally {
444
			subMonitor.done();
445
		}
477
		}
478
		return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus);
446
	}
479
	}
447
480
448
	public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) {
481
	public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) {
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryDownloadJob.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 Genuitec, LLC and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: Genuitec, LLC - initial API and implementation
8
 ******************************************************************************/
9
package org.eclipse.equinox.internal.p2.artifact.repository.simple;
10
11
import java.util.LinkedList;
12
import org.eclipse.core.runtime.*;
13
import org.eclipse.core.runtime.jobs.Job;
14
import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest;
15
import org.eclipse.equinox.p2.artifact.repository.IArtifactRequest;
16
17
public class SimpleArtifactRepositoryDownloadJob extends Job {
18
19
	private LinkedList requestsPending;
20
	private SimpleArtifactRepository repository;
21
	private IProgressMonitor masterMonitor;
22
	private MultiStatus overallStatus;
23
24
	SimpleArtifactRepositoryDownloadJob(String name) {
25
		super(name);
26
		setSystem(true);
27
	}
28
29
	void initialize(SimpleArtifactRepository repository, LinkedList requestsPending, IProgressMonitor masterMonitor, MultiStatus overallStatus) {
30
		this.repository = repository;
31
		this.requestsPending = requestsPending;
32
		this.masterMonitor = masterMonitor;
33
		this.overallStatus = overallStatus;
34
	}
35
36
	protected IStatus run(IProgressMonitor jobMonitor) {
37
		jobMonitor.beginTask("Downloading artifacts", 1);
38
		boolean workRemaining = false;
39
		do {
40
			// get the request we are going to process
41
			IArtifactRequest request;
42
			synchronized (requestsPending) {
43
				if (requestsPending.isEmpty())
44
					break;
45
				request = (IArtifactRequest) requestsPending.removeFirst();
46
			}
47
			if (masterMonitor.isCanceled())
48
				return Status.CANCEL_STATUS;
49
50
			// prepare a progress monitor that reports to both the master monitor and for the job
51
			IProgressMonitor monitor = new NullProgressMonitor();
52
			// progress monitor updating from getArtifact() doesn't seem to be working
53
			masterMonitor.subTask("Downloading " + request.getArtifactKey().getId() + ".");
54
55
			// process the actual request
56
			IStatus status = repository.getArtifact((ArtifactRequest) request, monitor);
57
			if (!status.isOK()) {
58
				synchronized (overallStatus) {
59
					overallStatus.add(status);
60
				}
61
			}
62
63
			// update progress
64
			masterMonitor.worked(1);
65
		} while (true);
66
67
		jobMonitor.done();
68
		return Status.OK_STATUS;
69
	}
70
}

Return to bug 207802