Time for action – building a product

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 plugin to the application project.
  4. Change the artifactId to com.packtpub.e4.application.
  5. The resulting pom.xml file will look like this:
    <?xml version="1.0" encoding="UTF-8"?>
      <project 
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.packtpub.e4</groupId>
        <artifactId>com.packtpub.e4.parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
      </parent>
      <groupId>com.packtpub.e4</groupId>
      <artifactId>com.packtpub.e4.application</artifactId>
      <!-- version>1.0.0-SNAPSHOT</version -->
      <packaging>eclipse-plugin</packaging>
    </project>
  6. Modify com.packtpub.e4.feature/feature.xml to add the reference to the application plug-in:
    <feature>
      ...
      <pluginid="com.packtpub.e4.application" download-
        size="0" install-size="0" version="0.0.0"
        unpack="false"/>
    </feature>
  7. Run mvn clean package from the parent, and the build should complete with the application plug-in.
  8. Now, create an additional project as a Java plug-in project, called com.packtpub.e4.product. Move the com.packtpub.e4.application.product file from the com.pactkpub.e4.application project into the product project.
  9. Copy com.packtpub.e4.application/pom.xml into the com.packtpub.e4.product project, and modify the artifactId to be com.packtpub.e4.product. Change the packaging type to eclipse-repository.
  10. Add the product to the parent by adding the module to the pom.xml file with <module>com.packtpub.e4.product</module>.
  11. Run mvn clean package from the parent, and it will complain with an error:
    [ERROR] Failed to execute goal 
      org.eclipse.tycho:tycho-p2-publisher-
      plugin:0.18.0:publish-products 
      (default-publish-products) on project
      com.packtpub.e4.application:
       The product file com.packtpub.e4.application.product does
       not contain the mandatory attribute 'uid' -> [Help 1]
  12. Edit the com.packtpub.e4.application/com.packtpub.e4.application.product and add uid as a copy of the id attribute.
  13. Switch to a feature-based build (if not already done so) and depend on the org.eclipse.rcp and com.packtpub.e4.feature features, removing the plugins element:
    <product name="com.packtpub.e4.application"
     uid="com.packtpub.e4.application.product"
     id="com.packtpub.e4.application.product"
     application="org.eclipse.e4.ui.workbench.swt.E4Application"
     version="1.0.0.qualifier"
     useFeatures="true"
     includeLaunchers="true">
      <features>
        <feature id="com.packtpub.e4.feature" version="0.0.0"/>
        <feature id="org.eclipse.rcp" version="0.0.0"/>
      </features>
      <plugins/>
      ...
    </product>
  14. Run mvn package from the parent again, and the build should succeed. The com.packtpub.e4.product/target/repository now contains the product for the target platform you're running on.
  15. To build for more than one platform, add the following to either the product's pom.xml file, or the parent pom.xml:
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>target-platform-configuration</artifactId>
      <version>${tycho-version}</version>
      <configuration>
        <environments>
          <environment>
            <os>win32</os>
            <ws>win32</ws>
            <arch>x86_64</arch> <!--arch>x86</arch-->
          </environment>
          <environment>
            <os>linux</os>
            <ws>gtk</ws>
            <arch>x86_64</arch> <!--arch>x86</arch-->
          </environment>
          <environment>
            <os>macosx</os>
            <ws>cocoa</ws>
            <arch>x86_64</arch> <!--arch>x86</arch-->
          </environment>
        </environments>
      </configuration>
    </plugin>
  16. Now, run the build and a product per OS should be built. The example builds for Windows, Linux and OS X on a 64-bit architecture; to build for the 32-bit versions, duplicate the environment block and use <arch>x86</arch> instead.
  17. To materialize the products, and not just provide a p2 repository for them, add the materialize-products goal to the com.packtpub.e4.application/pom.xml file:
    <build>
      <plugins>
        <plugin>
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-p2-director-plugin</artifactId>   
          <version>${tycho-version}</version>
          <configuration>
            <formats>
              <win32>zip</win32>
              <linux>tar.gz</linux>
              <macosx>tar.gz</macosx>
            </formats>
          </configuration>
          <executions>
            <execution>
              <id>materialize-products</id>
              <goals>
                <goal>materialize-products</goal>
              </goals>
            </execution>
            <execution>
              <id>archive-products</id>
              <goals>
                <goal>archive-products</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  18. Run the build from the parent with mvn clean package and the build will create com.packtpub.e4.application/target/products/os/ws/arch, as well as creating archives (ZIP files) of them.
  19. When running the product that is generated, an error may be seen (or can be seen running eclipse -consoleLog):
    java.lang.IllegalStateException: Unable to acquire
     application service.
    Ensure that the org.eclipse.core.runtime bundle is
     resolved and started (see config.ini).
  20. This is an Eclipse product error. In essence, Eclipse products need to have a number of plugins started at boot time in order to run eclipse -application. Add this to the com.packtpub.e4.application.product file:
    <configurations>
      <plugin id="org.eclipse.core.runtime"
       autoStart="true" startLevel="4"/>
      <plugin id="org.eclipse.equinox.common"
       autoStart="true" startLevel="2"/>
      <plugin id="org.eclipse.equinox.ds"
       autoStart="true" startLevel="2"/>
      <!-- for 'dropins' directory support -->
      <!-- plugin id="org.eclipse.equinox.p2.reconciler.dropins"
       autoStart="true" startLevel="4"/ -->
      <plugin id="org.eclipse.equinox.simpleconfigurator"
       autoStart="true" startLevel="1"/>
      <!-- disable old update manager -->
      <property name="org.eclipse.update.reconcile" value="false"/>
      <!-- for 'new' update manager support -->
      <!-- plugin id="org.eclipse.update.configurator"
       autoStart="true" startLevel="4"/ -->
    </configurations>
  21. Run mvn clean package and try running the product again. This time it should succeed.

What just happened?

Eclipse applications are built and made available as a p2 repository or as archived downloads. The p2 repository allows the product to be updated using the standard update mechanisms; this is how updates from 4.2.0 to 4.2.1 to 4.2.2 occur. The archives are used to provide direct download links, as are found at http://download.eclipse.org for the standard packages.

For RCP-based applications, it is easier to build on the RCP feature, which provides the necessary platform-specific fragments for SWT and file-systems. Although building a product based on plug-ins is possible, almost all RCP and SDK applications are built upon either the RCP feature or the IDE feature respectively.

For Eclipse to launch successfully, a number of plug-ins need to be started when the application starts. This is controlled using the config.ini file, which in turn is read by simpleconfigurator, so this needs to be started at the started at the launch of the runtime. In addition to this, the E4 platform requires Declarative Services (DS) to be installed and started, as well as the runtime bundle.

By decomposing the projects into a feature, and then having the same feature used for both the SWTBot and product definitions, it becomes the de-facto place for adding new content. Then these changes to the feature are automatically visible in the product, the automated tests, and in the update site.

Have a go hero – depending on Maven components

Sometimes, it is necessary to depend on components that have been built by ordinary Maven jobs. Although it's not possible to mix and match Tycho and ordinary Maven reactor builds in the same build, it is possible to allow Tycho to resolve Maven components as part of the target platform.

Since ordinary Maven dependencies are represented by the <dependencies> tag, it is possible to define additional dependencies that can be consumed or used by Tycho builds. Normally Tycho won't use this information, but to allow Tycho to resolve those and make them available as OSGi bundles for the purposes of the Eclipse build, modify the configuration for target-platform-configuration and add the line <pomDependencies>consider</pomDependencies> to the <configuration> element.

Note that only OSGi bundles are added to the dependencies list; others are silently ignored.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset