All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.robtimus.maven.plugins.buildhelper.JavadocLicenseMojo Maven / Gradle / Ivy

The newest version!
/*
 * JavadocLicenseMojo.java
 * Copyright 2023 Rob Spoor
 *
 * 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 com.github.robtimus.maven.plugins.buildhelper;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;

/**
 * Add a license file to created Javadoc JAR files.
 * 

* License files are first resolved relative to the current directory. If it cannot be found there, parent directories are checked until one of the * following occurs: *

    *
  • The parent directory is not part of the Maven project (does not contain a {@code pom.xml} file), and is not the root directory of the current * Git project.
  • *
  • The maximum number of parent directories has been reached.
  • *
* * @author Rob Spoor */ @Mojo(name = "javadoc-license", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, requiresProject = true, threadSafe = true) public class JavadocLicenseMojo extends AbstractLicenseMojo { @Override void processLicenseFile(Path licenseFile) throws MojoExecutionException { Path buildDir = Paths.get(project.getBuild().getDirectory()); copyLicenseFile(licenseFile, buildDir); } void copyLicenseFile(Path licenseFile, Path buildDir) throws MojoExecutionException { Path targetDir = buildDir.resolve("apidocs/META-INF"); //$NON-NLS-1$ Path targetFile = targetDir.resolve(licenseFile.getFileName()); try { Files.createDirectories(targetDir); Files.copy(licenseFile, targetFile, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); getLog().info(Messages.javadocLicense.copiedLicense(licenseFile, targetFile)); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy