001/*
002 * JDrupes Builder
003 * Copyright (C) 2025 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.builder.mvnrepo;
020
021import java.util.Optional;
022import org.jdrupes.builder.api.CoreProperties;
023import static org.jdrupes.builder.api.CoreProperties.*;
024import org.jdrupes.builder.api.FileTree;
025import static org.jdrupes.builder.api.Intent.Supply;
026import org.jdrupes.builder.api.Project;
027import org.jdrupes.builder.java.JarBuilder;
028import static org.jdrupes.builder.java.JavaTypes.*;
029import org.jdrupes.builder.java.JavadocDirectory;
030import static org.jdrupes.builder.mvnrepo.MvnProperties.ArtifactId;
031
032/// A special [JarBuilder] that generates a JAR with javadoc.
033///
034///   * The content of the JAR is obtained by requesting resources of
035///     type [JavadocDirectory] from the project's suppliers and using
036///     each as root for a [FileTree], which is then added to the JAR.
037///
038///   * The name of the JAR is set to `<artifactId>-<version>-javadoc.jar`,
039///     where `<artifactId>` is the value of the project's property
040///     [MvnProperties#ArtifactId] with a fallback to the project's name.
041///     `<version>` is the value of the project's property
042///     [CoreProperties#Version].
043///
044public class JavadocJarBuilder extends JarBuilder {
045
046    /// Initializes a new javadoc JAR generator.
047    ///
048    /// @param project the project
049    ///
050    @SuppressWarnings({ "PMD.ConstructorCallsOverridableMethod" })
051    public JavadocJarBuilder(Project project) {
052        super(project, JavadocJarFileType);
053        var trees = project().resources(
054            of(JavadocDirectoryType).using(Supply)).map(
055                d -> FileTree.of(project(), d.root(), "**/*"));
056        addTrees(trees);
057        jarName(Optional.ofNullable(project().get(ArtifactId))
058            .orElse(project().name()) + "-" + project().get(Version)
059            + "-javadoc.jar");
060    }
061
062}