We are attempting to generate coverage reports for our GWT application from a set of unit tests written using gwt-test-utils. The project is a multi-module maven project. We are using the sonar-plugin on jenkins in order to generate and collate our coverage and violation information.
When the build jobs run all the GWT unit tests pass as part of the normal build, however when the Sonar plugin attempts to rerun the tests they all fail with the following error:
initializationError(uk.co.card.gwt.retailpost.client.dialog.productmodify.CurrencyEditDialogTest) Time elapsed: 0 sec <<< ERROR! com.googlecode.gwt.test.exceptions.GwtTestException: Error while generating gwt-test-utils prerequisites at com.googlecode.gwt.test.internal.GwtFactory.(GwtFactory.java:113) at com.googlecode.gwt.test.internal.GwtFactory.initializeIfNeeded(GwtFactory.java:45) at com.googlecode.gwt.test.internal.junit.AbstractGwtRunner.(AbstractGwtRunner.java:30) at com.googlecode.gwt.test.GwtRunner.(GwtRunner.java:19) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries) at com.google.gwt.dev.cfg.ModuleDef.checkForSeedTypes(ModuleDef.java:559) at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:363) at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:354) at com.googlecode.gwt.test.internal.GwtFactory.createCompilationState(GwtFactory.java:151) at com.googlecode.gwt.test.internal.GwtFactory.(GwtFactory.java:106) ... 25 more
Looking through the rest of the console output from jenkins, and the workspace directories, I can't locate the log file that the "com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)" refers to.
Has anyone encountered a similar problem and knows how to get Sonar to run the gwt-test-utils successfully, or at least will have an idea when to look to find the previous log entries mentioned in the exception.
EDIT: After further experimentation the issue appears to be being caused by jacoco. trying to run just the unit tests instrumented with jacoco (and with no sonar involved) results in the same error
**EDIT:
sample from pom.xml
<build>
pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<excludedGroups combine.self="override" />
<reuseForks>true</reuseForks>
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<propertyName>jacoco.agent.argLine</propertyName>
<destFile>${sonar.jacoco.itReportPath}</destFile>
<append>true</append>
<excludes>
<exclude>*.osgi.*</exclude>
<exclude>*.apache.*</exclude>
<exclude>*.sourceforge.*</exclude>
<exclude>*.junit.*</exclude>
<!-- Test support code does not need to be covered -->
<exclude>uk.co.card.retailpost.clientintegration.utilities.*</exclude>
</excludes>
<classDumpDir>temp/classes</classDumpDir>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
As I mentioned in comments libraries are loaded in different order for jacoco with maven-surefire-plugin. To solve this problem write your own runner (extends com.googlecode.gwt.test.GwtRunner) and change classloader for thread contextClassLoader.
import com.googlecode.gwt.test.GwtRunner;
public class MyGwtRunner extends GwtRunner {
static {
URLClassLoader classLoader = (URLClassLoader) MyGwtRunner.class.getClassLoader();
try {
URL[] urls = getClassPath();
ClassLoader cl = URLClassLoader.newInstance(urls, classLoader);
Thread.currentThread().setContextClassLoader(cl);
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
}
public MyGwtRunner(Class<?> clazz) throws Throwable {
super(clazz);
}
private static URL[] getClassPath() throws MalformedURLException {
String classPath = System.getProperty("java.class.path");
String pathSeparator = System.getProperty("path.separator");
String[] array = classPath.split(pathSeparator);
List<URL> files = new ArrayList<URL>();
for (String a : array) {
files.add(new File(a).toURI().toURL());
}
return files.toArray(new URL[files.size()]);
}
}
In your tests override GwtRunner by MyGwtRunner
@GwtModule("com.my.module.GwtTestUtils")
@RunWith(MyGwtRunner.class)
public abstract class AbstractGwtJunit extends GwtTest {
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With