Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » P2 » p2 update mechanism problem(no updates found!)
p2 update mechanism problem [message #1269767] Wed, 12 March 2014 07:07
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member

  1. What to achieve: an application which can auto update itself.
  2. Help/Tutorial from: http://www.vogella.com/tutorials/EclipseP2Update/article.html


  3. Project Description:
    my Application project got a couple of plug-ins (version numbers in [])(description which dependencies are included, regarding the update mechanism)

    myApp.rcp[0.0.1.qualifier] (contains the .product)
    myApp.target (contains the target def.)
    myApp.update[0.0.1.qualifier] (contains the update Handler and
    Dependencies

    • org.eclipse.equinox.p2.core
    • org.eclipse.equinox.p2.engine
    • org.eclipse.equinox.p2.operation
    • org.eclipse.equinox.p2.metadata.repository

    @see 4. Update Handler Code below
    myApp.runtime[0.0.1.qualifier] (my runtime for the application used in all other plug-ins)
    Dependencies

    • org.eclipse.equinox.p2.core
    • org.eclipse.equinox.p2.engine
    • org.eclipse.equinox.p2.operation
    • org.eclipse.equinox.p2.metadata.repository


    myApp.View1[0.0.1.qualifier] (a view for a data type and its controller etc..)
    ...
    myApp.View9[0.0.1.qualifier]
    myApp.feature[1.0.0.qualifier]

    Plug-Ins


    • org.eclipse.equinox.p2.core
    • org.eclipse.equinox.p2.engine
    • org.eclipse.equinox.p2.operation
    • org.eclipse.equinox.p2.metadata.repository


    Features

    • org.eclipse.equinox.p2.core.feature



    Exporting the Application/Feature-Product

    first Step i do is export the initial Build
    Export > Eclipse Product > To: D:\Exports\updated
    when this is done i move the data to:
    D:\Exports\initial
    i launch the exe to see if there are any updates > no updates available!
    then i go and edit a label in one of my views, and change its version to version+0.0.1
    i also change the .product version number to version+0.0.1
    same for the feature version number to version+0.0.1
    after this i export the product again (p2 repository is checked) into the same folder (old stuff is moved out anyway)
    when this is done i move the repository (folder) to:
    D:\Exports\latest
    so finally i got this:
    D:\Exports\latest\repository

    • artifacts.jar
    • binary (folder)
    • content.jar
    • features (folder)
    • plugins (folder)


    now i launch the exe from D:\Exports\initial\eclipse and check for updates again
    (as the update is on the correct path D:\Exports\latest\repository
    and bam! no updates available!

    Questions
    Q: Do i need to change the version number or is the new build date (qualifier) enough to bring the plug-in up as 'new version'
    Q: If the last Q is answered NO, which version number has to be updated? is it enough to update the plug-in version?
    Q: Is it possible to update a plug-in only or does it always update the whole feature?
    Q: why is it not working at all? where is my mistake?

  4. Update Handler Code:

package at.biooffice.update.handlers;

import java.net.URI;

// 
// Require-Bundle: org.eclipse.equinox.p2.core|engine|operation|metadata.repository
// Feature: org.eclipse.equinox.p2.core.feature
//
// !!!!!!!!!!!!!!!!!
// do not run the update from for IDE. Update only works in an exported application 
// !!!!!!!!!!!!!!!!!
// 

public class PojoUpdateHandler {

	public static void main(String[] args) {
		URI uri = null;
		try {
			uri = new URI(REPOSITORY_LOC);
			System.out.println("Repository Location: " + uri);
		} catch (final URISyntaxException e) {
			e.printStackTrace();
		}
	}

	// repository location needs to be adjusted for your
	// location
	private static final String REPOSITORY_LOC = System.getProperty(
			"UpdateHandler.Repo",
			"file://D:/Exports/latest/repository");

	@Execute
	public void execute(final IProvisioningAgent agent, final Shell parent,
			final UISynchronize sync, final IWorkbench workbench) {
		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
				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 });
				
				/* 2. check for updates */

				// run update checks causing I/O
				final IStatus status = operation.resolveModal(monitor);

				// failed to find updates (inform user and exit)
				if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
					sync.syncExec(new Runnable() {
						@Override
						public void run() {
							MessageDialog
									.openWarning(parent, "No update",
											"No updates for the current installation have been found");
						}
					});
					return Status.CANCEL_STATUS;
				}

				try {
					throw new Exception(status.getException());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				/* 3. Ask if updates should be installed and run installation */

				// found updates, ask user if to install?
				if (status.isOK() && status.getSeverity() != IStatus.ERROR) {
					sync.syncExec(new Runnable() {
						@Override
						public void run() {
							String updates = "";
							Update[] possibleUpdates = operation
									.getPossibleUpdates();
							for (Update update : possibleUpdates) {
								updates += update + "\n";
							}
							doInstall = MessageDialog.openQuestion(parent,
									"Really install updates?", updates);
						}
					});
				}

				// 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();
	}
}
Previous Topic:Issues with native proxy settings
Next Topic:problems with headless self update
Goto Forum:
  


Current Time: Fri Apr 26 22:10:04 GMT 2024

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

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

Back to the top