Skip to content

Commit 76e1c52

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. - 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 76e1c52

4 files changed

Lines changed: 111 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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Jannis Weis 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+
*
12+
* SPDX-License-Identifier: MIT
13+
*
14+
* Copyright (c) 2025 Jannis Weis
15+
*
16+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
17+
* associated documentation files (the "Software"), to deal in the Software without restriction,
18+
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
19+
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
20+
* furnished to do so, subject to the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be included in all copies or
23+
* substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
26+
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30+
*
31+
*******************************************************************************/
32+
package org.eclipse.swt.svg.logging;
33+
34+
import java.util.function.Supplier;
35+
36+
import com.github.weisj.jsvg.logging.LogManager;
37+
import com.github.weisj.jsvg.logging.Logger;
38+
39+
public class JVSGLoggerLogManager implements LogManager {
40+
41+
@Override
42+
public Logger createLogger(String name) {
43+
return new SystemLoggerWrapper(System.getLogger(name));
44+
}
45+
46+
private static final class SystemLoggerWrapper implements Logger {
47+
private final System.Logger logger;
48+
49+
private SystemLoggerWrapper(System.Logger logger) {
50+
this.logger = logger;
51+
}
52+
53+
private static System.Logger.Level toSystemLevel(Logger.Level level) {
54+
switch (level) {
55+
case DEBUG:
56+
return System.Logger.Level.DEBUG;
57+
case INFO:
58+
return System.Logger.Level.INFO;
59+
case WARNING:
60+
return System.Logger.Level.WARNING;
61+
case ERROR:
62+
return System.Logger.Level.ERROR;
63+
default:
64+
throw new IllegalArgumentException("Unknown log level: " + level);
65+
}
66+
}
67+
68+
@Override
69+
public void log(Logger.Level level, String message) {
70+
logger.log(toSystemLevel(level), message);
71+
}
72+
73+
@Override
74+
public void log(Logger.Level level, String message, Throwable e) {
75+
logger.log(toSystemLevel(level), message, e);
76+
}
77+
78+
@Override
79+
public void log(Logger.Level level, Supplier<String> messageSupplier) {
80+
logger.log(toSystemLevel(level), messageSupplier);
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)