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: package org.apache.geronimo.mavenplugins.car;
021:
022: import java.io.File;
023: import java.io.IOException;
024:
025: import org.apache.geronimo.kernel.repository.Artifact;
026: import org.apache.geronimo.system.plugin.ArchiverGBean;
027: import org.apache.geronimo.system.serverinfo.BasicServerInfo;
028: import org.apache.geronimo.system.serverinfo.ServerInfo;
029: import org.apache.maven.project.MavenProject;
030: import org.apache.maven.project.MavenProjectHelper;
031: import org.codehaus.mojo.pluginsupport.MojoSupport;
032: import org.codehaus.plexus.archiver.ArchiverException;
033:
034: /**
035: * @version $Rev: 627659 $ $Date: 2008-02-13 20:23:33 -0800 (Wed, 13 Feb 2008) $
036: * @goal archive
037: */
038: public class ArchiveMojo extends MojoSupport {
039:
040: /**
041: * The maven project.
042: *
043: * @parameter expression="${project}"
044: * @required
045: * @readonly
046: */
047: private MavenProject project;
048:
049: /**
050: * The target directory of the project.
051: *
052: * @parameter expression="${project.build.directory}"
053: * @required
054: * @readonly
055: */
056: private File destDir;
057:
058: /**
059: * The maven project's helper.
060: *
061: * @component
062: * @required
063: * @readonly
064: */
065: private MavenProjectHelper projectHelper;
066:
067: /**
068: * The location of the server repository.
069: *
070: * @parameter expression="${project.build.directory}/assembly"
071: * @required
072: */
073: private File targetServerDirectory;
074:
075: /**
076: * Files to exclude from the archive
077: *
078: * @parameter
079: */
080: private String[] excludes;
081:
082: protected void doExecute() throws Exception {
083: ServerInfo serverInfo = new BasicServerInfo(
084: targetServerDirectory.getAbsolutePath(), false);
085: ArchiverGBean archiver = new ArchiverGBean(serverInfo);
086: if (excludes != null) {
087: for (String exclude : excludes) {
088: archiver.addExclude(exclude);
089: }
090: }
091: archive("tar.gz", archiver);
092: archive("zip", archiver);
093: }
094:
095: private void archive(String type, ArchiverGBean archiver)
096: throws ArchiverException, IOException {
097: Artifact artifact1 = new Artifact(project.getArtifact()
098: .getGroupId(), project.getArtifact().getArtifactId(),
099: project.getArtifact().getVersion(), type);
100: File target1 = archiver.archive("", destDir.getAbsolutePath(),
101: artifact1);
102: projectHelper.attachArtifact(project, artifact1.getType(),
103: "bin", target1);
104: }
105: }
|