How to configure properties for evosuite maven plugin in the pom file? - maven

I need to set a property for evosuite through maven. The property is assertion_strategy and I want to set it to all
I tried to pass it through the maven commandm didn't work.
I also tried to set it through the pom, but I guess I'm not using the right tags
<plugin>
<artifactId>evosuite-maven-plugin</artifactId>
<groupId>org.evosuite.plugins</groupId>
<version>${evosuiteVersion}</version>
<configuration>
<properties>
<property>
<name>assertion_strategy</name>
<value>all</value>
</property>
</properties>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare</goal>
</goals>
<phase>process-test-classes</phase>
</execution>
</executions>
</plugin>
I expect to see -Dassertion_strategy=all when I'm looking at the evosuite jar execution within the maven debug mode command.
Thanks

Related

JBoss AS Maven plugin

I am using the jboss-as-maven-plugin from redhat.
I have a standalone JBoss Server with port offset 100 and want to use a property with this value. But if I use the following configuration, the plugin uses the default port 9999
JBAS012144: Could not connect to remote://localhost:9999
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.7.Final</version>
<configuration>
<port>${jboss.port}</port>
</configuration>
</plugin>
<properties>
<jboss.port>10099</jboss.port>
</properties>
I know I can start the deployment with -Djboss-as.port=10099 but i prefer the property.
It would be really nice, to set the properties in an extra file.
So I took the properties-maven-plugin to read a user.properties file with the properties jboss.host and jboss.port.
This plugin is invoked by the initialized Phase
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<executions>
<execution>
<id>read-properties</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}\user.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
I can read and use the properties from the file in the whole lifecycle, but when I call jboss-as:deploy, the properties are empty
and the Plugin took the default values. The JBoss Plugin sais: Invokes the execution of the lifecycle phase package prior to executing itself.

gmaven plugin: how to set property in pom.xml for external groovy script

I'm running an external groovy script via gmaven plugin in pom.xml.
The external script is say 'myscript.groovy'.
I want to provide some parameters/arguments to myscript.groovy via the maven pom.xml [i.e. inside the plugin 'gmaven-plugin' execution]; but unable to do so..
I've tried using in ; but not sure how to retrieve its values in the groovy script. Simply calling properties.get is not giving the property value.
Snap of pom file:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
Not sure how to retrieve the value of 'installation.dir' property in 'configure.groovy' script.
Any hint in this regard will be useful.. thanks
There are two ways you can bind and retrieve properties. One would be through plugin-specific properties.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<installation.dir>${installation.dir}</installation.dir>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
These would be retrieved in the script like project.properties['installation.dir'].
GMaven isn't maintained anymore (I was the last maintainer). If you want to use versions of Groovy newer than 2.0.0, have a look at GMavenPlus. Here's the equivalent POM:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<bindPropertiesToSeparateVariables>false</bindPropertiesToSeparateVariables>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<scripts>
<script>file:///${pom.basedir}/src/main/groovy/configure.groovy</script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Retrieval in this case would be like properties['installation.dir']. I know the file:/// is annoying. I've removed the requirement for that in the next release.
For GMaven or GMavenPlus, if you choose the plugin properties approach, you will need to set the value elsewhere either with something like this in your project POM
<properties>
<installation.dir>C:\someDir</installation.dir>
</properties>
Or include it in your call like mvn -Dinstallation.dir=C:\someDir
The other option is to bind to project level properties directly. You would put it in your project level properties or in your call, like mentioned above, and don't include <properties> in the plugin <configuration>. If you go this route, you'd access in your script by project.properties['installation.dir'] for either GMaven or GMavenPlus (also take out <bindPropertiesToSeparateVariables> for GMavenPlus in this case).
If this doesn't work for you, try renaming installation.dir to something like installationDir. I can't remember offhand if periods were problematic.

Maven Increment property which is number inside the pom.xml

I want to change pom.xml property
So Build Number Maven Plugin not solve my problem because its based on other file (buidnumber.properties)
Given In pom.xml I have property my.number
<properties>
<my.number>125</my.number>
</properties>
When I run some maven plugin goal
Than In pom.xml I have incremented my.number property by one:
<properties>
<my.number>126</my.number>
</properties>
So what need to be done is to Increment value of property my.value by 1 each time I call maven goal. Is it possible to achieve that by some plugin?
you can use Maven Versions plugin, or maybe in your case the replacer plugin is even better.
You run the replacer-plugin by command such as:
mvn replacer:replace -Dccih.origion="my.number" -Dccih.target="some new value"
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>pom.xml</file>
<replacements>
<replacement>
<token>${ccih.origion}</token>
<value>${ccih.target}</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
so if you run your maven commands using a tool such as Jenkins or Hadson you can calculate the new value there, based on the existing one.
This will change your pom.xml accordingly:
mvn versions:set-property -Dproperty=my.number -DnewVersion=126

Integration tests with Maven in a Spring project

The question is how can I use different properties files for integration testing. Detailed explanation follows.
I'm trying to do in container integration tests with Maven, using tomcat7-maven-plugin. The project uses Spring and JPA. At present what I've figured out is the following:
Unit test class names follow the pattern *Test and run with mvn test by maven-surefire-plugin
Integration test class names follow the pattern *IT and run with mvn verify by maven-failsafe-plugin
With executions I can trigger to start and stop tomcat and deploy the war file
All of this works and when I run mvn verify Tomcat is started.
However instead of using a regular database, I would like to use an in memory database. My database configuration is defined in the file src/main/resources/META-INF/spring/database.properties loaded through context:property-placeholder.
I tried to define an alternative file in src/test/resources/META-INF/spring/database.properties, but is ignored. I know that is possible to define system properties within tomcat7-maven-plugin, but I don't know how to use them to trigger loading of different properties files.
My tomcat7-maven-plugin configuration is the following:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>9090</port>
<path>/processing</path>
<useTestClasspath>true</useTestClasspath>
<systemProperties>
<example.value.1>alpha</example.value.1>
</systemProperties>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war-only</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
Properties are loaded by context-main.xml with the following line:
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
I load context configuration from web.xml with the following:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/context-*.xml</param-value>
</context-param>
Any suggestion on how to load alternative properties file for testing?
One way to do it, is with Maven profiles and the ant plugin. I suspect that is not the most elegant way, and I'm open to listen for better solution, but for now it solves my problem.
A profile is a way to have a different Maven configuration depending on command line arguments, so in my case to run the integration tests, I run the command mvn -Pintegration clean verify. Here integration is the name of the profile, and is defined in pom.xml, after the properties as follows:
<profiles>
<profile>
<id>standard</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Copying test database.properties to ${project.build.outputDirectory}/META-INF/spring/</echo>
<copy file="src/test/resources/META-INF/spring/database.properties"
todir="${project.build.outputDirectory}/META-INF/spring/" verbose="true" overwrite="true" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Using mvn clean package will instead use the standard profile. It's interesting to mention that profiles can also be defined outside the pom, in .m2/settings.xml
See also: Building For Different Environments with Maven 2 -- Notice that the overwrite parameter in the copy is essential or it will work only at random, and is not mentioned in the linked document.

maven 3 surefire and maven gwt exclude / include problems

I have a root pom configured with the maven-surefire-plugin and a gwt module pom configured with the gwt-maven-plugin.
After upgrading to Maven 3 I get strange errors.
The project is similar configured like described here: Separate GwtTest tests from standard unit tests
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<useSystemClassLoader>true</useSystemClassLoader>
<useManifestOnlyJar>false</useManifestOnlyJar>
<forkMode>always</forkMode>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<argLine>-server -Xmx8192m -XX:MaxPermSize=1024M -XX:+CMSClassUnloadingEnabled</argLine>
<excludes>
<exclude>**/*GwtTest*.java</exclude>
</excludes>
</configuration>
</plugin>
AND
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>
</dependencies>
<configuration>
<modules>
<module>my.app.gwt</module>
</modules>
<runTarget>/</runTarget>
<extraJvmArgs>-Xss512m -Xmx2048m -XX:MaxPermSize=256M</extraJvmArgs>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<includes>**/*GwtTestSuite.java</includes>
<copyWebapp>true</copyWebapp>
<logLevel>INFO</logLevel>
<persistentunitcache>false</persistentunitcache>
<draftCompile>${gwt.draftCompile}</draftCompile>
<deploy>${project.build.directory}/${project.build.finalName}/WEB-INF/deploy</deploy>
<disableCastChecking>true</disableCastChecking>
<mode>htmlunit</mode>
<skipTests>${skipGwtTests}</skipTests></configuration>
<executions>
<execution>
<id>gwt-compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>gwt-test</id>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
It works with maven 2 but with maven 3 I get :
[ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.5.0:test (gwt-test) on project my-webapp: Unable to parse configuration of mojo org.codehaus.mojo:gwt-maven-plugin:2.5.0:test: When configuring a basic element the configuration cannot contain any child elements. Configuration element 'excludes'. -> [Help 1]
It seems that the gwt plugin can't parse the hierarchical style of the surefire plugin.
It only compiles if I set all excludes/includes inside the gwt plugin as one comma separated string line, but that doesn't work for me, because I need to exclude the gwt tests globally, and include them locally.
The include/exclude sections get merged however, so that the two incompatible syntax definitions won't work together.
I hope somebody can give me a hint.
You can run your GWTTestCases using straight Maven Surefire, see this link.

Resources