How to generate java files from .eiq files? - maven-3

In eclipse PDE( with EMF-IncQuery installed), if we have .eiq file and the corresponding .genmodel file just by refreshing it generates all the .java file and puts into src-gen package.
Just wondering If we could do the same through any maven plugin??
I have gone through https://wiki.eclipse.org/EMFIncQuery/UserDocumentation/Build where got the fair idea about how to generate java files from .genmodel but no info found about generating java files from .eiq files through EMF-IncQuery maven plug-in.
PF the concerned pom.xml entry
<!-- Setting up generator -->
<plugin>
<groupId>org.eclipse.incquery</groupId>
<artifactId>incquery-maven-plugin</artifactId>
<version>1.0.1</version>
<!-- Binding execution to the code generation lifecycle phase -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Output directory - required -->
<outputDirectory>${project.build.directory}/../src-gen</outputDirectory>
<metamodels>
<metamodel>
<!-- Java class for the EMF EPackage - use this if generated EMF code is in the classpath -->
<packageClass>${project.build.directory}/../abc.def.mnq.epackage.jar</packageClass>
<!-- genmodel file used for generating the EMF model classes - use this if EMF model is in the same project
<genmodelUri>${project.build.directory}/../XYZ.genmodel</genmodelUri> -->
</metamodel>
</metamodels>
</configuration>
</plugin>
</plugins>

The mentioned documentation page has an example pom.xml that also features the incquery-maven-compiler plugin, following the 'setting up the generator' comment.
The basic idea is that you should define the output folder, and select the EPackages your code used, and then the Maven compiler will generate the code.

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

How to include an excluded source file for tests?

