I'm trying to do a headless update at startup for my product com.example.product, which contains com.,example.feature which contains com.example.plugin. Here's the error I'm getting in my logs, and the code generating it follows that. It seems to be picking up the update site and the IUs ok, but then can't find the artifact.
(P2Util.java:139) - Got IU from metadata manager com.example.product 1.0.1
(P2Util.java:139) - Got IU from metadata manager com.example.feature.feature.group 1.0.1
(P2Util.java:130) - Found 1 repositories in artifacts
(P2Util.java:122) - Got repository file:/C:/workspace/example-product/p2/org.eclipse.equinox.p2.core/cache/
(P2Util.java:88) - Status is Status OK: unknown code=0 OK null
(P2Util.java:96) - Update is Update com.example.product 1.0.0 ==> com.example.product 1.0.1
(ApplicationWorkbenchWindowAdvisor.java:162) - Update status is:Status ERROR: org.eclipse.equinox.p2.engine code=4 An error occurred while collecting items to be installed null children=[Status ERROR: org.eclipse.equinox.p2.engine code=0 session context was:(profile="" phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action="" null Status ERROR: org.eclipse.equinox.p2.artifact.repository code=0 No repository found containing: osgi.bundle,com.example.plugin,1.0.1 null Status ERROR: org.eclipse.equinox.p2.artifact.repository code=0 No repository found containing: org.eclipse.update.feature,com.example.feature,1.0.1 null Status ERROR: org.eclipse.equinox.p2.artifact.repository code=0 No repository found containing: binary,com.example.product.executable.win32.win32.x86,1.0.1 null]
The binary folder in my update site contains "com.example.product.executable.win32.win32.x86_1.0.1" The artifact.xml inside artifact.jar contains:
<artifact classifier="binary" id="com.example.product.executable.win32.win32.x86" version="1.0.1">
<properties size="1">
<property name="download.size" value="23179" />
</properties>
</artifact>
and
<artifact classifier="org.eclipse.update.feature" id="com.example.feature" version="1.0.1">
<properties size="4">
<property name="artifact.size" value="1087" />
<property name="download.size" value="1087" />
<property name="download.md5" value="21511ebfa1cd6769cccf6debd7cfdb4b" />
<property name="download.contentType" value="application/zip" />
</properties>
</artifact>
and an entry for the plugin too.
Here's my code in P2Util:
public class P2Util {
private static final String UPDATE_URI = "http://localhost/";
private static final Logger logger = Logger.getLogger( P2Util.class );
// XXX Check for updates to this application and return a status.
static IStatus checkForUpdates(IProvisioningAgent agent,
IProgressMonitor monitor) throws OperationCanceledException,
InvocationTargetException {
addUpdateSite(agent);
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
logRepositories(metadataManager);
IQueryResult<IInstallableUnit> ius = queryIusFromMetadataManager(metadataManager);
ProvisioningSession session = new ProvisioningSession(agent);
UpdateOperation operation = new UpdateOperation(session);
SubMonitor sub = SubMonitor.convert(monitor,
"Checking for application updates...", 200);
IStatus status = operation.resolveModal(sub.newChild(100));
if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
return status;
}
if (status.getSeverity() == IStatus.CANCEL)
throw new OperationCanceledException();
if (status.getSeverity() != IStatus.ERROR) {
try {
logger.info( "Status is " + status );
// More complex status handling might include showing the user what
// updates
// are available if there are multiples, differentiating patches vs.
// updates, etc.
// In this example, we simply update as suggested by the operation.
Update[] updates = operation.getPossibleUpdates();
for( Update u : updates){
logger.info( "Update is " + u );
}
ProvisioningJob job = operation.getProvisioningJob(null);
if( job == null ){
logger.error( "Provisioning Job is null" );
}
status = job.runModal(sub.newChild(100));
if (status.getSeverity() == IStatus.CANCEL) {
throw new OperationCanceledException();
}
} catch ( Exception e ){
logger.error( "Exception while trying to get updates", e);
}
}
return status;
}
private static void logRepositories(
IMetadataRepositoryManager metadataManager) {
URI[] repos = metadataManager.getKnownRepositories( IMetadataRepositoryManager.REPOSITORIES_ALL);
logger.info( "Found " + repos.length + " repositories in metadata");
logRespositories(repos);
}
private static void logRespositories(URI[] repos) {
for( URI uri : repos ){
logger.info( "Got repository " + uri );
}
}
private static IQueryResult<IInstallableUnit> queryIusFromMetadataManager(
IMetadataRepositoryManager metadataManager) {
IQueryResult<IInstallableUnit> ius = metadataManager.query(QueryUtil.createIUGroupQuery(), new NullProgressMonitor());
for( Iterator<IInstallableUnit> y = ius.iterator(); y.hasNext(); ){
IInstallableUnit blah = y.next();
logger.info( "Got IU from metadata manager " + blah );
}
return ius;
}
public static void addUpdateSite(IProvisioningAgent provisioningAgent)
throws InvocationTargetException {
// Load repository manager
IMetadataRepositoryManager metadataManager = (IMetadataRepositoryManager) provisioningAgent
.getService(IMetadataRepositoryManager.SERVICE_NAME);
if (metadataManager == null) {
logger.error( "Metadata manager was null");
Throwable throwable = new
Throwable("Could not load Metadata Repository Manager");
throwable.fillInStackTrace();
throw new InvocationTargetException(throwable);
}
// Load artifact manager
IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) provisioningAgent
.getService(IArtifactRepositoryManager.SERVICE_NAME);
if (artifactManager == null) {
logger.error( "Artifact manager was null");
Throwable throwable = new Throwable(
"Could not load Artifact Repository Manager");
throwable.fillInStackTrace();
throw new InvocationTargetException(throwable);
}
// Load repo
try {
URI repoLocation = new URI(UPDATE_URI);
logger.info( "Adding repository " + repoLocation );
metadataManager.loadRepository(repoLocation, null);
artifactManager.loadRepository(repoLocation, null);
} catch (ProvisionException pe) {
logger.error( "Caught provisioning exception " + pe.getMessage(), pe);
throw new InvocationTargetException(pe);
} catch (URISyntaxException e) {
logger.error( "Caught URI syntax exception " + e.getMessage(), e);
throw new InvocationTargetException(e);
}
}
}