RCP: p2 update handler [message #1713203] |
Mon, 02 November 2015 10:33 |
Ludwig Moser Messages: 476 Registered: July 2009 |
Senior Member |
|
|
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 11:30] Report message to a moderator
|
|
|
|
Re: RCP: p2 update handler [message #1714398 is a reply to message #1714377] |
Thu, 12 November 2015 11:38 |
Ludwig Moser Messages: 476 Registered: July 2009 |
Senior Member |
|
|
thanks for your reply Alex!
i also think that the update site is not even accessed, because the response is coming immediately, and i guess it would take some time to process the remote files and see if updates are needed.
what i did now:
ALL (four) features AND the product file refer to [u]http://update.biooffice.at/p2/[/u]
ALL plugins/features contain the .qualifier tag after version.
i do NOT raise the version number itself (the .qualifier should be enough, right?
added your code to see which repositories get processed (and i removed the code where i manually specify the URI. the output is the following:
Checking updates from the following repositories :
+ http://update.biooffice.at/p2/
UpdateStatus : No updates were found.
http://update.biooffice.at/p2/ contains the folder repository, which gets created by maven.
it contains these files; folders are in []:
[binary]
[features]
[plugins]
artifacts.jar
content.jar
and the main code for updating (better say checking for updates) is
final ProvisioningSession session = new ProvisioningSession(agent);
final UpdateOperation operation = new UpdateOperation(session);
/* 2. check for updates */
final SubMonitor sub = SubMonitor.convert(monitor, "Checking for application updates...", 200);
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
URI[] lstRepositories = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
StringBuilder repoListBuilder = new StringBuilder();
if(lstRepositories != null && lstRepositories.length > 0){
System.out.println("Checking updates from the following repositories :");
for (URI anUri : lstRepositories) {
System.out.println(" + "+anUri.toString());
repoListBuilder.append("\t"+anUri.toString()+"\n");
}
}
final String repositories = repoListBuilder.toString();
//check if updates are available
IStatus status = operation.resolveModal(sub.newChild(100));
anything else you would suggest me?
NOTE: i do have an E3 Application running on compatibility layer in E4 (the update handler is in E4 style.)
[Updated on: Thu, 12 November 2015 11:51] Report message to a moderator
|
|
|
|
Re: RCP: p2 update handler [message #1714699 is a reply to message #1714615] |
Mon, 16 November 2015 06:20 |
Ludwig Moser Messages: 476 Registered: July 2009 |
Senior Member |
|
|
the repository gets generated using tycho
(tycho-p2-plugin:0.21.0)
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<resolver>p2</resolver>
<pomDependencies>consider</pomDependencies>
<environments>
<!-- environment> <os>linux</os> <ws>gtk</ws> <arch>x86</arch> </environment -->
<!-- environment> <os>linux</os> <ws>gtk</ws> <arch>x86_64</arch> </environment -->
<environment> <os>win32</os> <ws>win32</ws> <arch>x86</arch> </environment>
<environment> <os>win32</os> <ws>win32</ws> <arch>x86_64</arch> </environment>
<!-- <environment> <os>macosx</os> <ws>cocoa</ws> <arch>x86_64</arch> </environment> -->
</environments>
</configuration>
</plugin>
[Updated on: Mon, 16 November 2015 06:59] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03394 seconds