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

com.metaeffekt.conversion.plugin.AbstractInventoryConversionMojo Maven / Gradle / Ivy

package com.metaeffekt.conversion.plugin;

import com.metaeffekt.artifact.analysis.maven.AbstractTermsMetaDataBasedMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;

public abstract class AbstractInventoryConversionMojo extends AbstractTermsMetaDataBasedMojo {

    // Can either be a file or directory
    @Parameter(required = true)
    protected File input;

    // Can either be a file or directory
    @Parameter(required = true)
    protected File output;

    @Override
    protected void doRun() throws Exception {

        // Ensure input exists.
        if (!input.exists()) {
            if (input.getName().contains(".")) {
                throw new MojoFailureException("The input file " + input.getAbsolutePath() + " does not exist.");
            } else {
                throw new MojoFailureException("The input directory " + input.getAbsolutePath() + " does not exist.");
            }
        }

        // Ensure parent directories exist for output
        if (!output.exists()) {
            if (output.getName().contains(".")) { // Check if it's a file
                File parentDir = output.getParentFile();
                if (parentDir != null && !parentDir.exists()) {
                    if (!parentDir.mkdirs()) {
                        throw new MojoFailureException("Failed to create parent directory for output: " + parentDir.getAbsolutePath());
                    }
                }
                if (!output.createNewFile()) {
                    throw new MojoFailureException("Failed to create output file: " + output.getAbsolutePath());
                }
            } else {
                if (!output.mkdirs()) {
                    throw new MojoFailureException("Failed to create output directory: " + output.getAbsolutePath());
                }
            }
        }

        if (input.isDirectory() && output.isDirectory()) {
            runWithDirectories();
        } else if (input.isFile() && output.isFile()) {
            runWithFiles();
        } else {
            throw new MojoFailureException("Provide either directories or files for input and output.");
        }
    }

    protected abstract void runWithFiles() throws Exception;

    protected abstract void runWithDirectories() throws Exception;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy