Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » RCP: p2 update handler(no updates found.)
RCP: p2 update handler [message #1713203] Mon, 02 November 2015 10:33 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
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 #1714377 is a reply to message #1713203] Thu, 12 November 2015 09:47 Go to previous messageGo to next message
ALex W is currently offline ALex WFriend
Messages: 56
Registered: July 2012
Member
Hello,

Not sure if it helps, but did you try by not setting the URI to the ProvisioningContext ?
I'm using almost the same updater (visible here https://github.com/cncgoko/Goko/blob/dev/Goko/src/goko/GokoUpdateCheckRunnable.java) and it works with the update site in the feature/product file. (the code still needs some cleanup)

Your test method is fine. That's how I did as well.

Make sure you trace the actual repositories as I do. It might help. I suspect your update site is not even accessed.

[Updated on: Thu, 12 November 2015 09:48]

Report message to a moderator

Re: RCP: p2 update handler [message #1714398 is a reply to message #1714377] Thu, 12 November 2015 11:38 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
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 #1714615 is a reply to message #1714398] Fri, 13 November 2015 22:21 Go to previous messageGo to next message
ALex W is currently offline ALex WFriend
Messages: 56
Registered: July 2012
Member
No idea.
1. Make sure your qualifier gets updated (some plugins allow to use latest commit for the qualifier... but you have to activate it). The qualifier difference should be seen as an update
2. Maybe try to refresh the repo when querying it by calling manager.refreshRepository(location, monitor);

How is the repository generated ? with the tycho-p2-repository-plugin artifact of tycho/maven ?
Re: RCP: p2 update handler [message #1714699 is a reply to message #1714615] Mon, 16 November 2015 06:20 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
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

Re: RCP: p2 update handler [message #1714710 is a reply to message #1714699] Mon, 16 November 2015 07:37 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
seems my code is correct, but the version did not update, though there were loads of changes!

@see
https://www.eclipse.org/forums/index.php/t/1072106/
Re: RCP: p2 update handler [message #1714752 is a reply to message #1714710] Mon, 16 November 2015 12:11 Go to previous message
ALex W is currently offline ALex WFriend
Messages: 56
Registered: July 2012
Member
Does the update work after updating the product version ?

The feature you're trying to update is in the product content, right ?
Previous Topic:Versioning for RCP update
Next Topic:p2 slicingoption "resolve"
Goto Forum:
  


Current Time: Wed Oct 16 01:55:49 GMT 2024

Powered by FUDForum. Page generated in 0.03394 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top