build helper plugin not parsing project version - parsing

I have a project where I have a need to break the version number down and access it's component pieces when building a manifest file. After doing some searching around I found the build-helper-maven-plugin and figured my problem was solved. I added the plugin to the master POM, it's shown below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
The project version at this point in time is 3.0.0-SNAPSHOT. I wanted to see all the pieces (although in the final version I may not use them all) so I added these lines to my manifest file.
<value name="majorVersion">${parsedVersion.majorVersion}</value>
<value name="minorVersion">{$parsedVersion.minorVersion}</value>
<value name="incrementalVersion">${parsedVersion.incrementalVersion}</value>
<value name="versionQualifier">${parsedVersion.qualifier}</value>
<value name="parsedBuildNumber">${parsedVersion.buildNumber}</value>
After building I get this.
<value name="majorVersion">0</value>
<value name="minorVersion">{$parsedVersion.minorVersion}</value>
<value name="incrementalVersion">0</value>
<value name="versionQualifier">3.00.0-SNAPSHOT</value>
<value name="parsedBuildNumber">0</value>
The value tag is actually an XML tag and there is a closing value tag in the manifest file, I had to remove them since they were messing up the display.
So the incremental version appears to be correct, although I'm not all that confident given that the major version isn't correct, it found no minor version, and the qualifier comes back as the entire version number, rather than just the SNAPSHOT piece i had expected. I can see where a build number of zero would be correct since we don't have what Maven considers a build number.
Any ideas on why the version number doesn't seem to be parsing? Have I implemented this plugin incorrectly?
thanks
steve

Change {$parsedVersion.minorVersion} to ${parsedVersion.minorVersion}
When are you inspecting the property values? Ensure you're doing it after the validate phase in your example, or if you want it on the same phase ensure the build-helper-maven-plugin occurs before the plugin you're using to inspect the property values. If I have this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Major: ${parsedVersion.majorVersion}</echo>
<echo>Minor: ${parsedVersion.minorVersion}</echo>
<echo>Incremental: ${parsedVersion.incrementalVersion}</echo>
<echo>Qualifier: ${parsedVersion.qualifier}</echo>
<echo>BuildNumber: ${parsedVersion.buildNumber}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
after the build-helper-maven-plugin, I see this in the output of mvn validate:
[INFO] --- build-helper-maven-plugin:1.7:parse-version (parse-version) # so-example ---
[INFO]
[INFO] --- maven-antrun-plugin:1.1:run (default) # so-example ---
[INFO] Executing tasks
[echo] Major: 1
[echo] Minor: 0
[echo] Incremental: 0
[echo] Qualifier: SNAPSHOT
[echo] BuildNumber: 0
anew#buddha:~/dev/so-example$ grep "<version>" pom.xml | head -1
<version>1.0.0-SNAPSHOT</version>

Related

Donut report (donut-maven-plugin) is not getting generated when some of the tests fails

