From ca57656cc17470123a267f8d5cb10a729d196f10 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 16 Nov 2023 12:10:07 +0700 Subject: [PATCH] XALANJ-2709 Make build run on JDK 9+ The internal taglet module now exists in two variants for JDK 8 and 9+. Which one is included in the build depends on auto-activated profiles. This also works nicely in IntelliJ IDEA, it recognises profile activation and only builds the module corresponding to the current JDK, not yielding any build errors. I did not test on Eclipse, but hope that it works there, too. Either way, a stable Maven build is most important. I also streamlined the use of Maven Compiler Plugin. --- pom.xml | 52 ++++++++++--- serializer/pom.xml | 11 --- xalan/pom.xml | 10 +-- xalan2jtaglet/pom.xml | 27 +++---- .../src/main/java/xalan2jtaglet/XSLUsage.java | 56 +++++++------- .../main/java/xalan2jtaglet/XSLUsageTag.java | 75 ++++++++++--------- xalan2jtaglet_jdk9/pom.xml | 33 ++++++++ .../src/main/java/xalan2jtaglet/XSLUsage.java | 55 ++++++++++++++ .../main/java/xalan2jtaglet/XSLUsageTag.java | 63 ++++++++++++++++ 9 files changed, 273 insertions(+), 109 deletions(-) create mode 100644 xalan2jtaglet_jdk9/pom.xml create mode 100644 xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsage.java create mode 100644 xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsageTag.java diff --git a/pom.xml b/pom.xml index 7d89f5de6..6b94852f6 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,6 @@ serializer xalan samples - xalan2jtaglet + xalan2jtaglet.XSLUsageTag @@ -335,7 +363,7 @@ xalan - xalan2jtaglet + ${xalan.taglet.artifactId} ${project.version} @@ -347,6 +375,8 @@ build when the local Maven repo is clean. --> xalan2jtaglet + + 1.8 diff --git a/serializer/pom.xml b/serializer/pom.xml index 274a4fc8a..f58af0c9f 100644 --- a/serializer/pom.xml +++ b/serializer/pom.xml @@ -59,23 +59,12 @@ - - - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - org.apache.maven.plugins maven-dependency-plugin - diff --git a/xalan/pom.xml b/xalan/pom.xml index 0c832a97e..204b78242 100644 --- a/xalan/pom.xml +++ b/xalan/pom.xml @@ -32,15 +32,6 @@ - - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - + org.apache.maven.plugins maven-resources-plugin diff --git a/xalan2jtaglet/pom.xml b/xalan2jtaglet/pom.xml index be7b9e0a5..76b2c83a0 100644 --- a/xalan2jtaglet/pom.xml +++ b/xalan2jtaglet/pom.xml @@ -9,24 +9,21 @@ xalan2jtaglet - @xsl.usage taglet - Implementation of the @xsl.usage taglet, used in the Xalan package's javadoc to indicate classes which, while public for cross-module access, are not intended to be called by end-users. + @xsl.usage taglet JDK 8 + + Implementation of the @xsl.usage taglet, used in the Xalan package's javadoc + to indicate classes which, while public for cross-module access, are not + intended to be called by end-users. + - - - ${java.home}/../lib/tools.jar - + - com.sun - tools - 1.6.0 - system - ${toolsjar} + com.github.olivergondza + maven-jdk-tools-wrapper + 0.1 diff --git a/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsage.java b/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsage.java index 1aa18cc29..e7eff5fbe 100644 --- a/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsage.java +++ b/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsage.java @@ -1,49 +1,51 @@ -/** Taglet for Xalan-Java documentation, giving us a standard way to - indicate when classes are public only because they are shared - across packages within Xalan code, not because they are intended for use - by others. Typical: "@xsl.usage internal" - - Technically it might be better to OSGIfy the Xalan code, which - would also permit demand-loading of only the classes actually being - used by this execution... but that's an idea for the future. - - This code renders the tag keywords (internal, advanced, experimental) - into their expanded renderings in the Javadoc. - */ -// -// Source code recreated from xalan2jtaglet.jar by IntelliJ IDEA -// (powered by FernFlower decompiler) -// - package xalan2jtaglet; import com.sun.javadoc.Tag; +/** + * Taglet for Xalan-Java documentation, giving us a standard way to + * indicate when classes are public only because they are shared + * across packages within Xalan code, not because they are intended for use + * by others. Typical: "@xsl.usage internal" + *

+ * Technically it might be better to OSGIfy the Xalan code, which + * would also permit demand-loading of only the classes actually being + * used by this execution... but that's an idea for the future. + *

+ * This code renders the tag keywords (internal, advanced, experimental) + * into their expanded renderings in the Javadoc. + *

