Skip to content

Commit

Permalink
Remove java.desktop dependency from javax.xml.
Browse files Browse the repository at this point in the history
The only dependency to java.desktop was coming from JAXB.java where a 25
line method from java.beans.Introspector was used to decapitalize a Java
class name.

Partly fixes bazelbuild#7502.
This works around bazelbuild#6799 which seems to take longer than expected because
there is some implementation work left to do.

RELNOTES: None
  • Loading branch information
meisterT committed Apr 17, 2019
1 parent d7702b1 commit 68cc0dc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion third_party/jaxb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ filegroup(

java_import(
name = "jaxb",
jars = ["jaxb-api-2.3.1.jar"],
jars = ["jaxb-api-2.3.1-patched.jar"],
srcjar = "jaxb-api-2.3.1-sources.jar",
)
Binary file added third_party/jaxb/jaxb-api-2.3.1-patched.jar
Binary file not shown.
54 changes: 54 additions & 0 deletions third_party/jaxb/remove-java.desktop.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff -ur srcs/javax/xml/bind/JAXB.java srcs-patched/javax/xml/bind/JAXB.java
--- srcs/javax/xml/bind/JAXB.java 2018-09-12 06:26:24.000000000 +0200
+++ srcs-patched/javax/xml/bind/JAXB.java 2019-04-16 17:17:25.118768524 +0200
@@ -46,7 +46,6 @@
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import java.beans.Introspector;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -593,7 +592,30 @@
}

private static String inferName(Class clazz) {
- return Introspector.decapitalize(clazz.getSimpleName());
+ String name = clazz.getSimpleName();
+ try {
+ if (!Character.isUpperCase(name.charAt(0))) {
+ return name;
+ } else {
+ try {
+ if(Character.isUpperCase(name.charAt(1))) {
+ return name;
+ } else {
+ char[] c = name.toCharArray();
+ c[0] = Character.toLowerCase(c[0]);
+ return new String(c);
+ }
+ } catch(StringIndexOutOfBoundsException E) {
+ char[] c = new char[1];
+ c[0] = Character.toLowerCase(name.charAt(0));
+ return new String(c);
+ }
+ }
+ } catch(StringIndexOutOfBoundsException E) {
+ return name;
+ } catch(NullPointerException E) {
+ return null;
+ }
}

/**
diff -ur srcs/module-info.java srcs-patched/module-info.java
--- srcs/module-info.java 2018-09-12 06:26:24.000000000 +0200
+++ srcs-patched/module-info.java 2019-04-16 17:17:16.038792433 +0200
@@ -42,7 +42,6 @@
requires transitive java.activation;
requires transitive java.xml;
requires java.logging;
- requires java.desktop;

exports javax.xml.bind;
exports javax.xml.bind.annotation;
11 changes: 11 additions & 0 deletions third_party/jaxb/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -euxo pipefail

mkdir srcs
cd srcs
jar xvf ../jaxb-api-2.3.1-sources.jar
patch -p1 < ../remove-java.desktop.patch
rm -rf META-INF
find . -type f -name \*.java -print0 | xargs -0 javac
find . -type f -name \*.class -print0 | xargs -0 jar -cvf ../jaxb-api-2.3.1-patched.jar

0 comments on commit 68cc0dc

Please sign in to comment.