I have a initial data class which should be excluded in the normal (default profile) build. If I specify for example the run profile this class should be included.
Furthermore this class is needed by the tests. So it needs to be included all the tim.
I used the excludes to achieve the first part, but the dependency from the test breaks the testCompile goal.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>**/InitialDataBuilder.java</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<testIncludes>
<include>**/*.java</include>
</testIncludes>
</configuration>
</execution>
</executions>
</plugin>
What is wrong with my config?
Is there no way to include an excluded source file for tests?
Maven's directory structure allows you to easily separate source/production code and test code.
The details of how to layout a project are explained here: https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
Basically, you put your production code in:
src/main/java
Test code goes in:
src/test/java
The test code tree should include the actual unit tests themselves and supporting classes. So the code you described belongs there. It will only end up in the test jar, not the production jar.
Also if you do it this way, you don't need to mess with the compiler plugin settings. The defaults will do what you expect.
Oh one other thing I should mention is that if it is needed for another profile, you should likely make it it's own maven module with it's own POM file. Then this class can reference it as a <scope>test</scope> dependency and the other as a production dependency.

Using different package names for bindings and wsdl using the jaxws maven plugin

We have a special requirement with our application: files generated against the wsdl should have a given package name and files generated against xsd files should have another package name.
There does not seem to have a way to customize this with the jaxws maven plugin. Here is our current configuration:
<execution>
<id>wsimport-finderpro</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<bindingDirectory>src/main/resources/xml-resources/web-service-references/B2T_DataModel.asmx/xsd</bindingDirectory>
<bindingFiles>
<bindingFile>ServerResponse_login.xsd</bindingFile>
<bindingFile>OpenDirectAccessSession.xsd</bindingFile>
</bindingFiles>
<!--wsdls file directory -->
<wsdlDirectory>src/main/resources/xml-resources/web-service-references/B2T_DataModel.asmx/wsdl</wsdlDirectory>
<!-- which wsdl file -->
<wsdlFiles>
<wsdlFile>B2T_DataModel.asmx.wsdl</wsdlFile>
</wsdlFiles>
<!-- Keep generated files -->
<keep>true</keep>
<!-- Package name -->
<packageName>com.mycompany.world.worldlink.finderpro.ws</packageName>
<!-- generated source files destination-->
<sourceDestDir>target/generated-code/src</sourceDestDir>
<staleFile>target/jaxws/fp/.staleFlag</staleFile>
<target>2.1</target>
</configuration>
</execution>
Can anyone please advise?
edit 1: I came up with the following code:
<execution>
<id>wsimport-finderpro-01</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<bindingDirectory>src/main/resources/xml-resources/web-service-references/B2T_DataModel.asmx/xsd</bindingDirectory>
<bindingFiles>
<bindingFile>OpenDirectAccessSession.xsd</bindingFile>
</bindingFiles>
<!--wsdls file directory -->
<wsdlDirectory>src/main/resources/xml-resources/web-service-references/B2T_DataModel.asmx/wsdl</wsdlDirectory>
<!-- which wsdl file -->
<wsdlFiles>
<wsdlFile>B2T_DataModel.asmx.wsdl</wsdlFile>
</wsdlFiles>
<!-- Keep generated files -->
<keep>true</keep>
<!-- Package name -->
<packageName>com.ids.world.worldlink.finderpro.xmlstubs</packageName>
<!-- generated source files destination-->
<sourceDestDir>target/generated-code/src</sourceDestDir>
<staleFile>target/jaxws/fp-01/.staleFlag</staleFile>
<target>2.1</target>
</configuration>
</execution>
<execution>
<id>wsimport-finderpro-02</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<bindingDirectory>src/main/resources/xml-resources/web-service-references/B2T_DataModel.asmx/xsd</bindingDirectory>
<bindingFiles>
<bindingFile>GetAllMyEntityQuotes.xsd</bindingFile>
</bindingFiles>
<!--wsdls file directory -->
<wsdlDirectory>src/main/resources/xml-resources/web-service-references/B2T_DataModel.asmx/wsdl</wsdlDirectory>
<!-- which wsdl file -->
<wsdlFiles>
<wsdlFile>B2T_DataModel.asmx.wsdl</wsdlFile>
</wsdlFiles>
<!-- Keep generated files -->
<keep>true</keep>
<!-- Package name -->
<packageName>com.ids.world.worldlink.finderpro.xmlstubs.allMyEntityQuotes</packageName>
<!-- generated source files destination-->
<sourceDestDir>target/generated-code/src</sourceDestDir>
<staleFile>target/jaxws/fp-02/.staleFlag</staleFile>
<target>2.1</target>
</configuration>
</execution>
The issue is that I noticed that many classes are regenerated several times (here x2) and I end up with same classes in different packages.
How can I ensure that classes generated for the wsdl are generated once and classes for the xsd are generated and placed in their respective package?

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>
+---+

Create pom.xml file

Could anayone give me some sugestions on how to create a pom.xml file for a multimodules project, that is build with ant? I need to create this pom.xml file in order to analyze the project with Sonar.
I suggest to follow the instructions from the Sonar documentation. See Analyzing Java Projects:
Project with multiple sources directories
If your non-maven project contains
more than one sources directory, you
can specify which sources directories
to analyse by adding a new section
about the Build Helper Maven Plugin
into your pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[YOUR.ORGANIZATION]</groupId>
<artifactId>[YOUR.PROJECT]</artifactId>
<name>[YOUR PROJECT NAME]</name>
<version>[YOUR PROJECT VERSION]</version>
<build>
<sourceDirectory>[YOUR SOURCE DIRECTORY]</sourceDirectory>
<outputDirectory>[YOUR CLASSES/BIN DIRECTORY</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>[YOUR SOURCE DIRECTORY 2]</source>
<source>[YOUR SOURCE DIRECTORY 3]</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
<sonar.phase>generate-sources</sonar.phase>
</properties>
</project>
Replace the parameters :
...
And execute the maven2 plugin as explained in the installation guide :
mvn sonar:sonar
There is now a Sonar Ant Task that you can use, or there is also the Sonar Runner
What you put in the pom.xml is going to depend what dependencies you need to use and what plugins you need to run. Check out the Intro to POM to see what it is made up of.
I think you can try to use the builder-helper-maven-plugin, currently, latest version is 1.5.
as documented http://docs.codehaus.org/display/SONAR/Analyzing+Java+Projects. However, just change the plugin version to 1.5 and use mvn sonar3:sonar. Most importantly, dont forget <sonar.phase>generate-sources</sonar.phase>, without this, it doesn't work.
as for the output directory, if using eclipse, you can specify the output directory for each module, and make them point to the same folder. Use this folder as the outputdirectory for pom.xml. remember to disable scrub, if using eclipse.

Resources