+ * Source code recreated from xalan2jtaglet.jar by IntelliJ IDEA (powered by + * FernFlower decompiler), then adjusted to JDK 8 taglet API. + */ public class XSLUsage { public static final String TAG = "xsl.usage"; private static final int INTERNAL = 0; private static final int ADVANCED = 1; private static final int EXPERIMENTAL = 2; private static final int UNSPECIFIED = -1; - private static final String[] names = new String[]{"internal", "advanced", "experimental"}; - private static final String[] colours = new String[]{"FF0000", "00FF00", "0000FF"}; - private static final String[] messages = new String[]{"**For internal use only**", "**For advanced use only**", "**Experimental**"}; - - public XSLUsage() { - } + private static final String[] names = new String[]{ + "internal", "advanced", "experimental" + }; + private static final String[] colours = new String[]{ + "FF0000", "00FF00", "0000FF" + }; + private static final String[] messages = new String[]{ + "**For internal use only**", "**For advanced use only**", "**Experimental**" + }; public static String getHTML(Tag usageTag) { int key = getKey(usageTag); - return key == -1 ? "" : " " + messages[key] + "\n"; + return key == -1 + ? "" + : " " + messages[key] + "\n"; } private static int getKey(Tag usageTag) { for (int i = 0; i < names.length; ++i) { - if (names[i].equals(usageTag.text())) { + if (names[i].equals(usageTag.text())) return i; - } } - return -1; } } diff --git a/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsageTag.java b/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsageTag.java index c009ec0a4..c2cf80941 100644 --- a/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsageTag.java +++ b/xalan2jtaglet/src/main/java/xalan2jtaglet/XSLUsageTag.java @@ -1,17 +1,3 @@ -/** Taglet for Xalan-Java documentation, giving us a standard way to - indicate when classes are public only because they are shared - across packages within Xalan code, not because they are intended for use - by others. Typical: "@xsl.usage internal" - - Technically it might be better to OSGIfy the Xalan code, which - would also permit demand-loading of only the classes actually being - used by this execution... but that's an idea for the future. - */ -// -// Source code recreated from xalan2jtaglet.jar by IntelliJ IDEA -// (powered by FernFlower decompiler) -// - package xalan2jtaglet; import com.sun.javadoc.Tag; @@ -19,71 +5,88 @@ import java.util.Map; +/** + * Taglet for Xalan-Java documentation, giving us a standard way to + * indicate when classes are public only because they are shared + * across packages within Xalan code, not because they are intended for use + * by others. Typical: "@xsl.usage internal" + *

+ * Technically it might be better to OSGIfy the Xalan code, which + * would also permit demand-loading of only the classes actually being + * used by this execution... but that's an idea for the future. + *

+ * This code renders the tag keywords (internal, advanced, experimental) + * into their expanded renderings in the Javadoc. + *

