How can I get tycho materialize-product and archive-product to use a directory prefix for my RCP app archive file - eclipse-rcp

How can I add a prefix directory so when I unpack the zip containing my RCP app I get a directory containing the contents?
When tycho materalizes and archives my rcp app it zips up target/products/my.rcp.app/linux/gtk/x86_64/ contents without a directory prefix.
Current zip contents:
./features
./plugins
...
Desired zip contents:
./myapp/features
./myapp/plugins
...
When a user unpacks the zip, I'd like the app directory to be created. I looked through the tycho docs but neither archive nor materialize seems the right place to configure this. I could always use antrun or assembly plugin to do the work but that doesn't feel like the right maven way to solve the problem.
Please let me know how to add a prefix directory.

The configuration is really a bit messed up and not really documented. Since you (currently) can have multiple product files in one eclipse-repository module, you need to select the product ID for which you want to apply the configuration.
So to set the archive root folder for the product with ID product.id, you need the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<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>
<configuration>
<products>
<product>
<id>product.id</id>
<rootFolder>myapp</rootFolder>
</product>
</products>
</configuration>
</plugin>
</plugins>
</build>

Thanks but I needed to use the rootFolder option to add the extra directory. I tried injecting achivePrefix into the .product file but that didn't work. I finally broken down, grabbed tycho source and worked backwards to find rootFolder. After this journey, I saw it in the doc and grocked the meaning.
Doc: http://wiki.eclipse.org/Tycho/Packaging_Types#Creating_Product_Zip_Files
Related: https://issues.sonatype.org/browse/TYCHO-507
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<products>
<product>
<id>match-product-uid-field-from-foo.product-file</id>
<rootFolder>workbench</rootFolder>
</product>
</products>
</configuration>
<executions>
<execution>
<!-- install the product using the p2 director -->
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
<execution>
<!-- create zip file with the installed product -->
<id>archive-products</id>
<goals>
<goal>archive-products</goal>
</goals>
<configuration>
<formats>
<linux>tar.gz</linux>
<win32>zip</win32>
</formats>
</configuration>
</execution>
</executions>
</plugin>

Related

Is it possible to have the materialize-products goal of tycho-p2-director-plugin include source features?

I am using tycho-source-plugin and tycho-source-feature-plugin to generate plugin source jars and source features.
I am generating a p2 repository using tycho-p2-repository-plugin and a product using tycho-p2-director-plugin.
For the p2 repository, I was able to include source jars by adding a category.xml and appending ".source" to the id of all the features.
For the product, I can't find any documentation or examples for how to include source jars with the materialized product or the product archive.
Is it possible?
I've stumbled across this today during work.
Sorry for reviving this, but perhaps this helps someone.
The way it worked for me was to specify a source feature in my product file and let tycho generate sources and a source feature from an existing feature.
Product file:
<feature id="com.some.feature" installMode="root"/>
<feature id="com.some.feature.source" installMode="root"/>
In my "API" bundle that contributes source, I added this in the pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-source-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>doc</id>
<goals>
<goal>plugin-source</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I created a feature project that references this bundle. In the pom.xml of this project I added:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-source-feature-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>doc</id>
<goals>
<goal>source-feature</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>attached-p2-metadata</id>
<phase>package</phase>
<goals>
<goal>p2-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Finally, in the project's parent POM I added:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>attached-p2-metadata</id>
<phase>package</phase>
<goals>
<goal>p2-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
The product editor itself contains an error marker, but that can be ignored.
Tycho itself builds the product and the source attachment is automatically set in the running Eclipse IDE.

ANTLR4 doesn't work with custom configuration in Maven

I always used succesfully ANTLR4 combined with Maven inside Eclipse.
I just want to change the default directory where I store my grammar, since I do not like the standard path which is src/main/antlr4. The issue of this path is the creation of a new java package, that I really do not want.
So I simply decided to create another directory inside my project named grammar which contains another directory called imports. I did this following simply the website guidelines.
Despite this, when I change the grammar it doesn't generate automatically the new sources, even with the maven commands!
So, this is my configuration file pom.xml:
<!-- ANTLR4 -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<configuration>
<goals>
<goal>antlr4</goal>
</goals>
<libDirectory>grammar/imports</libDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
As you can see, the target directory is empty. Before this change, there was a generated-sources directory inside with all the .java files.
So, where is the error?
The correct way is:
<!-- ANTLR4 -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<libDirectory>grammar/imports</libDirectory>
</configuration>
</execution>
</executions>
</plugin>
The <configuration> tag must be at same level than <goals> tag, inside <execution> tag, according to Maven documentation: https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag and https://maven.apache.org/guides/mini/guide-default-execution-ids.html
In fact, the documentation in ANTLR4 Maven plugin is wrong:
http://www.antlr.org/api/maven-plugin/latest/examples/libraries.html

Automatic update of generated css files via m2e

I'm using the lesscss-maven-plugin to generate different css files to the target directory (target\generated-sources) and then use maven-war-plugin to add this directory as an webResouce. Those files will generate perfectly fine.
However the m2e-plugin (version 1.0.0) won't copy those files in the according web-resources folder (m2e-wtp\web-resources), when they have changed. Only when I run a eclipse "maven/update project" changes will be updated. But I want the changes to take affect automatically, when the files have changed. Here is my pom configuration:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions><pluginExecution>
<pluginExecutionFilter>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<versionRange>[1.3.3]</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
....
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/less</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/styles</outputDirectory>
<lessJs>${project.basedir}/tools/less/less-1.7.0.min.js</lessJs>
<includes>
<include>backend/backend-main.less</include>
<include>frontend/frontend-main.less</include>
</includes>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated-sources/styles</directory>
<targetPath>styles</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
There are two options:
Use an m2e specific profile
This is similar to the workaround you found, but a bit cleaner as it activates the profile only on m2e and you use a property to set an alternative value for when you package not using m2e.
You create an m2e specific profile that, when activated, will put the files directly in the m2e-wtp/web-resources/styles directory
<properties>
<lesscss.outputDirectory>${project.build.directory}/${project.build.finalName}/styles</lesscss.outputDirectory>
</properties>
<profiles>
<profile>
<id>m2e</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<lesscss.outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</lesscss.outputDirectory>
</properties>
</profile>
</profiles>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/styles</sourceDirectory>
<outputDirectory>${lesscss.outputDirectory}</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-sources</phase>
</execution>
</executions>
</plugin>
Source: https://github.com/marceloverdijk/lesscss-maven-plugin/issues/8
Use m2e-wro4j
It promises to:
execute wro4j-maven-plugin:run on Eclipse incremental builds, if a change is detected on css, js, less, json, sass resources under wro4j-maven-plugin's contextFolder (src/main/webapp by default)
Source: https://github.com/jbosstools/m2e-wro4j
The idea for my actual workaround was to modify the css file in target\m2e-wtp by "hand".
(First I tried to copy the css files from target\generated-sources to target\m2e-wtp with the maven-resource-plugin, but for a unkown reason, even the maven-resource-plugin was not coping when the filed css files in target\generated-sources gets updated.)
So I came up with this soution: let the lesscss-maven-plugin generate the files twice, one bunch to target\generated-sources and the second one to target\m2e-wtp. Of course the lesscss-maven-plugin has only one output folder, so one has to run the less:compile goal twice. (This is a bit slow, but it works.)
Because one need the second bunch of css files only in eclipse I have added the second execution to an profile.
<profile>
<id>less-eclipse-m2e-workarround</id>
<!--
problem: Eclipse is not updating m2e-wtp folder when css files in generated-sources get modified
workarround: generate the css twice: the normal nonce for generated-sources and a second bunch (only
for eclipse) directly into m2e-wtp folder
to enable this profile add the profile-id to: project/properties/maven/active maven profiles
details: http://stackoverflow.com/questions/23521410/automatic-update-of-generated-css-files-via-m2e
-->
<build>
<plugins>
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<executions>
<execution>
<id>for-eclipse</id>
<phase>generate-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/m2e-wtp/web-resources/styles</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Need to run a batch file inside Eclipse workspace

I have a workspace with multiple projects. All are Maven projects. The target directory of one of the projects contains a batch file after it is built. Now, I need one of the other projects in the workspace to run this batch file. So, I want to get the path to the current workspace programmatically without introducing new dependencies to accomplish this. Does anybody know of a way to do this?
Edit 1: I have a parent Maven project in the workspace. One of its children's target directory contians the batch file. A different child of the parent (which is a testing project) needs to run the batch file. I can use the Maven basedir variable to get the batch file which isn't pretty and doesn't work if I am running individual tests with Eclipse. So I'd like to avoid that solution.
The problem you'll have is that projects in Eclipse aren't necessarily stored in the workspace directory; they could be anywhere on the file system. This means that simply knowing where the workspace is won't necessarily help you find the batch file.
For example: my workspace is $HOME/workspace, but all my projects (the working copies) are in $HOME/code/project. Being able to determine the workspace isn't very helpful. Projects can exist outside the workspace, and still appear in Eclipse by using File -> Import.
Your best bet is probably to 'attach' the batch file to the build using the attach-artifact goal of build-helper-maven-plugin. There's an example of how to do that here.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>script.bat</file>
<type>bat</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Then, your other project can use the copy goal of maven-dependency-plugin to resolve the script into its own directory and run it from there.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<type>bat</type>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/scripts</outputDirectory>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
How about the maven-antrun-plugin? It's not pretty, but it gets the job done:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id><!-- insert an id --></id>
<phase><!-- insert a maven lifecycle phase --></phase>
<configuration>
<tasks>
<exec
dir="${basedir}"
executable="${basedir}/src/main/sh/your-script.sh"
failonerror="true">
<arg line="arg1 arg2 arg3" />
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Ref: http://maven.apache.org/plugins/maven-antrun-plugin/usage.html

How to remove directories from final build zip archive using maven 3

When the build is ready i have p2 folder in all build archives for different platforms.As i understand it's imposible to exclude p2 directory from archives on building stage. So I try pack archive myself instead of using archive-products execution.
The problem is if i want to make archives for others platform or architecture I will need to change pom.
Now i have the following build schema:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>pack-zip-files</id>
<phase>package</phase>
<configuration>
<target>
<zip basedir="${project.build.directory}/products/xxx/win32/win32/x86"
destfile="${project.build.directory}/products/xxx-1.0.${BUILD_NUMBER}-win32.win32.x86.zip"
excludes="${exclude_p2}" />
<zip basedir="${project.build.directory}/products/xxx/linux/gtk/x86"
destfile="${project.build.directory}/products/xxx-1.0.${BUILD_NUMBER}-linux.gtk.x86.zip"
excludes="${exclude_p2}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The quiestion is how to remove p2 folder from all zip files?
What you are doing now is really the only way to do it. You could change the packaging type to eclipse-application and that directory won't be created, but it is a deprecated packaging type and has a whole slew of problems.
The only way to help with multiple POM support would be to put that POM configuration into a profile and have your projects that build products inherit from it. You can also use the osgi.os osgi.arch properties in place of hard-coding things like win32 and linux.