Skip to content

Commit 0dd7bfd

Browse files
committed
transcoder: decrease the dependencies of the api and tosvg transcoders
1 parent 6cbda5f commit 0dd7bfd

File tree

104 files changed

+1835
-1037
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1835
-1037
lines changed

MIGRATING_FROM_BATIK.md

+8
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,11 @@ Batik:
8080

8181
13) The `css.engine.value.css2` package was renamed to `css.engine.value.css`,
8282
given that CSS as a whole isn't versioned anymore.
83+
84+
14) You can keep using the old `transcoder` module, but that one was split in
85+
four sub-modules. For example, for converting SVG to any image format (like
86+
PNG) you only need the `echosvg-transcoder-svg` module. Note that if you have
87+
a user agent that inherits from the `SVGAbstractTranscoderUserAgent`, that
88+
class is now located inside a new `SVGAbstractTranscoder` class that was
89+
created in the `io.sf.carte.echosvg.transcoder.svg` package, which shadows
90+
the old class of the same name located at `io.sf.carte.echosvg.transcoder`.

echosvg-svgrasterizer/build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ sourceSets {
1111

1212
dependencies {
1313
api project(':echosvg-transcoder-svg')
14-
testImplementation project(':echosvg-test')
14+
testImplementation project(':echosvg-test-util')
1515
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
1616
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
1717
}
1818

1919
test {
2020
useJUnitPlatform()
21+
}
22+
23+
tasks.withType(Test) {
2124
if (JavaVersion.current() > JavaVersion.VERSION_11) {
2225
systemProperty('java.security.manager', 'allow')
2326
}

echosvg-svgrasterizer/src/main/resources/io/sf/carte/echosvg/apps/rasterizer/resources/rasterizer.policy

+20
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,30 @@ grant codeBase "file:${app.dev.base}/echosvg-test-swing${app.dev.classdir}" {
128128
permission java.security.AllPermission;
129129
};
130130

131+
grant codeBase "file:${app.dev.base}/echosvg-test-util${app.dev.classdir}" {
132+
permission java.security.AllPermission;
133+
};
134+
131135
grant codeBase "file:${app.dev.base}/echosvg-transcoder${app.dev.classdir}" {
132136
permission java.security.AllPermission;
133137
};
134138

139+
grant codeBase "file:${app.dev.base}/echosvg-transcoder-api${app.dev.classdir}" {
140+
permission java.security.AllPermission;
141+
};
142+
143+
grant codeBase "file:${app.dev.base}/echosvg-transcoder-svg${app.dev.classdir}" {
144+
permission java.security.AllPermission;
145+
};
146+
147+
grant codeBase "file:${app.dev.base}/echosvg-transcoder-svg2svg${app.dev.classdir}" {
148+
permission java.security.AllPermission;
149+
};
150+
151+
grant codeBase "file:${app.dev.base}/echosvg-transcoder-tosvg${app.dev.classdir}" {
152+
permission java.security.AllPermission;
153+
};
154+
135155
grant codeBase "file:${app.dev.base}/echosvg-ttf2svg${app.dev.classdir}" {
136156
permission java.security.AllPermission;
137157
};

echosvg-test-util/build.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
plugins {
2+
id 'echosvg.java-conventions'
3+
}
4+
5+
sourceSets {
6+
// Tests
7+
test {
8+
resources.srcDirs += ["$rootDir/test-resources"]
9+
}
10+
}
11+
12+
dependencies {
13+
implementation project(':echosvg-awt-util')
14+
implementation project(':echosvg-i18n')
15+
implementation "io.sf.jclf:jclf-text:${jclfTextVersion}"
16+
implementation "io.sf.carte:xml-dtd:${xmlDtdVersion}"
17+
implementation "io.sf.carte:carte-util:${carteUtilVersion}"
18+
19+
testRuntimeOnly project(':echosvg-codec')
20+
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
21+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
22+
}
23+
24+
description = 'io.sf.carte:echosvg-test-util'
25+
26+
publishing.publications.maven(MavenPublication).pom {
27+
description = "EchoSVG testing utilities"
28+
}
29+
30+
test {
31+
useJUnitPlatform()
32+
}
33+
34+
tasks.withType(ProcessResources).configureEach {
35+
dependsOn ':echosvg-test-scripts:copyScriptJars',':echosvg-test-scripts:copyPolicyJar'
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
*
3+
* See the NOTICE file distributed with this work for additional
4+
* information regarding copyright ownership.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
*/
19+
package io.sf.carte.echosvg.test;
20+
21+
import java.io.File;
22+
import java.net.MalformedURLException;
23+
import java.net.URL;
24+
import java.nio.file.Paths;
25+
26+
public class TestUtil {
27+
28+
private TestUtil() {
29+
}
30+
31+
/**
32+
* Get the URL of the root project directory.
33+
*
34+
* @param cl a class provided by the project.
35+
* @param projectDirname the directory name of the subproject from which this is
36+
* executed.
37+
* @return the URL.
38+
*/
39+
public static String getRootProjectURL(Class<?> cl, String projectDirname) {
40+
String resName = cl.getName().replace(".", "/") + ".class";
41+
URL url = ResourceLoader.getInstance().getResource(cl, resName);
42+
if (url == null) {
43+
url = cwdURL();
44+
}
45+
String sUrl = url.toExternalForm();
46+
int testDirIdx = sUrl.lastIndexOf(projectDirname);
47+
if (testDirIdx != -1) {
48+
sUrl = sUrl.substring(0, testDirIdx);
49+
} // If no projectDirname, we probably got the root via CWD
50+
return sUrl;
51+
}
52+
53+
private static URL cwdURL() {
54+
try {
55+
return Paths.get(".").toAbsolutePath().normalize().toUri().toURL();
56+
} catch (MalformedURLException e) {
57+
return null;
58+
}
59+
}
60+
61+
/**
62+
* Get the URL of the Gradle-style project build directory.
63+
*
64+
* @param cl a class provided by the project.
65+
* @param projectDirname the directory name of the subproject from which this is
66+
* executed.
67+
* @return the URL.
68+
*/
69+
public static String getProjectBuildURL(Class<?> cl, String projectDirname) {
70+
String resName = cl.getName().replace(".", "/") + ".class";
71+
URL url = ResourceLoader.getInstance().getResource(cl, resName);
72+
String classUrl;
73+
if (url == null) {
74+
url = cwdURL();
75+
File f = new File(url.getFile(), projectDirname);
76+
if (f.exists()) {
77+
// CWD is root directory
78+
try {
79+
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), f.getAbsolutePath());
80+
} catch (MalformedURLException e) {
81+
return null;
82+
}
83+
classUrl = url.toExternalForm();
84+
} else {
85+
// CWD is the project directory instead of root
86+
classUrl = url.toExternalForm();
87+
if (classUrl.lastIndexOf(projectDirname) == -1) {
88+
return null;
89+
}
90+
}
91+
} else {
92+
classUrl = url.toExternalForm();
93+
}
94+
int testDirIdx = classUrl.lastIndexOf(projectDirname);
95+
String buildDir = classUrl.substring(5, testDirIdx + projectDirname.length()) + "/build/";
96+
return buildDir;
97+
}
98+
99+
}

echosvg-test/src/main/java/io/sf/carte/echosvg/test/image/TempImageFiles.java echosvg-test-util/src/main/java/io/sf/carte/echosvg/test/image/TempImageFiles.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.io.IOException;
2323
import java.net.URL;
2424

25-
import io.sf.carte.echosvg.test.TestUtil;
25+
import io.sf.carte.echosvg.test.xml.XmlUtil;
2626

2727
/**
2828
* Produce image-based filenames.
@@ -40,7 +40,7 @@ public class TempImageFiles implements ImageFileBuilder {
4040
*
4141
* @param projectBuildURL the url to the project's build directory. You
4242
* generally have to call
43-
* {@link TestUtil#getProjectBuildURL(Class, String)} to
43+
* {@link XmlUtil#getProjectBuildURL(Class, String)} to
4444
* obtain that. If {@code null}, then OS-supplied
4545
* temporary files will be produced.
4646
*/
@@ -53,7 +53,7 @@ public TempImageFiles(String projectBuildURL) {
5353
*
5454
* @param projectBuildURL the url to the project's build directory. You
5555
* generally have to call
56-
* {@link TestUtil#getProjectBuildURL(Class, String)} to
56+
* {@link XmlUtil#getProjectBuildURL(Class, String)} to
5757
* obtain that. If {@code null}, then OS-supplied
5858
* temporary files will be produced.
5959
* @param imageSubpath the subpath to images (for example in Gradle layout it
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
3+
See the NOTICE file distributed with this work for additional
4+
information regarding copyright ownership.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
*/
19+
20+
/**
21+
* Generic testing utilities.
22+
*/
23+
package io.sf.carte.echosvg.test;

0 commit comments

Comments
 (0)