Turn Off Logging Ant Copy Task in AntRun - ant

I'm copying some files in an Ant Task within Maven and I cannot figure out how to tell ant not to log the fact that it is copying some files.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>generateContext</id>
<phase>compile</phase>
<configuration>
<target>
<copy file="src/main/context/context.xml"
toDir="target/context/"
overwrite="true" verbose="false">
<filterset>
<filter token="deploy.path" value="${deploy.path}" />
<filter token="build.env.deployment.war.name"
value="${build.env.deployment.war.name}" />
</filterset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Every time I execute the task I see the following in the console:
[INFO] --- maven-antrun-plugin:1.7:run (generateContext) # jive-web ---
[INFO] Executing tasks
main:
[copy] Copying 1 file to /Users/jmajors/turbinetrunk/jive/jive-web/target/context
Based upon the ant copy task documentation I wouldn't have thought that I would even need to worry about it, because it appears that logging is turned off by default, but that doesn't appear to be impacting whether or not something is logged. Is there another setting that I should be paying attention to?
Thanks,
Jeremy

When running Ant standalone, you would add the -quiet command line argument.
Here within Maven, it is the Maven AntRun plugin which is controlling the verbosity of Ant. As far as I can see, the verbosity of Ant is equal to the setup of the log of the Maven AntRun plugin.
I don't know much of Maven, if you can figured out how to set the level of log of the Maven AntRun plugin to "WARN", it will become quieter.
You could use the -q command line argument of Maven, but everything in Maven will become quieter.

According the ant manual-->running apache ant, you can add the -quiet command line flag to ant. Update the run configuration to use this flag. You could also change out the default logger for a log4j ant logger and suppress unwanted log entries in a log4j configuration: ant manual-->loggers & listeners.

Related

Jenkins not showing all the Junit reports in the status of the build

I have a maven build which contains multiple projects which in-turn contains lot of sub maven modules. At the test phase each project will execute their test and programatically I am generating junit test reports and put it in corresponding modules target folder in /target/surefire-reports/. After the build get success in the status page of the build in Jenkins I am able to see the test result as graph. But the problem is Jenkins is not taking all the generated junit xml it takes only partial amount of it. I have totally 850 test cases in the whole build but it only shows 449 in the graph and test results. What will be the cause of it.
There is no problem in generating junit reports all the test cases are generating reports but the Jenkins is not able to identify all. The count of the test cases in Jenkins varies for each build without adding or removing any of the test files.
FYI :
I am manually generating the junit reports. To notify it to Jenkins I have enabled the maven sure fire plugin and added the reports in surefire-reports folder in target. I have created maven build project not the free style project.
Is there is anything i am missing ?
I ran into this as well, and here are my thougths on it:
http://javamemento.blogspot.no/2016/02/sonar-jacoco-maven-multi-module.html
The issue is you need to concatenate the results into one report file.
So your pom should have something like this:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>agent-for-ut</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
</execution>
<execution>
<id>agent-for-it</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<append>true</append>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The keyword here is
<append>true</append>
Now all your data will be stored in 1 report file.
Make sure you have called your maven-surefire-plugin in only your parent pom. If you include it in your child poms as well, the results will be overwritten by the parent pom. More quirks here: http://javamemento.blogspot.no/2016/06/sonar-maven-surefire-plugin-quirks.html
Lastly make sure you are using junit and void methods correctly. Test for the side effects of the method or surefire will behave strangely.
http://junit.org/junit4/faq.html#atests_4

Jenkins Publish TestNG Results not working

I am running Jenkins 1.571. I am building my project with a pom.xml. I have two executions of maven-surefire-plugin to execute two testng suites in a forked mode.
But Jenkins build#/testReport page shows test results for only first suite. Build logs show test cases from both suites are successfully executed.
I want to include results from both suites into report, so I added Publish TestNG Results plug-in, but that doesn't show any results at all. Any idea on what I might be missing?
In my Jenkins configuration, I specified 'TestNG XML report pattern' = '**/target/surefire-reports/testng-results.xml'
Build log shows:
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/target/surefire-reports/testng-results.xml
Did not find any matching files.
Finished: SUCCESS
My relevant pom.xml:
<!-- run unit test cases -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<environmentVariables>
<outputDirectory>${project.build.directory}</outputDirectory>
</environmentVariables>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<forkMode>once</forkMode>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/testngSuite1.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
<execution>
<id>special-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkMode>always</forkMode>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/testngSuite2.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</execution>
</executions>
</plugin>
Eventually I found out that I need to use forward slash for TestNG plugin to locate the file (My Jenkins runs on Windows).
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: C:/workspace/project/target/surefire-reports/Suite1/UnitTests.xml;C:/workspace/project/target/surefire-reports/Suite2/UnitTests.xml
Saving reports...
Processing 'C:\programs\Jenkins\jobs\project\builds\2014-10-02_21-57-48\testng\testng-results-1.xml'
Processing 'C:\programs\Jenkins\jobs\project\builds\2014-10-02_21-57-48\testng\testng-results.xml'
TestNG Reports Processing: FINISH
Finished: SUCCESS
Also this reference helped:
http://www.seleniumtests.com/p/testing-forum.html#nabble-td5001883
1.Select "Editable Email Notification" on Post-Build actions.
2.In the Default Content section : remove $DEFAULT_CONTENT.Place the following code to inject your html report into the default content :-
${FILE,path=”relative path to html file”}
Eg: ${FILE,path=”MyWorkspace/MyProj/test-output/emailable-report.html”}
More detailed steps given below in my tech blog:-
https://itisatechiesworld.wordpress.com/2015/01/06/including-testng-reports-within-the-jenkins-email-notifications/
Also let me know if you have any other reporting related questions using Jenkins.
Will try to help out. :)
Regards,
VJ

Jmeter Reports do not get generated if there are errors if the Jmeter Test executed using Jmeter Maven Plugin

I am running Jmeter tests using Jmeter Maven Plugin. After I run the test I want to generate simple reports that indicate if the tests passed/failed. I referred to
https://stackoverflow.com/questions/4669467/jmeter-how-to-create-summary-report-from-jtl-file?lq=1
for generating the reports. I have added a shell script to generate html reports from the jmeter jtl result files.Then I use the exec-maven plugin to execute the script that in turn generates the html report files.So far Everything works fine. The problem that I am facing is that if one of the Jmeter tests fails then the report isn't generated at all.
So I am assuming that maven exits once it detects error in the test-suites and doesn't execute the exec-maven plugin and hence the shell script isnt called at all.
Can someone give me directions on this? Is there any property in the pom file or any settings that I can try to get around this. Any help would be truly appreciated!
You can set the <ignoreResultFailures> configuration setting to true to make the plugin ignore the failures and continue executing everything else.
+---+
<project>
[...]
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreResultFailures>true</ignoreResultFailures>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
[...]
</project>
+---+

Jenkins job with different configuration?

I am refactoring a single "too" big multiple module maven Jenkins job to about 10 smaller maven Jenkins jobs (one parent maven module with childs).
I like to run a single maven job every 2 hours without the tests and source code analyzers like PMD and Checkstyle, and once a day during the night I want to run it with the tests and source code analyzers.
I am not sure how to do this best.
Jenkins is very flexible and I read the Jenkins O'Reilly book, but I am stil not sure how to do it :(
I was thinking about using the Maven Jenkins plugin with job inheritances, but I still end up with many jobs I guess. Is this the way to go ?
Please some advice?
- Ed
One trick I use is to set a property for build phase for any plugin that I want to disable and set it manually in jenkins. for example see the pmd plugin below:
See ${pmd.phase}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<targetJdk>1.6</targetJdk>
<linkXref>false</linkXref>
<failOnViolation>true</failOnViolation>
<failurePriority>1</failurePriority>
<rulesets>
<ruleset>${pom.basedir}/pmd-rulesets.xml</ruleset>
</rulesets>
</configuration>
<executions>
<execution>
<phase>${pmd.phase}</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Now define
<properties>
<pmd.phase>none</pmd.phase>
</properties>
In jenkins set the Goals and options field to clean install -Dpmd.phase=validate
The command line property overrides defined one so pmd will run only if the -Dpmd.phase=validate is present.

Upload file via Ant FTP task in Maven

I'm trying to upload a file using an Ant task. If I use Ant directly the file is uploaded, but if I call the ant task via Maven (using the maven-antrun-plugin) I get the following error:
An Ant BuildException has occured: The following error occurred while executing this line:
/home/me/proj/build.xml:15: Problem: failed to create task or type ftp
Cause: the class org.apache.tools.ant.taskdefs.optional.net.FTP was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-ANT_HOME/lib
ant-commonsnet.jar is clearly available to Ant:
$ ls $ANT_HOME/lib | grep ant-commons-net
ant-commons-net.jar
Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?
ant-commons-net.jar is clearly available to Ant
Yes, but Maven and the maven-antrun-plugin is not using your local Ant install.
Is the Ant classpath defined separately for maven-antrun-plugin, or am I missing something?
The way to use Ant Tasks not included in Ant's default jar is documented in Using tasks not included in Ant's default jar (which should definitely help):
To use Ant tasks not included in the
Ant jar, like Ant optional or custom
tasks you need to add the dependencies
needed for the task to run to the
plugin classpath and use the
maven.plugin.classpath reference if
needed.
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>my-test-app</artifactId>
<groupId>my-test-group</groupId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>ftp</id>
<phase>deploy</phase>
<configuration>
<target>
<ftp action="send" server="myhost" remotedir="/home/test" userid="x" password="y" depends="yes" verbose="yes">
<fileset dir="${project.build.directory}">
<include name="*.jar" />
</fileset>
</ftp>
<taskdef name="myTask" classname="com.acme.MyTask" classpathref="maven.plugin.classpath"/>
<myTask a="b"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-commons-net</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
As Pascal has mentioned, the maven-antrun-plugin is not using the ant specified by your $ANT_HOME environment variable, and the configuration that he's mentioned is probably the best way to do it consistently from a pure maven perspective.
However, the jar can be stored in $USER_HOME/.ant/lib instead of $ANT_HOME/lib, these jars should be available on the classpath for any instance of ant that is run by that user.
Note that your ant script cannot assume that the jars are present, and that the jars are only placed on the classpath at startup, so if the script defines a setup target to download the jars into $USER_HOME/.ant/lib, then this target would have to be run in a "separate-ant-session", before and is invoked again to execute the task that depends on the jar.
The only potential benefit that you may derive from this approach is that the Ant script may be runnable from maven and Ant.
There is a classpath property which can be set in <tasks> section of maven-antrun-plugin.
For instance,
<property name="classpath" refid="maven.compile.classpath"/>

Resources