Friday, June 17, 2011

p2 cheatsheet

I was writing a p2 mirror script suggestion for a colleague.  When it morphed into a sorta p2 cheatsheet, I thought I'd blog about it (so I can find it again when I need it :-).

repo syntax

Most repos are specified via URLs like http:, but they can be files on the disk or even zipped repos:

  • file:///home/data/httpd/
  • jar:file:///opt/pwebster/!/

Just a note: destinations are (almost) always normal directory paths, not URLs.

Mirroring repos

You can quickly (well, I/O bound :-) mirror 2 builds repos so you can compare them on your disk. Here's an ant script for current, important, build repos.

<project name="Mirror" default="mirrorRepos">
<property name="eclipse36Mirror" value="${baseDir}/eclipse36" />
<property name="eclipse36Repo" value="" />
<property name="eclipse37Mirror" value="${baseDir}/eclipse37" />
<property name="eclipse37Repo" value="" />

<target name="mirrorRepos">
<echo message="Mirror from ${eclipse36Repo} to ${eclipse36Mirror}" />
<p2.mirror destination="file:${eclipse36Mirror}" ignoreerrors="true">
<source location="${eclipse36Repo}" />
<!--slicingOptions includeOptional="false" includeNonGreedy="false" latestVersionOnly="true"/-->
<!--iu id="org.eclipse.sdk.ide"/-->
<echo message="Mirror from ${eclipse37Repo} to ${eclipse37Mirror}" />
<p2.mirror destination="file:${eclipse37Mirror}" ignoreerrors="true">
<source location="${eclipse37Repo}" />
<!--slicingOptions includeOptional="false" includeNonGreedy="false" latestVersionOnly="true"/-->
<!--iu id="org.eclipse.sdk.ide"/-->


You can run that from an eclipse instance, either in eclipse using an Eclipse Application, or from the command line (my preference):

bash$ eclipse/eclipse -noSplash \
-application org.eclipse.ant.core.antRunner \
-DbaseDir=/some/useful/basedir -buildfile mirror.xml

It'll spit out some messages about unsatisfied IUs, but that's OK because you're using the slicer, not the provisioner.

IUs and version numbers

If you're looking at plugin or IU versions, you can quickly get a list in the "IU=version" format:

bash$ eclipse/eclipse -noSplash \
-application org.eclipse.equinox.p2.director \
-repository \

If you pick a composite repo like you can list all of the IUs, and then install a specific version of org.eclipse.sdk.ide, for example.

Creating a product for your platform

You can use the same scripts that the PDE build uses to generate a complete install for a platform:

<project name="Build Product" default="buildProduct">
<property name="p2.repo.URL" value="" />
<property name="iuId" value="org.eclipse.sdk.ide" />
<!--property name="iuId" value="org.eclipse.platform.ide"/-->
<!--property name="iuId" value=""/-->
<property name="profile" value="SDKProfile" />
<property name="os" value="linux" />
<property name="ws" value="gtk" />
<property name="arch" value="x86_64" />

<target name="buildProduct">
<ant antfile="${eclipse.pdebuild.scripts}/genericTargets.xml" target="runDirector">
<property name="p2.director.installPath" value="${baseDir}/p2_${os}_${ws}_${arch}/eclipse" />
<property name="p2.director.profile" value="${profile}" />
<property name="p2.director.iu" value="${iuId} " />
<property name="os" value="${os}" />
<property name="ws" value="${ws}" />
<property name="arch" value="${arch}" />
<property name="p2.repo" value="${p2.repo.URL}" />
<!--property name="p2.director.version" value="an.IU.version"/-->

bash$ eclipse/eclipse -noSplash \
-application  org.eclipse.ant.core.antRunner \
-DbaseDir=/some/useful/basedir -buildfile  productBuild.xml

The exact same thing can be accomplished using the command-line director (just with a lot of arguments :-)

bash$ eclipse/eclipse -noSplash \
-application org.eclipse.equinox.p2.director \
-repository \
-installIU org.eclipse.sdk.ide \
-destination /some/useful/basedir/linux_gtk_x86_64  \
-bundlepool /some/useful/basedir/linux_gtk_x86_64 \
-profile SDKProfile \
-profileProperties org.eclipse.update.install.features=true \
-p2.os linux gtk -p2.arch x86_64 -roaming

Installing into your own eclipse

This is the shortest command line of all, and the easiest way to take a new eclipse and install features from scripts.

bash$ eclipse/eclipse -noSplash \
-application org.eclipse.equinox.p2.director \
-repository \

More info

More about the director command line:

More about the p2 tasks and all the options they can take: