From b57da2dadafa52b0e1f93845d01e572f118c23d2 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 16 Aug 2020 23:18:19 +0000 Subject: [PATCH] #64036 - Replace reflection calls in factories for Java 9+ ImageRenderer implementation are now loaded via ServiceLoader fixed the ServiceLoader.load invocations to pass a sensible ClassLoader as OSGi preparation git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880909 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/extractor/ExtractorFactory.java | 3 ++- .../org/apache/poi/sl/draw/ImageRenderer.java | 7 ++++--- .../poi/sl/usermodel/SlideShowFactory.java | 3 ++- .../poi/ss/usermodel/WorkbookFactory.java | 3 ++- src/multimodule/ooxml/java9/module-info.class | Bin 2828 -> 2923 bytes src/multimodule/ooxml/java9/module-info.java | 1 + src/multimodule/ooxml/test9/module-info.class | Bin 3697 -> 3792 bytes src/multimodule/ooxml/test9/module-info.java | 1 + src/multimodule/poi/java9/module-info.class | Bin 3222 -> 3320 bytes src/multimodule/poi/java9/module-info.java | 7 ++++--- src/multimodule/poi/test9/module-info.class | Bin 3349 -> 3447 bytes src/multimodule/poi/test9/module-info.java | 5 ++++- .../scratchpad/java9/module-info.class | Bin 2332 -> 2478 bytes .../scratchpad/java9/module-info.java | 1 + .../scratchpad/test9/module-info.class | Bin 2506 -> 2652 bytes .../scratchpad/test9/module-info.java | 1 + .../devtools/forbidden-signatures.txt | 5 ++++- .../org.apache.poi.sl.draw.ImageRenderer | 18 +++++++++++++++++ .../org.apache.poi.sl.draw.ImageRenderer | 18 +++++++++++++++++ .../org.apache.poi.sl.draw.ImageRenderer | 19 ++++++++++++++++++ 20 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 src/resources/main/META-INF/services/org.apache.poi.sl.draw.ImageRenderer create mode 100644 src/resources/ooxml/META-INF/services/org.apache.poi.sl.draw.ImageRenderer create mode 100644 src/resources/scratchpad/META-INF/services/org.apache.poi.sl.draw.ImageRenderer diff --git a/src/java/org/apache/poi/extractor/ExtractorFactory.java b/src/java/org/apache/poi/extractor/ExtractorFactory.java index bdeb740e20..ccab16a213 100644 --- a/src/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/src/java/org/apache/poi/extractor/ExtractorFactory.java @@ -81,7 +81,8 @@ public final class ExtractorFactory { private ExtractorFactory() { - ServiceLoader.load(ExtractorProvider.class).forEach(provider::add); + ClassLoader cl = ExtractorFactory.class.getClassLoader(); + ServiceLoader.load(ExtractorProvider.class, cl).forEach(provider::add); } /** diff --git a/src/java/org/apache/poi/sl/draw/ImageRenderer.java b/src/java/org/apache/poi/sl/draw/ImageRenderer.java index 0289fce7bf..5051d4593b 100644 --- a/src/java/org/apache/poi/sl/draw/ImageRenderer.java +++ b/src/java/org/apache/poi/sl/draw/ImageRenderer.java @@ -31,7 +31,8 @@ import org.apache.poi.util.Dimension2DDouble; /** * Classes can implement this interfaces to support other formats, for - * example, use Apache Batik to render WMF, PICT can be rendered using Apple QuickTime API for Java: + * example, use Apache Batik to render WMF (since POI 4.0, there's an internal WMF/EMF/EMF+ renderer in POI), + * PICT can be rendered using Apple QuickTime API for Java: * *
  * 
@@ -132,11 +133,11 @@ public interface ImageRenderer {
     /**
      * @param dim the dimension in pixels of the returned image
      * @return the image as buffered image or null if image could not be loaded
-     * 
+     *
      * @since POI 3.15-beta2
      */
     BufferedImage getImage(Dimension2D dim);
-    
+
     /**
      * Render picture data into the supplied graphics
      *
diff --git a/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java b/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
index 200120b211..8155fccb8d 100644
--- a/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
+++ b/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
@@ -48,7 +48,8 @@ public final class SlideShowFactory {
     private final List> provider = new ArrayList<>();
 
     private SlideShowFactory() {
-        ServiceLoader.load(SlideShowProvider.class).forEach(provider::add);
+        ClassLoader cl = SlideShowFactory.class.getClassLoader();
+        ServiceLoader.load(SlideShowProvider.class, cl).forEach(provider::add);
     }
 
     /**
diff --git a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
index e755b09f5e..965666904c 100644
--- a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
+++ b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
@@ -54,7 +54,8 @@ public final class WorkbookFactory {
     private final List provider = new ArrayList<>();
 
     private WorkbookFactory() {
-        ServiceLoader.load(WorkbookProvider.class).forEach(provider::add);
+        ClassLoader cl = WorkbookFactory.class.getClassLoader();
+        ServiceLoader.load(WorkbookProvider.class, cl).forEach(provider::add);
     }
 
 
diff --git a/src/multimodule/ooxml/java9/module-info.class b/src/multimodule/ooxml/java9/module-info.class
index 517b8bbe2c795ea4aaa15af69477f66ea30d1e4d..fd59cc5611206d7993ce890192192f4543747133 100644
GIT binary patch
delta 178
zcmeAXdo9Lw>ff$?3=9mW41F89VmRyB8M+x6RPu|`^%DyclQUBF3-UAdi*xi-iW1B9
zJ#!P&Q-f0TQc{aji`W@@85uOuR8|z{q(RgMhqff$?3=9mW3|$+!VmL(_7#J9VTnJ!fURNi9k(VrN*$$e=rUBd6r#Xd?v7=iK-z{tQ1
gYDNab$s1WjC-38ub6U&DpoK%PQ)WqSVgZT?4Gav7KwBYz
pk%1Y={j*t-`#z&A3&R42MGQ+AmH`D902QqO@)#Lb0r`v!YXHk?HC+Gz

delta 81
zcmew^HC2l1)W2Q(7#J8#8CGrNn#aXxIC&$B=wxYbxyk3b3`H6k7#M+)5WvX54CH><
dT+Mx-QIwfs0mCAOB@9eJl96E&1ff493
k2w-Gj26B@&A7b}q6lG>807?}xlmN*xh6)BIhAM^{08Q#VtN;K2

delta 59
zcmZ1{JV%J@)W2Q(7#J8#87ek%EnydFU|?Vbav^|`ff>k++U&#O%gD>bPym!FVkiNU
FWdNNU3iAK}

diff --git a/src/multimodule/scratchpad/java9/module-info.java b/src/multimodule/scratchpad/java9/module-info.java
index b936858c70..658ef8652b 100644
--- a/src/multimodule/scratchpad/java9/module-info.java
+++ b/src/multimodule/scratchpad/java9/module-info.java
@@ -22,6 +22,7 @@ module org.apache.poi.scratchpad {
 
     provides org.apache.poi.extractor.ExtractorProvider with org.apache.poi.extractor.ole2.OLE2ScratchpadExtractorFactory;
     provides org.apache.poi.sl.usermodel.SlideShowProvider with org.apache.poi.hslf.usermodel.HSLFSlideShowFactory;
+    provides org.apache.poi.sl.draw.ImageRenderer with org.apache.poi.hwmf.draw.HwmfImageRenderer, org.apache.poi.hemf.draw.HemfImageRenderer;
 
     exports org.apache.poi.hmef;
     exports org.apache.poi.hmef.dev;
diff --git a/src/multimodule/scratchpad/test9/module-info.class b/src/multimodule/scratchpad/test9/module-info.class
index 4ee1e56a657302645cc8efca30f6ca4d0a5e5f84..cfda7bb49527ea644a890b9504f41002075dc286 100644
GIT binary patch
delta 171
zcmX>ld`E=q)W2Q(7#J8#89Fv{$#EF4Gc+?YsN@%=>n9c@CTFDT7vyK^7w71w6eX7H
zd*&vlrv|0wrKA?67O^w5GBRjQ4q%p$(Dx|MO+%Ax2T5LF6VU?e^hiZh(7?dJ2(%Ug
j7#Wy>+-aL_I2sv6nHj2pQZ)>9K(c|MiGhisg`o`qw8t*V

delta 59
zcmca3a!Q!%)W2Q(7#J8#8Jae7$#IA@FfcFzxe&m}zzpQ}Z9c})$jHmYPz98#VW