Skip to content

Commit c1fd7a0

Browse files
committed
Update jsvg to 2.1.0 in org.eclipse.swt.svg
- Add class org.eclipse.swt.svg.logging.JVSGLoggerLogManager to implement the new logging service required by jsvg 2.1.0. - Simply print to System.err. - Only print ERROR level. - Support system property org.eclipse.swt.svg.logging to support other levels. - Update the lower bounds to 2.1.0 because that provides the export of the com.github.weisj.jsvg.logging package which is needed for JVSGLoggerLogManager. - Add /org.eclipse.swt.svg/resources/META-INF/services/com.github.weisj.jsvg.logging.LogManager which declares the org.eclipse.swt.svg.logging.JVSGLoggerLogManager service. - Add Provide-Capability declarations for the service. - Ensure that org.eclipse.swt.svg.JSVGRasterizer.SVG_LOADER is initialized while the context class loader references the bundle class loader of org.eclipse.swt.svg because the services are loaded using plain old Java which requires the service to be on the classpath. - Do not export the org.eclipse.swt.svg.logging package because it's not needed outside of the fragment.
1 parent 65f43d4 commit c1fd7a0

4 files changed

Lines changed: 83 additions & 5 deletions

File tree

bundles/org.eclipse.swt.svg/META-INF/MANIFEST.MF

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ Bundle-Vendor: %providerName
88
Bundle-Localization: fragment
99
Bundle-RequiredExecutionEnvironment: JavaSE-21
1010
Fragment-Host: org.eclipse.swt
11-
Import-Package: com.github.weisj.jsvg;version="[2.0.0,3.0.0)",
12-
com.github.weisj.jsvg.parser;version="[2.0.0,3.0.0)",
13-
com.github.weisj.jsvg.view;version="[2.0.0,3.0.0)"
11+
Import-Package: com.github.weisj.jsvg;version="[2.1.0,3.0.0)",
12+
com.github.weisj.jsvg.logging;version="[2.1.0,3.0.0)",
13+
com.github.weisj.jsvg.parser;version="[2.1.0,3.0.0)",
14+
com.github.weisj.jsvg.view;version="[2.1.0,3.0.0)"
1415
Export-Package: org.eclipse.swt.svg;x-internal:=true
15-
Provide-Capability: eclipse.swt;image.format="svg";version:Version="1.0"
16+
Provide-Capability:
17+
eclipse.swt;
18+
image.format="svg";
19+
version:Version="1.0",
20+
osgi.service;
21+
objectClass:List<String>="com.github.weisj.jsvg.logging.LogManager";
22+
effective:=active,
23+
osgi.serviceloader;
24+
osgi.serviceloader="com.github.weisj.jsvg.logging.LogManager";
25+
register:="org.eclipse.swt.svg.logging.JVSGLoggerLogManager"
26+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.swt.svg.logging.JVSGLoggerLogManager

bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@
5555
*/
5656
public class JSVGRasterizer implements SVGRasterizer {
5757

58-
private static final SVGLoader SVG_LOADER = new SVGLoader();
58+
private static final SVGLoader SVG_LOADER;
59+
60+
static {
61+
Thread thread = Thread.currentThread();
62+
ClassLoader contextClassLoader = thread.getContextClassLoader();
63+
try {
64+
thread.setContextClassLoader(JSVGRasterizer.class.getClassLoader());
65+
SVG_LOADER = new SVGLoader();
66+
} finally {
67+
thread.setContextClassLoader(contextClassLoader);
68+
}
69+
}
5970

6071
private final static Map<Key, Object> RENDERING_HINTS = Map.of( //
6172
KEY_ANTIALIASING, VALUE_ANTIALIAS_ON, //
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Eclipse contributors and others.
3+
*
4+
* This program and the accompanying materials are made available under the terms of the Eclipse
5+
* Public License 2.0 which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
*******************************************************************************/
11+
package org.eclipse.swt.svg.logging;
12+
13+
import java.util.function.Supplier;
14+
15+
import com.github.weisj.jsvg.logging.LogManager;
16+
import com.github.weisj.jsvg.logging.Logger;
17+
18+
public class JVSGLoggerLogManager implements LogManager {
19+
20+
private static final Logger.Level LEVEL = Logger.Level.valueOf(System.getProperty("org.eclipse.swt.svg.logging", "ERROR"));
21+
22+
@Override
23+
public Logger createLogger(String name) {
24+
return new Logger() {
25+
@Override
26+
public void log(Logger.Level level, String message, Throwable e) {
27+
if (level.compareTo(LEVEL) <= 0) {
28+
return;
29+
}
30+
doLog(level, message);
31+
e.printStackTrace();
32+
}
33+
34+
@Override
35+
public void log(Logger.Level level, Supplier<String> messageSupplier) {
36+
if (level.compareTo(LEVEL) < 0) {
37+
return;
38+
}
39+
doLog(level, messageSupplier.get());
40+
}
41+
42+
@Override
43+
public void log(Logger.Level level, String message) {
44+
if (level.compareTo(LEVEL) < 0) {
45+
return;
46+
}
47+
doLog(level, message);
48+
}
49+
50+
private void doLog(Logger.Level level, String message) {
51+
System.err.format("JSVGRasterizer: %s: %s: %s", level, name, message).println();
52+
}
53+
};
54+
}
55+
}

0 commit comments

Comments
 (0)