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:

  • http://download.eclipse.org/eclipse/updates/3.7-I-builds
  • file:///home/data/httpd/download.eclipse.org/eclipse/updates/3.7-I-builds
  • jar:file:///opt/pwebster/emf-xsd-Update-2.7.0RC3.zip!/

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="http://download.eclipse.org/eclipse/updates/3.6/R-3.6.2-201102101200" />
<property name="eclipse37Mirror" value="${baseDir}/eclipse37" />
<property name="eclipse37Repo" value="http://download.eclipse.org/eclipse/updates/3.7-I-builds/I20110613-1736" />

<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"/-->
</p2.mirror>
<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"/-->
</p2.mirror>
</target>

</project>


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 http://download.eclipse.org/eclipse/updates/3.7-I-builds/I20110613-1736 \
-list

If you pick a composite repo like http://download.eclipse.org/eclipse/updates/3.6 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="http://download.eclipse.org/eclipse/updates/3.7-I-builds" />
<property name="iuId" value="org.eclipse.sdk.ide" />
<!--property name="iuId" value="org.eclipse.platform.ide"/-->
<!--property name="iuId" value="org.eclipse.rcp.id"/-->
<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"/-->
</ant>
</target>
</project>



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 http://download.eclipse.org/eclipse/updates/3.7-I-builds \
-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 -p2.ws 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 http://download.eclipse.org/eclipse/updates/3.7-I-builds \
-i org.eclipse.releng.tools.feature.group

More info

More about the director command line: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/p2_director.html

More about the p2 tasks and all the options they can take: http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/p2_repositorytasks.htm