Eclipse RCP Tip of the Day: p2 Touchpoint Instructions

22

A very common use case in a domain specific RCP app is to update itself using p2. When deploying this app, it would be very convenient if a list of predefined update sites could be available for the application at the first start. This was possible (but not trivial) even with Eclipse 3.4. But now, with Eclipse 3.5.1, it is very easy to do:

  1. Put your product configuration file in a bundle (plug-in project), not in a feature
  2. Create a file at top level and name it p2.inf
  3. Put the following content in the file:
    instructions.configure=
    addRepository(type:0,location:YOUR METADATA REPOSITORY);
    addRepository(type:1,location:
    YOUR ARTIFACT REPOSITORY);
  4. Don’t forget to include p2.inf in the build.properties

You find a working example in my MP3 Manager demo application:

instructions.configure=
addRepository(type:0,location:http${#58}//max-server.myftp.org/mp3m/repository);
addRepository(type:1,location:http${#58}//max-server.myftp.org/mp3m/repository);

If you want to test is with file locations rather than Internet locations, you could use locations like

file${#58}/c:/repository

The above location works for Windows, mind that in the file case there is only one / after the colon.

A list of all available p2 touchpoint instructions you find in the Eclipse Wiki.

Have Fun!

Kai

22 Comments

  1. Frederic Conrotte
    Frederic Conrotte12-02-2009

    Really cool tip. Thanks Kai

  2. Ben
    Ben12-02-2009

    Do you have any idea why these repositories aren’t listed when the p2 directory is write protected, e.g., when you install your app into c:program files on Windows Vista or Windows 7 (these directories are write protected by default). As far as i have seen, this problem also happens with the MP3 Manager. It only works when the MP3 Manager is installed directly from the NSIS installer as the NSIS installer seems to grab the necessary priviliges to write to the p2 directory. My attempts to redirect configuration directories somewhere to user.home all failed unfortunately.

  3. Kai Tödter
    Kai Tödter12-02-2009

    Sorry @Ben, I have no idea. If I find the time I’ll check it out in Vista.

  4. Ben Vitale
    Ben Vitale12-03-2009

    @(other Ben)

    I’ve see the behavior you’re referring to. The problem is that the “configuration” directory can’t be modified if the user running Eclipse does not have permissions. The pre-populated update sites (in the form of touchpoint actions) cause files to get written out to that location the first time you launch Eclipse. This was also the case in 3.4, if you used the *.prefs workaround (like how Ganymede did it) to set up a pre-installed update site.

    I believe you can specify the -configuration area to a location that is writable (for example, the user home location). Alternatively, you can run Eclipse as an administrator.

  5. Ben
    Ben12-03-2009

    I believe i have tried redirecting the configuration directory to user.home as i have written already. i believe it was the p2 directory that needed write permissions and that one is separate and parallel to the configuration directory. I could redirect the p2 directory somewhere to user.home as well, but then it only works if i copy the p2 directory from the program directory to the p2 directory in user.home beforehand, otherwise some data seems to be missing. With some ugly installer hacks, this may be possible to achieve, but i was somehow hoping that someone dealt with this problem already and knows a better answer.

  6. Ben Vitale
    Ben Vitale12-03-2009

    @(other Ben)

    Sigh, should have read your post more carefully. Sorry!

    I’m more or less in the same boat as you. In general, my clients have typically just run the app as an admin to get around these issues… but that’s sort of a sledgehammer approach.

    In hopes of getting some feedback from the RT guys, I’ve started a thread on this topic in the Equinox forum: http://www.eclipse.org/forums/index.php?t=msg&th=158858&start=0&S=f891290a9cb140d2677d56dabca3432f

  7. Ben
    Ben12-04-2009

    I’d be surprised if anyone answers. I have mentioned this issue multiple times in the newsgroups and wrote a lengthy comment somewhere in the Bugzilla. I never got any reaction from anyone. I’m kind of happy that at least someone confirmed the problem, because i was seriously starting to believe that no one else has the issue.

  8. Kai Tödter
    Kai Tödter12-04-2009

    @Ben & @(Other Ben)
    One reason that not many people are picking up on this might be that some big companies still run XP internally. I guess if they start adopting Windows 7 these issues will get more interest.

  9. Ben
    Ben12-04-2009

    Wow, there is a reply in the newsgroups:

    http://www.eclipse.org/forums/index.php?t=msg&th=158858&start=0&S=f891290a9cb140d2677d56dabca3432f

    I have to process this information a little more. I have a hunch that the problems are in fact caused by the fact that the software is actually run directly from the installer for the first time with admin priviliges (because the installer passes the privileges to the app). The configuration then somehow gets written to the virtualstore for program files and everything is messed up. Something like that maybe.

  10. stephan
    stephan12-08-2009

    Great stuff!
    But why I have to put the product file in a bundle and not in a feature? Can you give me a little more background about this one?

  11. Kai Tödter
    Kai Tödter12-08-2009

    @stephan,

    Actually when you use p2 together with an RCP product, the p2.inf should be in the bundle that has the product definition in its plugin.xml. The actual product configuration probably could still remain in the feature since this file is not needed during deployment. I will check that out if I find the time.

  12. stephan
    stephan12-09-2009

    I tried it and it works even with features. But I have to use the fully qualified name for the Touchpoint action: org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(…

  13. Marcos
    Marcos08-06-2010

    hi, boys. i am test p2.inf, is very interesting but it’s possible create repository in https??

    instructions.configure=
    addRepository(type:0,location:https${#58}//max-server.myftp.org:8443/mp3m/repository);
    addRepository(type:1,location:https${#58}//max-server.myftp.org;8443/mp3m/repository);

    thanks for all. Very interesting web

  14. Suganya
    Suganya08-19-2010

    Hello,
    I’m getting Nullpointer exception at RepositoryTransport.download(RepositoryTransport.java:75) if I point to a remote repository. It works fine with local repository in the build directory. I have created the following bug – https://bugs.eclipse.org/bugs/show_bug.cgi?id=323149. Please let me know if anyone has a solution for this.

  15. Suganya
    Suganya09-27-2010

    Any help on the previous issue?

  16. Henry T
    Henry T01-27-2011

    Can we change the addRepository location path after we export our application

    So we don’t have to edit the p2.inf and create a new product export

    Is there anyway we can change it?

    Thank you…

  17. CarbonRider
    CarbonRider03-27-2011

    Hi,

    I am working on Eclipse RCP application and using p2 to update the feature.
    I am facing one problem while updating the feature installed in RCP. I will explain this in two scenarios

    1st scenario

    The feature is already included in the exported RCP Product. I am using p2.inf to include following information
    requires.1.namespace = org.eclipse.equinox.p2.iu
    requires.1.name = com.example.mail.core.feature.group
    requires.1.range = [1.0.0,2.0.0)

    Once the product is exported, it launches successfully. Later I update the feature and increment the version to 1.0.1 and publish it to web server.
    After that I added the update site url in the Eclipse RCP using Help > Install new software feature and I could see that it detects the updates and installs it successfully.

    2nd scenario
    Now I change the p2.inf to pre-configure the update url and added following lines
    instructions.configure=
    addRepository(type:0,location:http${#58}//localhost${#58}8080/mail/updates/);
    addRepository(type:0,location:http${#58}//localhost${#58}8080/mail/updates/);

    Reset all the versions to 1.0.0 and export the product again.
    After executing the exported product, I found that the update url is already configured in update manager.

    I exported the feature as 1.0.1 and selected “Check for updates” option. As expected it detected the update and asked to install it. When I clicked finish button, I got following error.

    !ENTRY org.eclipse.equinox.p2.engine 4 4 2011-03-27 21:06:30.822
    !MESSAGE An error occurred while collecting items to be installed
    !SUBENTRY 1 org.eclipse.equinox.p2.engine 4 0 2011-03-27 21:06:30.822
    !MESSAGE session context was:(profile=profile, phase=org.eclipse.equinox.internal.provisional.p2.engine.phases.Collect, operand=, action=).
    !SUBENTRY 1 org.eclipse.equinox.p2.artifact.repository 4 0 2011-03-27 21:06:30.822
    !MESSAGE No repository found containing: osgi.bundle,com.example.mail,1.0.0.201103272105
    !SUBENTRY 1 org.eclipse.equinox.p2.artifact.repository 4 0 2011-03-27 21:06:30.822
    !MESSAGE No repository found containing: org.eclipse.update.feature,com.example.mail.core,1.0.1

    Can you please help me to resolve the above problem, as why it worked in 1st scenario and failed in 2nd. I just added the entry of “instructions.configure” and it failed. Please let me know where I am going wrong.

  18. Eclipse RCP: Setting P2 repositories (update sites) programmatically (for when p2.inf fails). | Coopology: All things Coop.
    Eclipse RCP: Setting P2 repositories (update sites) programmatically (for when p2.inf fails). | Coopology: All things Coop.08-09-2012

    […] yours.  There are many resources that explain about using p2.inf to do this.  However, there is an issue when trying to do this with an application that will be installed into Program Files (or any […]

  19. Karsten Thoms
    Karsten Thoms12-20-2012

    I got this error when:
    An error occurred while configuring the installed items
    session context was:(profile=epp.package.java, phase=org.eclipse.equinox.internal.p2.engine.phases.Configure, operand=null –> [R], action=org.eclipse.equinox.internal.p2.engine.MissingAction).
    No action found for: addRepository.

    Solution was to write the qualified name “org.eclipse.equinox.p2.touchpoint.eclipse.addRepository” instead of “addRepository”

  20. Karsten Thoms
    Karsten Thoms12-20-2012

    Btw: Found the hint here: http://www.eclipse.org/forums/index.php/mv/msg/41373/134442/#msg_134442

Leave a Reply