Reader small image

You're reading from  Eclipse Plug-in Development Beginner's Guide - Second Edition

Product typeBook
Published inAug 2016
Reading LevelExpert
Publisher
ISBN-139781783980697
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Alex Blewitt
Alex Blewitt
author image
Alex Blewitt

contacted on 30 aug 16 _____________ Dr Alex Blewitt has over 20 years of experience in Objective-C and has been using Apple frameworks since NeXTstep 3.0. He upgraded his NeXTstation for a TiBook when Apple released Mac OS X in 2001 and has been developing on it ever since. Alex currently works for an investment bank in London, writes for the on-line technology news site InfoQ and has published two other books for Packt publishing. He also has a number of apps on the Apple AppStore through Bandlem Limited. When he's not working on technology, and if the weather is nice, he likes to go flying from the nearby Cranfield airport. Alex writes regularly at his blog, http://alblue.bandlem.com, as well tweeting regularly from Twitter as @alblue. Acknowledgements This book would not have been possible without the ongoing love and support of my wife Amy, who has helped me through both the highs and lows of life. She gave me the freedom to work during the many late nights and weekends that it takes to produce a book and its associated code repository. She truly is the Lem of my life. I'd also like to thank my parents, Ann and Derek, for their encouragement and support during my formative years. It was this work ethic that allowed me to start my technology career as a teenager and to incorporate my first company before I was 25. I'd also like to congratulate them on their 50th wedding anniversary in 2015, and I look forward to reaching that goal with Amy. Thanks are due especially to the reviewer of this version of the book: Antonio Bello, as well as the previous version of this book: Nate Cook, James Robert and Arvid Gerstmann, who provided excellent feedback on the contents of this book during development and caught many errors in both the text and code. Any remaining errors are my own. I'd also like to thank my children Sam and Holly for inspiring me and hope that they too can achieve anything that they set their minds to. Finally, I'd like to thank Ben Moseley and Eren Kotan, both of whom introduced me to NeXT in the first place and set my career going on a twenty year journey to this book.
Read more about Alex Blewitt

Right arrow

Chapter 12. Automated Builds with Tycho

Tycho – automated builds based on Maven

The final part of the puzzle is how to build plug-ins automatically. Most plug-ins are now built with Tycho, a Maven plugin infrastructure for building Eclipse plug-ins.

In this chapter, we shall:

  • Automate a plug-in build

  • Automate a feature build

  • Create an update site

  • Execute UI and non-UI tests

  • Sign the plug-ins

  • Learn how to publish the update site

Using Maven to build Eclipse plug-ins with Tycho


Maven is an automated build tool that builds using a file called pom.xml, which declaratively specifies how and what to build. Maven projects have a group, an artifact, and a version that identify them in repositories such as the Central Repository, and a packaging type that tells Maven what it is trying to build. The default is jar since the widest use for Maven is for building Java archives; for Tycho, we need to use Eclipse-specific types.

Maven Tycho is a set of plug-ins that allow the building of Eclipse plug-ins. Tycho requires at least Maven 3 to work; the instructions in this chapter have been tested with Maven 3.3.9 and Tycho 0.25.0. Check out the book's errata page for up-to-date information.

Time for action – installing Maven


This step will install and use Maven to build a simple Java project to ensure that the tool is configured appropriately. The first time it runs, it will cache many Jars from Central into a folder ${user.home}/.m2/repository; for subsequent runs, it will be much faster.

  1. Go to http://maven.apache.org/ and download the latest Maven zip (Windows) or Maven tgz (for macOS/Linux).

  2. Unzip/untar the install into a convenient directory, referred to in these instructions as MAVEN_HOME.

  3. Either add MAVEN_HOME/bin to the PATH or specify the full path to the Maven executable; run mvn –version, and a version message should be printed out. Maven requires a JDK (not just a JRE), which should be installed by following the instructions from the Java site.

  4. Run mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.1 (all on one line) to create a new Maven project.

    Note

    Maven can also be run with Eclipse...

Time for action – building with Tycho


Now that Maven is installed, it's time to build a plug-in with Tycho. Tycho is a set of plug-ins for Maven 3 that emulates the PDE build system used by Eclipse. The Eclipse platform has moved to building with Tycho and Maven 3.

  1. Change into the com.packtpub.e4.clock.ui project created in Chapter 2, Creating Views with SWT.

    Tip

    The project can also be downloaded from the site's GitHub repository at https://github.com/alblue/com.packtpub.e4/

  2. Create a file called pom.xml at the root of the project, with the following empty contents:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                         http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    </project>

    This can be copied from the pom.xml file generated in the previous section, since every pom...

Building features and update sites with Tycho


The process for building features and update sites is similar to that of plug-ins, but with different packaging types. However, it's common for features and plug-ins to be built in the same Maven build, which requires a little re-organization of the projects. These are typically organized into a parent project and then several child projects.

Time for action – creating a parent project


It's common for the parent and child projects to be located outside the workspace; for historical reasons, Eclipse doesn't deal well with nested projects in the workspace. It's also common for the parent project to host all of the Tycho configuration information, which makes setting up the child projects a lot easier.

  1. Create a General project by navigating to the File | New | Project | General | Project menu.

  2. Unselect Use default location.

  3. Put in a location that is outside the Eclipse workspace.

  4. Name the project com.packtpub.e4.parent.

  5. Click on Finish.

  6. Create a new file pom.xml in the root of the project.

  7. Copy the content of the com.packtpub.e4.clock.ui plug-in's pom.xml file to the parent, but change the artifactId to com.packtpub.e4.parent and the packaging to pom.

  8. Create a properties element in the pom.xml file and inside a tycho.version element with the value 0.25.0, as well as an eclipse element with the value http://download.eclipse.org/releases...

Time for action – building a feature


Features can be built in the same way as plug-ins, although this time the packaging type is eclipse-feature.

  1. Move the com.packtpub.e4.feature project underneath the com.packtpub.e4.parent project.

  2. Add the line <module>com.packtpub.e4.feature</module> to the parent pom.xml file.

  3. Copy the pom.xml file from the clock plug-in to the feature project.

  4. Modify the packaging type to <packaging>eclipse-feature</packaging>.

  5. Change the artifactId to com.packtpub.e4.feature.

  6. The resulting pom.xml file will look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                         http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.packtpub.e4</groupId>
        <artifactId>com.packtpub.e4.parent...

Time for action – building an update site


The update site created in Chapter 10, Adding an Update Site, is used to provide a standard hosting mechanism for Eclipse plug-ins and features. This can be built automatically with Tycho as well.

  1. Move the com.packtpub.e4.update project underneath the com.packtpub.e4.parent project.

  2. Add the line <module>com.packtpub.e4.update</module> to the parent pom.xml file.

  3. Copy the pom.xml file from the clock plug-in to the update project.

  4. Modify the packaging type to <packaging>eclipse-repository</packaging>.

  5. Change the artifactId to com.packtpub.e4.update.

  6. The resulting pom.xml file will look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                         http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
    ...

Time for action – building a product


Building a product (a branded Eclipse application, or one that is launched from eclipse -application from the command line) can also be built with Tycho using the eclipse-repository packaging type. To do this, the app project needs to be built with Tycho and made available in the feature, and a new project for the product needs to be created.

  1. Move the com.packtpub.e4.application project under the com.packtpub.e4.parent project.

  2. Add the line <module>com.packtpub.e4.application</module> to the parent pom.xml file.

  3. Copy the pom.xml file from the clock plug-in to the application project.

  4. Change the artifactId to com.packtpub.e4.application.

  5. The resulting pom.xml file will look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
     http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion...

Time for action – using the target platform


