|
Lines 13-21
Link Here
|
| 13 |
|
13 |
|
| 14 |
import java.net.URI; |
14 |
import java.net.URI; |
| 15 |
import java.util.*; |
15 |
import java.util.*; |
| 16 |
import org.eclipse.core.runtime.Assert; |
16 |
import org.eclipse.core.runtime.*; |
| 17 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
| 18 |
import org.eclipse.equinox.internal.p2.operations.Activator; |
17 |
import org.eclipse.equinox.internal.p2.operations.Activator; |
|
|
18 |
import org.eclipse.equinox.internal.p2.operations.Messages; |
| 19 |
import org.eclipse.equinox.p2.core.IProvisioningAgent; |
19 |
import org.eclipse.equinox.p2.core.IProvisioningAgent; |
| 20 |
import org.eclipse.equinox.p2.core.ProvisionException; |
20 |
import org.eclipse.equinox.p2.core.ProvisionException; |
| 21 |
import org.eclipse.equinox.p2.engine.*; |
21 |
import org.eclipse.equinox.p2.engine.*; |
|
Lines 23-28
Link Here
|
| 23 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
23 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
| 24 |
import org.eclipse.equinox.p2.metadata.IVersionedId; |
24 |
import org.eclipse.equinox.p2.metadata.IVersionedId; |
| 25 |
import org.eclipse.equinox.p2.query.*; |
25 |
import org.eclipse.equinox.p2.query.*; |
|
|
26 |
import org.eclipse.osgi.util.NLS; |
| 26 |
import org.osgi.framework.InvalidSyntaxException; |
27 |
import org.osgi.framework.InvalidSyntaxException; |
| 27 |
import org.osgi.framework.ServiceReference; |
28 |
import org.osgi.framework.ServiceReference; |
| 28 |
|
29 |
|
|
Lines 42-76
Link Here
|
| 42 |
//ignore can't happen since we write the filter ourselves |
43 |
//ignore can't happen since we write the filter ourselves |
| 43 |
} |
44 |
} |
| 44 |
if (ref == null || ref.size() == 0) |
45 |
if (ref == null || ref.size() == 0) |
| 45 |
throw new IllegalStateException("p2 is not configured properly. No provisioning agent could be found."); |
46 |
throw new IllegalStateException(Messages.OperationFactory_noAgent); |
| 46 |
IProvisioningAgent agent = Activator.getContext().getService(ref.iterator().next()); |
47 |
IProvisioningAgent agent = Activator.getContext().getService(ref.iterator().next()); |
| 47 |
Activator.getContext().ungetService(ref.iterator().next()); |
48 |
Activator.getContext().ungetService(ref.iterator().next()); |
| 48 |
return agent; |
49 |
return agent; |
| 49 |
} |
50 |
} |
| 50 |
|
51 |
|
| 51 |
private Collection<IInstallableUnit> gatherIUs(ProvisioningContext context, Collection<IVersionedId> ius, IProgressMonitor monitor) { |
52 |
//Return a list of IUs from the list of versionedIDs originally provided |
| 52 |
Collection<IInstallableUnit> unitsToInstall = new ArrayList<IInstallableUnit>(ius.size()); |
53 |
private Collection<IInstallableUnit> gatherIUs(IQueryable<IInstallableUnit> searchContext, Collection<IVersionedId> ius, boolean checkIUs, IProgressMonitor monitor) throws ProvisionException { |
|
|
54 |
Collection<IInstallableUnit> gatheredIUs = new ArrayList<IInstallableUnit>(ius.size()); |
| 53 |
|
55 |
|
| 54 |
for (IVersionedId versionedId : ius) { |
56 |
for (IVersionedId versionedId : ius) { |
| 55 |
if (ius instanceof IInstallableUnit) { |
57 |
if (!checkIUs && versionedId instanceof IInstallableUnit) { |
| 56 |
unitsToInstall.add((IInstallableUnit) versionedId); |
58 |
gatheredIUs.add((IInstallableUnit) versionedId); |
| 57 |
continue; |
59 |
continue; |
| 58 |
} |
60 |
} |
| 59 |
|
61 |
|
| 60 |
IQuery<IInstallableUnit> installableUnits = QueryUtil.createIUQuery(versionedId.getId(), versionedId.getVersion()); |
62 |
IQuery<IInstallableUnit> installableUnits = QueryUtil.createIUQuery(versionedId.getId(), versionedId.getVersion()); |
| 61 |
IQueryResult<IInstallableUnit> matches = context.getMetadata(monitor).query(installableUnits, monitor); |
63 |
IQueryResult<IInstallableUnit> matches = searchContext.query(installableUnits, monitor); |
| 62 |
// if (ius.isEmpty()) |
64 |
if (matches.isEmpty()) |
| 63 |
// Do something smart. like throw an exception |
65 |
throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.OperationFactory_noIUFound, versionedId))); |
|
|
66 |
|
| 64 |
//Add the first IU |
67 |
//Add the first IU |
| 65 |
Iterator<IInstallableUnit> iuIt = matches.iterator(); |
68 |
Iterator<IInstallableUnit> iuIt = matches.iterator(); |
| 66 |
unitsToInstall.add(iuIt.next()); |
69 |
gatheredIUs.add(iuIt.next()); |
| 67 |
|
|
|
| 68 |
if (iuIt.hasNext()) { |
| 69 |
// TODO |
| 70 |
System.out.println("Log the fact that we have a problem"); |
| 71 |
} |
| 72 |
} |
70 |
} |
| 73 |
return unitsToInstall; |
71 |
return gatheredIUs; |
| 74 |
} |
72 |
} |
| 75 |
|
73 |
|
| 76 |
private ProvisioningContext createProvisioningContext(Collection<URI> repos, IProvisioningAgent agent) { |
74 |
private ProvisioningContext createProvisioningContext(Collection<URI> repos, IProvisioningAgent agent) { |
|
Lines 92-102
Link Here
|
| 92 |
public InstallOperation createInstallOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { |
90 |
public InstallOperation createInstallOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { |
| 93 |
Assert.isNotNull(toInstall); |
91 |
Assert.isNotNull(toInstall); |
| 94 |
IProvisioningAgent agent = getAgent(); |
92 |
IProvisioningAgent agent = getAgent(); |
|
|
93 |
|
| 95 |
//add the repos |
94 |
//add the repos |
| 96 |
ProvisioningContext ctx = createProvisioningContext(repos, agent); |
95 |
ProvisioningContext ctx = createProvisioningContext(repos, agent); |
| 97 |
|
96 |
|
| 98 |
//find the ius to install and create the operation |
97 |
//find the ius to install and create the operation |
| 99 |
InstallOperation resultingOperation = new InstallOperation(new ProvisioningSession(agent), gatherIUs(ctx, toInstall, monitor)); |
98 |
InstallOperation resultingOperation = new InstallOperation(new ProvisioningSession(agent), gatherIUs(ctx.getMetadata(monitor), toInstall, false, monitor)); |
| 100 |
resultingOperation.setProvisioningContext(ctx); |
99 |
resultingOperation.setProvisioningContext(ctx); |
| 101 |
resultingOperation.setProfileId(IProfileRegistry.SELF); |
100 |
resultingOperation.setProfileId(IProfileRegistry.SELF); |
| 102 |
|
101 |
|
|
Lines 116-122
Link Here
|
| 116 |
ProvisioningContext ctx = createProvisioningContext(repos, agent); |
115 |
ProvisioningContext ctx = createProvisioningContext(repos, agent); |
| 117 |
|
116 |
|
| 118 |
//find the ius to uninstall and create the operation |
117 |
//find the ius to uninstall and create the operation |
| 119 |
UninstallOperation resultingOperation = new UninstallOperation(new ProvisioningSession(agent), gatherIUs(ctx, toUninstall, monitor)); |
118 |
UninstallOperation resultingOperation = new UninstallOperation(new ProvisioningSession(agent), gatherIUs(listInstalledElements(false, monitor), toUninstall, true, monitor)); |
| 120 |
resultingOperation.setProvisioningContext(ctx); |
119 |
resultingOperation.setProvisioningContext(ctx); |
| 121 |
resultingOperation.setProfileId(IProfileRegistry.SELF); |
120 |
resultingOperation.setProfileId(IProfileRegistry.SELF); |
| 122 |
|
121 |
|
|
Lines 149-155
Link Here
|
| 149 |
ProvisioningContext ctx = createProvisioningContext(repos, agent); |
148 |
ProvisioningContext ctx = createProvisioningContext(repos, agent); |
| 150 |
|
149 |
|
| 151 |
//find the ius to update and create the operation |
150 |
//find the ius to update and create the operation |
| 152 |
UpdateOperation resultingOperation = new UpdateOperation(new ProvisioningSession(agent), toUpdate == null ? null : gatherIUs(ctx, toUpdate, monitor)); |
151 |
UpdateOperation resultingOperation = new UpdateOperation(new ProvisioningSession(agent), toUpdate == null ? null : gatherIUs(listInstalledElements(false, monitor), toUpdate, false, monitor)); |
| 153 |
resultingOperation.setProvisioningContext(ctx); |
152 |
resultingOperation.setProvisioningContext(ctx); |
| 154 |
resultingOperation.setProfileId(IProfileRegistry.SELF); |
153 |
resultingOperation.setProfileId(IProfileRegistry.SELF); |
| 155 |
|
154 |
|
|
Lines 161-167
Link Here
|
| 161 |
* @param toInstall the elements to install. This can not be null. |
160 |
* @param toInstall the elements to install. This can not be null. |
| 162 |
* @param repos the repositories to install the elements from. |
161 |
* @param repos the repositories to install the elements from. |
| 163 |
* @param monitor the progress monitor |
162 |
* @param monitor the progress monitor |
| 164 |
* @return an instance of {@link InstallOperation}. |
163 |
* @return an instance of {@link SynchronizeOperation}. |
| 165 |
*/ |
164 |
*/ |
| 166 |
public SynchronizeOperation createSynchronizeOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { |
165 |
public SynchronizeOperation createSynchronizeOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { |
| 167 |
IProvisioningAgent agent = getAgent(); |
166 |
IProvisioningAgent agent = getAgent(); |
|
Lines 171-177
Link Here
|
| 171 |
if (toInstall == null) |
170 |
if (toInstall == null) |
| 172 |
iusToInstall = ctx.getMetadata(monitor).query(QueryUtil.createIUGroupQuery(), monitor).toUnmodifiableSet(); |
171 |
iusToInstall = ctx.getMetadata(monitor).query(QueryUtil.createIUGroupQuery(), monitor).toUnmodifiableSet(); |
| 173 |
else |
172 |
else |
| 174 |
iusToInstall = gatherIUs(ctx, toInstall, monitor); |
173 |
iusToInstall = gatherIUs(ctx.getMetadata(monitor), toInstall, false, monitor); |
| 175 |
|
174 |
|
| 176 |
SynchronizeOperation resultingOperation = new SynchronizeOperation(new ProvisioningSession(agent), iusToInstall); |
175 |
SynchronizeOperation resultingOperation = new SynchronizeOperation(new ProvisioningSession(agent), iusToInstall); |
| 177 |
resultingOperation.setProvisioningContext(ctx); |
176 |
resultingOperation.setProvisioningContext(ctx); |