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

(-).settings/org.eclipse.pde.core.prefs (-2 / +3 lines)
Lines 1-4 Link Here
1
1
#Mon Oct 29 09:10:03 EDT 2007
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
pluginProject.extensions=false
3
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
4
pluginProject.extensions=true
4
resolve.requirebundle=false
5
resolve.requirebundle=false
(-)src/org/eclipse/equinox/internal/p2/download/DownloadActivator.java (-4 / +10 lines)
Lines 10-30 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.download;
11
package org.eclipse.equinox.internal.p2.download;
12
12
13
import org.osgi.framework.BundleActivator;
13
import org.eclipse.equinox.internal.p2.download.strategy.DownloadStrategyManager;
14
import org.osgi.framework.BundleContext;
14
import org.eclipse.equinox.p2.download.strategy.IDownloadStrategyManager;
15
import org.osgi.framework.*;
15
16
16
public class DownloadActivator implements BundleActivator {
17
public class DownloadActivator implements BundleActivator {
17
	public static final String ID = "org.eclipse.equinox.p2.download";
18
	public static final String ID = "org.eclipse.equinox.p2.download";
18
19
19
	public static BundleContext context;
20
	public static BundleContext context;
20
21
22
	private ServiceRegistration strategyManagerRegistration;
23
21
	public void start(BundleContext context) throws Exception {
24
	public void start(BundleContext context) throws Exception {
22
		DownloadActivator.context = context;
25
		DownloadActivator.context = context;
23
26
		DownloadStrategyManager strategyManager = new DownloadStrategyManager();
27
		strategyManagerRegistration = context.registerService(IDownloadStrategyManager.class.getName(), strategyManager, null);
24
	}
28
	}
25
29
26
	public void stop(BundleContext context) throws Exception {
30
	public void stop(BundleContext context) throws Exception {
27
		DownloadActivator.context = null;
31
		DownloadActivator.context = null;
32
		if (strategyManagerRegistration != null)
33
			strategyManagerRegistration.unregister();
34
		strategyManagerRegistration = null;
28
	}
35
	}
29
30
}
36
}
(-)src/org/eclipse/equinox/p2/download/DownloadManager.java (-33 / +74 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.download;
11
package org.eclipse.equinox.p2.download;
12
12
13
import java.util.ArrayList;
13
import java.util.*;
14
import java.util.Iterator;
15
import org.eclipse.core.runtime.*;
14
import org.eclipse.core.runtime.*;
16
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
15
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
17
import org.eclipse.equinox.internal.p2.download.DownloadActivator;
16
import org.eclipse.equinox.internal.p2.download.DownloadActivator;
18
import org.eclipse.equinox.p2.artifact.repository.*;
17
import org.eclipse.equinox.p2.artifact.repository.*;
18
import org.eclipse.equinox.p2.download.strategy.*;
19
19
20
public class DownloadManager {
20
public class DownloadManager {
21
	ArrayList requestsToProcess = new ArrayList();
21
	ArrayList requestsToProcess = new ArrayList();
Lines 51-94 Link Here
51
		try {
51
		try {
52
			if (requestsToProcess.isEmpty())
52
			if (requestsToProcess.isEmpty())
53
				return Status.OK_STATUS;
53
				return Status.OK_STATUS;
54
55
			IDownloadStrategyManager strategyMgr = (IDownloadStrategyManager) ServiceHelper.getService(DownloadActivator.context, IDownloadStrategyManager.class.getName());
56
			IDownloadStrategy[] strategies = strategyMgr.getKnownStrategies();
57
			if (strategies.length == 0)
58
				return new Status(IStatus.ERROR, DownloadActivator.ID, "No strategy available");
59
54
			IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(DownloadActivator.context, IArtifactRepositoryManager.class.getName());
60
			IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(DownloadActivator.context, IArtifactRepositoryManager.class.getName());
55
			IArtifactRepository[] repositories = repoMgr.getKnownRepositories();
61
			IArtifactRepository[] repositories = repoMgr.getKnownRepositories();
56
			if (repositories.length == 0)
62
			if (repositories.length == 0)
57
				return new Status(IStatus.ERROR, DownloadActivator.ID, "No repository available");
63
				return new Status(IStatus.ERROR, DownloadActivator.ID, "No repository available");
58
			// TODO for now ensure that we try local repos first
64
59
			if (!fetch(sortRepositories(repositories, true), subMonitor))
65
			// determine which strategies will work best for these repositories
60
				return overallStatus(monitor);
66
			StrategyRequests[] strategyRequests = determineStrategies(monitor, strategies, repositories);
61
			// TODO then try the othe repositories.
67
62
			fetch(sortRepositories(repositories, false), subMonitor);
68
			// delegate work to the various strategies
69
			for (int i = 0; i < strategyRequests.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) {
70
				IStatus dlStatus = strategyRequests[i].process(subMonitor);
71
				if (dlStatus.getSeverity() == IStatus.CANCEL)
72
					return overallStatus(monitor);
73
				filterUnfetched();
74
				subMonitor.setWorkRemaining(requestsToProcess.size());
75
				//				notifyFetched();
76
			}
63
			return overallStatus(monitor);
77
			return overallStatus(monitor);
64
		} finally {
78
		} finally {
65
			subMonitor.done();
79
			subMonitor.done();
66
		}
80
		}
67
	}
81
	}
68
82
69
	private IArtifactRepository[] sortRepositories(IArtifactRepository[] repositories, boolean local) {
83
	private StrategyRequests[] determineStrategies(IProgressMonitor monitor, IDownloadStrategy[] strategies, IArtifactRepository[] repositories) {
70
		ArrayList result = new ArrayList(repositories.length);
84
		StrategyRequests[] strategyRequests = new StrategyRequests[strategies.length];
71
		for (int i = 0; i < repositories.length; i++) {
85
		for (int i = 0; i < repositories.length && !monitor.isCanceled(); i++) {
72
			IArtifactRepository repository = repositories[i];
73
			if (local && repository.getLocation().getProtocol().equals("file"))
74
				result.add(repository);
75
			else if (!local && !repository.getLocation().getProtocol().equals("file"))
76
				result.add(repository);
77
		}
78
		return (IArtifactRepository[]) result.toArray(new IArtifactRepository[result.size()]);
79
	}
80
81
	private boolean fetch(IArtifactRepository[] repositories, SubMonitor monitor) {
82
		for (int i = 0; i < repositories.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) {
83
			IArtifactRequest[] requests = getRequestsForRepository(repositories[i]);
86
			IArtifactRequest[] requests = getRequestsForRepository(repositories[i]);
84
			IStatus dlStatus = repositories[i].getArtifacts(requests, monitor.newChild(requests.length));
87
			if (requests.length == 0)
85
			if (dlStatus.getSeverity() == IStatus.CANCEL)
88
				continue;
86
				return false;
89
87
			filterUnfetched();
90
			IDownloadStrategy bestStrategy = null;
88
			monitor.setWorkRemaining(requestsToProcess.size());
91
			int strategyIdx = -1;
89
			//				notifyFetched();
92
			for (int j = 0; j < strategies.length; j++) {
93
				if (!strategies[j].supportsRepository(repositories[i]))
94
					break;
95
				if (bestStrategy == null || strategies[j].isBetterThan(bestStrategy, repositories[i])) {
96
					bestStrategy = strategies[j];
97
					strategyIdx = j;
98
				}
99
			}
100
			if (bestStrategy == null)
101
				continue;
102
103
			if (strategyRequests[strategyIdx] == null)
104
				strategyRequests[strategyIdx] = new StrategyRequests(strategies[strategyIdx]);
105
			strategyRequests[strategyIdx].queueWork(repositories[i], requests);
90
		}
106
		}
91
		return true;
107
108
		List toUse = new ArrayList(strategyRequests.length);
109
		for (int i = 0; i < strategyRequests.length; i++)
110
			if (strategyRequests[i] != null)
111
				toUse.add(strategyRequests[i]);
112
		return (StrategyRequests[]) toUse.toArray(new StrategyRequests[toUse.size()]);
92
	}
113
	}
93
114
94
	private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository) {
115
	private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository) {
Lines 115-126 Link Here
115
		if (requestsToProcess.size() == 0)
136
		if (requestsToProcess.size() == 0)
116
			return Status.OK_STATUS;
137
			return Status.OK_STATUS;
117
138
118
		MultiStatus result = new MultiStatus(DownloadActivator.ID, IStatus.OK, null, null);
139
		MultiStatus result = new MultiStatus();
119
		for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) {
140
		for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) {
120
			IStatus failed = ((IArtifactRequest) iterator.next()).getResult();
141
			IArtifactRequest failed = (IArtifactRequest) iterator.next();
121
			if (failed != null && !failed.isOK())
142
			result.add(failed.getResult());
122
				result.add(failed);
123
		}
143
		}
124
		return result;
144
		return result;
125
	}
145
	}
126
}
146
147
	private static final class StrategyRequests {
148
149
		private final IDownloadStrategy strategy;
150
		private final List strategyRequests = new ArrayList();
151
		private final Set totalRequests = new HashSet();
152
153
		StrategyRequests(IDownloadStrategy strategy) {
154
			this.strategy = strategy;
155
		}
156
157
		void queueWork(IArtifactRepository artifactRepository, IArtifactRequest[] requests) {
158
			totalRequests.addAll(Arrays.asList(requests));
159
			strategyRequests.add(new DownloadStrategyRequests(artifactRepository, requests));
160
		}
161
162
		IStatus process(SubMonitor subMonitor) {
163
			DownloadStrategyRequests requests[] = (DownloadStrategyRequests[]) strategyRequests.toArray(new DownloadStrategyRequests[strategyRequests.size()]);
164
			return strategy.getArtifacts(requests, subMonitor.newChild(totalRequests.size()));
165
		}
166
	}
167
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 7-13 Link Here
7
Bundle-Version: 0.1.0.qualifier
7
Bundle-Version: 0.1.0.qualifier
8
Export-Package: org.eclipse.equinox.internal.p2.download;x-internal:=true,
8
Export-Package: org.eclipse.equinox.internal.p2.download;x-internal:=true,
9
 org.eclipse.equinox.p2.download
