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.FileResource; 023import org.jdrupes.builder.api.FileTree; 024import static org.jdrupes.builder.api.Intend.Supply; 025import org.jdrupes.builder.api.Project; 026import static org.jdrupes.builder.api.Project.Properties.Version; 027import org.jdrupes.builder.api.ResourceRequest; 028import org.jdrupes.builder.api.ResourceType; 029import org.jdrupes.builder.java.JarGenerator; 030import static org.jdrupes.builder.java.JavaTypes.*; 031import org.jdrupes.builder.java.JavadocDirectory; 032import static org.jdrupes.builder.mvnrepo.MvnProperties.*; 033 034/// A special [JarGenerator] that generates a jar with javadoc. 035/// 036/// * The content of the jar is obtained by requesting resources of 037/// type [JavadocDirectory] from the project's suppliers and using 038/// each as root for a [FileTree], which is then added to the jar. 039/// 040/// * The name of the jar is set to `<artifactId>-<version>-javadoc.jar`, 041/// where `<artifactId>` is the value of the project's property 042/// [MvnProperties#ArtifactId] with a fallback to the project's name. 043/// `<version>` is the value of the project's property 044/// [Project.Properties#Version]. 045/// 046public class JavadocJarGenerator extends JarGenerator { 047 048 /// Initializes a new sources jar generator. 049 /// 050 /// @param project the project 051 /// 052 @SuppressWarnings({ "PMD.ConstructorCallsOverridableMethod" }) 053 public JavadocJarGenerator(Project project) { 054 super(project, JavadocJarFileType); 055 var trees = project().from(Supply).get( 056 new ResourceRequest<JavadocDirectory>(new ResourceType<>() {})).map( 057 d -> project().newResource( 058 new ResourceType<FileTree<FileResource>>() {}, 059 d.path(), "**/*")); 060 addTrees(trees); 061 jarName(Optional.ofNullable(project().get(ArtifactId)) 062 .orElse(project().name()) + "-" + project().get(Version) 063 + "-javadoc.jar"); 064 } 065 066}