Fix Javadoc generation issues on Java 9

1. The first issue is:

```
> Task :api
DefaultBatchConfigurer.java:18: error: cannot find symbol
import javax.annotation.PostConstruct;
                       ^
  symbol:   class PostConstruct
  location: package javax.annotation
DataSourceConfiguration.java:18: error: cannot find symbol
import javax.annotation.PostConstruct;
                       ^
  symbol:   class PostConstruct
  location: package javax.annotation
DefaultBatchConfigurer.java:94: error: cannot find symbol
        @PostConstruct
         ^
  symbol:   class PostConstruct
  location: class DefaultBatchConfigurer
DataSourceConfiguration.java:46: error: cannot find symbol
        @PostConstruct
         ^
  symbol:   class PostConstruct
  location: class DataSourceConfiguration
4 errors
```

This issue is fixed by adding the `javax.annotation-api` dependency

2. The second issue is:

```
javadoc: error - An internal exception has occurred.
(com.sun.tools.javac.code.ClassFinder$BadClassFile: bad class file:
/org/springframework/batch/core/configuration/support/
GenericApplicationContextFactory$ResourceAnnotationApplicationContext$1.class

class file contains malformed variable arity method:
GenericApplicationContextFactory$ResourceAnnotationApplicationContext$1
Please remove or make sure it appears in the correct subdirectory of the classpath.)
```

The workaround to this issue is to use a named inner class instead of
an anonymous one.

Upgrade jacoco to version 0.8.2

Fix failing tests on Java 9

* `javax.xml.bind` is no longer contained in the default class path in
Java SE 9. This commit adds the module `java.xml.bind` to the JVM args
for tests

* JsrBeanDefinitionDocumentReaderTests are failing because
`ClassLoader.class.getResourceAsStream` has a different behaviour on Java 9.
According to `https://stackoverflow.com/a/45173837/5019386`, it's best to
use the resource-lookup methods in Class rather than those in ClassLoader.

* DefaultJobParametersExtractorJobParametersTests#testGetAllJobParameters
is failing because jobParameters.toString() returns "{foo=bar, spam=bucket}"
on Java 9 and "{spam=bucket, foo=bar}" on Java 8. The fix asserts that
jobParameters contains the expected key/value pairs without relying on the
toString method

JIRA: BATCH-2751
This commit is contained in:
Mahmoud Ben Hassine
2018-09-11 11:21:09 +02:00
committed by Michael Minella
parent 8df674c4d8
commit 57c4acdf22
4 changed files with 29 additions and 8 deletions

View File

@@ -78,6 +78,7 @@ allprojects {
gsonVersion = '2.8.5'
javaMailVersion = '1.6.2'
javaxBatchApiVersion = '1.0'
javaxAnnotationApiVersion = '1.3.2'
javaxInjectVersion = '1'
javaxTransactionVersion = '1.3'
jbatchTckSpi = '1.0'
@@ -113,7 +114,7 @@ configure(subprojects - project(":spring-build-src")) { subproject ->
apply plugin: 'merge'
jacoco {
toolVersion = "0.7.6.201602180812"
toolVersion = "0.8.2"
}
compileJava {
@@ -169,6 +170,10 @@ configure(subprojects - project(":spring-build-src")) { subproject ->
// testLogging {
// showStandardStreams = true
// }
if (JavaVersion.current().isJava9Compatible()) {
jvmArgs '--add-modules', 'java.xml.bind'
}
}
task sourcesJar(type: Jar) {
@@ -288,6 +293,7 @@ project('spring-batch-core') {
optional "org.springframework:spring-jdbc:$springVersion"
optional "org.apache.logging.log4j:log4j-api:$log4jVersion"
optional "org.apache.logging.log4j:log4j-core:$log4jVersion"
optional "javax.annotation:javax.annotation-api:$javaxAnnotationApiVersion"
// JSR-305 only used for non-required meta-annotations
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
testCompileOnly("com.google.code.findbugs:jsr305:3.0.2")

View File

@@ -137,7 +137,13 @@ public class GenericApplicationContextFactory extends AbstractApplicationContext
* @param parent
*/
public ResourceXmlApplicationContext(ConfigurableApplicationContext parent, Object... resources) {
helper = new ApplicationContextHelper(parent, this, resources) {
class ResourceXmlApplicationContextHelper extends ApplicationContextHelper {
ResourceXmlApplicationContextHelper(ConfigurableApplicationContext parent, GenericApplicationContext context, Object... config) {
super(parent, context, config);
}
@Override
protected String generateId(Object... configs) {
Resource[] resources = Arrays.copyOfRange(configs, 0, configs.length, Resource[].class);
@@ -155,9 +161,10 @@ public class GenericApplicationContextFactory extends AbstractApplicationContext
@Override
protected void loadConfiguration(Object... configs) {
Resource[] resources = Arrays.copyOfRange(configs, 0, configs.length, Resource[].class);
load(resources);
load(resources);
}
};
}
helper = new ResourceXmlApplicationContextHelper(parent, this, resources);
refresh();
}
@@ -179,7 +186,13 @@ public class GenericApplicationContextFactory extends AbstractApplicationContext
private final ApplicationContextHelper helper;
public ResourceAnnotationApplicationContext(ConfigurableApplicationContext parent, Object... resources) {
helper = new ApplicationContextHelper(parent, this, resources) {
class ResourceAnnotationApplicationContextHelper extends ApplicationContextHelper {
public ResourceAnnotationApplicationContextHelper(ConfigurableApplicationContext parent, GenericApplicationContext context, Object... config) {
super(parent, context, config);
}
@Override
protected String generateId(Object... configs) {
if (allObjectsOfType(configs, Class.class)) {
@@ -205,7 +218,8 @@ public class GenericApplicationContextFactory extends AbstractApplicationContext
scan(pkgs);
}
}
};
}
helper = new ResourceAnnotationApplicationContextHelper(parent, this, resources);
refresh();
}

View File

@@ -251,7 +251,7 @@ public class JsrBeanDefinitionDocumentReaderTests extends AbstractJsrTestCase {
}
private Document getDocument(String location) {
InputStream inputStream = ClassLoader.class.getResourceAsStream(location);
InputStream inputStream = this.getClass().getResourceAsStream(location);
try {
return documentLoader.loadDocument(new InputSource(inputStream),

View File

@@ -49,7 +49,8 @@ public class DefaultJobParametersExtractorJobParametersTests {
StepExecution stepExecution = getStepExecution("foo=bar,spam=bucket");
extractor.setKeys(new String[] {"foo", "bar"});
JobParameters jobParameters = extractor.getJobParameters(null, stepExecution);
assertEquals("{spam=bucket, foo=bar}", jobParameters.toString());
assertEquals("bar", jobParameters.getString("foo"));
assertEquals("bucket", jobParameters.getString("spam"));
}
@Test