How do I build an Eclipse RCP app so that its features can be updated automatically?
Asked Answered
P

3

6

I am building an RCP application that will be made up of several Features.

My RCP application is configured to check for updates each time it starts. My current problem is that I need one of my Features to be 'Installed' at build time so that it will get updated during this automatic check for updates without forcing the user to manually install it. I need this feature to update independently from the other features in the system.

So, to recap, I'm just looking for a nice automated way to have a Feature installed in an RCP app in such a way that it updates independently from other features, and doesn't require the user of the RCP app to install it manually.

Pentobarbital answered 27/4, 2012 at 14:0 Comment(0)
N
2

In the meanwhile, Tycho has explicit support for this use case. Starting with Tycho 0.20.0, you can make Tycho install features of an RCP separately from the product. In this way, these features can be updated (or even be uninstalled) independently of the product.

To install features independently, just add an attribute installMode="root" to the respective feature tags in the product file. Example:

<features>
   <feature id="org.eclipse.platform"/>
   <feature id="updatable.feature" installMode="root"/>
</features>

For more information, see this documentation page.

Nostalgia answered 26/7, 2012 at 8:1 Comment(1)
Where can I find this .product file?Medellin
P
5

After a long search, I have found the answer. It's kind of a kludge, but I'm willing to do anything at this point. My solution is dependent upon the fact that my built RCP application includes p2 application org.eclipse.equinox.p2.director. I guess if your RCP app doesn't contain this application, you can refer to another Eclipse install in order to launch the Director. I just did it this way to avoid having an instance of Eclipse sitting on my build machine.

I used the p2-dev mailing list, and Paul Webster answered my question. (Thanks Paul)

He suggested using ant to launch the p2 director application to install the IU into my built RCP application.

Here's his answer on the p2-dev mailing list http://dev.eclipse.org/mhonarc/lists/p2-dev/msg04735.html

Here's the ant target I came up with.

<target name="install_IU">
  <path id="launcher.paths">
    <fileset
       dir="${app.dir}"
       includes="plugins/org.eclipse.equinox.launcher_*" />
  </path>
  <property
      name="launcherPath"
      refid="launcher.paths" />
  <echo>-installIU ${iu.id} </echo>
  <java 
      jar="${launcherPath}"
      failonerror="false"
      dir="${app.dir}"
      timeout="900000"
      fork="true"
      output="${basedir}/director.log"
      resultproperty="directorcode">
      <arg line="-application org.eclipse.equinox.p2.director" />
      <arg line="-noSplash" />
      <arg line="-installIUs ${iu.id}" />
      <arg line="-repository ${iu.repo}" />
      <arg line="-destination ${app.dir}" />
      <arg line="-bundlepool ${app.dir}" />
  </java>

  <zip destfile="${app.zip}"
    basedir="${app.dir}"/>
</target>

I put this in an ant file in the same project that produces my Eclipse RCP application via Tycho. Tycho produces my build artifacts in a directory called "target" so my parameters to the ant target above look like this...

<target name="modify_x86">
  <antcall target="install_IU">
    <param name="iu.id" value="com.mydomain.the.feature.i.want.to.install.feature.feature.group"/>
    <param name="iu.repo" value="http://mydomain.com/thep2repository/where/i/deploy/the/feature/to/install"/>
    <param name="app.dir" value="${basedir}/target/products/com.mydomain.myRCPapplication/win32/win32/x86"/>
    <param name="app.zip" value="${basedir}/target/products/com.mydomain.myRCPapplication-win32.win32.x86.zip"/>
  </antcall>
</target>

I have a few more of these targets for each platform that my RCP application is built for.

Hope this helps.

UPDATE: May 8th, 2014. Tobias has brought it to my attention that I should change the accepted answer from this one to the one that has the new feature that was added to Tycho 0.20.0 that enables this behavior in a much more simple fashion. So, the new accepted answer is the proper solution for this question now.

