This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new f2af582e7d Add EPSG license in optional "non-free" modules. This is done only if the EPSG data are present. f2af582e7d is described below commit f2af582e7df64450fd29a58842d30070c761099d Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Jul 30 10:59:58 2024 +0200 Add EPSG license in optional "non-free" modules. This is done only if the EPSG data are present. --- .../org/apache/sis/buildtools/maven/Generator.java | 52 +++++++++++++++++++--- optional/build.gradle.kts | 16 +++++++ 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/java/org/apache/sis/buildtools/maven/Generator.java b/buildSrc/src/main/java/org/apache/sis/buildtools/maven/Generator.java index 239a741b5b..0f6df6c1fc 100644 --- a/buildSrc/src/main/java/org/apache/sis/buildtools/maven/Generator.java +++ b/buildSrc/src/main/java/org/apache/sis/buildtools/maven/Generator.java @@ -102,11 +102,16 @@ public final class Generator { private final EnumMap<Element,String> info; /** - * The required dependencies as JPML module name. + * The required dependencies as JPMS module name. * Values are whether the dependency is optional. */ private final Map<String,Boolean> requires; + /** + * Whether we detected that the module needs an EPSG license. + */ + private boolean isEPSG; + /** * Creates a new generator which will read and rewrite in the given buffer. * @@ -158,6 +163,9 @@ public final class Generator { throw new SISBuildException("Tag not found: " + element.tag); } pom.replace(start, end, value); + if (element == Element.GROUB_ID) { + isEPSG |= value.contains("non-free"); + } } } final int start = pom.indexOf("${"); @@ -168,6 +176,42 @@ public final class Generator { } } + /** + * Returns the index at the beginning of the line containing the given keyword. + */ + private int indexBefore(String keyword) { + final int start = pom.lastIndexOf("\n", pom.lastIndexOf(keyword)) + 1; + if (start <= 0) { + throw new SISBuildException("Bad pom.xml template."); + } + return start; + } + + /** + * Adds the EPSG license if this module is for a non-free module. + * The license is inserted just before the dependencies. + */ + private void addLicensesIfEPSG() { + if (isEPSG) { + pom.insert(indexBefore("<dependencies>"), + """ + <licenses> + <license> + <name>EPSG terms of use</name> + <url>https://epsg.org/terms-of-use.html</url> + <distribution>manual</distribution> + </license> + <license> + <name>Apache License, Version 2.0</name> + <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + + """); + } + } + /** * Adds the given dependencies at the end of the {@code pom.xml}. * An initial POM must have been written by {@link #rewritePOM()}. @@ -176,10 +220,7 @@ public final class Generator { * @param dependencies the project dependencies to add. */ private void addDependencies(final Map<String,Dependency> dependencies) { - final int start = pom.lastIndexOf("\n", pom.lastIndexOf("</dependencies>")) + 1; - if (start <= 0) { - throw new SISBuildException("Bad pom.xml template."); - } + final int start = indexBefore("</dependencies>"); final String suffix = pom.substring(start); pom.setLength(start); for (final Map.Entry<String,Boolean> entry : requires.entrySet()) { @@ -227,6 +268,7 @@ public final class Generator { final var g = new Generator(xml.asString()); g.parseOriginalPOM(); g.rewritePOM(); + g.addLicensesIfEPSG(); try { g.findUsedDependencies(pub.getArtifacts()); g.addDependencies(Dependency.jpms(project, subProjects)); diff --git a/optional/build.gradle.kts b/optional/build.gradle.kts index 3393fafdc7..3c820e1655 100644 --- a/optional/build.gradle.kts +++ b/optional/build.gradle.kts @@ -165,6 +165,21 @@ fun downloadFontGIS() { } } +/* + * Adds symbolic links to EPSG license if those optional data are present. + */ +fun addLicenseEPSG() { + var targetFile = File(file("build"), "classes/java/main/org.apache.sis.referencing.epsg/META-INF/LICENSE") + if (!targetFile.exists()) { + val sourceFile = File(file("src"), "org.apache.sis.referencing.epsg/main/org/apache/sis/referencing/factory/sql/epsg/LICENSE.txt") + if (sourceFile.exists()) { + Files.createLink(targetFile.toPath(), sourceFile.toPath()) + targetFile = File(file("build"), "classes/java/main/org.apache.sis.referencing.database/META-INF/LICENSE") + Files.createLink(targetFile.toPath(), sourceFile.toPath()) + } + } +} + /* * Discover and execute JUnit-based tests. */ @@ -191,6 +206,7 @@ tasks.test { * Other attributes are hard-coded in `../buildSrc`. */ tasks.jar { + addLicenseEPSG(); downloadFontGIS(); manifest { attributes["Main-Class"] = "org.apache.sis.gui.DataViewer"