Maven Tycho: How to Exclude eclipsec.exe in a product build? - maven

I switched the build of our Eclipse RCP product from PDE-build to Maven Tycho. In addition to the main (branded) launcher executable, the product now includes the "eclipsec.exe" file. We would like to omit this console-based launcher from our product as it might confuse our customers. Is there a way to do that with Tycho?

I got this answer on the tycho-users list:
In your eclipse-repository project, assuming that you have a .product file, you can place another file in the same directory called .p2.inf
For the contents of your p2.inf file you can put a p2 touchpoint to remove the file:
instructions.configure=org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/eclipsec.exe);

I don't know how to solve with tycho directly, but you can achieve this with the maven-antrun-plugin. There's a little trick to get the deletion of the eclipsec.exe on the timely position.
You have to put the delete step between materialize and the archive goal of the p2-director-plugin. I put the delete step on the phase pre-integration-test and moved the archive step to the phase integration-test.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>delete-eclipsec.exe</id>
<phase>pre-integration-test</phase>
<configuration>
<target>
<delete file="${project.build.directory}/products/<<your.product.id>>/win32/win32/x86/eclipsec.exe"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
<phase>integration-test</phase>
<goals>
<goal>archive-products</goal>
</goals>
</execution>
</executions>
</plugin>
The result: No eclipsec.exe in the product.zip.
Hope that helps.

Related

Source feature generated by Tycho is not being included in p2 repository

I'm trying to create and include a source feature of my plugins in the generated p2 repository. Currently, the source jars for each plugin get created, as does the source feature to each normal feature. However, those source features then don't get included in the final product, an eclipse update site.
In my parent POM, I have
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-source-plugin</artifactId>
<executions>
<execution>
<id>plugin-source</id>
<goals>
<goal>plugin-source</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-source-feature-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<id>source-feature</id>
<phase>package</phase>
<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>attach-p2-metadata</id>
<phase>package</phase>
<goals>
<goal>p2-metadata</goal>
</goals>
</execution>
</executions>
</plugin>
Do I need to add something to the POM of the feature? Of the eclipse-repository? I'm out of ideas.
Gonna answer this myself. I found a solution thanks to this article.
I had to add the generated source feature to the category.xml that describes my update site.
I had tried that before but it didn't work because I made the mistake of writing *.source.feature instead of *.feature.source.

using maven dependency (:copy) plug in not working

I can't seem to figure this out.
I have the following in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
I plan to have all the dependencies copied to target/lib directory.
Why is not doing it?
My project is evolving, so I do not want specify each individual artifact to copy. I want it to take them all, and place it into a proper place during the "package" (or compile) phase.
I get only my mainProject.jar file in the lib folder.
Please, help. What am I missing?
The correct goal for copying dependencies is copy-dependencies, not compile. Also, if you want to invoke the plugin from the command line with mvn dependency:copy, the configuration section should not be inside the executions. Here is a configuration that should work in all cases:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</plugin>
As you can see, I'm running the plugin in the 'package' phase, but it also works in the 'compile' phase, unless you want to include the artifact just built by your own project.

Maven dependency plugin - How can I ensure that an artifact is present when using dependency-unpack

I'm wondering if there is a way to enforce the existence of a dependency to unpack when using the dependency-unpack goal of the maven dependency plugin. I'm using the configuration below and the problem is that if there is no dependency specified for "${properties.artifactId}" in the dependencies section of the pom the build goes ahead even though nothing has been unpacked. It invariably fails later at the test stage but it would be so much easier if the build could fail when no dependency is present. So does anyone know of a way that this can be enforced?
Thanks
Piers
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-properties</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>${properties.artifactId}</includeArtifactIds>
<outputDirectory>${project.build.directory}</outputDirectory>
<includes>${properties.file.name}</includes>
</configuration>
</execution>
</executions>
</plugin>
A couple of executions of the maven-enforcer-plugin should do it. You need one to run before the dependency plugin, to make sure ${properties.artifactId} has a value, then another that runs after the dependency plugin to make sure there are files in the target location. Here's the idea, modify for your requirements.
You may write your own rules too if those available don't quite fit.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>fillInTheVersion</version>
<executions>
<execution>
<id>enforce-config-properties</id>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>properties.artifactId</property>
<message><![CDATA[### Missing property 'properties.artifactId': the artifact that ....]]></message>
</requireProperty>
</rules>
</configuration>
</execution>
<execution>
<id>enforce-files-exist</id>
<phase>process-resources</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesExist>
<files>
<file>${project.build.directory}/${properties.artifactId}</file>
</files>
<message><![CDATA[### Did not find unpacked artifact ...]]></message>
</requireFilesExist>
</rules>
</configuration>
</execution>
</executions>
</plugin>

Run an ant task in maven build phase before war is packaged?

When deploying a webapp I need to update some variables in UI resources, unzip some assets and concat some files, currently this is achieved via an ant task. I'm trying to run this task in the maven build process using something like this...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>deploy-ui</id>
<phase>prepare-package</phase>
<inherited>false</inherited>
<configuration>
<target>
<property name="buildDir" value="${project.build.directory}/${project.build.finalName}" />
<ant antfile="build.xml" target="static-assets" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The above fails because the files have not yet been copied into target directory. If I set the phase to "package" the ant task runs fine and all the files are created/amended, but it's no help as the .war has already been built before the ant target is run.
Basically, I need to run my ant target near the end of the prepare-package phase.
Having looked though the Lifecycle Reference I can't workout how to expose the more granular Goals to the antrun plugin.
Any ideas?
Since I did not get any answer on my comment I guess that you want to stay using maven-antrun-plugin.
From what I've learned and experienced, if two plugins are to be executed on the same phase, then they will be executed in the order they are declared in pom.xml.
For this to work you will have to add the maven-war-plugin in the <plugins/> list after the maven-antrun-plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>deploy-ui</id>
<phase>package</phase>
<inherited>false</inherited>
<configuration>
<target>
<property name="buildDir" value="${project.build.directory}/${project.build.finalName}" />
<ant antfile="build.xml" target="static-assets" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<!-- First step is to disable the default-war build step. -->
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<!-- Second step is to create an exploded war. Done in prepare-package -->
<id>war-exploded</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
<execution>
<!-- Last step is to make sure that the war is built in the package phase -->
<id>custom-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
Added some more executions so that the default-war is first disabled, then the war is exploded and lastly the war is packaged.
As you observed this is a place where the lifecycle doesn't provide the granularity needed. I answered a similar question for someone earlier. It's not an exact answer to your question but the technique may apply.

How to bind ant to a maven-plugin custom goal

The way to integrate maven with ant is to simply use the maven-antrun-plugin like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>package</id>
<phase>package</phase>
<configuration>
<tasks>
<ant antfile="build.xml" target="package" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
in your project's pom.xml file
However I want to be able to have that associated build.xml script along with the execution configuration as part of a maven plugin that defines a custom packaging and a lifecycle.
Is there a way to do that?
I wrote an experiment that did this a little while ago. Have a look at the maven-plugin-in-ant branch of jslint4java.

Resources