Author: tveronezi
Date: Fri Sep  7 20:44:26 2012
New Revision: 1382166

URL: http://svn.apache.org/viewvc?rev=1382166&view=rev
Log:
https://issues.apache.org/jira/browse/TOMEE-245
Creating the deb package. 
We still need to complete the control, postinst and prerm files.

Added:
    openejb/trunk/openejb/tomee/apache-tomee-deb/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/pom.xml
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/MapBuilder.java
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageBuilder.java
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageException.java
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/control
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/postinst
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/prerm
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/
    openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/deb/
    
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/deb/AppTest.java
    openejb/trunk/openejb/tomee/apache-tomee-deb/pom.xml
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/commands/
    
openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/commands/BuildDeb.groovy
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/control
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/postinst
    openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/prerm
Modified:
    openejb/trunk/openejb/tomee/pom.xml

Added: openejb/trunk/openejb/tomee/apache-tomee-deb-package/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/pom.xml?rev=1382166&view=auto
==============================================================================
--- openejb/trunk/openejb/tomee/apache-tomee-deb-package/pom.xml (added)
+++ openejb/trunk/openejb/tomee/apache-tomee-deb-package/pom.xml Fri Sep  7 
20:44:26 2012
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <parent>
+        <artifactId>tomee</artifactId>
+        <groupId>org.apache.openejb</groupId>
+        <version>1.1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>apache-tomee-deb-package</artifactId>
+    <packaging>jar</packaging>
+
+    <name>OpenEJB :: TomEE :: Apache TomEE Debian Package</name>
+    <url>http://maven.apache.org</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.10</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>2.4</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.4</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.6</version>
+        </dependency>
+
+    </dependencies>
+</project>

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/MapBuilder.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/MapBuilder.java?rev=1382166&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/MapBuilder.java
 (added)
+++ 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/MapBuilder.java
 Fri Sep  7 20:44:26 2012
@@ -0,0 +1,39 @@
+/*
+ * 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.tomee.debian;
+
+import java.util.Map;
+
+public class MapBuilder<K, V> {
+    private final Map<K, V> map;
+
+    public MapBuilder(Map<K, V> map) {
+        this.map = map;
+    }
+
+    public MapBuilder<K, V> add(K key, V value) {
+        this.map.put(key, value);
+        return this;
+    }
+
+    public Map<K, V> getMap() {
+        return map;
+    }
+}

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageBuilder.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageBuilder.java?rev=1382166&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageBuilder.java
 (added)
+++ 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageBuilder.java
 Fri Sep  7 20:44:26 2012
@@ -0,0 +1,339 @@
+/*
+ * 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.tomee.debian;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.compressors.CompressorException;
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+import org.apache.commons.compress.compressors.CompressorStreamFactory;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.Map;
+
+public class PackageBuilder {
+
+    private File uncompress(File gz) throws IOException, CompressorException {
+        final File output = new File(gz.getParent(), 
FilenameUtils.getBaseName(gz.getName()));
+        output.delete();
+
+        final InputStream is = new FileInputStream(gz);
+        CompressorInputStream in = new 
CompressorStreamFactory().createCompressorInputStream("gz", is);
+        IOUtils.copy(in, new FileOutputStream(output));
+        in.close();
+
+        return output;
+    }
+
+    private File compress(File file) throws IOException, CompressorException {
+        final File output = new File(file.getParent(), file.getName() + ".gz");
+        output.delete();
+
+        final OutputStream out = new FileOutputStream(output);
+
+        final CompressorOutputStream cos = new 
CompressorStreamFactory().createCompressorOutputStream("gz", out);
+        final FileInputStream is = new FileInputStream(file);
+        IOUtils.copy(is, cos);
+
+        is.close();
+        cos.close();
+        out.close();
+
+        return output;
+    }
+
+    private File untar(File tar) throws IOException, ArchiveException {
+        final File output = new File(tar.getParent(), 
FilenameUtils.getBaseName(tar.getName()));
+        try {
+            FileUtils.deleteDirectory(output);
+        } catch (IOException e) {
+            throw new PackageException(e);
+        }
+
+        final InputStream is = new FileInputStream(tar);
+        final ArchiveInputStream in = new 
ArchiveStreamFactory().createArchiveInputStream("tar", is);
+
+        for (TarArchiveEntry entry = (TarArchiveEntry) in.getNextEntry(); 
entry != null; entry = (TarArchiveEntry) in.getNextEntry()) {
+            final File newFile = new File(output, entry.getName());
+
+            if (entry.isDirectory()) {
+                newFile.mkdirs();
+            } else {
+                final OutputStream out = new FileOutputStream(newFile);
+                IOUtils.copy(in, out);
+                out.close();
+            }
+        }
+        in.close();
+
+        return output;
+    }
+
+    private String getCheckSumLine(String name, File file) throws IOException {
+        FileInputStream fis = new FileInputStream(file);
+        String md5 = DigestUtils.md5Hex(fis);
+        fis.close();
+        return md5 + " " + name;
+    }
+
+    private void tar(File baseDir, PrintWriter checksumWriter, File file, 
ArchiveOutputStream os, Map<String, Integer> modeMappings) throws IOException {
+        if (!baseDir.equals(file)) {
+            final int length = baseDir.getAbsolutePath().length();
+            final String name = 
file.getAbsolutePath().substring(length).replaceAll("\\\\", "/");
+            final TarArchiveEntry entry = new TarArchiveEntry(file);
+            entry.setName(name);
+
+            //TODO: remove hard-coded value
+            entry.setUserName("tomee");
+            entry.setGroupName("tomee");
+
+            if (modeMappings != null && modeMappings.containsKey(name)) {
+                entry.setMode(modeMappings.get(name));
+            }
+
+            os.putArchiveEntry(entry);
+            if (file.isFile()) {
+                if (checksumWriter != null) {
+                    checksumWriter.println(getCheckSumLine(name, file));
+                }
+
+                final FileInputStream is = new FileInputStream(file);
+                IOUtils.copy(is, os);
+                is.close();
+            }
+            os.closeArchiveEntry();
+        }
+
+        if (file.isDirectory()) {
+            final File[] children = file.listFiles();
+            for (File child : children) {
+                tar(baseDir, checksumWriter, child, os, modeMappings);
+            }
+        }
+    }
+
+    private File tar(File src, File checksum, Map<String, Integer> 
modeMappings) throws IOException, ArchiveException {
+        final File output = new File(src.getParent(), src.getName() + ".tar");
+        output.delete();
+
+        final OutputStream out = new FileOutputStream(output);
+        final ArchiveOutputStream os = new 
ArchiveStreamFactory().createArchiveOutputStream("tar", out);
+
+        if (checksum == null) {
+            tar(src, null, src, os, modeMappings);
+
+        } else {
+            final PrintWriter checksumWriter = new PrintWriter(checksum);
+            tar(src, checksumWriter, src, os, modeMappings);
+            checksumWriter.close();
+
+        }
+
+        os.close();
+        out.flush();
+        out.close();
+
+        return output;
+    }
+
+
+    private File ar(File folder, String name) throws IOException, 
ArchiveException {
+        final File output = new File(folder.getParent(), name + ".deb");
+        output.delete();
+
+        final OutputStream out = new FileOutputStream(output);
+        final ArchiveOutputStream os = new 
ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.AR, out);
+
+        ar(new File(folder, "debian-binary"), os);
+        ar(new File(folder, "control.tar.gz"), os);
+        ar(new File(folder, "data.tar.gz"), os);
+
+        os.close();
+        out.flush();
+        out.close();
+
+        return output;
+    }
+
+    private void ar(File file, ArchiveOutputStream os) throws IOException {
+        os.putArchiveEntry(new ArArchiveEntry(file.getName(), file.length()));
+
+        final InputStream input = new FileInputStream(file);
+        try {
+            IOUtils.copy(input, os);
+        } finally {
+            input.close();
+        }
+
+        os.closeArchiveEntry();
+    }
+
+    public File expandTarGz(File tarGz) {
+        try {
+            final File tar = uncompress(tarGz);
+            final File result = untar(tar);
+
+            tar.delete();
+
+            return result;
+        } catch (Exception e) {
+            throw new PackageException(e);
+        }
+    }
+
+    public File buildDataTarGzFolder(File baseDir, Map<String, String> 
dirMappings) {
+        final File dataTarGzDir = new File(baseDir.getParent(), "data");
+        try {
+            FileUtils.deleteDirectory(dataTarGzDir);
+        } catch (IOException e) {
+            throw new PackageException(e);
+        }
+
+        final int baseDirLength = baseDir.getAbsolutePath().length();
+        final File[] files = baseDir.listFiles();
+        for (File entry : files) {
+            final String basePath = 
entry.getAbsolutePath().substring(baseDirLength).replaceAll("\\\\", "/");
+
+            final String dest = dirMappings.get(basePath);
+            if (dest == null) {
+                throw new PackageException("i don't know where the entry 
should go. Entry: " + basePath);
+            }
+
+            final File destFile = new File(dataTarGzDir, dest);
+            try {
+                FileUtils.moveToDirectory(entry, destFile, true);
+            } catch (IOException e) {
+                throw new PackageException(e);
+            }
+        }
+
+        try {
+            FileUtils.deleteDirectory(baseDir);
+        } catch (IOException e) {
+            throw new PackageException(e);
+        }
+
+        return dataTarGzDir;
+    }
+
+    public File compressTarGz(File src, File checksum, Map<String, Integer> 
modeMappings) {
+        if (checksum != null) {
+            checksum.delete();
+        }
+
+        try {
+            final File tar = tar(src, checksum, modeMappings);
+
+            if (src.isDirectory()) {
+                FileUtils.deleteDirectory(src);
+            } else {
+                src.delete();
+            }
+
+            final File result = compress(tar);
+            tar.delete();
+
+            return result;
+        } catch (Exception e) {
+            throw new PackageException(e);
+        }
+    }
+
+    public void createDebPackage(String isControl, String isPostinst, String 
isPrerm, File md5sums, File data, File deb) throws IOException {
+        final File debFolder = new File(deb.getParent(), "DEBIAN");
+        debFolder.mkdirs();
+
+        FileUtils.cleanDirectory(debFolder);
+        FileUtils.moveToDirectory(data, debFolder, true);
+
+        final File control = new File(debFolder, "control");
+        control.mkdirs();
+
+        FileUtils.writeStringToFile(new File(control, "control"), isControl);
+        FileUtils.writeStringToFile(new File(control, "postinst"), isPostinst);
+        FileUtils.writeStringToFile(new File(control, "prerm"), isPrerm);
+        FileUtils.moveToDirectory(md5sums, control, true);
+
+        FileUtils.writeStringToFile(new File(debFolder, "debian-binary"), 
"2.0\n");
+
+        compressTarGz(control, null, null);
+
+        try {
+            ar(debFolder, FilenameUtils.getBaseName(deb.getName()));
+        } catch (ArchiveException e) {
+            throw new PackageException(e);
+        }
+
+        FileUtils.deleteDirectory(debFolder);
+    }
+
+    public File createDebPackage(String name, String version,
+                                 File sourceTarGz, String isControl, String 
isPostinst, String isPrerm,
+                                 Map<String, String> dirMapping,
+                                 Map<String, Integer> modeMapping
+    ) {
+        final File expandedTarGz = expandTarGz(sourceTarGz);
+
+        final File dataTarGzFolder = 
buildDataTarGzFolder(expandedTarGz.listFiles()[0], dirMapping);
+
+        final File md5sums = new File(sourceTarGz.getParent(), "md5sums");
+        final File data = compressTarGz(
+                dataTarGzFolder,
+                md5sums,
+                modeMapping);
+
+        final File deb = new File(sourceTarGz.getParent(), name + "-" + 
version + ".deb");
+        try {
+            createDebPackage(
+                    isControl,
+                    isPostinst,
+                    isPrerm,
+                    md5sums,
+                    data,
+                    deb
+            );
+        } catch (IOException e) {
+            throw new PackageException(e);
+        }
+
+        try {
+            FileUtils.deleteDirectory(expandedTarGz);
+        } catch (IOException e) {
+            throw new PackageException(e);
+        }
+
+        return deb;
+    }
+}

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageException.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageException.java?rev=1382166&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageException.java
 (added)
+++ 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/java/org/apache/tomee/debian/PackageException.java
 Fri Sep  7 20:44:26 2012
@@ -0,0 +1,31 @@
+/*
+ * 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.tomee.debian;
+
+public class PackageException extends RuntimeException {
+
+    public PackageException(Throwable cause) {
+        super(cause);
+    }
+
+    public PackageException(String message) {
+        super(message);
+    }
+}

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/control
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/control?rev=1382166&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/control 
(added)
+++ 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/control 
Fri Sep  7 20:44:26 2012
@@ -0,0 +1,12 @@
+Package: tomee
+Version: {0}
+Section: web
+Priority: optional
+Architecture: all
+Maintainer: Dev Team <[email protected]>
+Description: Apache Tomee
+ Apache TomEE, pronounced "Tommy", is an all-Apache Java EE 6
+ Web Profile certified stack where Tomcat is top dog. Apache
+ TomEE is assembled from a vanilla Apache Tomcat zip file. We
+ start with Tomcat, add our jars and zip up the rest. The
+ result is Tomcat with added EE features - TomEE.

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/postinst
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/postinst?rev=1382166&view=auto
==============================================================================
    (empty)

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/prerm
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/main/resources/prerm?rev=1382166&view=auto
==============================================================================
    (empty)

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/deb/AppTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/deb/AppTest.java?rev=1382166&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/deb/AppTest.java
 (added)
+++ 
openejb/trunk/openejb/tomee/apache-tomee-deb-package/src/test/java/deb/AppTest.java
 Fri Sep  7 20:44:26 2012
@@ -0,0 +1,33 @@
+/*
+ * 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 deb;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class AppTest {
+
+    @Test
+    public void testApp() throws IOException {
+        Assert.assertTrue(true);
+    }
+}

Added: openejb/trunk/openejb/tomee/apache-tomee-deb/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb/pom.xml?rev=1382166&view=auto
==============================================================================
--- openejb/trunk/openejb/tomee/apache-tomee-deb/pom.xml (added)
+++ openejb/trunk/openejb/tomee/apache-tomee-deb/pom.xml Fri Sep  7 20:44:26 
2012
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- $Rev: 600338 $ $Date: 2007-12-02 09:08:04 -0800 (Sun, 02 Dec 2007) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+    <parent>
+        <artifactId>tomee</artifactId>
+        <groupId>org.apache.openejb</groupId>
+        <version>1.1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>apache-tomee-deb</artifactId>
+    <packaging>pom</packaging>
+    <name>OpenEJB :: TomEE :: Apache TomEE Debian</name>
+
+    <dependencies>
+        <dependency> <!-- to be sure to have it -->
+            <groupId>org.apache.openejb</groupId>
+            <artifactId>apache-tomee</artifactId>
+            <version>1.1.0-SNAPSHOT</version>
+            <type>pom</type>
+            <scope>provided</scope>
+        </dependency>
+        <dependency> <!-- to be sure to have it -->
+            <groupId>org.apache.openejb</groupId>
+            <artifactId>apache-tomee-deb-package</artifactId>
+            <version>1.1.0-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.5</version>
+                <executions>
+                    <execution>
+                        <id>filter-resources</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>resources</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.gmaven</groupId>
+                <artifactId>gmaven-plugin</artifactId>
+                <version>1.3</version>
+                <configuration>
+                    <scriptpath>
+                        <element>${project.basedir}/src/main/groovy</element>
+                    </scriptpath>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>build-deb-execute-plus-profile</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>execute</goal>
+                        </goals>
+                        <configuration>
+                            <source>new 
commands.BuildDeb(this).execute()</source>
+                            <properties>
+                                
<file>${project.build.directory}/../../apache-tomee/target/apache-tomee-plus-${project.version}.tar.gz</file>
+                                <name>apache-tomee-plus</name>
+                                <version>${project.version}</version>
+                                
<project.folder>${project.build.directory}</project.folder>
+                            </properties>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+

Added: 
openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/commands/BuildDeb.groovy
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/commands/BuildDeb.groovy?rev=1382166&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/commands/BuildDeb.groovy
 (added)
+++ 
openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/groovy/commands/BuildDeb.groovy
 Fri Sep  7 20:44:26 2012
@@ -0,0 +1,114 @@
+/*
+ * 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 commands
+
+import org.apache.commons.io.IOUtils
+import org.apache.commons.lang.StringUtils
+import org.apache.commons.io.FileUtils
+import org.apache.tomee.debian.MapBuilder
+import org.apache.tomee.debian.PackageBuilder
+
+class BuildDeb {
+    def project
+    def log
+
+    def BuildDeb(def source) {
+        this.project = source.project
+        this.log = source.log
+    }
+
+    String get(name) {
+        assert name != null
+
+        def value = project.properties.getProperty(name)
+
+        log.debug("Get property: $name=$value")
+
+        return value
+    }
+
+    String require(name) {
+        assert name != null
+
+        log.debug("Require property: $name")
+
+        if (!project.properties.containsKey(name) && 
!System.properties.containsKey(name)) {
+            throw new Exception("Missing required property: $name")
+        }
+
+        def value = get(name)
+
+        if (value == 'null') {
+            throw new Exception("Missing required property: $name (resolved to 
null)")
+        }
+
+        return value
+    }
+
+    String getResource(String name) {
+        def result = this.getClass().getClassLoader().getResourceAsStream(name)
+        return result.getText()
+    }
+
+       def execute() {
+               String file = require('file')
+        String name = require('name')
+        String version = require('version')
+
+        final PackageBuilder builder = new PackageBuilder()
+
+        Map<String, String> dirMapping = new MapBuilder<String, String>(new 
HashMap<String, String>())
+                .add("/bin", "/usr/tomee")
+                .add("/conf", "/usr/tomee")
+                .add("/endorsed", "/usr/tomee")
+                .add("/lib", "/usr/tomee")
+                .add("/LICENSE", "/usr/tomee")
+                .add("/NOTICE", "/usr/tomee")
+                .add("/RELEASE-NOTES", "/usr/tomee")
+                .add("/RUNNING.txt", "/usr/tomee")
+                .add("/work", "/usr/tomee")
+                .add("/logs", "/var/tomee")
+                .add("/webapps", "/var/tomee")
+                .add("/temp", "/tmp/tomee")
+                .getMap()
+
+        Map<String, Integer> modeMapping = new MapBuilder<String, Integer>(new 
HashMap<String, Integer>())
+                .add("/usr/tomee/bin/startup.sh", 700)
+                .getMap()
+
+        final File original = new File(file)
+        final File gz = new File(new File(require('project.folder')), 'build/' 
+ original.getName())
+        FileUtils.copyFile(original, gz)
+
+        final String control = StringUtils.replace(getResource("control"), 
"{0}", version)
+        builder.createDebPackage(name, version, gz,
+                control,
+                getResource("postinst"),
+                getResource("prerm"),
+                dirMapping,
+                modeMapping
+        )
+        gz.delete()
+
+
+
+    }
+}
+

Added: openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/control
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/control?rev=1382166&view=auto
==============================================================================
--- openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/control 
(added)
+++ openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/control Fri 
Sep  7 20:44:26 2012
@@ -0,0 +1,12 @@
+Package: tomee
+Version: {0}
+Section: web
+Priority: optional
+Architecture: all
+Maintainer: Dev Team <[email protected]>
+Description: Apache Tomee
+ Apache TomEE, pronounced "Tommy", is an all-Apache Java EE 6
+ Web Profile certified stack where Tomcat is top dog. Apache
+ TomEE is assembled from a vanilla Apache Tomcat zip file. We
+ start with Tomcat, add our jars and zip up the rest. The
+ result is Tomcat with added EE features - TomEE.

Added: openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/postinst
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/postinst?rev=1382166&view=auto
==============================================================================
    (empty)

Added: openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/prerm
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/apache-tomee-deb/src/main/resources/prerm?rev=1382166&view=auto
==============================================================================
    (empty)

Modified: openejb/trunk/openejb/tomee/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/pom.xml?rev=1382166&r1=1382165&r2=1382166&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/pom.xml (original)
+++ openejb/trunk/openejb/tomee/pom.xml Fri Sep  7 20:44:26 2012
@@ -44,6 +44,8 @@
     <module>tomee-jaxrs</module>
     <module>tomee-jaxrs-webapp</module>
     <module>apache-tomee</module>
+    <module>apache-tomee-deb</module>
+    <module>apache-tomee-deb-package</module>
     <module>apache-tomcat</module>
   </modules>
 


Reply via email to