+ * Source code recreated from xalan2jtaglet.jar by IntelliJ IDEA (powered by + * FernFlower decompiler), then adjusted to JDK 8 taglet API. + */ public class XSLUsageTag implements Taglet { private static final String HEADER = "Usage:"; - public XSLUsageTag() {} - + @Override public boolean inConstructor() { return true; } + @Override public boolean inField() { return true; } + @Override public boolean inMethod() { return true; } + @Override public boolean inOverview() { return true; } + @Override public boolean inPackage() { return true; } + @Override public boolean inType() { return true; } + @Override public boolean isInlineTag() { return false; } + @Override public String getName() { return "xsl.usage"; } - public String toString(Tag arg0) { - return "\n

Usage:
" + XSLUsage.getHTML(arg0) + "
\n"; + @Override + public String toString(Tag tag) { + return "\n
Usage:
" + XSLUsage.getHTML(tag) + "
\n"; } - public String toString(Tag[] arg0) { - String string = ""; - if (arg0 != null && arg0.length != 0) { - string = "\n
Usage:
"; - - for (int i = 0; i < arg0.length - 1; ++i) { - string = string + XSLUsage.getHTML(arg0[i]) + ", "; - } - - string = string + XSLUsage.getHTML(arg0[arg0.length - 1]); - string = string + "
\n"; - return string; - } else { - return string; - } + @Override + public String toString(Tag[] tags) { + if (tags == null || tags.length == 0) + return ""; + + String string = "\n
Usage:
"; + for (Tag tag : tags) + string = string + XSLUsage.getHTML(tag) + ", "; + + // Remove trailing ", ", add end tag + return string.substring(0, string.length() - 2) + "
\n"; } public static void register(Map tagletMap) { XSLUsageTag tag = new XSLUsageTag(); Taglet t = (Taglet) tagletMap.get(tag.getName()); - if (t != null) { + if (t != null) tagletMap.remove(tag.getName()); - } - tagletMap.put(tag.getName(), tag); } } diff --git a/xalan2jtaglet_jdk9/pom.xml b/xalan2jtaglet_jdk9/pom.xml new file mode 100644 index 000000000..f515f9c99 --- /dev/null +++ b/xalan2jtaglet_jdk9/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + xalan + xalan-project + 2.7.3 + + + xalan2jtaglet_jdk9 + @xsl.usage taglet JDK9+ + + Implementation of the @xsl.usage taglet, used in the Xalan package's javadoc + to indicate classes which, while public for cross-module access, are not + intended to be called by end-users. + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + 9 + 9 + + + + + + diff --git a/xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsage.java b/xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsage.java new file mode 100644 index 000000000..be7ad1ff2 --- /dev/null +++ b/xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsage.java @@ -0,0 +1,55 @@ +package xalan2jtaglet; + +import com.sun.source.doctree.DocTree; +import com.sun.source.doctree.UnknownBlockTagTree; + +/** + * Taglet for Xalan-Java documentation, giving us a standard way to + * indicate when classes are public only because they are shared + * across packages within Xalan code, not because they are intended for use + * by others. Typical: "@xsl.usage internal" + *

+ * Technically it might be better to OSGIfy the Xalan code, which + * would also permit demand-loading of only the classes actually being + * used by this execution... but that's an idea for the future. + *

+ * This code renders the tag keywords (internal, advanced, experimental) + * into their expanded renderings in the Javadoc. + *

+ * Source code recreated from xalan2jtaglet.jar by IntelliJ IDEA (powered by + * FernFlower decompiler), then adjusted to JDK 9+ taglet API. + */ +public class XSLUsage { + public static final String TAG = "xsl.usage"; + private static final int INTERNAL = 0; + private static final int ADVANCED = 1; + private static final int EXPERIMENTAL = 2; + private static final int UNSPECIFIED = -1; + private static final String[] names = new String[]{ + "internal", "advanced", "experimental" + }; + private static final String[] colours = new String[]{ + "FF0000", "00FF00", "0000FF" + }; + private static final String[] messages = new String[]{ + "**For internal use only**", "**For advanced use only**", "**Experimental**" + }; + + public static String getHTML(DocTree usageTag) { + int key = getKey(usageTag); + return key == -1 + ? "" + : " " + messages[key] + "\n"; + } + + private static int getKey(DocTree usageTag) { + if (usageTag instanceof UnknownBlockTagTree) { + UnknownBlockTagTree tag = (UnknownBlockTagTree) usageTag; + for (int i = 0; i < names.length; ++i) { + if (names[i].equals(tag.getContent().toString())) + return i; + } + } + return -1; + } +} diff --git a/xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsageTag.java b/xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsageTag.java new file mode 100644 index 000000000..e29f8d53a --- /dev/null +++ b/xalan2jtaglet_jdk9/src/main/java/xalan2jtaglet/XSLUsageTag.java @@ -0,0 +1,63 @@ +package xalan2jtaglet; + +import com.sun.source.doctree.DocTree; +import jdk.javadoc.doclet.Taglet; + +import javax.lang.model.element.Element; +import java.util.*; + +/** + * Taglet for Xalan-Java documentation, giving us a standard way to + * indicate when classes are public only because they are shared + * across packages within Xalan code, not because they are intended for use + * by others. Typical: "@xsl.usage internal" + *

+ * Technically it might be better to OSGIfy the Xalan code, which + * would also permit demand-loading of only the classes actually being + * used by this execution... but that's an idea for the future. + *

+ * This code renders the tag keywords (internal, advanced, experimental) + * into their expanded renderings in the Javadoc. + *

+ * Source code recreated from xalan2jtaglet.jar by IntelliJ IDEA (powered by + * FernFlower decompiler), then adjusted to JDK 9+ taglet API. + */ +public class XSLUsageTag implements Taglet { + private static final String HEADER = "Usage:"; + + @Override + public Set getAllowedLocations() { + return new HashSet<>(Arrays.asList(Location.values())); + } + + @Override + public boolean isInlineTag() { + return false; + } + + @Override + public String getName() { + return "xsl.usage"; + } + + @Override + public String toString(List tags, Element element) { + if (tags == null || tags.isEmpty()) + return ""; + + String string = "\n

Usage:
"; + for (DocTree tag : tags) + string = string + XSLUsage.getHTML(tag) + ", "; + + // Remove trailing ", ", add end tag + return string.substring(0, string.length() - 2) + "
\n"; + } + + public static void register(Map tagletMap) { + XSLUsageTag tag = new XSLUsageTag(); + Taglet t = (Taglet) tagletMap.get(tag.getName()); + if (t != null) + tagletMap.remove(tag.getName()); + tagletMap.put(tag.getName(), tag); + } +}