Skip to content

Commit

Permalink
[CXF-7741]ensure we can build CXF with JDK11
Browse files Browse the repository at this point in the history
  • Loading branch information
ffang committed Jul 13, 2018
1 parent 75435cb commit a3295e6
Show file tree
Hide file tree
Showing 71 changed files with 455 additions and 979 deletions.
1 change: 1 addition & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
org.objectweb.asm*;resolution:=optional;version="${cxf.osgi.asm.version}",
javax.activation;version="${cxf.osgi.javax.activation.version}",
javax.annotation;version="${cxf.osgi.javax.annotation.version}",
javax.xml.ws*;version="${cxf.osgi.javax.xml.ws.version}",
javax.xml.bind*;version="${cxf.osgi.javax.bind.version}",
javax.xml.stream*;version="${cxf.osgi.javax.stream.version}",
javax.validation*;resolution:=optional;version="${cxf.validation.api.package.version}",
Expand Down
6 changes: 0 additions & 6 deletions core/src/main/java/org/apache/cxf/common/util/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import javax.tools.ToolProvider;

import org.apache.cxf.helpers.FileUtils;
import org.apache.cxf.helpers.JavaUtils;

public class Compiler {
private long maxMemory = Runtime.getRuntime().maxMemory();
Expand Down Expand Up @@ -178,11 +177,6 @@ public boolean compileFiles(String[] files) {
//fix for CXF-2081, set maximum heap of this VM to javac.
list.add("-J-Xmx" + maxMemory);

if (JavaUtils.isJava9Compatible()) {
list.add("--add-modules");
list.add("java.activation,java.xml.ws.annotation,java.corba,java.transaction,java.xml.bind,java.xml.ws");
}

addArgs(list);
int classpathIdx = list.indexOf("-classpath");
String classpath = list.get(classpathIdx + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public void write(Object obj, XMLStreamWriter writer) {
}

} else if (obj instanceof Node) {
if (obj instanceof DocumentFragment) {
obj = org.apache.cxf.helpers.DOMUtils.getDomDocumentFragment((DocumentFragment)obj);
}
if (schema != null) {
Validator schemaValidator = schema.newValidator();
schemaValidator.setErrorHandler(
Expand Down
27 changes: 25 additions & 2 deletions core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
Expand All @@ -42,6 +43,7 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -739,13 +741,13 @@ public static List<Element> findAllElementsByTagNameNS(Element elem, String name
}

/**
* Try to get the DOM Node from the SAAJ Node with JAVA9
* Try to get the DOM Node from the SAAJ Node with JAVA9 afterwards
* @param node The original node we need check
* @return The DOM node
*/
public static Node getDomElement(Node node) {
if (node != null && isJava9SAAJ()) {
//java9 hack since EA 159
//java9plus hack
try {
Method method = node.getClass().getMethod("getDomElement");
node = (Node)method.invoke(node);
Expand All @@ -757,6 +759,27 @@ public static Node getDomElement(Node node) {
}
return node;
}

/**
* Try to get the DOM DocumentFragment from the SAAJ DocumentFragment with JAVA9 afterwards
* @param DocumentFragment The original documentFragment we need check
* @return The DOM DocumentFragment
*/
public static DocumentFragment getDomDocumentFragment(DocumentFragment fragment) {
if (fragment != null && isJava9SAAJ()) {
//java9 plus hack
try {
Field f = fragment.getClass().getDeclaredField("documentFragment");
f.setAccessible(true);
fragment = (DocumentFragment) f.get(fragment);
} catch (NoSuchFieldException e) {
//best effort to try, do nothing if NoSuchMethodException
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return fragment;
}

private static void findAllElementsByTagNameNS(Element el, String nameSpaceURI, String localName,
List<Element> elementList) {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public final class JavaUtils {

if (version.indexOf('.') > 0) {
version = version.substring(0, version.indexOf('.'));
}
if (version.indexOf("-") > 0) {
version = version.substring(0, version.indexOf("-"));
}

setJava9Compatible(Integer.valueOf(version) >= 9);
Expand Down
22 changes: 0 additions & 22 deletions integration/jca/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>java9plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<!-- needed for easymock-->
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.0_ALPHA</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
33 changes: 0 additions & 33 deletions maven-plugins/codegen-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,38 +223,5 @@
</dependency>
</dependencies>
</profile>
<profile>
<id>java9-plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
28 changes: 28 additions & 0 deletions maven-plugins/codegen-plugin/src/it/mark-generated/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,32 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,32 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
<version>1.1.3</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,8 @@ public AbstractCodegenMoho() {
public void execute() throws MojoExecutionException {
if (JavaUtils.isJava9Compatible()) {
fork = "true";
additionalJvmArgs = "--add-modules java.activation,java.xml.bind,java.xml.ws "
+ "--add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED "
+ "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
additionalJvmArgs = "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
+ "--add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED "
+ "--add-exports=java.xml.bind/com.sun.xml.internal.bind.marshaller=ALL-UNNAMED "
+ "--add-opens java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED "
+ "--add-opens java.base/java.security=ALL-UNNAMED "
+ "--add-opens java.base/java.net=ALL-UNNAMED "
+ "--add-opens java.base/java.lang=ALL-UNNAMED "
Expand Down
30 changes: 0 additions & 30 deletions maven-plugins/corba/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,4 @@
<version>${project.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>java9plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
18 changes: 0 additions & 18 deletions maven-plugins/java2swagger-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,5 @@
</plugins>
</build>
</profile>
<profile>
<id>java9plus</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,8 @@ public class Java2WSMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
if (JavaUtils.isJava9Compatible()) {
fork = true;
additionalJvmArgs = "--add-modules java.activation,java.xml.bind,java.xml.ws "
+ "--add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED "
+ "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
additionalJvmArgs = "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
+ "--add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED "
+ "--add-exports=java.xml.bind/com.sun.xml.internal.bind.marshaller=ALL-UNNAMED "
+ "--add-opens java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED "
+ "--add-opens java.base/java.security=ALL-UNNAMED "
+ "--add-opens java.base/java.net=ALL-UNNAMED "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ private void mergeOptions(List<WadlOption> effectiveOptions) {
public void execute() throws MojoExecutionException {
if (JavaUtils.isJava9Compatible()) {
fork = "true";
additionalJvmArgs = "--add-modules java.activation,java.xml.bind,java.xml.ws "
+ "--add-exports=java.xml.bind/com.sun.xml.internal.bind.v2.runtime=ALL-UNNAMED "
+ "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
additionalJvmArgs = "--add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED "
+ "--add-exports=java.xml/com.sun.org.apache.xerces.internal.impl.xs=ALL-UNNAMED "
+ "--add-exports=java.xml.bind/com.sun.xml.internal.bind.marshaller=ALL-UNNAMED "
+ "--add-opens java.xml.ws/javax.xml.ws.wsaddressing=ALL-UNNAMED "
+ "--add-opens java.base/java.security=ALL-UNNAMED "
+ "--add-opens java.base/java.net=ALL-UNNAMED "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Option[] config() {
return new Option[] {
cxfBaseConfig(),
testUtils(),
features(karafUrl, "spring"),
features(cxfUrl, "cxf-core", "cxf-jaxws", "cxf-transports-jms"),
features(amqUrl, "aries-blueprint", "shell-compat", "activemq-broker-noweb"),
provision(serviceBundle())
Expand Down
5 changes: 3 additions & 2 deletions osgi/karaf/features/src/main/resources/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
<bundle start-level="9">mvn:org.apache.geronimo.specs/geronimo-osgi-registry/1.1</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.activation-api-1.1/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10">mvn:javax.annotation/javax.annotation-api/${cxf.javax.annotation-api.version}</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.geronimo.specs/geronimo-ws-metadata_2.0_spec/1.1.3</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.stax-api-1.0/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxws-api-2.2/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxws-api-2.2/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.saaj-api-1.3/${cxf.servicemix.specs.version}</bundle>
<bundle start-level="10" dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxrs-api-2.1/${cxf.servicemix.jaxrs.specs.version}</bundle>
<bundle start-level="10" dependency="true">mvn:javax.mail/mail/${cxf.javax.mail.version}</bundle>
Expand Down
Loading

0 comments on commit a3295e6

Please sign in to comment.