Although building against a remote repository works as expected, it may have dependencies on plug-ins or features that aren't represented in the target platform created in Chapter 10, Using a Target Platform. To compile against a target platform, a new Maven module needs to be created.

  1. Move the com.packtpub.e4.target.mars project underneath the com.packtpub.e4.parent project.

  2. Add the line <module>com.packtpub.e4.target.mars</module> to the parent pom.xml file.

  3. Comment out the repositories tags in the parent pom.xml file.

  4. In the configuration element of the target-plugin-configuration entry, add the co-ordinates of the com.packtpub.e4.target.mars project:

    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-platform-configuration</artifactId>
      <version>${tycho.version}</version>
      <configuration>
        <target>
          <artifact>
            <groupId>com.packtpub.e4...

Testing and releasing


The final step of an Eclipse build is to ensure that any automated tests are run, and any versions that need to be bumped for the release stage are done prior to the code being published.

Time for action – running automated tests


Although a plug-in's code-based tests (those under src/test/java) will be run automatically as part of a Maven build, very often it is necessary to test them in a running Eclipse application. The previous chapter covered creating automated UI tests; now they will be run as part of the automated build.

  1. Move the com.packtpub.e4.junit.plugin project underneath the com.packtpub.e4.parent project.

  2. Add the line <module>com.packtpub.e4.junit.plugin</module> to the parent pom.xml file.

  3. Copy the pom.xml file from the com.packtpub.e4.clock.ui plug-in to the com.packtpub.e4.junit.plugin project.

  4. Modify the packaging type to <packaging>eclipse-test-plugin</packaging>.

  5. Change the artifactId to com.packtpub.e4.junit.plugin

  6. To run the Tycho tests, add the following as a build plugin:

    <build>
      <sourceDirectory>src</sourceDirectory> 
      <plugins>
        <plugin>
          <groupId>org.eclipse.tycho</groupId>
     ...

Time for action – changing the version numbers


When a new version of the project is released, the plug-in and feature numbers need to be updated. This can be done manually, by modifying the pom.xml and MANIFEST.MF version numbers, or by running the tycho-versions-plugin:set-version tool.

  1. From the parent directory, run (all on one line):

    mvn org.eclipse.tycho:tycho-versions-plugin:set-version-DnewVersion=1.2.3-SNAPSHOT
  2. The output should say SUCCESS for the parent and SKIPPED for the others:

    [INFO] Reactor Summary:
    [INFO] 
    [INFO] com.packtpub.e4.parent .................. SUCCESS [5.569s]
    [INFO] com.packtpub.e4.clock.ui ................ SKIPPED
    [INFO] com.packtpub.e4.junit.plugin ............ SKIPPED
    [INFO] com.packtpub.e4.feature ................. SKIPPED
    [INFO] com.packtpub.e4.update .................. SKIPPED
    
  3. Now run a build to verify that the versions were updated correctly:

    [INFO] Building com.packtpub.e4.parent 1.2.3-SNAPSHOT
    [INFO] Building com.packtpub.e4.clock.ui 1.2.3-SNAPSHOT
    [INFO...

Signing update sites


When installing the content into a repository, Eclipse will report whether the plug-ins are signed or not. Digital signatures ensure that the contents of the plug-ins have not changed, and the identity of the signer can be verified.

Time for action – creating a self-signed certificate


To sign content, a private key and public key must be used. The private key is used for signing the content, and the public key is used for verifying that the content has not been modified. A key-pair can be created using the Java keytool utility on the command line.

  1. Run keytool to see a list of options, and to verify that it is on the path.

  2. Create a new key-pair by running (all on one line):

    keytool -genkey
     -alias packtpub
     -keypass SayK3ys
     -keystore /path/to/keystore
     -storepass BarC0der
     -dname "cn=packtpub,ou=pub,o=packt"
  3. Verify that the key was generated correctly:

    keytool -list -keystore /path/to/keystore -storepass BarC0der
  4. Create a JAR file for testing purposes, for example by zipping the contents of the directory:

    jar cf test.jar .
  5. Sign the JAR to verify that it works, by running (all on one line):

    jarsigner 
     -keypass SayK3ys
     -storepass BarC0der
     -keystore /path/to/keystore
     test.jar
     packtpub
  6. Verify the Jar signature by running:

    jarsigner...

Time for action – signing the plug-ins


Integrating signatures into a Tycho build is a matter of adding a plug-in to the build script. In addition, Java properties need to be passed in to provide access to the arguments required by the jarsigner tool.

  1. Add the plug-in to the parent pom.xml file:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jarsigner-plugin</artifactId>
      <version>1.4</version>
      <executions>
        <execution>
          <id>sign</id>
          <goals>
            <goal>sign</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <verbose>true</verbose>
        <!-- alias>packtpub</alias -->
        <keystore>${project.parent.basedir}/keystore</keystore>
        <!-- storepass>...</storepass -->
        <!-- keypass>...</keypass -->
      </configuration>
    </plugin>
  2. Run mvn package and...

Time for action – serving an update site


Now that the update site has been developed, tested and automatically built, the final stage is to upload the contents of the update site (under com.packtpub.e4.update/target/repository) and make it available on a website or FTP server so that others can install it. If Python 2.7+ is installed, run a simple web server as follows.

  1. Change to the directory com.packtpub.e4.update/target/repository.

  2. Run the Python SimpleHTTPServer module (for Python 2) or the http.server module (for Python 3):

    python -m SimpleHTTPServer 8080
    Serving HTTP on 0.0.0.0 port 8080 ...
    
    python3 -m http.server 8080
    Serving HTTP on 0.0.0.0 port 8080 ...
    
  3. Verify the update site by adding http://localhost:8080/ as a remote update site in Eclipse.

If you don't have Python installed, then some operating systems have a means to serve web-based content already, or another web server can be used. macOS has web sharing where files in ~/Sites are served from, Linux systems typically have Apache...

Summary


This chapter concludes the creation of Eclipse plug-ins and features. Since the final step is building and making it available to others, the steps in this chapter focused on how to automate the builds with Tycho and then take the published update site and make it available for others.

The final chapter will introduce the Eclipse development process, and how to contribute patches to Eclipse.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Eclipse Plug-in Development Beginner's Guide - Second Edition
Published in: Aug 2016Publisher: ISBN-13: 9781783980697
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Alex Blewitt

contacted on 30 aug 16 _____________ Dr Alex Blewitt has over 20 years of experience in Objective-C and has been using Apple frameworks since NeXTstep 3.0. He upgraded his NeXTstation for a TiBook when Apple released Mac OS X in 2001 and has been developing on it ever since. Alex currently works for an investment bank in London, writes for the on-line technology news site InfoQ and has published two other books for Packt publishing. He also has a number of apps on the Apple AppStore through Bandlem Limited. When he's not working on technology, and if the weather is nice, he likes to go flying from the nearby Cranfield airport. Alex writes regularly at his blog, http://alblue.bandlem.com, as well tweeting regularly from Twitter as @alblue. Acknowledgements This book would not have been possible without the ongoing love and support of my wife Amy, who has helped me through both the highs and lows of life. She gave me the freedom to work during the many late nights and weekends that it takes to produce a book and its associated code repository. She truly is the Lem of my life. I'd also like to thank my parents, Ann and Derek, for their encouragement and support during my formative years. It was this work ethic that allowed me to start my technology career as a teenager and to incorporate my first company before I was 25. I'd also like to congratulate them on their 50th wedding anniversary in 2015, and I look forward to reaching that goal with Amy. Thanks are due especially to the reviewer of this version of the book: Antonio Bello, as well as the previous version of this book: Nate Cook, James Robert and Arvid Gerstmann, who provided excellent feedback on the contents of this book during development and caught many errors in both the text and code. Any remaining errors are my own. I'd also like to thank my children Sam and Holly for inspiring me and hope that they too can achieve anything that they set their minds to. Finally, I'd like to thank Ben Moseley and Eren Kotan, both of whom introduced me to NeXT in the first place and set my career going on a twenty year journey to this book.
Read more about Alex Blewitt