Search code examples
javaeclipsemavenosgitycho

Different io packaging operation by os using tycho create-distributions?


My eclipse product need to be packaged (zip,tar.gz,app) for three os (win, linux, mac) using tycho maven plugin.

My parent pom which contain the env filtering used by tycho to produce the different version of product during package phase :

    <?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>
  <groupId>msi.gama</groupId>
  <artifactId>msi.gama.parent</artifactId>
  <version>1.7.0-SNAPSHOT</version>
  <packaging>pom</packaging>
<build>
<plugins>
   <plugin>
         <!-- You can see the effect of Execution Environnement here : https://wiki.eclipse.org/Tycho/Execution_Environments : 
         Tycho ensures that package imports may only be matched against the selected execution environment , 
         b) Tycho hides packages which are not provided by the configured execution environment. -->
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>${tycho.version}</version>
                <configuration>
                   <filters>
            <!-- FIX the JDT core due to bug in tycho https://www.eclipse.org/forums/index.php/t/1068443/ -->
                     <filter>
                        <type>eclipse-plugin</type>
                            <id>org.eclipse.jdt.core</id>
                            <restrictTo>
                                <version>3.11.2.v20160128-0629</version>
                                <!--<version>3.4.0.v20150518-1201</version>-->
                            </restrictTo>
                    </filter>
                    <!-- work around Equinox bug 348045 -->
                    <filter>
                        <type>p2-installable-unit</type>
                            <id>org.eclipse.equinox.servletbridge.extensionbundle</id>
                            <removeAll />
                    </filter>
                    </filters>
            <resolver>p2</resolver>
            <pomDependencies>consider</pomDependencies>
                    <environments>
                        <environment>
                            <os>linux</os>
                            <ws>gtk</ws>
                            <arch>x86</arch>
                        </environment>
                        <environment>
                            <os>linux</os>
                            <ws>gtk</ws>
                            <arch>x86_64</arch>
                        </environment>
                        <environment>
                            <os>win32</os>
                            <ws>win32</ws>
                            <arch>x86</arch>
                        </environment>
                        <environment>
                            <os>win32</os>
                            <ws>win32</ws>
                            <arch>x86_64</arch>
                        </environment>
                        <environment>
                            <os>macosx</os>
                            <ws>cocoa</ws>
                            <arch>x86_64</arch>
                        </environment>
                    </environments>
                </configuration>
                </plugin>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-resources-plugin</artifactId>
              <version>2.5</version>
              <configuration>
                <encoding>UTF-8</encoding>
              </configuration>
            </plugin>

     </plugins>
          </build>
        </project>

My pom.xml for product folder :

<?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>msi.gama</groupId>
    <artifactId>msi.gama.parent</artifactId>
    <version>1.7.0-SNAPSHOT</version>
    <relativePath>../msi.gama.parent/</relativePath>
  </parent>
  <artifactId>msi.gama.application.product</artifactId>
  <packaging>eclipse-repository</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-repository-plugin</artifactId>
                <version>${tycho.version}</version>
                <configuration>
                    <includeAllDependencies>true</includeAllDependencies>
                </configuration>
            </plugin>
            <!-- If the project contains more than one product file ... -->
             <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-director-plugin</artifactId>
                <version>${tycho.version}</version>
                <executions>
                    <execution>
                        <id>create-distributions</id>
                        <goals>
                            <goal>materialize-products</goal>
                            <goal>archive-products</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin> 
          </build>
        </project>

The result in folder :

➜  products git:(master) ls
msi.gama.application.product                       msi.gama.application.product-linux.gtk.x86.zip        msi.gama.application.product-win32.win32.x86_64.zip
msi.gama.application.product-linux.gtk.x86_64.zip  msi.gama.application.product-macosx.cocoa.x86_64.zip  msi.gama.application.product-win32.win32.x86.zip

➜  products git:(master) cd msi.gama.application.product 
➜  msi.gama.application.product git:(master) ls
linux  macosx  win32

My problem is that some specific operation need to be for each OS.

For example, for MACOS packaging, i need to recopy some folders and files to build the metadata of .app application.

Is there a way to specify copy, filter IO operations using tycho, or i need to use something like maven-resource-plugin ?

If this is the case, how can i specify to maven-resource-plugin operation by os at this step of packaging in tycho ?


Solution

  • 1- Is there a way to specify copy, filter IO operations using tycho, or i need to use something like maven-resource-plugin ?

    Yes, you can use maven-resource-plugin and it have filter operations.

    2- If this is the case, how can i specify to maven-resource-plugin operation by os at this step of packaging in tycho ?

    you can define multiple executions in maven-resource-plugin every execution may copy some files to your desired target OS Package.

    Example:

         <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources-win</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/products/msi.gama.application.product/win32/win32/x86/configurations</outputDirectory>
                            <nonFilteredFileExtensions>
                                <nonFilteredFileExtension>app</nonFilteredFileExtension>
                                <nonFilteredFileExtension>config</nonFilteredFileExtension>
                            </nonFilteredFileExtensions>
                            <resources>
                                <resource>
                                    <directory>sourcefolder</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resources-mac</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/products/msi.gama.application.product/macosx/cocoa/x86_64</outputDirectory>
                            <nonFilteredFileExtensions>
                                <nonFilteredFileExtension>extension1</nonFilteredFileExtension>
                                <nonFilteredFileExtension>extesion2</nonFilteredFileExtension>
                            </nonFilteredFileExtensions>
                            <resources>
                                <resource>
                                    <directory>macfolder</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    please refer to maven-resources-plugin optional parameters for more details

    hope this helps.