Deploying to Package Drone with Maven Tycho
Deploying to Package Drone with Maven Tycho
Join the DZone community and get the full member experience.Join For Free
Easily enforce open source policies in real time and reduce MTTRs from six weeks to six seconds with the Sonatype Nexus Platform. See for yourself - Free Vulnerability Scanner.
This article is a sneak peek into deploying OSGi artifacts from a Maven Tycho build directly into Package Drone .
Installation and Setup
The first thing is to setup up an instance of Package Drone. In short you will need a Linux machine, a MySQL instance and Java 8. There already are a few pages in the wiki of Package Drone, so this article will focus on the actual deployment process:
There also is a video on YouTube on how to perform the initial configuration.
Creating and configuring a channel
The first thing which is required is a new channel. Got the "Channels" view (from the top menu) and click "Create Channel".
This will create an unnamed channel. Which can then be given a name using "Edit Channel".
For this tutorial we will use
maven1 as channel name. The ID of the channel will be different since it is generated automatically.
Channels are mostly only a container for artifacts (BLOBs) and can be extended with functionality by adding "aspects".
Go to "Edit" -> "Configure Aspects" and add the following aspects:
- Hasher – Create hashes of the BLOB
- Mime – Extract the MIME type
- OSGi – Extract OSGi meta data
- P2 Repository – Create information for P2
Since the channel is still empty, there will be no visible difference to the state before.
The next step is to add "deploy keys". So instead of re-using the users credentials, Package Drone uses "deploy keys" to authenticate applications which want to deploy content to the repository. The idea is to create a deploy group, which contains one are more deploy keys. The deploy groups get assigned to channel, so all keys in the assigned groups are allowed to deploy to these channels. If a deploy key gets compromised, it can easily be removed from the group, and replaced by a different one, without the requirement to re-configure all channels.
Switching to the tab "Deploy Keys" allows you do configure the deploy groups/keys for this channel. Initially there is none, so you need to create at least one.
Once it is created it can be added to the channel in the same screen as before. Clicking on the key (the element on right side) will pop up a dialog with the Maven deploy settings. The password which has to be used in the actual deployment is present in the <password> tag.
It is also possible to click in the deploy group (on the left side) and get a full list of all deploy keys for this group.
Building and deploying
So instead of creating a creating a full Maven Tycho project in this article, we will re-use one of the demo projects provided by Maven Tycho in their repositories and deploy them to Package Drone using the Maven option "
First of course, we need to fetch the source code of the demo projects using "
git" from the command line:
git clone http://git.eclipse.org/gitroot/tycho/org.eclipse.tycho-demo.git
This will check out a few samples projects, and we will use "
ipt01" for this step. Building and deploying is easy a changing into the right directory and issuing "mvn deploy" with the correct parameters. Since we don't want to change to demo project's "
pom.xml", we will use the Maven property "
altDeploymentRepository", specified on the command line. For more information on this property see .
The important part of this property is the server URL. Since Maven deploy uses Basic HTTP authentication, it is possible to provided the deploy key from Package Drone in the form of username:password, directly in the URL:
http://deploy:deploy-key@server/maven/maven1 where "deploy-key" of course is the deploy key from Package Drone (the one from the <password> element in the previous section), not the ID of the deploy key and not the term "deploy-key" ;-) So the key used in the next command (a06b637e…) will NOT WORK on your setup, since your server will create a different key and you have to replace it with one of your keys (see the previous section).
cd org.eclipse.tycho-demo/itp01 mvn deploy -DaltDeploymentRepository=pdrone::default::http://deploy:a06b637e55a75d501d879c09079d189a796208cbd6d220395df4c5749e42f88f@localhost:8080/maven/maven1
So after a while of download, building and uploading, Maven should finish with "BUILD SUCCESS" and looking back into the channel, you should see a few artifacts. Basically this what Maven uploaded and Package Drone stored it it as is. Peeking into the "Details" of one ".jar" artifact, you will see that Package Drone extracted the OSGi meta data during the upload process, and checking out the view "OSGi" -> "Bundles" will give you a nicer overview of OSGi related artifacts. Please note that the OSGi view will only be visible when the "OSGi" aspect was added to the channel.
Since we also added the "P2 repository" aspect earlier, it is possible to follow the "P2 Repository" link, directly to the P2 Repository adapter of this channel. Looking into the
artifacts.xml will give you the same meta data that Tycho generated and uploaded.
Note: This scenario re-uses the P2 meta data which was generated by Maven Tycho during the build process. It got uploaded and will be re-assembled as a complete P2 repository. However it also is possible to let Package Drone drop the Tycho meta data during upload and create its own version. This is useful if you also want to upload artifacts from non-Maven Tycho build, where P2 meta data is not being generated and uploaded during the build. But this setup might be part of a follow up article.
Accessing the channel using P2
After the artifacts got uploaded to the channel these can be accessed by and P2 compatible software (like Eclipse PDE or Maven Tycho). The entry point for the P2 adapter is
http://localhost:8080/p2/> where "channel" is either the channel ID or name ("maven1" in this case).
If course, in the current there is no Eclipse feature or category present. This is why the Eclipse P2 dialog will not find anything in that repository. But this is a limitation of the Dialog itself. All P2 tools will be able to pull out the bundle
So the next step would be to add an Eclipse feature to the Maven Tycho build and deploy it together with the bundle, or create another bundle, depending on "tycho.demo.itp01" and configuring Maven Tycho to resolve from
http://localhost:8080/p2/maven1 for the build.
Opinions expressed by DZone contributors are their own.