I am using Donut report (donut-maven-plugin) for aggregating a report for parallel cucumber tests ran using cucumber-jvm-parallel-plugin from github.temyers team.
Here is my POM snippet:
<profiles>
<profile>
<id>TestSuite1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<app.config>//src//test//java//envConfig//localGridConfig.properties</app.config>
<test.tag>#android</test.tag>
<dummy.tag>#dummy</dummy.tag>
<device.name>browserstack.ios</device.name>
<!--<target.env>browserStackEnv</target.env>-->
</properties>
</profile>
<profile>
<id>TestSuite2</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<app.config>//src//test//java//envConfig//sauceLabsGridConfigAndroid.properties</app.config>
</properties>
</profile>
<profile>
<id>TestSuite3</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<app.config>//src//test//java//envConfig//sauceLabsGridConfigIOS.properties</app.config>
</properties>
</profile>
</profiles>
<build>
<!--<sourceDirectory>src</sourceDirectory>-->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<parallel>methods</parallel>
<threadCount>5</threadCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<forkCount>5</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/Parallel*IT.class</include>
</includes>
<systemPropertyVariables>
<deviceName>${device.name}</deviceName>
<targetEnv>${target.env}</targetEnv>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>4.2.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<!--<phase>validate</phase>-->
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<!-- Mandatory -->
<!-- List of package names to scan for glue code. -->
<glue>
<package>stepDefs</package>
</glue>
<!-- These are optional, with the default values -->
<!-- Where to output the generated tests -->
<outputDirectory>${project.build.directory}/cucumber-parallel/html</outputDirectory>
<!--<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>-->
<!-- The directory, which must be in the root of the runtime classpath, containing your feature files. -->
<featuresDirectory>src/main/resources/features/</featuresDirectory>
<!-- Directory where the cucumber report files shall be written -->
<!--<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>-->
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<!-- List of cucumber plugins. When none are provided the json formatter is used. For more
advanced usage see section about configuring cucumber plugins -->
<format>json,html,rerun</format>
<plugins>
<plugin>
<name>json</name>
<extension>json</extension>
<!--Optional output directory. Overrides cucumberOutputDirectory. Usefull when different
plugins create files with the same extension-->
<outputDirectory>${project.build.directory}/cucumber-parallel/json</outputDirectory>
</plugin>
<!--<plugin>-->
<!--<name>com.example.CustomHtmlFormatter</name>-->
<!--<extension>html</extension>-->
<!--</plugin>-->
<plugin>
<name>com.cucumber.listener.ExtentCucumberFormatter</name>
<extension>html</extension>
</plugin>
</plugins>
<customVmTemplate>
src/main/resources/cucumber-extents-report-runner.java.vm
</customVmTemplate>
<!-- CucumberOptions.strict property -->
<strict>true</strict>
<!-- CucumberOptions.monochrome property -->
<monochrome>true</monochrome>
<!-- The tags to run, maps to CucumberOptions.tags property. Default is no tags. -->
<tags>
<tag>
<!--${dummy.tag}-->
</tag>
</tags>
<!-- Generate TestNG runners instead of JUnit ones. -->
<useTestNG>false</useTestNG>
<!-- The naming scheme to use for the generated test classes. One of 'simple' or 'feature-title' -->
<namingScheme>simple</namingScheme>
<!-- The class naming pattern to use. Only required/used if naming scheme is 'pattern'.-->
<!--<namingPattern>**/Parallel*IT.class</namingPattern>-->
<namingPattern>Parallel{c}IT</namingPattern>
<!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per scenario. FEATURE generates a runner per feature. -->
<parallelScheme>SCENARIO</parallelScheme>
<!--<parallelScheme>FEATURE</parallelScheme> <!–Using Feature for accomodating Scenario Outline –>-->
<!-- Specify a custom template for the generated sources (this is a path relative to the project base directory) -->
<!--<customVmTemplate>src/test/resources/cucumber-custom-runner.vm</customVmTemplate>-->
<!-- Specify a custom package name for generated sources. Default is no package.-->
<packageName>
</packageName>
</configuration>
</execution>
</executions>
</plugin>
<!-- Cucumber report merger
-->
<plugin>
<groupId>report.donut</groupId>
<artifactId>donut-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<id>execution</id>
<phase>post-integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<sourceDirectory>${project.build.directory}/cucumber-parallel</sourceDirectory>
<outputDirectory>${project.build.directory}/TrackMergeReport</outputDirectory>
<timestamp>${maven.build.timestamp}</timestamp>
<template>default</template>
<projectName>NativeAppsAutomation</projectName>
<!-- optional -->
<customAttributes>
<customAttribute>
<name>App Name</name>
<!--<value>${app.name}</value>-->
<value>smartphone.editor.beta</value>
</customAttribute>
<customAttribute>
<name>Device Name</name>
<!--<value>${app.name}</value>-->
<value>${device.name}</value>
</customAttribute>
<customAttribute>
<name>Target Env</name>
<value>${target.env}</value>
</customAttribute>
</customAttributes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Note:
- There's no trace/mention about attempt to generate Donut report in maven run log (when one of the tests fail):
- I use mvn clean verify or mvn clean integration-test to run the framework
Run 1: PASS
Run 2: PASS
Run 3: Can't locate an element by this strategy: Locator map:
- native content: "By.chained({By.xpath: //*[contains(#text,'rints')]})"
- html content: "By.cssSelector: div[data-id='print'] > .caption"
Tests run: 51, Failures: 0, Errors: 9, Skipped: 5
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13:49 min
[INFO] Finished at: 2018-01-05T14:54:50+01:00
[INFO] Final Memory: 27M/306M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test
(default-test) on project NativeAppsAutomation-project: There are test
failures.
[ERROR]
[ERROR] Please refer to /../target/surefire-reports
for the individual test results.
[ERROR] -> [Help 1]
Noticed that - individual plain Cucumber reports (json, Html, xml) are getting generated in the target/cucumber-parallel folder as expected for both All pass & runs with failures or all failures.
Whereas , when all tests pass then Donut aggregate report is getting generated,

Append or merge default maven plugin configuration

Is it possible to not override but merge or append to default plugin configuration in Apache Maven just like it's possible with parent POM configuration elements?
I'm note sure if i understand your questions correctly:
If you like for example to change the configuration of an already defined plugin you should be aware that you need to use the correct execution id which can be looked at during a default build which is printed out in the log output (something like this):
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) # parent ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-maven) # parent ---
[INFO]
The value in braces gives the hint: default-clean can now be used to add information to the configuration or also to change behaviour:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>default-clean</id>
<configuration>
<.. combine.children="append">
</...>
</configuration>
See more explanations following.
You can do this if you need. Lets say you have defined the following in a parent pom file:
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<configuration>
<values>
<value>First</value>
</values>
</configuration>
</plugin>
In an inheriting pom file you can now write the following:
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<configuration>
<values combine.children="append">
<value>Second</value>
</values>
</configuration>
</plugin>
Or if you do something different:
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<configuration>
<values combine.children="override">
<value>Second</value>
</values>
</configuration>
</plugin>
or you can give explicitly what is already the default:
<plugin>
<groupId>..</groupId>
<artifactId>..</artifactId>
<configuration>
<values combine.children="merge">
<value>Second</value>
</values>
</configuration>
</plugin>
This is documented in the pom reference.

