summaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
diff options
context:
space:
mode:
authorMark Donszelmann <Mark.Donszelmann@gmail.com>2009-11-05 16:17:51 +0100
committerMark Donszelmann <Mark.Donszelmann@gmail.com>2009-11-05 16:17:51 +0100
commit5f3d4a7de54c13dff30f3e61761b693e26c406fa (patch)
tree083bfae72124c0e3a2b68854cae58c426d0bea3c /src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
parent707da2d176a5c04878cfb84c4f71bdb799a128e0 (diff)
downloadmaven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.tar.gz
maven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.tar.bz2
maven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.tar.xz
maven-nar-plugin-5f3d4a7de54c13dff30f3e61761b693e26c406fa.zip
Added test for layout change, it0016
Diffstat (limited to 'src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java')
-rw-r--r--src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java b/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
new file mode 100644
index 0000000..7dc2f65
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugin/nar/AbstractNarLayout.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.maven.plugin.nar;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.codehaus.plexus.archiver.Archiver;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.zip.ZipArchiver;
+
+/**
+ *
+ * @author Mark Donszelmann (Mark.Donszelmann@gmail.com)
+ * @version $Id$
+ */
+public abstract class AbstractNarLayout
+ implements NarLayout, NarConstants
+{
+
+ protected void attachNar( MavenProjectHelper projectHelper, MavenProject project, String classifier, File dir,
+ String include )
+ throws MojoExecutionException
+ {
+ File narFile =
+ new File( project.getBuild().getDirectory(), project.getBuild().getFinalName() + "-" + classifier + "."
+ + NarConstants.NAR_EXTENSION );
+ if ( narFile.exists() )
+ narFile.delete();
+ Archiver archiver = new ZipArchiver();
+ try
+ {
+ archiver.addDirectory( dir, new String[] { include }, null );
+ archiver.setDestFile( narFile );
+ archiver.createArchive();
+ }
+ catch ( ArchiverException e )
+ {
+ throw new MojoExecutionException( "NAR: cannot create NAR archive '" + narFile + "'", e );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "NAR: cannot create NAR archive '" + narFile + "'", e );
+ }
+ projectHelper.attachArtifact( project, NarConstants.NAR_TYPE, classifier, narFile );
+ }
+}