diff --git a/build.gradle b/build.gradle index 9a320cd73..e66b32b70 100644 --- a/build.gradle +++ b/build.gradle @@ -63,7 +63,7 @@ repositories { configurations { bootstrap genresources - java9 + jpms } ext { @@ -127,9 +127,6 @@ dependencies { implementation "com.github.javaparser:javaparser-core:${javaparserVersion}" implementation "com.github.javaparser:javaparser-symbol-solver-core:${javaparserVersion}" - // only necessary to compile against JDK8 internals - for Java9+ there's a multimodule implementation - implementation 'com.sun.org.apache.xml.internal:resolver:20050927' - // NOTE: newer JUnit breaks some tests for some reason testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.3' @@ -161,16 +158,17 @@ dependencies { genresources "com.github.javaparser:javaparser-core:${javaparserVersion}" genresources "com.github.javaparser:javaparser-symbol-solver-core:${javaparserVersion}" - // need an own configuration for Java9 builds, as the maven plugin module-config is overlapping lot - java9 "org.apache.logging.log4j:log4j-api:${log4jVersion}" - java9("net.sf.saxon:Saxon-HE:${saxonVersion}") { + // module path for compiling module-info.java - kept separate, as the maven plugin dependencies + // would otherwise end up on the module path too + jpms "org.apache.logging.log4j:log4j-api:${log4jVersion}" + jpms("net.sf.saxon:Saxon-HE:${saxonVersion}") { exclude group: 'xml-apis', module: 'xml-apis' exclude group: 'org.apache.httpcomponents', module: 'httpclient' exclude group: 'org.apache.httpcomponents', module: 'httpcore' } - java9 "org.apache.ant:ant:${antVersion}" - java9 "com.github.javaparser:javaparser-core:${javaparserVersion}" - java9("com.github.javaparser:javaparser-symbol-solver-core:${javaparserVersion}") { + jpms "org.apache.ant:ant:${antVersion}" + jpms "com.github.javaparser:javaparser-core:${javaparserVersion}" + jpms("com.github.javaparser:javaparser-symbol-solver-core:${javaparserVersion}") { exclude group: 'com.google.guava', module: 'failureaccess' exclude group: 'com.google.guava', module: 'listenablefuture' exclude group: 'com.google.code.findbugs', module: 'jsr305' @@ -286,21 +284,20 @@ compileTestJava { dependsOn testSchemas.collect {"${it.name}_SchemaGen" } } -task compileJava9(type: JavaCompile) { +// Compiles module-info.java on its own: the already compiled classes are patched into the module +// and its dependencies are taken from the module path. The module-info.class ends up in the jar root. +tasks.register('compileModuleInfo', JavaCompile) { dependsOn 'compileJava' - - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(jdkVersion) - } - sourceCompatibility = 17 - targetCompatibility = 17 - destinationDirectory = file('build/classes/java9/main/META-INF/versions/9') - source = file('src/main/java9') + options.release = 17 + destinationDirectory = layout.buildDirectory.dir('classes/jpms/main') + source = file('src/main/jpms') classpath = files() - options.compilerArgs = [ - '--patch-module', "org.apache.xmlbeans=${sourceSets.main.output.asPath}", - '--module-path', files(sourceSets.main.output.files + configurations.java9.asFileTree.files).asPath - ] + doFirst { + options.compilerArgs = [ + '--patch-module', "org.apache.xmlbeans=${sourceSets.main.output.asPath}", + '--module-path', files(sourceSets.main.output.files + configurations.jpms.files).asPath + ] + } } processTestResources { @@ -310,7 +307,7 @@ processTestResources { task export4anttest(type: Copy) { dependsOn 'jar' into "build/libs" - from configurations.java9 + from configurations.jpms } test { @@ -330,7 +327,6 @@ idea { } jar { - dependsOn compileJava9 archiveBaseName = "xmlbeans-${XMLBeansVersion}" from(project.rootDir) { @@ -339,7 +335,7 @@ jar { into 'META-INF' } - from('build/classes/java9/main') + from(tasks.named('compileModuleInfo')) from('src/main/maven') { exclude '**/*.java' @@ -350,7 +346,6 @@ jar { duplicatesStrategy = DuplicatesStrategy.INCLUDE manifest { - attributes('Multi-Release':'true') attributes([ 'Comment': "Apache XmlBeans version ${XMLBeansVersion}", 'Specification-Title': 'Apache XmlBeans', @@ -375,6 +370,7 @@ javadocJar { sourcesJar { archiveBaseName = "xmlbeans-${XMLBeansVersion}" + from('src/main/jpms') metaInf { from("$projectDir/LICENSE.txt") from("$projectDir/NOTICE.txt") @@ -824,6 +820,8 @@ animalsniffer { //sourceSets = [sourceSets.main] ignore 'javax.xml.stream.*' ignore 'javax.xml.namespace.*' + // only used by the maven plugin, which never runs on Android + ignore 'javax.xml.catalog.*' } // The Android API signature only makes sense for code we ship. ParseUrlRedirectTest diff --git a/build.xml b/build.xml index 47aaf14c1..7dddb9d45 100644 --- a/build.xml +++ b/build.xml @@ -152,15 +152,12 @@ - - - @@ -206,6 +203,7 @@ we often had hard-to-find build/CI-problems because of these! --> + @@ -229,7 +227,6 @@ - @@ -267,7 +264,6 @@ - @@ -439,14 +435,14 @@ + + fork="true"> @@ -660,14 +656,13 @@ - + -
diff --git a/src/main/java/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java b/src/main/java/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java index 61d330f31..2db4ea499 100644 --- a/src/main/java/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java +++ b/src/main/java/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java @@ -15,22 +15,26 @@ package org.apache.xmlbeans.impl.tool; -import com.sun.org.apache.xml.internal.resolver.CatalogManager; -import com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver; -import org.apache.xmlbeans.impl.util.SuppressForbidden; import org.xml.sax.EntityResolver; +import javax.xml.catalog.Catalog; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; +import java.io.File; + /** - * Helper class for XML catalogs, which is provided as Java 8 and Java 9+ version (multi release) + * Helper class for XML catalogs, based on the JDK {@code javax.xml.catalog} API */ -@SuppressForbidden("class is available in Java 8 and multi-release version handles newer official package namespace") public class MavenPluginResolver { public static EntityResolver getResolver(String catalogLocation) { if (catalogLocation == null) { return null; } - CatalogManager catalogManager = CatalogManager.getStaticManager(); - catalogManager.setCatalogFiles(catalogLocation); - return new CatalogResolver(catalogManager); + + CatalogFeatures features = CatalogFeatures.builder() + .with(CatalogFeatures.Feature.PREFER, "system") + .build(); + Catalog catalog = CatalogManager.catalog(features, new File(catalogLocation).toURI()); + return CatalogManager.catalogResolver(catalog); } } diff --git a/src/main/java9/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java b/src/main/java9/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java deleted file mode 100644 index 2152a9835..000000000 --- a/src/main/java9/org/apache/xmlbeans/impl/tool/MavenPluginResolver.java +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright 2004 The Apache Software Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.xmlbeans.impl.tool; - -import org.xml.sax.EntityResolver; - -import javax.xml.catalog.Catalog; -import javax.xml.catalog.CatalogFeatures; -import javax.xml.catalog.CatalogManager; -import java.io.File; - -/** - * Helper class for XML catalogs, which is provided as Java 8 and Java 9+ version (multi release) - */ -public class MavenPluginResolver { - public static EntityResolver getResolver(String catalogLocation) { - if (catalogLocation == null) { - return null; - } - - CatalogFeatures features = CatalogFeatures.builder() - .with(CatalogFeatures.Feature.PREFER, "system") - .build(); - Catalog catalog = CatalogManager.catalog(features, new File(catalogLocation).toURI()); - return CatalogManager.catalogResolver(catalog); - } -} diff --git a/src/main/java9/module-info.java b/src/main/jpms/module-info.java similarity index 100% rename from src/main/java9/module-info.java rename to src/main/jpms/module-info.java diff --git a/src/main/maven/org.apache.xmlbeans/xmlbeans/pom.xml b/src/main/maven/org.apache.xmlbeans/xmlbeans/pom.xml index 17169cd33..01892be8e 100644 --- a/src/main/maven/org.apache.xmlbeans/xmlbeans/pom.xml +++ b/src/main/maven/org.apache.xmlbeans/xmlbeans/pom.xml @@ -118,12 +118,6 @@ 3.28.2 provided - - com.sun.org.apache.xml.internal - resolver - 20050927 - provided -