Skip to content

Commit 147acbd

Browse files
committed
Refactor to remove XMLUtils.getDocumentBuilder
Signed-off-by: Jarno Elovirta <[email protected]>
1 parent b352c0a commit 147acbd

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

.github/workflows/gradle.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
steps:
11-
- uses: actions/checkout@v1
12-
- name: Set up JDK 1.8
13-
uses: actions/setup-java@v1
9+
- uses: actions/checkout@v4
10+
- name: Set up JDK 17
11+
uses: actions/setup-java@v4
1412
with:
15-
java-version: 1.8
13+
distribution: 'temurin'
14+
java-version: '17'
15+
cache: 'gradle'
1616
- name: Build with Gradle
1717
run: ./gradlew build

build.gradle

+22-11
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,35 @@ plugins {
1010
}
1111

1212
apply plugin: 'java'
13-
apply plugin: 'maven'
13+
apply plugin: 'maven-publish'
1414

1515
group = 'org.dita-ot'
16-
version = '1.0.0'
16+
version = '2.0.0'
1717
description = """DITA Open Toolkit indexing plug-in."""
1818

19-
sourceCompatibility = 1.8
20-
targetCompatibility = 1.8
19+
sourceCompatibility = 17
20+
targetCompatibility = 17
2121

2222
repositories {
2323
mavenCentral()
24-
jcenter()
2524
}
2625
dependencies {
27-
compile group: 'org.dita-ot', name: 'dost', version: '[2.1,)'
28-
testCompile group: 'junit', name: 'junit', version: '4.12'
29-
testCompile group: 'org.xmlunit', name: 'xmlunit-core', version: '2.6.3'
30-
testCompile group: 'org.xmlunit', name: 'xmlunit-matchers', version: '2.6.3'
26+
implementation group: 'org.apache.ant', name: 'ant', version: '1.10.14'
27+
implementation(group: 'com.google.guava', name: 'guava', version: '32.1.1-jre') {
28+
exclude group: 'org.checkerframework', module: 'checker-qual'
29+
exclude group: 'com.google.code.findbugs', module: 'jsr305'
30+
exclude group: 'com.google.guava', module: 'failureaccess'
31+
exclude group: 'com.google.guava', module: 'listenablefuture'
32+
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
33+
exclude group: 'com.google.j2objc', module: 'j2objc-annotations'
34+
}
35+
implementation group: 'net.sf.saxon', name: 'Saxon-HE', version: '12.4'
36+
implementation group: 'com.ibm.icu', name: 'icu4j', version: '74.2'
37+
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.12'
38+
implementation group: 'org.dita-ot', name: 'dost', version: '4.0.1'
39+
testImplementation group: 'junit', name: 'junit', version: '4.12'
40+
testImplementation group: 'org.xmlunit', name: 'xmlunit-core', version: '2.6.3'
41+
testImplementation group: 'org.xmlunit', name: 'xmlunit-matchers', version: '2.6.3'
3142
}
3243

3344
sourceSets {
@@ -46,12 +57,12 @@ compileTestJava.options.encoding = "UTF-8"
4657
jar.setArchiveFileName "${project.name}.jar"
4758

4859
task copyInstall(type: Copy) {
49-
from(configurations.runtime.allArtifacts.files)
60+
from(tasks.jar.outputs.files)
5061
destinationDir = file("lib")
5162
}
5263

5364
task dist(type: Zip) {
54-
from(configurations.runtime.allArtifacts.files) {
65+
from(tasks.jar.outputs.files) {
5566
into "lib"
5667
}
5768
from("src/main/resources") {

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Thu Oct 10 19:53:32 EEST 2019
2-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
33
distributionBase=GRADLE_USER_HOME
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists

src/main/java/org/dita/index/IndexPreprocessor.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF
3535
import static org.dita.dost.util.Constants.*;
3636

3737
import java.util.*;
38-
import javax.xml.parsers.DocumentBuilder;
3938
import org.dita.dost.log.DITAOTLogger;
4039
import org.dita.dost.util.XMLUtils;
4140
import org.dita.index.configuration.IndexConfiguration;
@@ -101,8 +100,7 @@ public void setLogger(final DITAOTLogger logger) {
101100
* @return read index terms
102101
*/
103102
IndexPreprocessResult process(final Document input) {
104-
final DocumentBuilder documentBuilder = XMLUtils.getDocumentBuilder();
105-
final Document doc = documentBuilder.newDocument();
103+
final Document doc = input.getImplementation().createDocument(null, null, null);
106104
final Node rootElement = input.getDocumentElement();
107105
final List<IndexEntry> indexes = new ArrayList<>();
108106
final Node node = processCurrNode(rootElement, doc, indexes::add).get(0);

src/main/java/org/dita/index/IndexPreprocessorTask.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF
3838
import java.util.Collection;
3939
import java.util.Locale;
4040
import javax.xml.parsers.DocumentBuilder;
41+
import javax.xml.parsers.DocumentBuilderFactory;
42+
import javax.xml.parsers.ParserConfigurationException;
4143
import javax.xml.transform.OutputKeys;
4244
import javax.xml.transform.Transformer;
4345
import javax.xml.transform.TransformerFactory;
@@ -47,7 +49,6 @@ RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF
4749
import org.apache.tools.ant.Project;
4850
import org.apache.tools.ant.Task;
4951
import org.dita.dost.log.DITAOTAntLogger;
50-
import org.dita.dost.util.XMLUtils;
5152
import org.dita.index.configuration.IndexConfiguration;
5253
import org.dita.index.configuration.ParseException;
5354
import org.w3c.dom.Document;
@@ -71,7 +72,14 @@ public class IndexPreprocessorTask extends Task {
7172
public void execute() throws BuildException {
7273
checkParameters();
7374

74-
final DocumentBuilder documentBuilder = XMLUtils.getDocumentBuilder();
75+
final DocumentBuilder documentBuilder;
76+
try {
77+
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
78+
factory.setNamespaceAware(true);
79+
documentBuilder = factory.newDocumentBuilder();
80+
} catch (ParserConfigurationException e) {
81+
throw new BuildException(e);
82+
}
7583

7684
final Document doc;
7785
try {

0 commit comments

Comments
 (0)