Simplifying the p2 Process, Part 4: Using p2.inf to add/remove update sites
Join the DZone community and get the full member experience.
Join For FreeIn Part 1 of this series, I looked at use of composite repos to provide a way of combining update sites into a single URL for ease of use and a single point of entry from which to do updates.
In Part 2, I discussed why we switched from using a collection of SDKs against which to build - using the now-deprecated brute-force "just unzip into eclipse root folder or dropins" approach - to using a single target platform update site so as to simplify maintenance and provide a reusable artifact for both build and workspace provisioning.
In Part 3, I looked at the idea of associating your repo with its upstream requirement sites, so that end-users need only use a single URL, rather than a half-dozen.
Finally, let's look at how you can use a p2.inf file to remove sites you don't support and add sites you do.
In JBDS 4, we include only two update sites - one for core features, and one for certified third-party extras, so that users will only get official updates from us, rather than from Spring, Eclipse, or anywhere else. Sure, they can manually add other URLs themselves, but that's a bit like pulling off the 'do not remove this tag' tag on a mattress or removing the 'warranty void if removed' sticker on your laptop.
So, first, we remove all the update site and discovery site URLs from our upstream features' feature.xml files, so they don't trickle down into the product.
Next, we use a p2.inf file:
# To explicitly remove a site, use instructions.unconfigure
instructions.configure=\
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(type:0,location:https${#58}//www.your.server.com/,name:Core Product Updates);\
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(type:1,location:https${#58}//www.your.server.com/,name:Core Product Updates);\
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(type:0,location:https${#58}//www.your.server.com/extras/,name:Extra Product Updates);\
org.eclipse.equinox.p2.touchpoint.eclipse.addRepository(type:1,location:https${#58}//www.your.server.com/extras/,name:Extra Product Updates);\
Then, to generate a site using that p2.inf instruction, here's a bit of Ant code:
<echo>Run p2.publisher.UpdateSitePublisher using launcherjar = @{launcherjar}</echo>
<java jar="@{launcherjar}"
fork="true" timeout="10800000" jvm="${java.home}/bin/java" failonerror="true"
maxmemory="256m" taskname="p2"
>
<classpath>
<fileset dir="${builder.build.path}/plugins"
includes="org.eclipse.equinox.launcher_*.jar, org.eclipse.equinox.p2.publisher_*.jar, org.eclipse.equinox.p2.updatesite_*.jar"
/>
<fileset dir="${clean.eclipse.home}/plugins"
includes="org.eclipse.equinox.launcher_*.jar, org.eclipse.equinox.p2.publisher_*.jar, org.eclipse.equinox.p2.updatesite_*.jar"
/>
<pathelement location="${builder.build.path}/plugins" />
<pathelement location="${clean.eclipse.home}/plugins" />
</classpath>
<arg line=" org.eclipse.equinox.launcher.Main -consolelog -application org.eclipse.equinox.p2.publisher.UpdateSitePublisher"
/>
<arg line=" -metadataRepository file:${updateSiteJarDir}/ -metadataRepositoryName "${update.site.product.name} ${update.site.description} Update Site""
/>
<arg line=" -artifactRepository file:${updateSiteJarDir}/ -artifactRepositoryName "${update.site.product.name} ${update.site.description} Artifacts""
/>
<arg line=" -source ${updateSiteJarDir}/" />
<arg line=" -compress -publishArtifacts -reusePack200Files -configs *,*,*" />
</java>
Or, put your p2.inf file in the same directory as your build.properties ...
product=${builderDirectory}/jbds-all.product
runPackager=true
p2.gathering=true
p2.category.site=file:${builderDirectory}/site.xml
# locations. Don't need a baseLocation, the transformedRepoLocation will have what we need
buildDirectory=${product.build.directory}/jbds-all-package
transformedRepoLocation=${product.build.directory}/jbds-all-package/transformed
repoBaseLocation=${product.build.directory}/jbds-all-package/toTransform
# The prefix that will be used in the generated archive.
archivePrefix=studio
# The location underwhich all of the build output will be collected.
collectingFolder=${archivePrefix}
# The list of {os, ws, arch} configurations to build.
configs = linux,gtk,x86 & win32,win32,x86 & linux,gtk,x86_64 & macosx,cocoa,x86 & macosx,cocoa,x86_64
buildId=${product.name}-product-${versionTag}
buildLabel=${buildId}
skipBase=true
skipMaps=true
skipFetch=true
... and your .product file ...
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>
<product name="JBoss Developer Studio for Web and SOA Development" uid="com.jboss.jbds.all" id="com.jboss.jbds.product.product" application="org.eclipse.ui.ide.workbench" version="4.0.0.qualifier" useFeatures="true" includeLaunchers="true">
<configIni use="default">
</configIni>
<launcherArgs>
<programArgs>--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile</programArgs>
<vmArgs>-Xms512m
-Xmx1024m
-Dosgi.bundles=reference:file:org.eclipse.equinox.simpleconfigurator_1.0.200.v20100503.jar@1:start
-Dosgi.instance.area.default=@user.home/workspace</vmArgs>
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
-Xdock:icon=../Resources/JBDevStudio.icns</vmArgsMac>
</launcherArgs>
<windowImages/>
<splash
location="com.jboss.jbds.product" />
<launcher name="jbdevstudio">
<solaris/>
<win useIco="true">
<ico path="jbds.ico"/>
<bmp/>
</win>
</launcher>
<vm>
</vm>
<plugins>
</plugins>
<features>
<feature id="com.jboss.jbds.product.feature" version="4.0.0.qualifier"/>
</features>
</product>
... and when generating a product using PDE, that file and its instructions should be read at the correct time.
Hope this series has been helpful! If you have any examples of what you've done with .product or p2.inf files, please feel free to send me a link to your post or the file in your cvs, svn, or git repo. I'd love to see what else you can do with p2 and product builds.
See also:
From http://divby0.blogspot.com/2011/02/simplifying-p2-process-part-4-using.html
Opinions expressed by DZone contributors are their own.
Comments