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

org.ow2.util.maven.jbuilding.AssembleArtifactItemsMojo Maven / Gradle / Ivy

There is a newer version: 1.0.37
Show newest version
/**
 * OW2 Util
 * Copyright (C) 2007-2010 Bull S.A.S.
 * Contact: [email protected]
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 *
 * --------------------------------------------------------------------------
 * $Id: AssembleArtifactItemsMojo.java 5520 2010-06-02 09:41:18Z loris $
 * --------------------------------------------------------------------------
 */

package org.ow2.util.maven.jbuilding;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.FileUtils;

/**
 * Get the declared files and copy them in the given directory.
 * @goal assemble
 * @phase process-sources
 */
public class AssembleArtifactItemsMojo extends AbstractResolverMojo {

    /**
     * Location new resources directory.
     * @parameter expression="${project.build.directory}/assemble-resources"
     * @required
     */
    private File output;

    /**
     * Where do I place my artifacts ?
     * @parameter expression="repositories/maven2-internal"
     * @required
     */
    private String directory;

    /**
     * @throws MojoExecutionException When I cannot copy the artifacts in the
     *         output directory.
     * @see org.ow2.util.maven.jbuilding.AbstractResolverMojo#execute()
     */
    public void execute() throws MojoExecutionException {

        Map> map = resolveArtifacts(SERVER_SIDE, BOTH_MODE, ALL_ARTIFACT_ITEMS);

        // OK, now we're sure that everything is in the local repository
        // We have to copy theses files in the output directory
        File repositoryDirectory = new File(output, directory.replace('/', File.separatorChar));

        // Create the directory
        if (!repositoryDirectory.exists()) {
            if (!repositoryDirectory.mkdirs()) {
                throw new MojoExecutionException("Cannot create directory: " + repositoryDirectory);
            }
        }

        // List all plans
        for (Collection artifacts: map.values()) {
            // Copy the artifacts in the directory
            for (Artifact artifact : artifacts) {

                final String localPath = getLocal().pathOf( artifact );

                final String targetPath;
                if (!artifact.getVersion().equals(artifact.getBaseVersion())) {
                    // Bug fix UTIL-84
                    targetPath =
                        localPath.replace(artifact.getVersion(), artifact.getBaseVersion());
                } else {
                    targetPath = localPath;
                }

                final File source = new File(getLocal().getBasedir(), localPath);

                final File target = new File(repositoryDirectory, targetPath);
                try {
                    FileUtils.copyFileIfModified(source, target);
                } catch (IOException e) {
                    throw new MojoExecutionException("Cannot copy bundle " + artifact + "into " + repositoryDirectory, e);
                }
            }
        }

        getProject().addCompileSourceRoot(output.getPath());

    }

    /**
     * @return the output file.
     */
    public File getOutput() {
        return output;
    }

    /**
     * @return the directory.
     */
    public String getDirectory() {
        return directory;
    }

    /**
     * Set the given output.
     * @param output the output file
     */
    public void setOutput(final File output) {
        this.output = output;
    }

    /**
     * Sets the given directory.
     * @param directory the directory path
     */
    public void setDirectory(final String directory) {
        this.directory = directory;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy