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

org.bluestemsoftware.open.eoa.plugin.install.FileMojo Maven / Gradle / Ivy

/**
 * Copyright 2008 Bluestem Software LLC.  All Rights Reserved.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 * 
 */

package org.bluestemsoftware.open.eoa.plugin.install;

import java.io.File;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;

/**
 * Similar to maven's install:file, but can be included as an execution within a project. Installs
 * indicated file and optional source attachment.
 * 
 * @goal install-file
 */
public class FileMojo extends AbstractInstallMojo {

    /**
     * @parameter expression="${project.file}"
     * @required
     * @readonly
     */
    private File pomFile;

    /**
     * The file to be deployed
     * 
     * @parameter expression="${file}"
     * @required
     */
    private File file;

    /**
     * The source file to be attached
     * 
     * @parameter expression="${sources}"
     */
    private File sources;

    /*
     * (non-Javadoc)
     * @see org.apache.maven.plugin.AbstractMojo#execute()
     */
    public void execute() throws MojoExecutionException {

        String groupId = project.getGroupId();
        String artifactId = project.getArtifactId();
        String version = project.getVersion();
        String packaging = project.getPackaging();

        Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging,
                null);
        artifact.addMetadata(new ProjectArtifactMetadata(artifact, pomFile));

        try {
            installer.install(file, artifact, localRepository);
        } catch (ArtifactInstallationException ae) {
            throw new MojoExecutionException(ae.toString());
        }

        if (sources != null) {
            Artifact source = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version,
                    packaging, "sources");
            try {
                installer.install(sources, source, localRepository);
            } catch (ArtifactInstallationException ae) {
                throw new MojoExecutionException(ae.toString());
            }
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy