Skip to content

Commit

Permalink
transcoder: decrease the dependencies of the api and tosvg transc…
Browse files Browse the repository at this point in the history
…oders
  • Loading branch information
carlosame committed Dec 28, 2024
1 parent 6cbda5f commit 0dd7bfd
Show file tree
Hide file tree
Showing 104 changed files with 1,835 additions and 1,037 deletions.
8 changes: 8 additions & 0 deletions MIGRATING_FROM_BATIK.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ Batik:

13) The `css.engine.value.css2` package was renamed to `css.engine.value.css`,
given that CSS as a whole isn't versioned anymore.

14) You can keep using the old `transcoder` module, but that one was split in
four sub-modules. For example, for converting SVG to any image format (like
PNG) you only need the `echosvg-transcoder-svg` module. Note that if you have
a user agent that inherits from the `SVGAbstractTranscoderUserAgent`, that
class is now located inside a new `SVGAbstractTranscoder` class that was
created in the `io.sf.carte.echosvg.transcoder.svg` package, which shadows
the old class of the same name located at `io.sf.carte.echosvg.transcoder`.
5 changes: 4 additions & 1 deletion echosvg-svgrasterizer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ sourceSets {

dependencies {
api project(':echosvg-transcoder-svg')
testImplementation project(':echosvg-test')
testImplementation project(':echosvg-test-util')
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
useJUnitPlatform()
}

tasks.withType(Test) {
if (JavaVersion.current() > JavaVersion.VERSION_11) {
systemProperty('java.security.manager', 'allow')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,30 @@ grant codeBase "file:${app.dev.base}/echosvg-test-swing${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-test-util${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-transcoder${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-transcoder-api${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-transcoder-svg${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-transcoder-svg2svg${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-transcoder-tosvg${app.dev.classdir}" {
permission java.security.AllPermission;
};

grant codeBase "file:${app.dev.base}/echosvg-ttf2svg${app.dev.classdir}" {
permission java.security.AllPermission;
};
Expand Down
36 changes: 36 additions & 0 deletions echosvg-test-util/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id 'echosvg.java-conventions'
}

sourceSets {
// Tests
test {
resources.srcDirs += ["$rootDir/test-resources"]
}
}

dependencies {
implementation project(':echosvg-awt-util')
implementation project(':echosvg-i18n')
implementation "io.sf.jclf:jclf-text:${jclfTextVersion}"
implementation "io.sf.carte:xml-dtd:${xmlDtdVersion}"
implementation "io.sf.carte:carte-util:${carteUtilVersion}"

testRuntimeOnly project(':echosvg-codec')
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

description = 'io.sf.carte:echosvg-test-util'

publishing.publications.maven(MavenPublication).pom {
description = "EchoSVG testing utilities"
}

test {
useJUnitPlatform()
}

tasks.withType(ProcessResources).configureEach {
dependsOn ':echosvg-test-scripts:copyScriptJars',':echosvg-test-scripts:copyPolicyJar'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.sf.carte.echosvg.test;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;

public class TestUtil {

private TestUtil() {
}

/**
* Get the URL of the root project directory.
*
* @param cl a class provided by the project.
* @param projectDirname the directory name of the subproject from which this is
* executed.
* @return the URL.
*/
public static String getRootProjectURL(Class<?> cl, String projectDirname) {
String resName = cl.getName().replace(".", "/") + ".class";
URL url = ResourceLoader.getInstance().getResource(cl, resName);
if (url == null) {
url = cwdURL();
}
String sUrl = url.toExternalForm();
int testDirIdx = sUrl.lastIndexOf(projectDirname);
if (testDirIdx != -1) {
sUrl = sUrl.substring(0, testDirIdx);
} // If no projectDirname, we probably got the root via CWD
return sUrl;
}

private static URL cwdURL() {
try {
return Paths.get(".").toAbsolutePath().normalize().toUri().toURL();
} catch (MalformedURLException e) {
return null;
}
}

/**
* Get the URL of the Gradle-style project build directory.
*
* @param cl a class provided by the project.
* @param projectDirname the directory name of the subproject from which this is
* executed.
* @return the URL.
*/
public static String getProjectBuildURL(Class<?> cl, String projectDirname) {
String resName = cl.getName().replace(".", "/") + ".class";
URL url = ResourceLoader.getInstance().getResource(cl, resName);
String classUrl;
if (url == null) {
url = cwdURL();
File f = new File(url.getFile(), projectDirname);
if (f.exists()) {
// CWD is root directory
try {
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), f.getAbsolutePath());
} catch (MalformedURLException e) {
return null;
}
classUrl = url.toExternalForm();
} else {
// CWD is the project directory instead of root
classUrl = url.toExternalForm();
if (classUrl.lastIndexOf(projectDirname) == -1) {
return null;
}
}
} else {
classUrl = url.toExternalForm();
}
int testDirIdx = classUrl.lastIndexOf(projectDirname);
String buildDir = classUrl.substring(5, testDirIdx + projectDirname.length()) + "/build/";
return buildDir;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.IOException;
import java.net.URL;

import io.sf.carte.echosvg.test.TestUtil;
import io.sf.carte.echosvg.test.xml.XmlUtil;

/**
* Produce image-based filenames.
Expand All @@ -40,7 +40,7 @@ public class TempImageFiles implements ImageFileBuilder {
*
* @param projectBuildURL the url to the project's build directory. You
* generally have to call
* {@link TestUtil#getProjectBuildURL(Class, String)} to
* {@link XmlUtil#getProjectBuildURL(Class, String)} to
* obtain that. If {@code null}, then OS-supplied
* temporary files will be produced.
*/
Expand All @@ -53,7 +53,7 @@ public TempImageFiles(String projectBuildURL) {
*
* @param projectBuildURL the url to the project's build directory. You
* generally have to call
* {@link TestUtil#getProjectBuildURL(Class, String)} to
* {@link XmlUtil#getProjectBuildURL(Class, String)} to
* obtain that. If {@code null}, then OS-supplied
* temporary files will be produced.
* @param imageSubpath the subpath to images (for example in Gradle layout it
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
See the NOTICE file distributed with this work for additional
information regarding copyright ownership.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
* Generic testing utilities.
*/
package io.sf.carte.echosvg.test;
Loading

0 comments on commit 0dd7bfd

Please sign in to comment.