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/p2/tests/TestArtifactRepository.java (-3 / +2 lines)
Lines 13-20 Link Here
13
import java.util.*;
13
import java.util.*;
14
import junit.framework.Assert;
14
import junit.framework.Assert;
15
import org.eclipse.core.runtime.*;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest;
16
import org.eclipse.equinox.internal.p2.artifact.repository.*;
17
import org.eclipse.equinox.internal.p2.artifact.repository.Transport;
18
import org.eclipse.equinox.p2.artifact.repository.*;
17
import org.eclipse.equinox.p2.artifact.repository.*;
19
import org.eclipse.equinox.p2.artifact.repository.processing.ProcessingStepHandler;
18
import org.eclipse.equinox.p2.artifact.repository.processing.ProcessingStepHandler;
20
import org.eclipse.equinox.p2.core.repository.RepositoryCreationException;
19
import org.eclipse.equinox.p2.core.repository.RepositoryCreationException;
Lines 47-53 Link Here
47
	 */
46
	 */
48
	Set artifactDescriptors = new HashSet();
47
	Set artifactDescriptors = new HashSet();
49
48
50
	Transport testhandler = new Transport() {
49
	IArtifactTransport testhandler = new Transport() {
51
		public IStatus download(String toDownload, OutputStream target, IProgressMonitor pm) {
50
		public IStatus download(String toDownload, OutputStream target, IProgressMonitor pm) {
52
			byte[] contents = (byte[]) locationsToContents.get(toDownload);
51
			byte[] contents = (byte[]) locationsToContents.get(toDownload);
53
			if (contents == null)
52
			if (contents == null)
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties (+3 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.
31
downloading_requests=Downloading {0} request(s).
29
	
32
	
(-)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
	public static String downloading_requests;
45
}
47
}
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/Transport.java (-1 / +5 lines)
Lines 13-19 Link Here
13
import java.io.OutputStream;
13
import java.io.OutputStream;
14
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.equinox.p2.artifact.repository.IArtifactTransport;
16
17
17
public abstract class Transport {
18
public abstract class Transport implements IArtifactTransport {
19
	/* (non-Javadoc)
20
	 * @see org.eclipse.equinox.internal.p2.artifact.repository.IArtifactTransport#download(java.lang.String, java.io.OutputStream, org.eclipse.core.runtime.IProgressMonitor)
21
	 */
18
	public abstract IStatus download(String toDownload, OutputStream target, IProgressMonitor pm);
22
	public abstract IStatus download(String toDownload, OutputStream target, IProgressMonitor pm);
19
}
23
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 6-17 Link Here
6
Bundle-Localization: plugin
6
Bundle-Localization: plugin
7
Bundle-Version: 0.1.0.qualifier
7
Bundle-Version: 0.1.0.qualifier
8
Export-Package: org.eclipse.equinox.internal.p2.artifact.mirror;x-internal:=true,
8
Export-Package: org.eclipse.equinox.internal.p2.artifact.mirror;x-internal:=true,
9
 org.eclipse.equinox.internal.p2.artifact.repository;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.tests",
9
 org.eclipse.equinox.internal.p2.artifact.repository;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.artifact.dlmirrors,org.eclipse.equinox.p2.tests",
10
 org.eclipse.equinox.internal.p2.artifact.repository.simple;x-friends:="org.eclipse.equinox.p2.selfhosting,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.tests",
10
 org.eclipse.equinox.internal.p2.artifact.repository.simple;x-friends:="org.eclipse.equinox.p2.selfhosting,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.tests",
11
 org.eclipse.equinox.p2.artifact.repository,
11
 org.eclipse.equinox.p2.artifact.repository,
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/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java (-5 / +12 lines)
Lines 18-25 Link Here
18
import org.eclipse.equinox.internal.p2.artifact.repository.*;
18
import org.eclipse.equinox.internal.p2.artifact.repository.*;
19
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
19
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
20
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryIO;
20
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryIO;
21
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
21
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
22
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
22
import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository;
23
import org.eclipse.equinox.p2.artifact.repository.*;
23
import org.eclipse.equinox.p2.core.ProvisionException;
24
import org.eclipse.equinox.p2.core.ProvisionException;
24
import org.eclipse.osgi.util.NLS;
25
import org.eclipse.osgi.util.NLS;
25
26
Lines 42-52 Link Here
42
			boolean compress = true;
43
			boolean compress = true;
43
			try {
44
			try {
44
				artifacts = new BufferedOutputStream(new FileOutputStream(temp));
45
				artifacts = new BufferedOutputStream(new FileOutputStream(temp));
45
				IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
46
				IStatus status = getTransport(location).download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
46
				if (!status.isOK()) {
47
				if (!status.isOK()) {
47
					// retry uncompressed
48
					// retry uncompressed
48
					compress = false;
49
					compress = false;
49
					status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
50
					status = getTransport(location).download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100));
50
					if (!status.isOK())
51
					if (!status.isOK())
51
						throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null));
52
						throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null));
52
				}
53
				}
Lines 98-104 Link Here
98
		return new SimpleArtifactRepository(name, location);
99
		return new SimpleArtifactRepository(name, location);
99
	}
100
	}
100
101
101
	private Transport getTransport() {
102
	private IArtifactTransport getTransport(URL location) {
102
		return ECFTransport.getInstance();
103
		IArtifactTransport transport = null;
104
		IArtifactTransportFactory manager = (IArtifactTransportFactory) ServiceHelper.getService(Activator.getContext(), IArtifactTransportFactory.class.getName());
105
		if (manager != null)
106
			transport = manager.getTransport(location);
107
		if (transport == null)
108
			transport = ECFTransport.getInstance();
109
		return transport;
103
	}
110
	}
104
}
111
}
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java (-17 / +75 lines)
Lines 24-31 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, IMultiThreadedArtifactRepository {
29
30
30
	public class ArtifactOutputStream extends OutputStream implements IStateful {
31
	public class ArtifactOutputStream extends OutputStream implements IStateful {
31
		private boolean closed;
32
		private boolean closed;
Lines 159-168 Link Here
159
	protected Set artifactDescriptors = new HashSet();
160
	protected Set artifactDescriptors = new HashSet();
160
	private transient BlobStore blobStore;
161
	private transient BlobStore blobStore;
161
	transient private Mapper mapper = new Mapper();
162
	transient private Mapper mapper = new Mapper();
163
	transient private IArtifactTransport transport;
162
164
163
	static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$
165
	static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$
164
	static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$
166
	static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$
165
167
168
	static final private int DEFAULT_MAX_THREADS = 4;
169
166
	protected String[][] mappingRules = DEFAULT_MAPPING_RULES;
170
	protected String[][] mappingRules = DEFAULT_MAPPING_RULES;
167
171
168
	private boolean signatureVerification = false;
172
	private boolean signatureVerification = false;
Lines 379-385 Link Here
379
		return super.getAdapter(adapter);
383
		return super.getAdapter(adapter);
380
	}
384
	}
381
385
382
	private IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) {
386
	IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) {
383
		request.setSourceRepository(this);
387
		request.setSourceRepository(this);
384
		request.perform(monitor);
388
		request.perform(monitor);
385
		return request.getResult();
389
		return request.getResult();
Lines 429-448 Link Here
429
	}
433
	}
430
434
431
	public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
435
	public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) {
432
		SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length);
436
		final MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null);
433
		try {
437
		LinkedList requestsPending = new LinkedList(Arrays.asList(requests));
434
			MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null);
438
435
			for (int i = 0; i < requests.length; i++) {
439
		if (!isMultiThreadingEnabled() || requests.length <= 1) {
436
				if (monitor.isCanceled())
440
			// multi-threading isn't enabled or too few requests, use simple inline download of artifacts
437
					return Status.CANCEL_STATUS;
441
			SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length);
438
				IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1));
442
			try {
439
				if (!result.isOK())
443
				for (int i = 0; i < requests.length; i++) {
440
					overallStatus.add(result);
444
					if (monitor.isCanceled())
445
						return Status.CANCEL_STATUS;
446
					IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1));
447
					if (!result.isOK())
448
						overallStatus.add(result);
449
				}
450
			} finally {
451
				subMonitor.done();
452
			}
453
		} else {
454
			// initialize the various jobs needed to process the get artifact requests
455
			monitor.beginTask(NLS.bind(Messages.downloading_requests, new Integer(requests.length)), requests.length);
456
			try {
457
				// don't allocate more jobs than we have requests
458
				int numberOfJobs = Math.min(requests.length, getMaximumThreads());
459
				SimpleArtifactRepositoryDownloadJob jobs[] = new SimpleArtifactRepositoryDownloadJob[numberOfJobs];
460
				for (int i = 0; i < numberOfJobs; i++) {
461
					jobs[i] = new SimpleArtifactRepositoryDownloadJob("downloadjob-" + i); //$NON-NLS-1$
462
					jobs[i].initialize(this, requestsPending, monitor, overallStatus);
463
				}
464
				// schedule the various jobs
465
				for (int i = 0; i < numberOfJobs; i++) {
466
					jobs[i].schedule();
467
				}
468
				// wait for all the jobs to complete
469
				for (int i = 0; i < numberOfJobs; i++) {
470
					try {
471
						jobs[i].join();
472
					} catch (InterruptedException e) {
473
						synchronized (overallStatus) {
474
							overallStatus.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.download_thread_interrupted, jobs[i].getName())));
475
						}
476
					}
477
				}
478
			} finally {
479
				monitor.done();
441
			}
480
			}
442
			return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus);
443
		} finally {
444
			subMonitor.done();
445
		}
481
		}
482
		return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus);
446
	}
483
	}
447
484
448
	public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) {
485
	public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) {
Lines 507-512 Link Here
507
		return null;
544
		return null;
508
	}
545
	}
509
546
547
	private int getMaximumThreads() {
548
		try {
549
			Object value = getProperties().get(PROP_MAX_THREADS);
550
			if (value != null && value instanceof String)
551
				return Math.max(1, Integer.parseInt((String) getProperties().get(PROP_MAX_THREADS)));
552
		} catch (NumberFormatException nfe) {
553
			// return default number of threads
554
		}
555
		return DEFAULT_MAX_THREADS;
556
	}
557
510
	public OutputStream getOutputStream(IArtifactDescriptor descriptor) {
558
	public OutputStream getOutputStream(IArtifactDescriptor descriptor) {
511
		assertModifiable();
559
		assertModifiable();
512
		// TODO we need a better way of distinguishing between errors and cases where 
560
		// TODO we need a better way of distinguishing between errors and cases where 
Lines 577-584 Link Here
577
		return signatureVerification;
625
		return signatureVerification;
578
	}
626
	}
579
627
580
	private Transport getTransport() {
628
	private IArtifactTransport getTransport() {
581
		return ECFTransport.getInstance();
629
		if (transport == null) {
630
			IArtifactTransportFactory manager = (IArtifactTransportFactory) ServiceHelper.getService(Activator.getContext(), IArtifactTransportFactory.class.getName());
631
			if (manager != null)
632
				transport = manager.getTransport(getLocation());
633
			if (transport == null)
634
				transport = ECFTransport.getInstance();
635
		}
636
		return transport;
582
	}
637
	}
583
638
584
	// use this method to setup any transient fields etc after the object has been restored from a stream
639
	// use this method to setup any transient fields etc after the object has been restored from a stream
Lines 615-620 Link Here
615
		return isLocal();
670
		return isLocal();
616
	}
671
	}
617
672
673
	public boolean isMultiThreadingEnabled() {
674
		return !isLocal() && getMaximumThreads() > 1;
675
	}
676
618
	public OutputStream processDestination(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
677
	public OutputStream processDestination(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
619
		destination = addPostSteps(handler, descriptor, destination, monitor);
678
		destination = addPostSteps(handler, descriptor, destination, monitor);
620
		destination = handler.createAndLink(descriptor.getProcessingSteps(), descriptor, destination, monitor);
679
		destination = handler.createAndLink(descriptor.getProcessingSteps(), descriptor, destination, monitor);
Lines 752-756 Link Here
752
	public String toString() {
811
	public String toString() {
753
		return location.toExternalForm();
812
		return location.toExternalForm();
754
	}
813
	}
755
756
}
814
}
(-)src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirrorsDelegate.java (+19 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.p2.artifact.repository.dlmirrors;
10
11
import java.net.URL;
12
13
public interface IDownloadMirrorsDelegate {
14
15
	boolean worksWith(URL artifactRepoLocation);
16
17
	IDownloadMirror determineDownloadMirror(String toDownload);
18
19
}
(-)src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransport.java (+24 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Genuitec, LLC 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
 *     Genuitec, LLC - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.artifact.repository;
12
13
import java.io.OutputStream;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16
17
public interface IArtifactTransport {
18
19
	/**
20
	 * Download the given artifact to the specified output stream.
21
	 */
22
	public IStatus download(String toDownload, OutputStream target, IProgressMonitor pm);
23
24
}
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/ECFTransportWithMirrors.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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;
10
11
import java.io.OutputStream;
12
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.equinox.p2.artifact.repository.IArtifactTransport;
15
import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirror;
16
import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirrorsDelegate;
17
18
/**
19
 * A transport implementation that looks up a download mirror before
20
 * calling down to the ECF transport implementation.
21
 */
22
public class ECFTransportWithMirrors implements IArtifactTransport {
23
24
	private final IDownloadMirrorsDelegate downloadMirrorsDelegate;
25
26
	public ECFTransportWithMirrors(IDownloadMirrorsDelegate delegate) {
27
		this.downloadMirrorsDelegate = delegate;
28
	}
29
30
	public IStatus download(String toDownload, OutputStream target, IProgressMonitor monitor) {
31
32
		// use a download mirror if available
33
		IDownloadMirror mirror = downloadMirrorsDelegate.determineDownloadMirror(toDownload);
34
		if (mirror != null) {
35
			IStatus result = ECFTransport.getInstance().download(mirror.getLocation(toDownload), target, monitor);
36
			mirror.reportStatus(result);
37
			return result;
38
		}
39
40
		return ECFTransport.getInstance().download(toDownload, target, monitor);
41
	}
42
}
(-)src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransportFactory.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.p2.artifact.repository;
10
11
import java.net.URL;
12
import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirrorsDelegate;
13
14
public interface IArtifactTransportFactory {
15
16
	/**
17
	 * Determine and return the transport for the specified base location.
18
	 * Return null if a default transport should be used by the consuming
19
	 * artifact repository.
20
	 */
21
	public IArtifactTransport getTransport(URL artifactRepoLocation);
22
23
	/**
24
	 * Register the specified download mirrors delegate which can provide
25
	 * mirrors for one or more artifact repositories.
26
	 */
27
	public void registerDownloadMirrors(IDownloadMirrorsDelegate downloadMirrorsDelegate);
28
}
(-)src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirror.java (+19 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.p2.artifact.repository.dlmirrors;
10
11
import org.eclipse.core.runtime.IStatus;
12
13
public interface IDownloadMirror {
14
15
	String getLocation(String toDownload);
16
17
	void reportStatus(IStatus result);
18
19
}
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryDownloadJob.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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
}
(-)src/org/eclipse/equinox/p2/artifact/repository/IMultiThreadedArtifactRepository.java (+27 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Genuitec, LLC 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
 *     Genuitec, LLC - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.artifact.repository;
12
13
public interface IMultiThreadedArtifactRepository extends IArtifactRepository {
14
15
	/** 
16
	 * The property key for a integer property controls the maximum number
17
	 * of threads that should be used when optimizing downloads from a remote
18
	 * artifact repository.
19
	 */
20
	static public String PROP_MAX_THREADS = "p2.max.threads"; //$NON-NLS-1$
21
22
	/**
23
	 * Indicates if the artifact repository may choose to use multiple threads
24
	 * when a request is received for multiple artifacts.
25
	 */
26
	public boolean isMultiThreadingEnabled();
27
}
(-)src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactTransportFactory.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 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.spi.p2.artifact.repository;
10
11
import java.net.URL;
12
import java.util.*;
13
import org.eclipse.equinox.internal.p2.artifact.repository.ECFTransport;
14
import org.eclipse.equinox.internal.p2.artifact.repository.ECFTransportWithMirrors;
15
import org.eclipse.equinox.p2.artifact.repository.IArtifactTransport;
16
import org.eclipse.equinox.p2.artifact.repository.IArtifactTransportFactory;
17
import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirrorsDelegate;
18
19
public class SimpleArtifactTransportFactory implements IArtifactTransportFactory {
20
21
	private Set delegates = new HashSet();
22
23
	public IArtifactTransport getTransport(URL artifactRepoLocation) {
24
		for (Iterator iter = delegates.iterator(); iter.hasNext();) {
25
			IDownloadMirrorsDelegate delegate = (IDownloadMirrorsDelegate) iter.next();
26
			if (delegate.worksWith(artifactRepoLocation))
27
				return new ECFTransportWithMirrors(delegate);
28
		}
29
		return ECFTransport.getInstance();
30
	}
31
32
	public void registerDownloadMirrors(IDownloadMirrorsDelegate downloadMirrorsDelegate) {
33
		delegates.add(downloadMirrorsDelegate);
34
	}
35
}

Return to bug 207802