run calabash-android tests during Maven build - maven

First off, I suspect this isn't going to be easy, because there isn't an entry for calabash-android in the Maven central repository and the calabash-android project doesn't provide one.
That being said, does anyone know how to manage calabash-android tests during a Maven build? Are there any plugins for this? I can't find any, but in the off chance my google-fu has failed me or there's a workaround... I'd love to hear about it.
[edit] I'm using the maven-android plugin for the apk build.

I am assuming you are familiar with the Android Maven plugin? If not, you should check it out. Here is a method that is not bulletproof, but should work:
1- Start by writing a shell script that launches the Calabash tests. This shell script, say calabash.sh, wouldn't be too complicated, just something along the lines of:
calabash-android run ../target/<app>.apk /path/to/calabash/tests
2- Launch this script once maven has finished its integration-test phase (if you are using Android Maven, that's when you run your unit tests). This is taken from this SO question:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Version Calculation</id>
<phase>validate</phase> //This occurs [after integration-test][3]
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/calabash.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
This is not a bulletproof solution because I suspect that Maven cannot report any calabash test failures. Also, you might need to add some bash magic to make the script run until completion before Maven finishes building.

Related

How to run script in mvn as test

I would like to have the following scenario in Maven/Jenkins:
Run test scripts (bash/shell)
when the script exited with a problem (an error), then the Maven build on Jenkins should be on UNSTABLE and not FAILURE status
Question: How can I do it?
You can run scripts in Maven using the Exec Maven Plugin and its exec goal.
If you want to run the script during the test phase, then you can bind an execution of the plugin to it as following:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>run-test-script</id>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable><!-- configure here your script .sh/.cmd --> </executable>
<arguments>
<argument><!-- configure here arguments, if any --></argument>
</arguments>
<workingDirectory><!-- configure here PWD, if required --></workingDirectory>
</configuration>
</plugin>
</plugins>
</build>
Note that you can also configure different successful exit codes via the successCodes configuration entry.
If the script fails, then the build will fail. However, you can change this behavior on the Jenkins build via the Jenkins Text Finder Plugin and configure it as Post-build Action:
You should set-up a regular expression which could be found as part of the Maven build output on Jenkins. As example, the regex .*Script Failed.* would match the string Script Failed printed by the script in such a case. So the build will actually fail, however we can change its status on Jenkins (but not on Maven)
You should check the option Unstable if found which will convert the status of the build from FAILED to UNSTABLE
As per documentation of the Unstable if found option:
Use this option to set build unstable instead of failing the build.
You can see an example of such a configuration in the image below:
As such, you would have a script executed in the test phase as you desired, the Maven build would fail if the script did so but the Jenkins build would change its status according to your configuration of the Text Finder plugin.
Also note: if you want Maven not to fail in case the script did, you can play with the successCodes as mentioned above and still make the Jenkins build change its status to UNSTABLE according to the same configuration of the Text Finder plugin. Hence different combinations are possible.

Incomplete WAR automatically uploaded by Maven

To ease up the deployment process of my Jave EE application, I instructed Maven to automatically copy the resulting WAR file to the application server.
pom.xml:
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution><!-- Run our version calculation script -->
<id>Copy to Application Server</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/copy-to-appserver.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
copy-to-appserver.sh:
scp /home/user/.m2/repository/com/wolf/apix/1.0/apix-1.0.war user#srv-web:/opt/wildfly-8.2.0.Final/standalone/deployments/apix.war
Unfortunately, this fails! The WAR is successfully transmitted to the application server, but it's mixed with old and new code. My assumption is that Maven tries to send it while still being in the WAR creation process, because when I run the copy script copy-to-appserver.sh manually after the deployment, everything works fine with it on the application server.
My question is, what do I have to change, so that Maven only accesses the WAR file when its creation / manipulation is complete?
Your plugin is being executed prematurely in the generate-sources phase
Run it in the last phase by changing the phase to deploy
<phase>deploy</phase>
In addition running the plugin in the correct phase, as suggested by 6ton, you might also want to consider using the Maven WildFly plugin, which specifically designed to solve your problem. That way, you can get rid of that nasty, nasty script.
I would recommend to separate the build process and the deployment process cause the deploy life cycle phase is intended to upload the artifacts to a remote repository.

Intellij IDEA 13 - Artifact build process with latest JS files (Via grunt build)

Is it possible in Intellij (13) to execute grunt build (shell command) as part of the artifact build process so that the artifact to be deploy contains the up to date JS/CSS/HTML files? I see 'Run Ant target'that looks like it would execute a shell command but i'm not using ant (nor do I want to)?
I believe that IntelliJ is using Ant as an adapter to all other tools, because you can run pretty much anything with it.
Just add the following build.xml to your project.
<project name="grunt" default="build">
<target name="build">
<exec executable="grunt">
<arg value="build"/>
</exec>
</target>
</project>
I stumbled upon this question when I was interested in exactly the same. I am using IntelliJ Idea for more than a decade. Now, when I started to work with Angular, NodeJS/NPM and build by Grunt, I really wanted to be able to continue building and launching my development artifacts from the IDE seamlessly, without any manual steps to execute Grunt/browserify even if it is "just" another click on a button before you build. So...
One solution to trigger a Grunt task execution in IntelliJ Idea as a part of the artifact build process, would be to add exec-maven-plugin and bind it to an execution phase e.g. prepare-package, most likely in some separate profile. Something like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>grunt</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>grunt${script.extension}</executable>
<workingDirectory>angular-app</workingDirectory>
<arguments>
<argument>--no-color</argument>
<argument>${grunt.task}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Now in the "Maven Projects" tool window you can right-click the appropriate lifecycle phase in the list and mark as "Execute before rebuild".
This should do the job and satisfy your requirement not to use Ant.
But in my case (though I don't use Ant as a build system for a long time now, nor I like Ant too much), I decided to take the approach proposed by #kukido in his answer. This way I didn't modify Maven to suit IDE which I consider to be conceptually incorrect as the build system (Maven in my case) should not be influenced by anything imposed by IDE. I really think that such a great tool as IntelliJ Idea can take one step further and provide possibility to run more arbitrary commands/goals on "Pre-precess" of preparing an artifact in IDE. For now I will use the Ant as a thin adapter here and keep my POM clean.

How do I write a maven plugin which actually runs?

The instructions here seem very clear:
http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
However, the first problem I run into is that the dependencies are wrong. I also needed to reference the maven-plugin-annotations dependency.
Then, when I attempt to run I get the "No plugin descriptor found at META-INF/maven/plugin.xml" error. I haven't figured out what to do about that.
I've found lots of pages referencing the maven-plugin-plugin, but I can't figure out how to add it to the pom so that it actually does anything which allows my own plugin to run.
Is there an updated version of the plugin development instructions which actually mentions the need to use maven-plugin-plugin?
If I can't get this to work I'm just going to go back to using exec-maven-plugin. It's uglier, but at least it works easily.
There are actually several terrific resources from Sonatype for learning how to write plugins:
Maven the Complete Reference: Writing Plugins
Maven Cookbook: Creating an Ant Maven Plugin
Maven Cookbook: Writing Plugins in Groovy
If I recall correctly, you need to configure the maven-plugin-plugin this way to avoid the "No plugin descriptor found..." issue.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
I forked a simple GitHub project called maven-wrapper (port of the Gradle wrapper) to make it a Maven plugin.
"It should be easy" for you to figure out pieces that you may eventually be missing:
Maven wrapper plugin(Mojo)
Maven Wrapper full POM

Maven generate-source ALWAYS Successful

I am trying to run a ant task in maven generate-sources phase.
However, after many non productive "successes" i've realised, that the build always succeeds regardless of anything i enter.
Here is the plugin config for the pom.xml of my module.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<configuration>
<tasks>
<fail message="Something wrong here."/>
</tasks>
</configuration>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
It still succeeds. If i place a bad ant file. Still succeeds.
Does anyone know what i could be doing wrong here?
The Compile/Clean/Install/Deploy phases all work fine. Just "generate-source" doesnt work at all.
My settings.xml file only contains Repo information
Thanks for any advice
Edit:
I've been able to narrow the error down a little.
<configuration>
<target>
<echo message="hello ant, from Maven!"/>
<echo>Maybe this will work?</echo>
</target>
</configuration>
If place that within the configuration of the plugin, Not in the nested configuration in the execution tag. and run "mvn antrun:run" I see the echos. However If i place it in the nested configuration in the execution element, it doesnt show... Is there some link missing between my mvn goal and the antrun instruction?
I don't get it. The same configuration runs outside of the executions/execution tags, but not within.
Solution *Solution* Solution
AHHH I found it!
In my pom.xml I had all my 'plugins''plugin' configured under the 'pluginManagement' .. This 'pluginManagement' configures the plugins not for this project, but for all children project. Effectively a parent default config file for all children implementing the plugin.. I simply removed the 'pluginManagement' tags and it works...
Thank heavens. I've been looking at this for a full day...
Try adding <failOnError>false</failOnError> to the execution.
Per the documentation, this parameter "specifies whether a failure in the ant build leads to a failure of the Maven build. If this value is 'true', the Maven build will proceed even if the ant build fails. If it is 'false', then the Maven build fails if the ant build fails."
This is counterintuitive to me. I would think that the default value of "true" would cause the Maven build to fail if the ant build failed, but that isn't what the docs appear to be saying.

Resources