From 147acbdd568de75c3bab8b09d88dca06e4388b1e Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Fri, 1 Nov 2024 08:29:40 +0200 Subject: [PATCH 1/3] Refactor to remove XMLUtils.getDocumentBuilder Signed-off-by: Jarno Elovirta --- .github/workflows/gradle.yml | 12 +++---- build.gradle | 33 ++++++++++++------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../org/dita/index/IndexPreprocessor.java | 4 +-- .../org/dita/index/IndexPreprocessorTask.java | 12 +++++-- 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 0e12312..646c03a 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -4,14 +4,14 @@ on: [push] jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - java-version: 1.8 + distribution: 'temurin' + java-version: '17' + cache: 'gradle' - name: Build with Gradle run: ./gradlew build diff --git a/build.gradle b/build.gradle index ee63d1a..0e53315 100644 --- a/build.gradle +++ b/build.gradle @@ -10,24 +10,35 @@ plugins { } apply plugin: 'java' -apply plugin: 'maven' +apply plugin: 'maven-publish' group = 'org.dita-ot' -version = '1.0.0' +version = '2.0.0' description = """DITA Open Toolkit indexing plug-in.""" -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 17 +targetCompatibility = 17 repositories { mavenCentral() - jcenter() } dependencies { - compile group: 'org.dita-ot', name: 'dost', version: '[2.1,)' - testCompile group: 'junit', name: 'junit', version: '4.12' - testCompile group: 'org.xmlunit', name: 'xmlunit-core', version: '2.6.3' - testCompile group: 'org.xmlunit', name: 'xmlunit-matchers', version: '2.6.3' + implementation group: 'org.apache.ant', name: 'ant', version: '1.10.14' + implementation(group: 'com.google.guava', name: 'guava', version: '32.1.1-jre') { + exclude group: 'org.checkerframework', module: 'checker-qual' + exclude group: 'com.google.code.findbugs', module: 'jsr305' + exclude group: 'com.google.guava', module: 'failureaccess' + exclude group: 'com.google.guava', module: 'listenablefuture' + exclude group: 'com.google.errorprone', module: 'error_prone_annotations' + exclude group: 'com.google.j2objc', module: 'j2objc-annotations' + } + implementation group: 'net.sf.saxon', name: 'Saxon-HE', version: '12.4' + implementation group: 'com.ibm.icu', name: 'icu4j', version: '74.2' + implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.12' + implementation group: 'org.dita-ot', name: 'dost', version: '4.0.1' + testImplementation group: 'junit', name: 'junit', version: '4.12' + testImplementation group: 'org.xmlunit', name: 'xmlunit-core', version: '2.6.3' + testImplementation group: 'org.xmlunit', name: 'xmlunit-matchers', version: '2.6.3' } sourceSets { @@ -46,12 +57,12 @@ compileTestJava.options.encoding = "UTF-8" jar.setArchiveFileName "${project.name}.jar" task copyInstall(type: Copy) { - from(configurations.runtime.allArtifacts.files) + from(tasks.jar.outputs.files) destinationDir = file("lib") } task dist(type: Zip) { - from(configurations.runtime.allArtifacts.files) { + from(tasks.jar.outputs.files) { into "lib" } from("src/main/resources") { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c398049..df8cfe5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ #Thu Oct 10 19:53:32 EEST 2019 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/main/java/org/dita/index/IndexPreprocessor.java b/src/main/java/org/dita/index/IndexPreprocessor.java index 36f4bb8..ecdaad4 100644 --- a/src/main/java/org/dita/index/IndexPreprocessor.java +++ b/src/main/java/org/dita/index/IndexPreprocessor.java @@ -35,7 +35,6 @@ RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF import static org.dita.dost.util.Constants.*; import java.util.*; -import javax.xml.parsers.DocumentBuilder; import org.dita.dost.log.DITAOTLogger; import org.dita.dost.util.XMLUtils; import org.dita.index.configuration.IndexConfiguration; @@ -101,8 +100,7 @@ public void setLogger(final DITAOTLogger logger) { * @return read index terms */ IndexPreprocessResult process(final Document input) { - final DocumentBuilder documentBuilder = XMLUtils.getDocumentBuilder(); - final Document doc = documentBuilder.newDocument(); + final Document doc = input.getImplementation().createDocument(null, null, null); final Node rootElement = input.getDocumentElement(); final List indexes = new ArrayList<>(); final Node node = processCurrNode(rootElement, doc, indexes::add).get(0); diff --git a/src/main/java/org/dita/index/IndexPreprocessorTask.java b/src/main/java/org/dita/index/IndexPreprocessorTask.java index d834dd7..8c497f9 100644 --- a/src/main/java/org/dita/index/IndexPreprocessorTask.java +++ b/src/main/java/org/dita/index/IndexPreprocessorTask.java @@ -38,6 +38,8 @@ RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF import java.util.Collection; import java.util.Locale; import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; @@ -47,7 +49,6 @@ RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.dita.dost.log.DITAOTAntLogger; -import org.dita.dost.util.XMLUtils; import org.dita.index.configuration.IndexConfiguration; import org.dita.index.configuration.ParseException; import org.w3c.dom.Document; @@ -71,7 +72,14 @@ public class IndexPreprocessorTask extends Task { public void execute() throws BuildException { checkParameters(); - final DocumentBuilder documentBuilder = XMLUtils.getDocumentBuilder(); + final DocumentBuilder documentBuilder; + try { + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + documentBuilder = factory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + throw new BuildException(e); + } final Document doc; try { From a6cd0f3678a55fbe10ec20b5b9002f3c614a6576 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Fri, 1 Nov 2024 10:19:39 +0200 Subject: [PATCH 2/3] Add release GHA workflow Signed-off-by: Jarno Elovirta --- .github/workflows/gradle.yml | 4 ++-- .github/workflows/release.yml | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 646c03a..e289529 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -1,4 +1,4 @@ -name: Java CI +name: Test on: [push] @@ -14,4 +14,4 @@ jobs: java-version: '17' cache: 'gradle' - name: Build with Gradle - run: ./gradlew build + run: ./gradlew build --no-daemon diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..25abf77 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,24 @@ +name: Release + +on: + push: + tags: + - "*" +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + cache: 'gradle' + - name: Build with Gradle + run: ./gradlew dist --no-daemon + - name: Deploy distribution package to releases + uses: softprops/action-gh-release@v1 + with: + files: | + build/distributions/*.zip From 309d53c76e2b8f87d4fca64bb9b57412ac63c051 Mon Sep 17 00:00:00 2001 From: Jarno Elovirta Date: Fri, 1 Nov 2024 10:22:44 +0200 Subject: [PATCH 3/3] Fix install docs Signed-off-by: Jarno Elovirta --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2140b54..3c62d1f 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# DITA-OT Index plug-in [![badge]](https://github.com/dita-ot/org.dita.index/actions?workflow=Java+CI) +# DITA-OT Index plug-in [![badge]](https://github.com/dita-ot/org.dita.index/actions?workflow=Test) ## Installation Run the plug-in installation command: ```shell -dita --install org.dita.index +dita install org.dita.index ``` ## License