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 17c3f73eca Generate sources JAR and Javadoc JAR together with the Maven artifacts. 17c3f73eca is described below commit 17c3f73eca02c394d0897b18176d82ee0d5487cc Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Oct 4 18:10:23 2023 +0200 Generate sources JAR and Javadoc JAR together with the Maven artifacts. --- .../apache/sis/buildtools/gradle/BuildHelper.java | 1 + .../apache/sis/buildtools/gradle/Dependency.java | 2 +- .../apache/sis/buildtools/gradle/ModularJAR.java | 9 +- .../sis/buildtools/gradle/ModularSources.java | 146 +++++++++++++++++++++ .../apache/sis/buildtools/gradle/ZipWriter.java | 2 +- endorsed/build.gradle.kts | 85 +++++++++--- incubator/build.gradle.kts | 15 ++- optional/build.gradle.kts | 5 +- 8 files changed, 240 insertions(+), 25 deletions(-) diff --git a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/BuildHelper.java b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/BuildHelper.java index 729fa33f0e..0408b27a8f 100644 --- a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/BuildHelper.java +++ b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/BuildHelper.java @@ -160,6 +160,7 @@ public final class BuildHelper implements Plugin<Project> { }); }); tasks.withType(Jar.class).forEach((task) -> { + task.getInputs().dir(Conventions.SOURCE_DIRECTORY); task.getOutputs().dir(Conventions.fileRelativeToBuild(project, Conventions.LIBS_DIRECTORY)); task.setActions(List.of((t) -> { // Replace the default action by our own. ModularJAR.execute(BuildHelper.this, (Jar) t); diff --git a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/Dependency.java b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/Dependency.java index f05b607943..c4b4ef9f4a 100644 --- a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/Dependency.java +++ b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/Dependency.java @@ -151,7 +151,7 @@ public final class Dependency { } } } - return null; + return name.replace('-', '.'); } /** diff --git a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularJAR.java b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularJAR.java index 72f4be0535..ba1e3b96b3 100644 --- a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularJAR.java +++ b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularJAR.java @@ -81,7 +81,7 @@ final class ModularJAR extends ZipWriter.JDK { * Invoked when the {@code jar} task is executed. * * @param context the extension which is invoking this task. - * @param task the {@link Javadoc} task to configure. + * @param task the {@link Jar} task to configure. */ static void execute(final BuildHelper context, final Jar task) { final Project project = task.getProject(); @@ -106,9 +106,14 @@ final class ModularJAR extends ZipWriter.JDK { } } try { - write(project, module, new File(target, module.getName() + ".jar"), filteredAttributes); + final String name = module.getName(); + write(project, module, new File(target, name + ".jar"), filteredAttributes); + ModularSources.write(task, name, false); + ModularSources.write(task, name, true); } catch (IOException e) { throw new UncheckedIOException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); } filteredAttributes.clear(); } diff --git a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularSources.java b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularSources.java new file mode 100644 index 0000000000..b07e0cc9ca --- /dev/null +++ b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ModularSources.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.sis.buildtools.gradle; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.util.zip.ZipOutputStream; +import org.gradle.api.Project; +import org.gradle.api.Task; + + +/** + * Generates the source codes on a per-module basis. + * + * @author Martin Desruisseaux (Geomatys) + */ +final class ModularSources extends ZipWriter.JDK { + /** + * The directory where the ZIP files will be written. + */ + private static final String OUTPUT_DIRECTORY = "docs"; + + /** + * The Java system property to set to {@code true} for enabling Javadoc generation. + */ + private static final String CREATE_JAVADOC_PROPERTY = "org.apache.sis.create-javadoc"; + + /** + * Creates a helper instance. + * + * @param project the sub-project being compiled. + * @param out output stream of the JAR file to create. + */ + private ModularSources(final Project project, final ZipOutputStream out) { + super(project, out); + } + + /** + * Deletes the given directory recursively. + * + * @param f file or directory to delete. + * @throws IOException if the file or directory cannot be deleted. + */ + private static void delete(final File f) throws IOException { + final File[] files = f.listFiles(); + if (files != null) { + for (File c : files) + delete(c); + } + if (!f.delete()) { + throw new IOException("Cannot delete " + f); + } + } + + /** + * Returns the path to the sources of the given module. + * + * @param project the project. + * @param module name of the module. + * @return path to the sources of the specified module. + */ + private static File sourcesDir(final Project project, final String module) { + return new File(new File(project.file(Conventions.SOURCE_DIRECTORY), module), Conventions.MAIN_DIRECTORY); + } + + /** + * Creates the JAR files for source codes or javadoc. + * + * @param task the JAR task being executed. + * @param module name of the module for which to create sources JAR. + * @param javadoc whether to create Javadoc. + * @throws IOException if an error occurred while writing the source ZIP files. + * @throws InterruptedException if the process has been interrupted while generating javadoc. + */ + static void write(final Task task, final String module, final boolean javadoc) throws IOException, InterruptedException { + final Project project = task.getProject(); + final File sources; + if (javadoc) { + sources = new File(task.getTemporaryDir(), "javadoc"); + if (!sources.mkdir()) { + delete(sources); + if (!sources.mkdir()) { + throw new IOException("Cannot create " + sources); + } + } + /* + * For performance reason, we actually generate the Javadoc only of the + * "org.apache.sis.create-javadoc" system property is set to `true`. + * Otherwise the Javadoc files will be empty. + */ + if (Boolean.getBoolean(CREATE_JAVADOC_PROPERTY)) { + final var pb = new ProcessBuilder("javadoc", + "-locale", "en", + "-doctitle", "Apache SIS API", + "-tag", "category:X:Category:", + "-tag", "todo:a:TODO:", + "-nonavbar", "-noindex", "-nodeprecatedlist", "-notree", "-nohelp", + "--module-path", Conventions.fileRelativeToBuild(project, LIBS_DIRECTORY).getPath(), + "--module-source-path", sourcesDir(project, "*").getPath(), + "--add-modules", "org.apache.sis.storage", // For allowing some forward references. + "-d", sources.getPath(), + "--module", module); + + final File errors = new File(sources, "errors.log"); + pb.redirectError(errors); + final Process p = pb.start(); + p.waitFor(); + if (p.exitValue() == 0) { + errors.delete(); + } + } else { + Files.writeString(new File(sources, "README").toPath(), + "For performance reason, Javadoc generation is disabled by default.\n" + + "For generating Javadoc, set the following system property:\n" + + "\n" + + " " + CREATE_JAVADOC_PROPERTY + "=true\n" + + "\n"); + } + } else { + sources = sourcesDir(project, module); + } + final var target = Conventions.fileRelativeToBuild(project, OUTPUT_DIRECTORY); + target.mkdir(); + final File file = new File(target, module + '-' + (javadoc ? "javadoc" : "sources") + ".jar"); + try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))) { + final var writer = new ModularSources(project, out); + writer.writeDirectory(sources, null, ""); + } + } +} diff --git a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ZipWriter.java b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ZipWriter.java index b8440e088f..7529994b00 100644 --- a/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ZipWriter.java +++ b/buildSrc/src/org.apache.sis.buildtools/main/org/apache/sis/buildtools/gradle/ZipWriter.java @@ -214,7 +214,7 @@ abstract class ZipWriter extends Conventions { * Copies to the ZIP file the content of the given directory. * * @param source the directory to zip. - * @param filter filter to apply on the files, or {@code null} if none. + * @param filter filter to apply on the files of the root directory, or {@code null} if none. * @param target where to write the files in the ZIP file. Empty for writing in the root. * @throws IOException if an error occurred while reading the source or writing the ZIP file. */ diff --git a/endorsed/build.gradle.kts b/endorsed/build.gradle.kts index 2cf5c89f2e..b8671e60c3 100644 --- a/endorsed/build.gradle.kts +++ b/endorsed/build.gradle.kts @@ -232,18 +232,24 @@ tasks.jar { publishing { publications { create<MavenPublication>("util") { + var module = "org.apache.sis.util" groupId = "org.apache.sis.core" artifactId = "sis-utility" - artifact(layout.buildDirectory.file("libs/org.apache.sis.util.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS utilities" description = "Units of measurement and miscellaneous utility methods required by Apache SIS." } } create<MavenPublication>("metadata") { + var module = "org.apache.sis.metadata" groupId = "org.apache.sis.core" artifactId = "sis-metadata" - artifact(layout.buildDirectory.file("libs/org.apache.sis.metadata.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS metadata" description = "Implementations of metadata derived from ISO 19115. " + @@ -252,9 +258,12 @@ publishing { } } create<MavenPublication>("referencing") { + var module = "org.apache.sis.referencing" groupId = "org.apache.sis.core" artifactId = "sis-referencing" - artifact(layout.buildDirectory.file("libs/org.apache.sis.referencing.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS referencing" description = "Implementations of Coordinate Reference Systems (CRS), " + @@ -262,9 +271,12 @@ publishing { } } create<MavenPublication>("referencing.gazetteer") { + var module = "org.apache.sis.referencing.gazetteer" groupId = "org.apache.sis.core" artifactId = "sis-referencing-by-identifiers" - artifact(layout.buildDirectory.file("libs/org.apache.sis.referencing.gazetteer.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS referencing by geographic identifiers" description = "Implementations of Spatial Reference Systems using Geographic Identifiers " + @@ -272,9 +284,12 @@ publishing { } } create<MavenPublication>("feature") { + var module = "org.apache.sis.feature" groupId = "org.apache.sis.core" artifactId = "sis-feature" - artifact(layout.buildDirectory.file("libs/org.apache.sis.feature.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS features" description = "Representations of geographic features. " + @@ -282,108 +297,144 @@ publishing { } } create<MavenPublication>("portrayal") { + var module = "org.apache.sis.portrayal" groupId = "org.apache.sis.core" artifactId = "sis-portrayal" - artifact(layout.buildDirectory.file("libs/org.apache.sis.portrayal.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS portrayal" description = "Symbology and map representations, together with a rendering engine for display." } } create<MavenPublication>("storage") { + var module = "org.apache.sis.storage" groupId = "org.apache.sis.storage" artifactId = "sis-storage" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS common storage" description = "Provides the interfaces and base classes to be implemented by various storage formats." } } create<MavenPublication>("storage.xml") { + var module = "org.apache.sis.storage.xml" groupId = "org.apache.sis.storage" artifactId = "sis-xmlstore" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.xml.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS XML storage" description = "Read and write files in the GPX format." } } create<MavenPublication>("storage.netcdf") { + var module = "org.apache.sis.storage.netcdf" groupId = "org.apache.sis.storage" artifactId = "sis-netcdf" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.netcdf.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS netCDF storage" description = "Bridge between netCDF Climate and Forecast (CF) convention and ISO 19115 metadata." } } create<MavenPublication>("storage.geotiff") { + var module = "org.apache.sis.storage.geotiff" groupId = "org.apache.sis.storage" artifactId = "sis-geotiff" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.geotiff.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS GeoTIFF storage" description = "Cloud Optimized GeoTIFF reader and bridge to ISO 19115 metadata." } } create<MavenPublication>("storage.earthobservation") { + var module = "org.apache.sis.storage.earthobservation" groupId = "org.apache.sis.storage" artifactId = "sis-earth-observation" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.earthobservation.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS Earth Observation storage" description = "Read a directory of Landsat files as a single resource." } } create<MavenPublication>("storage.sql") { + var module = "org.apache.sis.storage.sql" groupId = "org.apache.sis.storage" artifactId = "sis-sqlstore" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.sql.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS SQL storage" description = "Read and write features from SQL databases." } } create<MavenPublication>("cloud.aws") { + var module = "org.apache.sis.cloud.aws" groupId = "org.apache.sis.cloud" artifactId = "sis-cloud-aws" - artifact(layout.buildDirectory.file("libs/org.apache.sis.cloud.aws.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS storage from Amazon AWS S3" description = "Provides access to Amazon AWS S3 storage from Apache SIS data stores." } } create<MavenPublication>("profile.france") { + var module = "org.apache.sis.profile.france" groupId = "org.apache.sis.profiles" artifactId = "sis-french-profile" - artifact(layout.buildDirectory.file("libs/org.apache.sis.profile.france.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS French profiles" description = "Extensions to ISO-19115 metadata mandated by the French government." } } create<MavenPublication>("profile.japan") { + var module = "org.apache.sis.profile.japan" groupId = "org.apache.sis.profiles" artifactId = "sis-japan-profile" - artifact(layout.buildDirectory.file("libs/org.apache.sis.profile.japan.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS Japanese profiles" description = "Extensions to netCDF reader for file formats published by Japanese Aerospace Exploration Agency (JAXA)." } } create<MavenPublication>("console") { + var module = "org.apache.sis.console" groupId = "org.apache.sis.application" artifactId = "sis-console" - artifact(layout.buildDirectory.file("libs/org.apache.sis.console.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS console" description = "Console application." } } create<MavenPublication>("openoffice") { + var module = "org.apache.sis.openoffice" groupId = "org.apache.sis.application" artifactId = "sis-openoffice" - artifact(layout.buildDirectory.file("libs/org.apache.sis.openoffice.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Bridges to Apache OpenOffice or LibreOffice" description = "Provides some Apache SIS functionalities as Apache OpenOffice addins. " + diff --git a/incubator/build.gradle.kts b/incubator/build.gradle.kts index ef4227ef12..e2e76b96bd 100644 --- a/incubator/build.gradle.kts +++ b/incubator/build.gradle.kts @@ -115,27 +115,36 @@ tasks.test { publishing { publications { create<MavenPublication>("cql") { + var module = "org.apache.sis.cql" groupId = "org.apache.sis.core" artifactId = "sis-cql" - artifact(layout.buildDirectory.file("libs/org.apache.sis.cql.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS CQL" description = "CQL parser." } } create<MavenPublication>("storage.shapefile") { + var module = "org.apache.sis.storage.shapefile" groupId = "org.apache.sis.storage" artifactId = "sis-shapefile" - artifact(layout.buildDirectory.file("libs/org.apache.sis.storage.shapefile.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS Shapefile storage" description = "Read and write files in the Shapefile format." } } create<MavenPublication>("webapp") { + var module = "org.apache.sis.webapp" groupId = "org.apache.sis.application" artifactId = "sis-webapp" - artifact(layout.buildDirectory.file("libs/org.apache.sis.webapp.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS web services layer" description = "Placeholder for future developments." diff --git a/optional/build.gradle.kts b/optional/build.gradle.kts index 52a2f77766..0bfacae2f5 100644 --- a/optional/build.gradle.kts +++ b/optional/build.gradle.kts @@ -160,9 +160,12 @@ tasks.jar { publishing { publications { create<MavenPublication>("gui") { + var module = "org.apache.sis.gui" groupId = "org.apache.sis.application" artifactId = "sis-javafx" - artifact(layout.buildDirectory.file("libs/org.apache.sis.gui.jar")) + artifact(layout.buildDirectory.file("libs/${module}.jar")) + artifact(layout.buildDirectory.file("docs/${module}-sources.jar")) {classifier = "sources"} + artifact(layout.buildDirectory.file("docs/${module}-javadoc.jar")) {classifier = "javadoc"} pom { name = "Apache SIS application for JavaFX (optional)" description = "Client application for JavaFX. " +