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

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.

Related

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

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>

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

Tycho puts "p2" folder in the product with eclipse-repository and tycho-p2-director-plugin plugins

I changed my Tycho+Maven build (RCP application) to use Tycho 0.13 and eclipse-repository plus tycho-p2-director-plugin (instead of my old "eclipse-application" in Tycho 0.10).
I managed to get the build working (producing the ZIP files), but they are 2 times bigger than they used to be.
I see Tycho puts a lot of additional stuff my product does not need:
1) "p2" folder at the root level - 35 Mb.
2) a lot of useless plugins, like
plugins/org.eclipse.jdt.debug_3.6.1.v20100715_r361
plugins/org.eclipse.pde.build_3.6.2.R36x_20110203
plugins/org.junit_4.8.1.v4_8_1_v20100427-1100
......etc.........
how to configure "eclipse-repository" and "tycho-p2-director-plugin" to avoid this? At least to not put "p2" folder in the product. My software does not use "p2 update" mechanism for auto-updates.
your product may drag in transitive optional dependencies.
See [1] for how to avoid this.
The p2/ folder is always created but should not be 35MB.
If you can provide a sample project to reproduce the problem, open a bug [2] and attach it along with steps how to reproduce.
[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=342704
[2] https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Tycho&rep_platform=All&op_sys=All
I ended up removing "archive-products" completely - it's not flexible and requires a lot of horrible hacking with unpacking/repacking/renaming. I'm packing the ZIP files myself now:
<properties>
<distributive.prefix>${project.build.directory}/products/taskadapter</distributive.prefix>
<exclude_p2>**/p2/**</exclude_p2>
</properties>
<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>create-zip-files</id>
<phase>package</phase>
<configuration>
<target>
<zip basedir="${distributive.prefix}/win32/win32/x86"
destfile="${project.build.directory}/taskadapter-win-${project.version}.zip"
excludes="${exclude_p2}" />
<zip basedir="${distributive.prefix}/linux/gtk/x86"
destfile="${project.build.directory}/taskadapter-linuxgtk-${project.version}.zip"
excludes="${exclude_p2}" />
<zip basedir="${distributive.prefix}/macosx/cocoa/x86"
destfile="${project.build.directory}/taskadapter-macos-${project.version}.zip"
excludes="${exclude_p2}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
"p2" folder, the folder is created by p2 itself when materializing the product. if your application doesn't support update itself, you can simply remove it from the built product.
useless plugins. There is no way to remove them from your final materialized product, they are transitively required by your product. See this for detail.

Maven : How to generate project's war file in two folders

I want that when I run the mvn install, a war can be generated in the /target and an other war in the c:....tomcat 6\deploy directory.
I'm using maven2, Eclipse and m2eclipse. How to do this ??
Thnx :)
You could try to use the maven-antrun-plugin to copy your war to the tomcat deploy directory like this:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="{project.build.directory}/${project.actifactId}-${project.version}.war" tofile="<your tomcat path>/${project.actifactId}-${project.version}.war" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Maybe you don't need to copy the war file if you try the Maven Jetty Plugin. This plugin is for running a web application directly from Maven.
Try the cargo-maven2-plugin. Probably something like this would work:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>deploy-local</id>
<phase>install</phase>
<goals>
<goal>deployer-deploy</goal>
<goals>
</execution>
</executions>
<configuration>
<container>
<containerId>tomcat6x</containerId>
</container>
<configuration>
<type>existing</type>
<home>/your/tomcat/dir</home> <!-- replace as needed -->
</configuration>
</configuration>
</plugin>
... slap that into a profile or the top-level <build><plugins> section and see if it works for you ...

How to check and access javadoc/source for Maven Artifacts

I am writing a Maven plugin which needs to check if a certain project
dependency has javadocs and sources available... and if so, would like
to download them and archive them on a server.
I cannot find out how to check if the javadocs and source are available
or how to access them if they are.
Any help would be appreciated.
You can reference additional artifacts by adding the classifier tag to a dependency. The classifier is the additional part of the artifact's name in the repository, e.g junit-4.5-sources.jar
So to directly declare a dependency on the junit sources jar you can specify it as follows:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
If you want to download all the dependency sources, use the maven-dependency-plugin's copy-dependencies goal specifying the classifier sources. The following example defines two executions, one for sources and one for javadocs.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>sources</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
</configuration>
</execution>
<execution>
<id>javadocs</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<classifier>javadoc</classifier>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.build.directory}/javadocs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you want to package all the downloaded artifacts into a zip, you can use the maven-assembly-plugin to create an archive of the project. The example below are the contents of an assembly descriptor file to include the sources and javadocs directories:
<assembly>
<id>project</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>${project.build.directory}/sources</include>
<include>${project.build.directory}/javadocs</include>
</includes>
</fileSet>
</fileSets>
</assembly>
To reference the assembly, add a plugin configuration to your pom. This assumes the above contents have been put in src/main/assembly/sources.xml (make sure it is defined after the dependency configuration above):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/sources.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>