|
Lines 10-22
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.download.DownloadActivator; |
15 |
import org.eclipse.equinox.internal.p2.download.DownloadActivator; |
| 17 |
import org.eclipse.equinox.p2.artifact.repository.*; |
16 |
import org.eclipse.equinox.p2.artifact.repository.*; |
| 18 |
import org.eclipse.equinox.p2.core.helpers.MultiStatus; |
17 |
import org.eclipse.equinox.p2.core.helpers.MultiStatus; |
| 19 |
import org.eclipse.equinox.p2.core.helpers.ServiceHelper; |
18 |
import org.eclipse.equinox.p2.core.helpers.ServiceHelper; |
|
|
19 |
import org.eclipse.equinox.p2.download.strategy.*; |
| 20 |
|
20 |
|
| 21 |
public class DownloadManager { |
21 |
public class DownloadManager { |
| 22 |
ArrayList requestsToProcess = new ArrayList(); |
22 |
ArrayList requestsToProcess = new ArrayList(); |
|
Lines 52-64
Link Here
|
| 52 |
try { |
52 |
try { |
| 53 |
if (requestsToProcess.isEmpty()) |
53 |
if (requestsToProcess.isEmpty()) |
| 54 |
return Status.OK_STATUS; |
54 |
return Status.OK_STATUS; |
|
|
55 |
|
| 56 |
IDownloadStrategyManager strategyMgr = (IDownloadStrategyManager) ServiceHelper.getService(DownloadActivator.context, IDownloadStrategyManager.class.getName()); |
| 57 |
IDownloadStrategy[] strategies = strategyMgr.getKnownStrategies(); |
| 58 |
if (strategies.length == 0) |
| 59 |
return new Status(IStatus.ERROR, DownloadActivator.ID, "No strategy available"); |
| 60 |
|
| 55 |
IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(DownloadActivator.context, IArtifactRepositoryManager.class.getName()); |
61 |
IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) ServiceHelper.getService(DownloadActivator.context, IArtifactRepositoryManager.class.getName()); |
| 56 |
IArtifactRepository[] repositories = repoMgr.getKnownRepositories(); |
62 |
IArtifactRepository[] repositories = repoMgr.getKnownRepositories(); |
| 57 |
if (repositories.length == 0) |
63 |
if (repositories.length == 0) |
| 58 |
return new Status(IStatus.ERROR, DownloadActivator.ID, "No repository available"); |
64 |
return new Status(IStatus.ERROR, DownloadActivator.ID, "No repository available"); |
| 59 |
for (int i = 0; i < repositories.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) { |
65 |
|
| 60 |
IArtifactRequest[] requests = getRequestsForRepository(repositories[i]); |
66 |
// determine which strategies will work best for these repositories |
| 61 |
IStatus dlStatus = repositories[i].getArtifacts(requests, subMonitor.newChild(requests.length)); |
67 |
StrategyRequests[] strategyRequests = determineStrategies(monitor, strategies, repositories); |
|
|
68 |
|
| 69 |
// delegate work to the various strategies |
| 70 |
for (int i = 0; i < strategyRequests.length && !requestsToProcess.isEmpty() && !monitor.isCanceled(); i++) { |
| 71 |
IStatus dlStatus = strategyRequests[i].process(subMonitor); |
| 62 |
if (dlStatus.getSeverity() == IStatus.CANCEL) |
72 |
if (dlStatus.getSeverity() == IStatus.CANCEL) |
| 63 |
return overallStatus(monitor); |
73 |
return overallStatus(monitor); |
| 64 |
filterUnfetched(); |
74 |
filterUnfetched(); |
|
Lines 71-76
Link Here
|
| 71 |
} |
81 |
} |
| 72 |
} |
82 |
} |
| 73 |
|
83 |
|
|
|
84 |
private StrategyRequests[] determineStrategies(IProgressMonitor monitor, IDownloadStrategy[] strategies, IArtifactRepository[] repositories) { |
| 85 |
StrategyRequests[] strategyRequests = new StrategyRequests[strategies.length]; |
| 86 |
for (int i = 0; i < repositories.length && !monitor.isCanceled(); i++) { |
| 87 |
IArtifactRequest[] requests = getRequestsForRepository(repositories[i]); |
| 88 |
if (requests.length == 0) |
| 89 |
continue; |
| 90 |
|
| 91 |
IDownloadStrategy bestStrategy = null; |
| 92 |
int strategyIdx = -1; |
| 93 |
for (int j = 0; j < strategies.length; j++) { |
| 94 |
if (!strategies[j].supportsRepository(repositories[i])) |
| 95 |
break; |
| 96 |
if (bestStrategy == null || strategies[j].isBetterThan(bestStrategy, repositories[i])) { |
| 97 |
bestStrategy = strategies[j]; |
| 98 |
strategyIdx = j; |
| 99 |
} |
| 100 |
} |
| 101 |
if (bestStrategy == null) |
| 102 |
continue; |
| 103 |
|
| 104 |
if (strategyRequests[strategyIdx] == null) |
| 105 |
strategyRequests[strategyIdx] = new StrategyRequests(strategies[strategyIdx]); |
| 106 |
strategyRequests[strategyIdx].queueWork(repositories[i], requests); |
| 107 |
} |
| 108 |
|
| 109 |
List toUse = new ArrayList(strategyRequests.length); |
| 110 |
for (int i = 0; i < strategyRequests.length; i++) |
| 111 |
if (strategyRequests[i] != null) |
| 112 |
toUse.add(strategyRequests[i]); |
| 113 |
return (StrategyRequests[]) toUse.toArray(new StrategyRequests[toUse.size()]); |
| 114 |
} |
| 115 |
|
| 74 |
private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository) { |
116 |
private IArtifactRequest[] getRequestsForRepository(IArtifactRepository repository) { |
| 75 |
ArrayList applicable = new ArrayList(); |
117 |
ArrayList applicable = new ArrayList(); |
| 76 |
for (Iterator it = requestsToProcess.iterator(); it.hasNext();) { |
118 |
for (Iterator it = requestsToProcess.iterator(); it.hasNext();) { |
|
Lines 102-105
Link Here
|
| 102 |
} |
144 |
} |
| 103 |
return result; |
145 |
return result; |
| 104 |
} |
146 |
} |
| 105 |
} |
147 |
|
|
|
148 |
private static final class StrategyRequests { |
| 149 |
|
| 150 |
private final IDownloadStrategy strategy; |
| 151 |
private final List strategyRequests = new ArrayList(); |
| 152 |
private final Set totalRequests = new HashSet(); |
| 153 |
|
| 154 |
StrategyRequests(IDownloadStrategy strategy) { |
| 155 |
this.strategy = strategy; |
| 156 |
} |
| 157 |
|
| 158 |
void queueWork(IArtifactRepository artifactRepository, IArtifactRequest[] requests) { |
| 159 |
totalRequests.addAll(Arrays.asList(requests)); |
| 160 |
strategyRequests.add(new DownloadStrategyRequests(artifactRepository, requests)); |
| 161 |
} |
| 162 |
|
| 163 |
IStatus process(SubMonitor subMonitor) { |
| 164 |
DownloadStrategyRequests requests[] = (DownloadStrategyRequests[]) strategyRequests.toArray(new DownloadStrategyRequests[strategyRequests.size()]); |
| 165 |
return strategy.getArtifacts(requests, subMonitor.newChild(totalRequests.size())); |
| 166 |
} |
| 167 |
} |
| 168 |
} |