#405 SVG OSGi issue

This commit is contained in:
Harald Kuhr 2018-03-07 09:25:40 +01:00
parent 9b871322f7
commit 0c66ad82dd
2 changed files with 12 additions and 12 deletions

View File

@ -29,7 +29,7 @@
package com.twelvemonkeys.imageio.plugins.svg;
import com.twelvemonkeys.imageio.spi.ImageReaderSpiBase;
import com.twelvemonkeys.imageio.util.IIOUtil;
import com.twelvemonkeys.lang.SystemUtil;
import javax.imageio.ImageReader;
import javax.imageio.spi.ServiceRegistry;
@ -38,8 +38,7 @@ import java.io.EOFException;
import java.io.IOException;
import java.util.Locale;
import static com.twelvemonkeys.imageio.plugins.svg.SVGProviderInfo.SVG_READER_AVAILABLE;
import static com.twelvemonkeys.imageio.util.IIOUtil.*;
import static com.twelvemonkeys.imageio.util.IIOUtil.deregisterProvider;
/**
* SVGImageReaderSpi
@ -50,6 +49,8 @@ import static com.twelvemonkeys.imageio.util.IIOUtil.*;
*/
public final class SVGImageReaderSpi extends ImageReaderSpiBase {
final static boolean SVG_READER_AVAILABLE = SystemUtil.isClassAvailable("com.twelvemonkeys.imageio.plugins.svg.SVGImageReader", SVGImageReaderSpi.class);
/**
* Creates an {@code SVGImageReaderSpi}.
*/
@ -59,7 +60,7 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
}
public boolean canDecodeInput(final Object pSource) throws IOException {
return pSource instanceof ImageInputStream && SVG_READER_AVAILABLE && canDecode((ImageInputStream) pSource);
return pSource instanceof ImageInputStream && canDecode((ImageInputStream) pSource);
}
@SuppressWarnings("StatementWithEmptyBody")
@ -166,13 +167,15 @@ public final class SVGImageReaderSpi extends ImageReaderSpiBase {
@SuppressWarnings({"deprecation"})
@Override
public void onRegistration(final ServiceRegistry registry, final Class<?> category) {
// TODO: Perhaps just try to create an instance, and de-register if we fail?
if (!SVG_READER_AVAILABLE) {
System.err.println("Could not instantiate SVGImageReader (missing support classes).");
try {
// NOTE: This will break, but it gives us some useful debug info
new SVGImageReader(this);
}
catch (Throwable t) {
System.err.println("Could not instantiate SVGImageReader (missing support classes).");
t.printStackTrace();
}

View File

@ -29,7 +29,6 @@
package com.twelvemonkeys.imageio.plugins.svg;
import com.twelvemonkeys.imageio.spi.ReaderWriterProviderInfo;
import com.twelvemonkeys.lang.SystemUtil;
/**
* SVGProviderInfo.
@ -39,14 +38,12 @@ import com.twelvemonkeys.lang.SystemUtil;
* @version $Id: SVGProviderInfo.java,v 1.0 20/03/15 harald.kuhr Exp$
*/
final class SVGProviderInfo extends ReaderWriterProviderInfo {
final static boolean SVG_READER_AVAILABLE = SystemUtil.isClassAvailable("com.twelvemonkeys.imageio.plugins.svg.SVGImageReader");
protected SVGProviderInfo() {
SVGProviderInfo() {
super(
SVGProviderInfo.class,
SVG_READER_AVAILABLE ? new String[]{"svg", "SVG"} : new String[]{""}, // Names
SVG_READER_AVAILABLE ? new String[]{"svg"} : null, // Suffixes
SVG_READER_AVAILABLE ? new String[]{"image/svg", "image/x-svg", "image/svg+xml", "image/svg-xml"} : null, // Mime-types
new String[]{"svg", "SVG"}, // Names
new String[]{"svg"}, // Suffixes
new String[]{"image/svg", "image/x-svg", "image/svg+xml", "image/svg-xml"}, // Mime-types
"com.twelvemonkeys.imageio.plugins.svg.SVGImageReader", // Reader class name
new String[] {"com.twelvemonkeys.imageio.plugins.svg.SVGImageReaderSpi"},
null,