| package org.apache.maven.plugin.assembly; |
| |
| /* |
| * Copyright 2001-2005 The Apache Software Foundation. |
| * |
| * 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. |
| */ |
| |
| import org.apache.maven.artifact.repository.ArtifactRepository; |
| import org.apache.maven.artifact.resolver.ArtifactResolver; |
| import org.apache.maven.plugin.AbstractMojo; |
| import org.apache.maven.plugin.MojoExecutionException; |
| import org.apache.maven.project.MavenProject; |
| import org.codehaus.plexus.archiver.ArchiverException; |
| import org.codehaus.plexus.archiver.UnArchiver; |
| import org.codehaus.plexus.archiver.manager.ArchiverManager; |
| import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; |
| |
| import java.io.File; |
| import java.io.IOException; |
| import java.util.HashSet; |
| import java.util.List; |
| import java.util.Set; |
| |
| /** |
| * Base routines for assembly and unpack goals. |
| * |
| * @version $Id$ |
| */ |
| public abstract class AbstractUnpackingMojo |
| extends AbstractMojo |
| { |
| protected static final String[] EMPTY_STRING_ARRAY = {}; |
| |
| /** |
| * The output directory of the assembled distribution file. |
| * |
| * @parameter expression="${project.build.directory}" |
| * @required |
| */ |
| protected File outputDirectory; |
| |
| /** |
| * The filename of the assembled distribution file. |
| * |
| * @parameter expression="${project.build.finalName}" |
| * @required |
| */ |
| protected String finalName; |
| |
| /** |
| * Directory to unpack JARs into if needed |
| * |
| * @parameter expression="${project.build.directory}/assembly/work" |
| * @required |
| */ |
| protected File workDirectory; |
| |
| /** |
| * To look up Archiver/UnArchiver implementations |
| * |
| * @parameter expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}" |
| * @required |
| */ |
| protected ArchiverManager archiverManager; |
| |
| /** |
| * @component |
| */ |
| protected ArtifactResolver artifactResolver; |
| |
| /** |
| * @parameter expression="${localRepository}" |
| */ |
| protected ArtifactRepository localRepository; |
| |
| /** |
| * Contains the full list of projects in the reactor. |
| * |
| * @parameter expression="${reactorProjects}" |
| * @required |
| * @readonly |
| */ |
| protected List reactorProjects; |
| |
| /** |
| * @parameter expression="${classifier}" |
| * @deprecated Please use the Assembly's id for classifier instead |
| */ |
| protected String classifier; |
| |
| /** |
| * The Maven Project. |
| * |
| * @parameter expression="${project}" |
| * @required |
| * @readonly |
| */ |
| protected MavenProject project; |
| |
| |
| protected MavenProject getExecutedProject() |
| { |
| return project; |
| } |
| |
| /** |
| * Unpacks the archive file. |
| * |
| * @param file File to be unpacked. |
| * @param location Location where to put the unpacked files. |
| */ |
| protected void unpack( File file, File location ) |
| throws MojoExecutionException, NoSuchArchiverException |
| { |
| try |
| { |
| UnArchiver unArchiver = this.archiverManager.getUnArchiver( file ); |
| |
| unArchiver.setSourceFile( file ); |
| |
| unArchiver.setDestDirectory( location ); |
| |
| unArchiver.extract(); |
| } |
| catch ( IOException e ) |
| { |
| throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e ); |
| } |
| catch ( ArchiverException e ) |
| { |
| throw new MojoExecutionException( "Error unpacking file: " + file + "to: " + location, e ); |
| } |
| } |
| |
| public String getClassifier() |
| { |
| return classifier; |
| } |
| |
| protected void setArchiverManager( ArchiverManager archiverManager ) |
| { |
| this.archiverManager = archiverManager; |
| } |
| |
| protected void setArtifactResolver( ArtifactResolver artifactResolver ) |
| { |
| this.artifactResolver = artifactResolver; |
| } |
| |
| protected void setClassifier( String classifier ) |
| { |
| this.classifier = classifier; |
| } |
| |
| protected void setFinalName( String finalName ) |
| { |
| this.finalName = finalName; |
| } |
| |
| protected void setLocalRepository( ArtifactRepository localRepository ) |
| { |
| this.localRepository = localRepository; |
| } |
| |
| protected void setOutputDirectory( File outputDirectory ) |
| { |
| this.outputDirectory = outputDirectory; |
| } |
| |
| protected void setProject( MavenProject project ) |
| { |
| this.project = project; |
| } |
| |
| protected void setReactorProjects( List reactorProjects ) |
| { |
| this.reactorProjects = reactorProjects; |
| } |
| |
| protected void setWorkDirectory( File workDirectory ) |
| { |
| this.workDirectory = workDirectory; |
| } |
| } |