Pentobarbital answered 15/5, 2012 at 21:15 Comment(4)
FYI, this is why this works: First Tycho internally calls an (embedded) p2 director and installs the product IU. Then, you call the director again and install the feature IU. The resulting installation then has two "root IUs" (i.e. entry points the span the installation). A check for updates will check each of the root IUs for newer versions - so you your feature would get updated when there is a newer version available in the configured repositories.Nostalgia
I've got good news: Tycho has now explicit support for this use case, so you can probably get rid of about a mile of pom.xml configuration ;-)Nostalgia
Thanks, I had removed the old ant code from above and taken advantage of the new feature. I was one of the 18 voters on the bug :) bugs.eclipse.org/bugs/show_bug.cgi?id=361722Pentobarbital
In this case, you should probably change the accepted answer to this answer.Nostalgia
N
2

In the meanwhile, Tycho has explicit support for this use case. Starting with Tycho 0.20.0, you can make Tycho install features of an RCP separately from the product. In this way, these features can be updated (or even be uninstalled) independently of the product.

To install features independently, just add an attribute installMode="root" to the respective feature tags in the product file. Example:

<features>
   <feature id="org.eclipse.platform"/>
   <feature id="updatable.feature" installMode="root"/>
</features>

For more information, see this documentation page.

Nostalgia answered 26/7, 2012 at 8:1 Comment(1)
Where can I find this .product file?Medellin
P
1

Before I found the answer that is documented here and accepted, I tried and failed to solve this problem in the following ways:

I tried putting the Feature in the product definition. This get's the feature installed successfully, but it takes away my ability to have it update independently from other features in the RCP application.

I have a p2 touchpoint command that is currently working. It adds a repository to the available update sites in the RCP application using a p2.inf file. It looks like this...

instructions.configure=\
 org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(location:http${#58}//myUpdateSsite/myFeature,type:0,name:My Feature Name,enabled:true);\
 org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(location:http${#58}//myUpdateSsite/myFeature,type:1,name:My Feature Name,enabled:true);\\

I've tried to add a line like this to get that feature installed, but my tycho build fails when I run mvn clean install

instructions.configure=\
 org.eclipse.equinox.p2.touchpoint.eclipse.installFeature(feature:My Feature Name,featureId:com.my.domain.my.feature.id,version:1.0.0);

Here's some of the error message from maven / tycho

An error occurred while configuring the installed items session context was:
(profile=DefaultProfile, phase=org.eclipse.equinox.internal.p2.engine.phases.Configure, operand=null --> 
[R]{my.domain.my.rcp.product.plugin 1.1.6.20120427-1346}, 
action=org.eclipse.equinox.internal.p2.touchpoint.eclipse.actions.InstallFeatureAction).
Installable unit contains no artifacts: [R]my.domain.my.rcp.product.plugin 1.1.6.20120427-1346.

My intuition tells me that this error message is saying that my RCP application plugin is missing something that will tell p2 where to find the feature that I want to install at build time. I think???

Pentobarbital answered 29/8, 2012 at 18:19 Comment(3)
Good effort! Still, the installFeature touchpoint cannot work here. Touchpoints are the physical (i.e. file I/O) layer of p2. You need a change in the high-level p2 metadata of the installation to achieve your goal.Nostalgia
Well, I agree that the above examples don't work. I'm leaving them here so that others struggling with the same thing can find it during a web search. I would really like to learn more about what p2 is doing here. It's been difficult to figure out how to work with p2 since IMHO, it's not very intuitive. I do want to learn more... so, what do you mean by "You need a change in the high-level p2 metadata of the installation" ? OBTW, the answer Paul Webster gave me is working for me, therefore, I haven't been pursuing other possible solutions recently.Pentobarbital
Added some more explanation in a comment to the working solution.Nostalgia

© 2022 - 2024 — McMap. All rights reserved.