Author: rmannibucau
Date: Mon Sep 24 12:44:52 2012
New Revision: 1389341

URL: http://svn.apache.org/viewvc?rev=1389341&view=rev
Log:
TOMEE-425 attach and zip a custom tomee distribution

Added:
    
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DebugTomEEMojo.java
    
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/util/
    
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/util/Zips.java
Modified:
    
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/BuildTomEEMojo.java
    
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/HelpTomEEMojo.java

Modified: 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/BuildTomEEMojo.java
URL: 
http://svn.apache.org/viewvc/openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/BuildTomEEMojo.java?rev=1389341&r1=1389340&r2=1389341&view=diff
==============================================================================
--- 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/BuildTomEEMojo.java
 (original)
+++ 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/BuildTomEEMojo.java
 Mon Sep 24 12:44:52 2012
@@ -17,11 +17,77 @@
 
 package org.apache.openejb.maven.plugin;
 
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.apache.openejb.maven.plugin.util.Zips.zip;
+
 /**
  * @goal build
  * @requiresDependencyResolution runtime
  */
 public class BuildTomEEMojo extends AbstractTomEEMojo {
+    /**
+     * @parameter expression="${tomee-plugin.zip}" default-value="true"
+     */
+    protected boolean zip;
+
+    /**
+     * @parameter expression="${tomee-plugin.attach}" default-value="true"
+     */
+    protected boolean attach;
+
+    /**
+     * @parameter expression="${tomee-plugin.zip-file}" 
default-value="${project.build.directory}/${project.build.finalName}.zip""
+     * @required
+     * @readOnly
+     */
+    private File zipFile;
+
+    /**
+     * @component
+     */
+    private MavenProjectHelper projectHelper;
+
+    /**
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
+     * @parameter expression="${tomee-plugin.classifier}"
+     */
+    protected String classifier = null;
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        super.execute();
+        if (zip) {
+            getLog().info("Zipping Custom TomEE Distribution");
+            try {
+                zip(catalinaBase, zipFile);
+            } catch (IOException e) {
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+
+            if (attach) {
+                getLog().info("Attaching Custom TomEE Distribution");
+                if (classifier != null) {
+                    projectHelper.attachArtifact(project, "zip", classifier, 
zipFile);
+                } else {
+                    projectHelper.attachArtifact(project, "zip", zipFile);
+                }
+            }
+        }
+    }
+
     @Override
     protected void run() {
         // don't start

Added: 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DebugTomEEMojo.java
URL: 
http://svn.apache.org/viewvc/openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DebugTomEEMojo.java?rev=1389341&view=auto
==============================================================================
--- 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DebugTomEEMojo.java
 (added)
+++ 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/DebugTomEEMojo.java
 Mon Sep 24 12:44:52 2012
@@ -0,0 +1,30 @@
+/*
+ * 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.openejb.maven.plugin;
+
+/**
+ * @goal debug
+ * @requiresDependencyResolution runtime
+ */
+public class DebugTomEEMojo extends RunTomEEMojo {
+    @Override
+    protected void run() {
+        debug = true;
+        super.run();
+    }
+}

Modified: 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/HelpTomEEMojo.java
URL: 
http://svn.apache.org/viewvc/openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/HelpTomEEMojo.java?rev=1389341&r1=1389340&r2=1389341&view=diff
==============================================================================
--- 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/HelpTomEEMojo.java
 (original)
+++ 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/HelpTomEEMojo.java
 Mon Sep 24 12:44:52 2012
@@ -28,7 +28,8 @@ public class HelpTomEEMojo extends Abstr
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         getLog().info("Available commands:");
-        getLog().info("\t- tomee:run: run and wait the server");
+        getLog().info("\t- tomee:run: run and wait for the server");
+        getLog().info("\t- tomee:debug: run in debug mode and wait for the 
server (alias of run)");
         getLog().info("\t- tomee:start: run the server");
         getLog().info("\t- tomee:stop: stop the server (to use with start)");
         getLog().info("\t- tomee:configtest: run configtest tomcat command");

Added: 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/util/Zips.java
URL: 
http://svn.apache.org/viewvc/openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/util/Zips.java?rev=1389341&view=auto
==============================================================================
--- 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/util/Zips.java
 (added)
+++ 
openejb/branches/openejb-4.5.0/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/util/Zips.java
 Mon Sep 24 12:44:52 2012
@@ -0,0 +1,60 @@
+package org.apache.openejb.maven.plugin.util;
+
+import org.apache.openejb.loader.IO;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public final class Zips {
+    private static final int BUFFER_SIZE = 1024;
+
+    private Zips() {
+        // no-op
+    }
+
+    public static void zip(final File dir, final File zipName) throws 
IOException, IllegalArgumentException {
+        final String[] entries = dir.list();
+        final ZipOutputStream out = new ZipOutputStream(new 
FileOutputStream(zipName));
+
+        String prefix = dir.getAbsolutePath();
+        if (!prefix.endsWith(File.separator)) {
+            prefix += File.separator;
+        }
+
+        for (String entry : entries) {
+            File f = new File(dir, entry);
+            zip(out, f, prefix);
+        }
+        IO.close(out);
+    }
+
+    private static void zip(final ZipOutputStream out, final File f, final 
String prefix) throws IOException {
+        if (f.isDirectory()) {
+            final File[] files = f.listFiles();
+            if (files != null) {
+                for (File child : files) {
+                    zip(out, child, prefix);
+                }
+            }
+        } else {
+            final byte[] buffer = new byte[BUFFER_SIZE];
+            int bytesRead;
+
+            final String path = f.getPath().replace(prefix, "");
+
+            final FileInputStream in = new FileInputStream(f);
+            final ZipEntry entry = new ZipEntry(path);
+            out.putNextEntry(entry);
+            while ((bytesRead = in.read(buffer)) != -1) {
+                out.write(buffer, 0, bytesRead);
+            }
+            IO.close(in);
+        }
+    }
+}


Reply via email to