liquibase maven plugin disable checksum

I'm using liquibase with maven-3. The first run works as expected. Consecutive runs though (even if the sql files contain changes) fail, as they are viewed as equivalent from liquibase and ignored (checksum).
All the sql actions in my sql scripts have taken into account the previous runs, so I don't want this behaviour. With this setup that you see below, how can I force liquibase to always execute my scripts, no matter the changes?
As you can see below I've already tried setting clearCheckSums as a goal and indeed it clears the hash values, but still no luck (thus commented out).
This is the profile I've created
<profile>
<id>liquibase-executions</id>
<build>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.2</version>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>update-schema</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
<!--<goal>clearCheckSums</goal>-->
</goals>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${basedir}/src/main/resources/liquibase.sql</changeLogFile>
</configuration>
</execution>
<execution>
<id>update-data</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
<!--<goal>clearCheckSums</goal>-->
</goals>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${basedir}/src/main/resources/liquibase-populate.sql</changeLogFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
And this is how I execute it
mvn process-resources -Pliquibase-executions -Ddb.url=POSTGRES_IP:5432/POSTGRES_DB -Dliquibase.username=POSTGRES_USERNAME
The Liquibase Maven plugin expects a changelog file, no plain .sql file. This file should contain your changeSets that you want Liquibase to execute. These changeSets can be instructed to be run every time you run Liquibase (by default they're only executed once). So there's no need to tamper with the checksum. For example your changelog file could look something like this:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet id="your-id" author="msp" runAlways="true">
...
</changeSet>
</databaseChangeLog>
The important part to achieve your intended behaviour is to set the runAlways="true" attribute in your liquibase changeset.

Maven: Overview for the values of Maven properties

I would like to find out the values of all Maven properties as they apply to some Maven project.
mvn help:system lists OS environment variables and JVM system properties, but no Maven properties.
mvn help:evaluate only works in an interactive mode, that means I have to type a single Maven property, (e.g. ${project.build.outputDirectory}) to get the value of that property.
I'm looking for a way get a full list of all Maven properties and their values.
As a workaround, add this to the <plugins> ... </plugins> section inside your project's pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Now execute mvn validate.
On the console, prefixed with [echoproperties], there will be the full list of system properties, including those set by Maven such as project.build.outputDirectory, basedir, and settings.localRepository.
the maven-help-plugin does what you want, just call it with -Dexpression=project.properties this will print the properties tag of the effective pom.
mvn help:evaluate -Dexpression=project.properties
Bonus Points when you just want the properties output and not the maven output
mvn help:evaluate -Dexpression=project.properties -q -DforceStdout
or with the explicit version because -DforceStdout works since version 3.1.0
mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.properties -q -DforceStdout
Not sure if helps, but I found this when trying to do the same thing:
mvn com.github.ekryd.echo-maven-plugin:echo-maven-plugin:echo -Decho.message='${project.build.testOutputDirectory}'
From here.
Adding the following to ${user.home}/.m2/settings.xml:
<pluginGroups>
<pluginGroup>com.github.ekryd.echo-maven-plugin</pluginGroup>
</pluginGroups>
the command can be shortened to:
mvn echo:echo -Decho.message='${project.build.testOutputDirectory}'
I don't know how to get them "officially", but here is a workaround. Add maven-antrun-plugin to your project and run mvn test -X. The plugin will show all properties passed to it from Maven. The list looks complete to me.
Actually project.build.outputDirectory is there but you need to execute in 'compile' phase, and NOT in 'validate'. I guess what properties are available also depends on the current phase for the executing goal of a particular plug-in, in this case 'maven-antrun-plugin'.
<!-- Ant Run Plugin for debugging pom.xml and calling ant tasks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${ant.plugin.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Had the same issue. Changed the timeout and maxheap in findbugs configuration through maven.
The below fixed it for me :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<maxHeap>2048</maxHeap>
<timeout>1800000</timeout>
</configuration>
</plugin>

Maven: mavent--ant-run does not support attribute

Currently I'm working on a maven build script and my next issue is to copy source files into a target folder. I found this thread and it works fine unless I don't use the 'flattern' attribute. I know that the computer makes all things right, but I wonder why the build will fail.
Here my code using the maven antrun plugin:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<target>
<copy todir="${project.basedir}/target" flattern="true" overwrite="true">
<fileset dir="${project.basedir}/src/main"/>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The error message I get is
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (default) on project setup_core: An Ant BuildException has occured: copy doesn't support the "flattern" attribute
[ERROR] around Ant part ...<copy todir="C:\Projekte\CQ5_Migration\setup\core_upload/target" overwrite="true" flattern="true">... # 4:101 in C:\Projekte\CQ5_Migration\setup\core_upload\target\antrun\build-main.xml: The <copy> type doesn't support the "flattern" attribute.
[ERROR] -> [Help 1]
Have I overseen somthing and if so what is/are the missing fact(s)?
Thanks again for your help :-)
It should be "flatten" not "flattern".
Remove the 'r'.

Resources