|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.p2.internal.repository.tools; |
11 |
package org.eclipse.equinox.p2.internal.repository.tools; |
| 12 |
|
12 |
|
|
|
13 |
import java.net.URI; |
| 13 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
| 14 |
import java.util.Iterator; |
15 |
import java.util.Iterator; |
| 15 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.core.runtime.*; |
|
Lines 17-32
Link Here
|
| 17 |
import org.eclipse.equinox.app.IApplicationContext; |
18 |
import org.eclipse.equinox.app.IApplicationContext; |
| 18 |
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring; |
19 |
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring; |
| 19 |
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; |
20 |
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; |
|
|
21 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
| 22 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; |
| 20 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
23 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
|
|
24 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager; |
| 21 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; |
25 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; |
| 22 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; |
26 |
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; |
| 23 |
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; |
27 |
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; |
|
|
28 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; |
| 24 |
import org.eclipse.equinox.internal.provisional.p2.query.Collector; |
29 |
import org.eclipse.equinox.internal.provisional.p2.query.Collector; |
| 25 |
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable; |
30 |
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable; |
| 26 |
|
31 |
|
| 27 |
public class MirrorApplication extends AbstractApplication { |
32 |
public class MirrorApplication extends AbstractApplication { |
| 28 |
protected SlicingOptions slicingOptions = new SlicingOptions(); |
33 |
protected SlicingOptions slicingOptions = new SlicingOptions(); |
| 29 |
|
34 |
|
|
|
35 |
private URI baseline; |
| 36 |
//private URI baseline; |
| 37 |
private String comparatorID; |
| 38 |
private boolean compare = false; |
| 39 |
private boolean failOnError = true; |
| 40 |
private boolean raw = true; |
| 41 |
private boolean verbose = false; |
| 42 |
|
| 30 |
public Object start(IApplicationContext context) throws Exception { |
43 |
public Object start(IApplicationContext context) throws Exception { |
| 31 |
run(null); |
44 |
run(null); |
| 32 |
return IApplication.EXIT_OK; |
45 |
return IApplication.EXIT_OK; |
|
Lines 36-54
Link Here
|
| 36 |
try { |
49 |
try { |
| 37 |
validate(); |
50 |
validate(); |
| 38 |
initializeRepos(new NullProgressMonitor()); |
51 |
initializeRepos(new NullProgressMonitor()); |
|
|
52 |
intializeIUs(); |
| 39 |
IQueryable slice = slice(new NullProgressMonitor()); |
53 |
IQueryable slice = slice(new NullProgressMonitor()); |
| 40 |
IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); |
54 |
if (destinationArtifactRepository != null) { |
| 41 |
if (mirrorStatus.getSeverity() == IStatus.ERROR) { |
55 |
IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); |
| 42 |
return mirrorStatus; |
56 |
if (mirrorStatus.getSeverity() == IStatus.ERROR) { |
|
|
57 |
return mirrorStatus; |
| 58 |
} |
| 43 |
} |
59 |
} |
| 44 |
mirrorMetadata(slice, new NullProgressMonitor()); |
60 |
if (destinationMetadataRepository != null) |
|
|
61 |
mirrorMetadata(slice, new NullProgressMonitor()); |
| 45 |
} finally { |
62 |
} finally { |
| 46 |
finalizeRepositories(); |
63 |
finalizeRepositories(); |
| 47 |
} |
64 |
} |
| 48 |
return Status.OK_STATUS; |
65 |
return Status.OK_STATUS; |
| 49 |
} |
66 |
} |
| 50 |
|
67 |
|
| 51 |
private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) { |
68 |
private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException { |
| 52 |
Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor); |
69 |
Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor); |
| 53 |
ArrayList keys = new ArrayList(ius.size()); |
70 |
ArrayList keys = new ArrayList(ius.size()); |
| 54 |
for (Iterator iterator = ius.iterator(); iterator.hasNext();) { |
71 |
for (Iterator iterator = ius.iterator(); iterator.hasNext();) { |
|
Lines 58-66
Link Here
|
| 58 |
keys.add(iuKeys[i]); |
75 |
keys.add(iuKeys[i]); |
| 59 |
} |
76 |
} |
| 60 |
} |
77 |
} |
| 61 |
Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true); |
78 |
Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw); |
|
|
79 |
|
| 80 |
mirror.setCompare(compare); |
| 81 |
mirror.setComparatorId(comparatorID); |
| 82 |
mirror.setBaseline(initializeBaseline()); |
| 62 |
mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()])); |
83 |
mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()])); |
| 63 |
return mirror.run(true, false); |
84 |
|
|
|
85 |
return mirror.run(failOnError, verbose); |
| 86 |
} |
| 87 |
|
| 88 |
private IArtifactRepository initializeBaseline() throws ProvisionException { |
| 89 |
if (baseline == null) |
| 90 |
return null; |
| 91 |
IArtifactRepositoryManager mgr = Activator.getArtifactRepositoryManager(); |
| 92 |
|
| 93 |
if (!mgr.contains(baseline)) |
| 94 |
artifactReposToRemove.add(baseline); |
| 95 |
return mgr.loadRepository(baseline, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); |
| 64 |
} |
96 |
} |
| 65 |
|
97 |
|
| 66 |
private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) { |
98 |
private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) { |
|
Lines 77-85
Link Here
|
| 77 |
private void validate() throws ProvisionException { |
109 |
private void validate() throws ProvisionException { |
| 78 |
if (sourceMetadataRepositories == null) |
110 |
if (sourceMetadataRepositories == null) |
| 79 |
throw new ProvisionException("Need to set the source metadata repository location."); |
111 |
throw new ProvisionException("Need to set the source metadata repository location."); |
| 80 |
if (sourceIUs == null) |
112 |
} |
| 81 |
throw new ProvisionException("Mirroring root needs to be specified."); |
113 |
|
| 82 |
//TODO Check that the IU is in repo |
114 |
/* |
|
|
115 |
* If no IUs have been specified we want to mirror them all |
| 116 |
*/ |
| 117 |
private void intializeIUs() throws ProvisionException { |
| 118 |
if (sourceIUs == null || sourceIUs.isEmpty()) { |
| 119 |
sourceIUs = new ArrayList(); |
| 120 |
IMetadataRepository metadataRepo = getCompositeMetadataRepository(); |
| 121 |
Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null); |
| 122 |
|
| 123 |
for (Iterator iter = collector.iterator(); iter.hasNext();) { |
| 124 |
IInstallableUnit iu = (IInstallableUnit) iter.next(); |
| 125 |
sourceIUs.add(iu); |
| 126 |
} |
| 127 |
|
| 128 |
if (collector.size() == 0) { |
| 129 |
throw new ProvisionException("No IUs specified and no IUs obtained from metadata repositories."); |
| 130 |
} |
| 131 |
} else { |
| 132 |
//TODO Check that the IU is in repo |
| 133 |
} |
| 83 |
} |
134 |
} |
| 84 |
|
135 |
|
| 85 |
private IQueryable slice(IProgressMonitor monitor) { |
136 |
private IQueryable slice(IProgressMonitor monitor) { |
|
Lines 92-95
Link Here
|
| 92 |
public void setSlicingOptions(SlicingOptions options) { |
143 |
public void setSlicingOptions(SlicingOptions options) { |
| 93 |
slicingOptions = options; |
144 |
slicingOptions = options; |
| 94 |
} |
145 |
} |
|
|
146 |
|
| 147 |
/* |
| 148 |
* Set the location of the baseline repository. (used in comparison) |
| 149 |
*/ |
| 150 |
public void setBaseline(URI baseline) { |
| 151 |
this.baseline = baseline; |
| 152 |
compare = true; |
| 153 |
} |
| 154 |
|
| 155 |
/* |
| 156 |
* Set the identifier of the comparator to use. |
| 157 |
*/ |
| 158 |
public void setComparatorID(String value) { |
| 159 |
comparatorID = value; |
| 160 |
compare = true; |
| 161 |
} |
| 162 |
|
| 163 |
/* |
| 164 |
* Set whether or not the application should be calling a comparator when mirroring. |
| 165 |
*/ |
| 166 |
public void setCompare(boolean value) { |
| 167 |
compare = value; |
| 168 |
} |
| 169 |
|
| 170 |
/* |
| 171 |
* Set whether or not we should ignore errors when running the mirror application. |
| 172 |
*/ |
| 173 |
public void setIgnoreErrors(boolean value) { |
| 174 |
failOnError = !value; |
| 175 |
} |
| 176 |
|
| 177 |
/* |
| 178 |
* Set whether or not the the artifacts are raw. |
| 179 |
*/ |
| 180 |
public void setRaw(boolean value) { |
| 181 |
raw = value; |
| 182 |
} |
| 183 |
|
| 184 |
/* |
| 185 |
* Set whether or not the mirror application should be run in verbose mode. |
| 186 |
*/ |
| 187 |
public void setVerbose(boolean value) { |
| 188 |
verbose = value; |
| 189 |
} |
| 95 |
} |
190 |
} |