9
 org.eclipse.equinox.p2.download
10
Require-Bundle: org.eclipse.equinox.common
10
Require-Bundle: org.eclipse.equinox.common,
11
 org.eclipse.equinox.registry
11
Import-Package: org.eclipse.equinox.internal.p2.core,
12
Import-Package: org.eclipse.equinox.internal.p2.core,
12
 org.eclipse.equinox.internal.p2.core.helpers,
13
 org.eclipse.equinox.internal.p2.core.helpers,
13
 org.eclipse.equinox.p2.artifact.repository,
14
 org.eclipse.equinox.p2.artifact.repository,
(-)src/org/eclipse/equinox/p2/download/strategy/IDownloadStrategy.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.download.strategy;
12
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository;
16
17
/**
18
 * Provides a strategy that understands how to perform downloading from one or more
19
 * repositories.
20
 */
21
public interface IDownloadStrategy {
22
23
	boolean supportsRepository(IArtifactRepository artifactRepository);
24
25
	boolean isBetterThan(IDownloadStrategy other, IArtifactRepository artifactRepository);
26
27
	IStatus getArtifacts(DownloadStrategyRequests[] requests, IProgressMonitor monitor);
28
}
(-)src/org/eclipse/equinox/p2/download/strategy/DownloadStrategyRequests.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.download.strategy;
12
13
import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository;
14
import org.eclipse.equinox.p2.artifact.repository.IArtifactRequest;
15
16
public class DownloadStrategyRequests {
17
18
	private final IArtifactRepository artifactRepository;
19
	private final IArtifactRequest[] requests;
20
21
	public DownloadStrategyRequests(IArtifactRepository artifactRepository, IArtifactRequest[] requests) {
22
		this.artifactRepository = artifactRepository;
23
		this.requests = requests;
24
	}
25
26
	public IArtifactRepository getRepository() {
27
		return artifactRepository;
28
	}
29
30
	public IArtifactRequest[] getRequests() {
31
		return requests;
32
	}
33
}
(-)plugin.xml (+12 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.2"?>
3
<plugin>
4
   <extension-point id="downloadStrategies" name="Download Strategies" schema="schema/downloadStrategies.exsd"/>
5
   <extension
6
         point="org.eclipse.equinox.p2.download.downloadStrategies">
7
      <strategy
8
            class="org.eclipse.equinox.internal.p2.download.strategy.SimpleDownloadStrategy">
9
      </strategy>
10
   </extension>
11
12
</plugin>
(-)src/org/eclipse/equinox/internal/p2/download/strategy/SimpleDownloadStrategy.java (+76 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.internal.p2.download.strategy;
12
13
import java.util.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository;
16
import org.eclipse.equinox.p2.artifact.repository.IArtifactRequest;
17
import org.eclipse.equinox.p2.download.strategy.DownloadStrategyRequests;
18
import org.eclipse.equinox.p2.download.strategy.IDownloadStrategy;
19
20
/**
21
 * The simplest download strategy that can work with all repository formats
22
 * and is better than no other repository -- single threaded, sequential through
23
 * the various artifacts until all requests are processed. 
24
 */
25
public class SimpleDownloadStrategy implements IDownloadStrategy {
26
27
	public IStatus getArtifacts(DownloadStrategyRequests[] requests, IProgressMonitor monitor) {
28
29
		Set requestsToProcess = new HashSet();
30
		for (int i = 0; i < requests.length; i++)
31
			requestsToProcess.addAll(Arrays.asList(requests[i].getRequests()));
32
		SubMonitor subMonitor = SubMonitor.convert(monitor, "Downloading artifacts", requestsToProcess.size());
33
34
		for (int i = 0; i < requests.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) {
35
			IStatus dlStatus = requests[i].getRepository().getArtifacts(requests[i].getRequests(), subMonitor.newChild(requests[i].getRequests().length));
36
			if (dlStatus.getSeverity() == IStatus.CANCEL)
37
				return overallStatus(requestsToProcess, monitor);
38
			filterUnfetched(requestsToProcess);
39
			subMonitor.setWorkRemaining(requestsToProcess.size());
40
		}
41
42
		return overallStatus(requestsToProcess, monitor);
43
	}
44
45
	public boolean isBetterThan(IDownloadStrategy other, IArtifactRepository artifactRepository) {
46
		return false;
47
	}
48
49
	public boolean supportsRepository(IArtifactRepository artifactRepository) {
50
		return true;
51
	}
52
53
	private void filterUnfetched(Set requestsToProcess) {
54
		for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) {
55
			IArtifactRequest request = (IArtifactRequest) iterator.next();
56
			if (request.getResult() != null && request.getResult().isOK()) {
57
				iterator.remove();
58
			}
59
		}
60
	}
61
62
	private IStatus overallStatus(Set requestsToProcess, IProgressMonitor monitor) {
63
		if (monitor.isCanceled())
64
			return Status.CANCEL_STATUS;
65
66
		if (requestsToProcess.size() == 0)
67
			return Status.OK_STATUS;
68
69
		MultiStatus result = new MultiStatus();
70
		for (Iterator iterator = requestsToProcess.iterator(); iterator.hasNext();) {
71
			IArtifactRequest failed = (IArtifactRequest) iterator.next();
72
			result.add(failed.getResult());
73
		}
74
		return result;
75
	}
76
}
(-)src/org/eclipse/equinox/p2/download/strategy/IDownloadStrategyManager.java (+20 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.download.strategy;
12
13
public interface IDownloadStrategyManager {
14
15
	IDownloadStrategy[] getKnownStrategies();
16
17
	void add(IDownloadStrategy strategy);
18
19
	void remove(IDownloadStrategy strategy);
20
}
(-)schema/downloadStrategies.exsd (+105 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.equinox.p2.download">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.equinox.p2.download" id="downloadStrategies" name="Download Strategies"/>
7
      </appInfo>
8
      <documentation>
9
         Definition of strategies that understand how to efficiently download software from a set of artifact repositories.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <complexType>
15
         <sequence minOccurs="1" maxOccurs="unbounded">
16
            <element ref="strategy"/>
17
         </sequence>
18
         <attribute name="point" type="string" use="required">
19
            <annotation>
20
               <documentation>
21
                  
22
               </documentation>
23
            </annotation>
24
         </attribute>
25
         <attribute name="id" type="string">
26
            <annotation>
27
               <documentation>
28
                  
29
               </documentation>
30
            </annotation>
31
         </attribute>
32
         <attribute name="name" type="string">
33
            <annotation>
34
               <documentation>
35
                  
36
               </documentation>
37
               <appInfo>
38
                  <meta.attribute translatable="true"/>
39
               </appInfo>
40
            </annotation>
41
         </attribute>
42
      </complexType>
43
   </element>
44
45
   <element name="strategy">
46
      <complexType>
47
         <attribute name="class" type="string" use="required">
48
            <annotation>
49
               <documentation>
50
                  
51
               </documentation>
52
               <appInfo>
53
                  <meta.attribute kind="java" basedOn=":org.eclipse.equinox.p2.download.strategy.IDownloadStrategy"/>
54
               </appInfo>
55
            </annotation>
56
         </attribute>
57
      </complexType>
58
   </element>
59
60
   <annotation>
61
      <appInfo>
62
         <meta.section type="since"/>
63
      </appInfo>
64
      <documentation>
65
         [Enter the first release in which this extension point appears.]
66
      </documentation>
67
   </annotation>
68
69
   <annotation>
70
      <appInfo>
71
         <meta.section type="examples"/>
72
      </appInfo>
73
      <documentation>
74
         [Enter extension point usage example here.]
75
      </documentation>
76
   </annotation>
77
78
   <annotation>
79
      <appInfo>
80
         <meta.section type="apiInfo"/>
81
      </appInfo>
82
      <documentation>
83
         [Enter API information here.]
84
      </documentation>
85
   </annotation>
86
87
   <annotation>
88
      <appInfo>
89
         <meta.section type="implementation"/>
90
      </appInfo>
91
      <documentation>
92
         [Enter information about supplied implementation of this extension point.]
93
      </documentation>
94
   </annotation>
95
96
   <annotation>
97
      <appInfo>
98
         <meta.section type="copyright"/>
99
      </appInfo>
100
      <documentation>
101
         
102
      </documentation>
103
   </annotation>
104
105
</schema>
(-)src/org/eclipse/equinox/internal/p2/download/strategy/ThreadedDownloadStrategy.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.internal.p2.download.strategy;
12
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository;
16
import org.eclipse.equinox.p2.artifact.repository.IArtifactRepositoryWithRangeSupport;
17
import org.eclipse.equinox.p2.download.strategy.DownloadStrategyRequests;
18
import org.eclipse.equinox.p2.download.strategy.IDownloadStrategy;
19
20
/** 
21
 * Place holder implementation for the threaded download strategy that will utilize
22
 * knowledge about certain artificat repositories for greater overall throughput.
23
 */
24
public class ThreadedDownloadStrategy implements IDownloadStrategy {
25
26
	public IStatus getArtifacts(DownloadStrategyRequests[] requests, IProgressMonitor monitor) {
27
		// TODO Auto-generated method stub
28
		return null;
29
	}
30
31
	public boolean isBetterThan(IDownloadStrategy other, IArtifactRepository artifactRepository) {
32
		// TODO Auto-generated method stub
33
		return false;
34
	}
35
36
	public boolean supportsRepository(IArtifactRepository artifactRepository) {
37
		return artifactRepository instanceof IArtifactRepositoryWithRangeSupport;
38
	}
39
}
(-)src/org/eclipse/equinox/internal/p2/download/strategy/DownloadStrategyManager.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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.internal.p2.download.strategy;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.RegistryFactory;
17
import org.eclipse.equinox.internal.p2.download.DownloadActivator;
18
import org.eclipse.equinox.p2.download.strategy.IDownloadStrategy;
19
import org.eclipse.equinox.p2.download.strategy.IDownloadStrategyManager;
20
21
public class DownloadStrategyManager implements IDownloadStrategyManager {
22
23
	private List strategies = new ArrayList();
24
25
	public DownloadStrategyManager() {
26
		IConfigurationElement[] elt = RegistryFactory.getRegistry().getConfigurationElementsFor(DownloadActivator.ID + ".downloadStrategies");
27
		for (int i = 0; i < elt.length; i++) {
28
			try {
29
				strategies.add((IDownloadStrategy) elt[i].createExecutableExtension("class"));
30
			} catch (Exception e) {
31
				// should do something with this
32
				e.printStackTrace();
33
			}
34
		}
35
	}
36
37
	public void add(IDownloadStrategy strategy) {
38
		strategies.add(strategy);
39
	}
40
41
	public void remove(IDownloadStrategy strategy) {
42
		strategies.remove(strategy);
43
	}
44
45
	public IDownloadStrategy[] getKnownStrategies() {
46
		return (IDownloadStrategy[]) strategies.toArray(new IDownloadStrategy[strategies.size()]);
47
	}
48
}

Return to bug 207802