RCP: p2 update handler [message #1713203] |
Mon, 02 November 2015 05:33  |
Eclipse User |
|
|
|
Hello NG,
i try to add update functionality via p2 for some time (months) but always fail with error - 'no updates found'
i ran throug some tutorials (vogella and co) also tried an new update handler from Tom Schindl. but till i cant get it up and running.
FYI: when i browse to my update site with my IDE, eclipse shows me bunch of possible features to install (so the update site gets generated correctly) further i log the location, where the app shall search for the update, which resolves (i tried a local folder and a url) correctly.
my structure is the following
basic-features
admin-features
free-addon-features
the basic-features includes all the required bundles to run my app including the update bundle!
the feature.xml of basic-features includes the following plug-ins (required for the p2 update)
...
at.biooffice.update < this is my update bundle
...
org.eclipse.equinox.p2.core
org.eclipse.equinox.p2.engine
org.eclipse.equinox.p2.metadata.repository
org.eclipse.equinox.p2.operations
org.eclipse.equinox.p2.simpleconfigurator
...
the feature.xml of basic-features includes the following features (required for the p2 update)
...
org.eclipse.equinox.p2.core.feature
...
NOTE: the bundle at.biooffice.update also has these plug-ins in the dependencies:
org.eclipse.equinox.p2.core
org.eclipse.equinox.p2.engine
org.eclipse.equinox.p2.metadata.repository
org.eclipse.equinox.p2.operations
org.eclipse.equinox.p2.simpleconfigurator
NOTE: i do not have any special additions in my pom.xml
finally this is my PojoUpdateHandler
public class PojoUpdateHandler {
@Execute
public void execute(final IProvisioningAgent agent, final Shell parent, final UISynchronize sync,
final IWorkbench workbench) {
// BioConstants.getRepository() simply returns the path to my repository - tried both, local directory and online on my webhost
final String REPOSITORY_LOC = System.getProperty("UpdateHandler.Repo", BioConstants.getRepository());
Job j = new Job("Update Job") {
private boolean doInstall = false;
@Override
protected IStatus run(final IProgressMonitor monitor) {
/* 1. Prepare update plumbing */
final ProvisioningSession session = new ProvisioningSession(agent);
final UpdateOperation operation = new UpdateOperation(session);
// create uri - optional?
URI uri = null;
try {
uri = new URI(REPOSITORY_LOC);
System.out.println("Repository Location: " + uri);
} catch (final URISyntaxException e) {
sync.syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(parent, "URI invalid", e.getMessage());
}
});
return Status.CANCEL_STATUS;
}
// set location of artifact and metadata repo
operation.getProvisioningContext().setArtifactRepositories(new URI[] { uri });
operation.getProvisioningContext().setMetadataRepositories(new URI[] { uri });
System.out.println("Searching for update @ " + REPOSITORY_LOC);
// end of optional
/* 2. check for updates */
// run update checks causing I/O
SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
IStatus status = operation.resolveModal(sub.newChild(100));
System.out.println("status -> " + status);
// failed to find updates (inform user and exit)
switch (status.getCode()) {
case UpdateOperation.STATUS_NOTHING_TO_UPDATE:
sync.syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(parent, "No update", String.format(
"No updates for the current installation have been found at '%s'", REPOSITORY_LOC));
}
});
return Status.CANCEL_STATUS;
default:
/*
* 3. Ask if updates should be installed and run
* installation
*/
// found updates, ask user if to install?
System.out.println("found updates -> ask user to install");
if (status.isOK() && status.getSeverity() != IStatus.ERROR) {
String updates = "";
Update[] possibleUpdates = operation.getPossibleUpdates();
for (Update update : possibleUpdates) {
updates += update + "\n";
}
final String fUpdates = updates;
sync.syncExec(new Runnable() {
@Override
public void run() {
doInstall = MessageDialog.openQuestion(parent, "Really install these updates?",
fUpdates);
}
});
}
break;
}
// start installation
if (doInstall) {
final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
// updates cannot run from within Eclipse IDE!!!
if (provisioningJob == null) {
System.err.println("Running update from within Eclipse IDE? This won't work!!!");
throw new NullPointerException();
}
// register a job change listener to track
// installation progress and notify user upon success
provisioningJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
sync.syncExec(new Runnable() {
@Override
public void run() {
boolean restart = MessageDialog.openQuestion(parent,
"Updates installed, restart?",
"Updates have been installed successfully, do you want to restart?");
if (restart) {
workbench.restart();
}
}
});
}
super.done(event);
}
});
provisioningJob.schedule();
}
return Status.OK_STATUS;
}
};
j.schedule();
}
}
no matter what i do i always end up in:
"No updates for the current installation have been found..."
can anyone point me towards my mistake?
or is there a better way to debug/find out what is going wrong?
NOTE: for testing i run maven, then copy the exported product. then build again, and copy the p2 repository to my target dir or webhost. afterwards i execute the previously copied product and push the update button.
Update: i'm still trying to figure out whats going wrong.
so i tried to list all ExtraInstallable units (do i need to do this before or after i call operation.resolveModal (does this give the installable units i search for or the one i got back?
any way to get information about ALL available installable units?
anyway, i tried both and always get 0 back!
List<IInstallableUnit> installable = operation.getProvisioningContext().getExtraInstallableUnits();
System.out.println("number of ExtraInstallable Units BEFORE/AFTER resolveModal "+installable.size());
for (int i = 0; i < installable.size(); i++) {
System.out.println(String.format("[%d] installable is ", i, installable.get(i).getId()));
}
i'll keep this thread up to date, if i still find new results
UPDATE: i added some lines of code to manually query the p2 repository. and i gain results from the site (so the site is verified working!)
i query
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
repository = manager.loadRepository(uri, monitor);
IQueryResult<IInstallableUnit> units = repository.query(QueryUtil.createIUAnyQuery(), monitor);
this returns me all bundles available in the repository. i log the name and version to console.
further i logged all installed bundles and their versions to console.
BundleContext context = LumoCoreRuntimeActivator.getDefault().getBundle().getBundleContext();
Bundle[] bundles = context.getBundles();
for (int i = 0; i < bundles.length; i++) {
System.out.println(bundles[i].getSymbolicName() + " - "+bundles[i].getVersion().toString());
}
doing so i can confirm that the files in the p2 repository DO have a newer qualifier (version is equal) but this should be fine, and reported as UPDATE
though all this seems fine, i still get the response, that NO UPDATES ARE AVAILABLE
this is a follow up for this 1,5 years old thread
[Updated on: Fri, 06 November 2015 06:30] by Moderator
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04596 seconds