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

com.metaeffekt.artifact.analysis.mojo.ReportMojo Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2021-2024 the original author or authors.
 *
 * 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.metaeffekt.artifact.analysis.mojo;

import com.metaeffekt.artifact.analysis.report.InventoryReportModel;
import com.metaeffekt.artifact.analysis.utils.FileUtils;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.metaeffekt.core.inventory.InventoryUtils;
import org.metaeffekt.core.inventory.processor.model.Inventory;
import org.metaeffekt.core.maven.kernel.AbstractProjectAwareMojo;

import java.io.File;
import java.io.IOException;

/**
 * Creates a single-page HTML report comparing the expected licenses with the ones found by the (up to) five last scans
 * from the scan-artifacts goal.
* The individual artifacts and licenses can then be compared and manually authored. */ @Mojo(name = "report-artifacts", defaultPhase = LifecyclePhase.COMPILE) public class ReportMojo extends AbstractProjectAwareMojo { @Parameter(defaultValue = "${project}", required = true, readonly = true) private MavenProject project; @Parameter(required = true) private String id; @Parameter(required = true) private File referenceInventoryDir; /** * The includes pattern to match the inventory files against.
* By default, this is all .xls files in the inventory directory. */ @Parameter(defaultValue = "inventory/*.xls*") private String referenceInventoryIncludes; @Parameter(defaultValue = "${project.basedir}/.analysis") private File analysisBaseDir; @Parameter(defaultValue = "${project.basedir}/.results") private File resultTargetDir; @Override public MavenProject getProject() { return project; } @Override public void execute() throws MojoFailureException { try { report(); } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } } private void report() throws IOException, MojoFailureException { final File reportFile = new File(resultTargetDir, id + "-report.html"); final Inventory referenceInventory = InventoryUtils.readInventory(referenceInventoryDir, referenceInventoryIncludes); final InventoryReportModel inventoryReportModel = new InventoryReportModel() .from(resultTargetDir) .withAnalysisPath(analysisBaseDir) .withReferenceInventory(referenceInventory); inventoryReportModel.evaluate(); inventoryReportModel.createHtmlReport(reportFile); if (inventoryReportModel.isReportFailure()) { String reportPathUrl = FileUtils.normalizePathToLinux(FileUtils.asRelativePath(project.getBasedir(), reportFile)); throw new MojoFailureException("A problem was detected. Please check file: [" + reportPathUrl + "]"); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy