001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020
021 package org.apache.geronimo.mavenplugins.car;
022
023 import java.io.File;
024 import java.io.IOException;
025
026 import org.apache.geronimo.kernel.repository.Artifact;
027 import org.apache.geronimo.system.plugin.ArchiverGBean;
028 import org.apache.geronimo.system.serverinfo.BasicServerInfo;
029 import org.apache.geronimo.system.serverinfo.ServerInfo;
030 import org.apache.maven.project.MavenProject;
031 import org.apache.maven.project.MavenProjectHelper;
032 import org.codehaus.mojo.pluginsupport.MojoSupport;
033 import org.codehaus.plexus.archiver.ArchiverException;
034
035 /**
036 * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
037 * @goal archive
038 */
039 public class ArchiveMojo extends MojoSupport {
040
041 /**
042 * The maven project.
043 *
044 * @parameter expression="${project}"
045 * @required
046 * @readonly
047 */
048 private MavenProject project;
049
050 /**
051 * The target directory of the project.
052 *
053 * @parameter expression="${project.build.directory}"
054 * @required
055 * @readonly
056 */
057 private File destDir;
058
059 /**
060 * The maven project's helper.
061 *
062 * @component
063 * @required
064 * @readonly
065 */
066 private MavenProjectHelper projectHelper;
067
068 /**
069 * The location of the server repository.
070 *
071 * @parameter expression="${project.build.directory}/assembly"
072 * @required
073 */
074 private File targetServerDirectory;
075
076 /**
077 * Files to exclude from the archive
078 *
079 * @parameter
080 */
081 private String[] excludes;
082
083 /**
084 * The target file to set as the project's artifact.
085 *
086 * @parameter expression="${project.file}"
087 * @required
088 */
089 private File targetFile;
090
091 protected void doExecute() throws Exception {
092 //this installs the pom using the default artifact handler configured in components.xml
093 log.info("Setting artifact file: " + targetFile);
094
095 org.apache.maven.artifact.Artifact artifact = project.getArtifact();
096 artifact.setFile(targetFile);
097 //now pack up the server.
098 ServerInfo serverInfo = new BasicServerInfo(targetServerDirectory.getAbsolutePath(), false);
099 ArchiverGBean archiver = new ArchiverGBean(serverInfo);
100 if (excludes != null) {
101 for (String exclude : excludes) {
102 archiver.addExclude(exclude);
103 }
104 }
105 archive("tar.gz", archiver);
106 archive("zip", archiver);
107 }
108
109 private void archive(String type, ArchiverGBean archiver) throws ArchiverException, IOException {
110 Artifact artifact1 = new Artifact(project.getArtifact().getGroupId(), project.getArtifact().getArtifactId(), project.getArtifact().getVersion(), type);
111 File target1 = archiver.archive("", destDir.getAbsolutePath(), artifact1);
112 projectHelper.attachArtifact( project, artifact1.getType(), "bin", target1 );
113 }
114 }