Difference between revisions of "Scout/Tutorial/3.8/Maven Tycho Build"

From Eclipsepedia

< Scout‎ | Tutorial‎ | 3.8
Jump to: navigation, search
(Testing an Eclipse Scout Client/Server Application (using JUnit/Maven Tycho Surefire))
(Maven Tycho Integration of existing Plugins)
 
(2 intermediate revisions by one user not shown)
Line 35: Line 35:
 
     -DgroupId=org.eclipse.minicrm
 
     -DgroupId=org.eclipse.minicrm
 
     -Dversion=1.0.0-SNAPSHOT
 
     -Dversion=1.0.0-SNAPSHOT
     -DextraDirs==../org.eclipse.minicrm.client,../org.eclipse.minicrm.server,../org.eclipse.minicrm.shared,../org.eclipse.minicrm.ui.rap,../org.eclipse.minicrm.ui.swing,../org.eclipse.minicrm.ui.swt
+
     -DextraDirs=../org.eclipse.minicrm.client,../org.eclipse.minicrm.server,../org.eclipse.minicrm.shared,../org.eclipse.minicrm.ui.rap,../org.eclipse.minicrm.ui.swing,../org.eclipse.minicrm.ui.swt
 
</source>
 
</source>
 
Sample pom.xml:
 
Sample pom.xml:
Line 450: Line 450:
 
=== Testing Shared ===
 
=== Testing Shared ===
 
=== Testing Client ===
 
=== Testing Client ===
 +
=== Debugging a Test ===
 +
* Add the "debugPort" to your pom.xml
 +
<source lang="xml"><plugin>
 +
<groupId>org.eclipse.tycho</groupId>
 +
<artifactId>tycho-surefire-plugin</artifactId>
 +
<version>${tycho.version}</version>
 +
<configuration>
 +
      <debugPort>18081</debugPort>
 +
</configuration>
 +
</plugin>
 +
</source>
 +
* Create a new Debug Configuration in Eclipse of type "Remote Java Application" (localhost:18081)
 +
* Tycho stops with "Listening for transport dt_socket at address: 18081"
 +
* At this point, Run your Debug Configuration
  
 
== Advanced Topics ==
 
== Advanced Topics ==

Latest revision as of 06:32, 1 March 2013

Contents

[edit] Introduction

This tutorial shows how to build an existing Scout application using Maven Tycho. Therefore we use the Minicrm application as base Scout application to integrate it into the Maven Tycho world.

[edit] Installation / Prerequisites

This tutorial assumes that your environment fulfills the following requirements.

[edit] Eclipse

[edit] Eclipse for Scout Developers Juno

Download-URL: http://www.eclipse.org/downloads/packages/eclipse-scout-developers/junor

[edit] m2eclipse

Updatesite-URL: http://download.eclipse.org/releases/juno (or http://download.eclipse.org/technology/m2e/releases)

choose: m2e - Maven Integration for Eclipse	(1.1.0.20120530-0009)
Idea.png
Old version
Version 1.1.0 is not the current version. Therefore you might need to uncheck "Show only the latest versions of available software" to see this version in the list.


Install m2e connectors: Window > Preferences > Maven > Discovery > Open Catalog

choose: Tycho Configurator

[edit] Optional: EGit

Updatesite-URL: http://download.eclipse.org/releases/juno (or http://download.eclipse.org/egit/updates)

choose: Eclipse EGit	(2.0.0.201206130900-r)
        Eclipse JGit	(2.0.0.201206130900-r)

[edit] Maven

Installation guide: http://maven.apache.org/download.html#Installation

[edit] Maven Tycho Integration of existing Plugins

1. Create new Eclipse Project (used as parent POM)
2. Generate POMs for existing projects / plug-ins
mvn org.eclipse.tycho:tycho-pomgenerator-plugin:generate-poms
    -DgroupId=org.eclipse.minicrm
    -Dversion=1.0.0-SNAPSHOT
    -DextraDirs=../org.eclipse.minicrm.client,../org.eclipse.minicrm.server,../org.eclipse.minicrm.shared,../org.eclipse.minicrm.ui.rap,../org.eclipse.minicrm.ui.swing,../org.eclipse.minicrm.ui.swt

Sample pom.xml:

<?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>org.eclipse.scout.autotest</groupId>
    <artifactId>org.eclipse.scout.autotest</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../org.eclipse.scout.autotest.parent/</relativePath>
  </parent>
  <artifactId>org.eclipse.scout.autotest.client</artifactId>
  <packaging>eclipse-plugin</packaging>
</project>
3. Convert every project into a Maven Project: Configure > Convert to Maven Project...
4. [Optional] Resolve Warnings caused by the previous steps (see Problems-View)
  • Delete every bin directory and fix build.properties files (Cause: The project's output folder was changed from /bin to /target/classes)
  • Delete duplicate Maven Coordinates (groupId and version)
5. Extend parent POM configuration
<profiles>
  <profile>
    <id>platform-juno</id>
    <activation>
      <activeByDefault>true</activeByDefault>
      <property>
        <name>platform-version-name</name>
        <value>juno</value>
      </property>
    </activation>
    <properties>
      <eclipse.repo.url>http://download.eclipse.org/releases/juno</eclipse.repo.url>
      <rap.repo.url>http://download.eclipse.org/rt/rap/1.5/runtime</rap.repo.url>
      <platform.version>[3.8,3.9)</platform.version>
      <tycho.version>0.15.0</tycho.version>
    </properties>
  </profile>
</profiles>
 
<repositories>
  <repository>
    <id>eclipse platform</id>
    <url>${eclipse.repo.url}</url>
    <layout>p2</layout>
  </repository>
  <repository>
    <id>rap platform</id>
    <url>${rap.repo.url}</url>
    <layout>p2</layout>
  </repository>
</repositories>
<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-maven-plugin</artifactId>
      <version>${tycho.version}</version>
      <extensions>true</extensions>
    </plugin>
 
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>target-platform-configuration</artifactId>
      <configuration>
        <environments>
          <environment>
            <os>win32</os>
            <ws>win32</ws>
            <arch>x86</arch>
          </environment>
        </environments>
      </configuration>
    </plugin>
  </plugins>
 
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
        <version>${tycho.version}</version>
        <configuration>
          <filters>
            <!-- work around Equinox bug 348045 -->
            <filter>
              <type>p2-installable-unit</type>
              <id>org.eclipse.equinox.servletbridge.extensionbundle</id>
              <removeAll />
            </filter>
          </filters>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>
6. Build parent POM
mvn clean package

[edit] Build Eclipse Scout Swing client application (building an Eclipse Product)

1. Create new Eclipse Project (holding the client Product)
2. Add / Create Swing client Product
  • Important: Tycho only supports *.product file in the project root
  • Important: The *.product file has to contain the attribute 'uid' (correspond to the ID field in the Product Configurator view)
3. Create POM configuration
  • pom.xml
<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>org.eclipse.minicrm</groupId>
    <artifactId>org.eclipse.minicrm</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../org.eclipse.minicrm/</relativePath>
  </parent>
  <artifactId>org.eclipse.minicrm.swing.product</artifactId>
  <packaging>eclipse-repository</packaging>
 
  <properties>
    <product.id>org.eclipse.minicrm.swing</product.id>
    <product.outputDirectory>${project.build.directory}/products/${product.id}/win32/win32/x86</product.outputDirectory>
    <product.finalName>minicrm</product.finalName>
  </properties>
 
  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-p2-director-plugin</artifactId>
        <executions>
          <execution>
            <id>materialize-products</id>
            <phase>package</phase>
            <goals>
              <goal>materialize-products</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <products>
            <product>
              <id>${product.id}</id>
            </product>
          </products>
        </configuration>
      </plugin>
 
      <!-- Workaround: Use an existing config.ini file (caused by the problem that tycho will always generate a default one) -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>${project.build.directory}/../</directory>
                  <filtering>false</filtering>
                  <includes>
                    <include>config.ini</include>
                  </includes>
                </resource>
              </resources>
              <outputDirectory>${product.outputDirectory}/configuration</outputDirectory>
              <overwrite>true</overwrite>
            </configuration>
          </execution>
        </executions>
      </plugin>
 
 
      <!-- Configure the assembly plugin to build the final client zip file -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>assembly.xml</descriptor>
          </descriptors>
          <finalName>${product.finalName}</finalName>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
  • assembly.xml
<assembly>
  <id>org.eclipse.minicrm.client.zip</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <!-- exported product files -->
    <fileSet>
      <directory>${product.outputDirectory}</directory>
      <outputDirectory>/${product.finalName}</outputDirectory>
      <excludes>
        <exclude>p2/**</exclude>
        <exclude>eclipsec.exe</exclude>
        <exclude>artifacts.xml</exclude>
      </excludes>
    </fileSet>
  </fileSets>
</assembly>
4. Convert to a Maven Project: Configure > Convert to Maven Project...
5. Update the parent POM
  • Extend the modules by the new Maven Module
  • Define the newly used Maven Plugins in pluginManagement
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <encoding>UTF-8</encoding>
  </configuration>
</plugin>
 
<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>tycho-p2-director-plugin</artifactId>
  <version>${tycho.version}</version>
</plugin>
6. Build parent POM

[edit] Build Eclipse Scout Server WAR (building an Eclipse Product)

1. Create new Eclipse Project (holding the server Product)
2. Add / Create server Product
3. Create POM configuration
  • pom.xml
<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>org.eclipse.minicrm</groupId>
    <artifactId>org.eclipse.minicrm</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../org.eclipse.minicrm/</relativePath>
  </parent>
  <artifactId>org.eclipse.minicrm.server.product</artifactId>
  <packaging>eclipse-repository</packaging>
 
  <properties>
    <product.id>org.eclipse.minicrm.server.product</product.id>
    <product.outputDirectory>${project.build.directory}/products/${product.id}/win32/win32/x86</product.outputDirectory>
    <product.finalName>minicrm</product.finalName>
  </properties>
 
  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-p2-director-plugin</artifactId>
        <executions>
          <execution>
            <id>materialize-products</id>
            <phase>package</phase>
            <goals>
              <goal>materialize-products</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <products>
            <product>
              <id>${product.id}</id>
            </product>
          </products>
        </configuration>
      </plugin>
 
      <!-- Workaround: Use an existing config.ini file (caused by the problem that tycho will always generate a default one) -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>${project.build.directory}/../</directory>
                  <filtering>false</filtering>
                  <includes>
                    <include>config.ini</include>
                  </includes>
                </resource>
              </resources>
              <outputDirectory>${product.outputDirectory}/configuration</outputDirectory>
              <overwrite>true</overwrite>
            </configuration>
          </execution>
        </executions>
      </plugin>
 
 
      <!-- Configure the assembly plugin to build the final server war file -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>assembly.xml</descriptor>
          </descriptors>
          <finalName>${product.finalName}</finalName>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
  • assembly.xml
<assembly>
  <id>org.eclipse.minicrm.server.war</id>
  <formats>
    <format>war</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <!-- web-inf template -->
    <fileSet>
      <directory>${basedir}/templates/WEB-INF</directory>
      <outputDirectory>/WEB-INF</outputDirectory>
      <includes>
        <include>**</include>
      </includes>
    </fileSet>
 
    <!-- exported product files -->
    <fileSet>
      <directory>${product.outputDirectory}</directory>
      <outputDirectory>/WEB-INF/eclipse</outputDirectory>
      <includes>
        <include>configuration/**</include>
        <include>plugins/**</include>
      </includes>
    </fileSet>
  </fileSets>
</assembly>
4. Convert to a Maven Project: Configure > Convert to Maven Project...
5. Update the parent POM
  • Extend the modules by the new Maven Module
6. Add WEB-INF template to match Equinox in a Servlet Container requirements (directory location has to match the referred fileSet in assembly.xml)
  • A running WEB-INF template can be extracted from a Scout SDK exported war file. Details can be found here.
7. Build parent POM

[edit] Testing an Eclipse Scout Client/Server Application (using JUnit/Maven Tycho Surefire)

Using Maven Tycho Surefire you can test your Eclipse Scout Application automatically. A sample application is on https://github.com/innovad/scout.autotest.demo. More details tbd.

[edit] Plugin/Fragment/Feature Setup

Create the required testing plugins and fragments for your Scout application. You will have to create a plugin and a fragment for each module (client, server, shared) to be tested. We recommend to use the following naming conventions:

  • org.yourapp.client
  • org.yourapp.client.test
    • A plugin holding some support classes (no JUnit tests here)
  • org.yourapp.client.test.fragment
    • A fragment with host org.yourapp.client containing the JUnit tests. The tests will be loaded with the plugin to be tested by the OSGi framework.
  • org.yourapp.server
  • org.yourapp.server.test
    • similar as above
  • org.yourapp.server.test.fragment
    • similar as above
  • org.yourapp.shared
  • org.yourapp.shared.test
    • similar as above
  • org.yourapp.shared.test.fragment
    • similar as above
  • org.yourapp.client.feature
  • org.yourapp.server.feature
  • org.yourapp.server.product
  • org.yourapp.ui.swing.product
  • org.yourapp.ui.swing
  • org.yourapp.parent
  • org.yourapp.target

[edit] Testing Server

[edit] Testing Shared

[edit] Testing Client

[edit] Debugging a Test

  • Add the "debugPort" to your pom.xml
<plugin>
	<groupId>org.eclipse.tycho</groupId>
		<artifactId>tycho-surefire-plugin</artifactId>
		<version>${tycho.version}</version>
		<configuration>
 		      <debugPort>18081</debugPort>
		</configuration>
</plugin>
  • Create a new Debug Configuration in Eclipse of type "Remote Java Application" (localhost:18081)
  • Tycho stops with "Listening for transport dt_socket at address: 18081"
  • At this point, Run your Debug Configuration

[edit] Advanced Topics

[edit] Support Rayo Look and Feel for Eclipse Scout

Add new P2-Repository with the corresponding Update Site URL

[edit] Support JDBC Drivers for Eclipse Scout

Add new P2-Repository with the corresponding Update Site URL

[edit] Integrate the JRE into the client zip

Extend the assembly.xml's fileSets definition:

<!-- integrate the JRE into the client zip -->
<fileSet>
  <directory>/path/to/jre</directory>
  <outputDirectory>/${product.finalName}/jre</outputDirectory>
</fileSet>

[edit] Bundle client and server together (to support direct client download)

Note.png
TODO
Add a description