Author: tveronezi
Date: Sun Mar 23 10:24:06 2014
New Revision: 1580483

URL: http://svn.apache.org/r1580483
Log:
debian package (second try)
still not a valid package for the debian standards, but it already does the job

Added:
    tomee/sandbox/tomee-deb/src/main/java/
    tomee/sandbox/tomee-deb/src/main/java/readme.txt
    tomee/sandbox/tomee-deb/src/main/resources/
    tomee/sandbox/tomee-deb/src/main/resources/control/
    tomee/sandbox/tomee-deb/src/main/resources/control/control.template
    tomee/sandbox/tomee-deb/src/main/resources/control/postinst.sh
    tomee/sandbox/tomee-deb/src/main/resources/control/prerm.sh
    tomee/sandbox/tomee-deb/src/main/resources/init/
    tomee/sandbox/tomee-deb/src/main/resources/init/tomee.sh
    
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/PackageBuilderTest.groovy
Removed:
    
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/TestPlaceholder.groovy
Modified:
    tomee/sandbox/tomee-deb/pom.xml
    
tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy

Modified: tomee/sandbox/tomee-deb/pom.xml
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/pom.xml?rev=1580483&r1=1580482&r2=1580483&view=diff
==============================================================================
--- tomee/sandbox/tomee-deb/pom.xml (original)
+++ tomee/sandbox/tomee-deb/pom.xml Sun Mar 23 10:24:06 2014
@@ -14,115 +14,118 @@
 -->
 <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";>
-    <modelVersion>4.0.0</modelVersion>
+  <modelVersion>4.0.0</modelVersion>
 
-    <groupId>org.apache.tomee</groupId>
-    <artifactId>tomee-deb</artifactId>
-    <version>1.0-SNAPSHOT</version>
-    <packaging>pom</packaging>
-    <name>tomee-deb</name>
-    <properties>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <tomee.version>1.6.0-SNAPSHOT</tomee.version>
-        <openejb.version>4.6.0-SNAPSHOT</openejb.version>
+  <groupId>org.apache.tomee</groupId>
+  <artifactId>tomee-deb</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+  <name>tomee-deb</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <tomee.version>1.6.1-SNAPSHOT</tomee.version>
+    <openejb.version>4.6.1-SNAPSHOT</openejb.version>
 
-        <commons.compress>1.5-SNAPSHOT</commons.compress>
-        <commons.io>2.5-SNAPSHOT</commons.io>
-        <commons.codec>1.8-SNAPSHOT</commons.codec>
+    <commons.compress>1.8</commons.compress>
+    <commons.io>2.4</commons.io>
+    <commons.codec>1.9</commons.codec>
 
-    </properties>
-    <repositories>
-        <repository>
-            <id>apache.snapshots</id>
-            <url>http://repository.apache.org/snapshots/</url>
-            <releases>
-                <updatePolicy>daily</updatePolicy>
-            </releases>
-            <snapshots>
-                <updatePolicy>daily</updatePolicy>
-            </snapshots>
-        </repository>
-    </repositories>
-    <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>${commons.compress}</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-io</groupId>
-            <artifactId>commons-io</artifactId>
-            <version>${commons.io}</version>
-        </dependency>
-        <dependency>
-            <groupId>commons-codec</groupId>
-            <artifactId>commons-codec</artifactId>
-            <version>${commons.codec}</version>
-        </dependency>
-    </dependencies>
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.codehaus.gmaven</groupId>
-                <artifactId>gmaven-plugin</artifactId>
-                <version>1.4</version>
-                <configuration>
-                    <scriptpath>
-                        <element>${project.basedir}/src/main/groovy</element>
-                    </scriptpath>
-                </configuration>
-                <executions>
-                    <execution>
-                        <id>build-deb-execute-plus-profile</id>
-                        <phase>install</phase>
-                        <goals>
-                            <goal>execute</goal>
-                        </goals>
-                        <configuration>
-                            <source>new 
org.apache.tomee.deb.PackageBuilder(this).execute()</source>
-                            <properties>
-                                
<targetDir>${project.basedir}/target</targetDir>
-                                <tomeeVersion>${tomee.version}</tomeeVersion>
-                            </properties>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <version>2.6</version>
-                <executions>
-                    <execution>
-                        <id>copy</id>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>copy</goal>
-                        </goals>
-                        <configuration>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>org.apache.openejb</groupId>
-                                    <artifactId>apache-tomee</artifactId>
-                                    <version>${tomee.version}</version>
-                                    <classifier>plus</classifier>
-                                    <type>tar.gz</type>
-                                    <overWrite>true</overWrite>
-                                    
<outputDirectory>${project.basedir}/target/</outputDirectory>
-                                    <destFileName>plus.tar.gz</destFileName>
-                                </artifactItem>
-                            </artifactItems>
-                            <!-- other configurations here -->
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
+  </properties>
+  <repositories>
+    <repository>
+      <id>apache.snapshots</id>
+      <url>http://repository.apache.org/snapshots/</url>
+      <releases>
+        <updatePolicy>daily</updatePolicy>
+      </releases>
+      <snapshots>
+        <updatePolicy>daily</updatePolicy>
+      </snapshots>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.10</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-jsr223</artifactId>
+      <version>2.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-ant</artifactId>
+      <version>2.2.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-compress</artifactId>
+      <version>${commons.compress}</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>${commons.io}</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+      <version>${commons.codec}</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <compilerId>groovy-eclipse-compiler</compilerId>
+          <verbose>true</verbose>
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-eclipse-compiler</artifactId>
+            <version>2.8.0-01</version>
+          </dependency>
+          <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-eclipse-batch</artifactId>
+            <version>2.1.8-01</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <version>2.6</version>
+        <executions>
+          <execution>
+            <id>copy</id>
+            <phase>package</phase>
+            <goals>
+              <goal>copy</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.openejb</groupId>
+                  <artifactId>apache-tomee</artifactId>
+                  <version>${tomee.version}</version>
+                  <classifier>plus</classifier>
+                  <type>tar.gz</type>
+                  <overWrite>true</overWrite>
+                  <outputDirectory>${project.basedir}/target/</outputDirectory>
+                  <destFileName>plus.tar.gz</destFileName>
+                </artifactItem>
+              </artifactItems>
+              <!-- other configurations here -->
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
 </project>

Modified: 
tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy?rev=1580483&r1=1580482&r2=1580483&view=diff
==============================================================================
--- 
tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy
 (original)
+++ 
tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy
 Sun Mar 23 10:24:06 2014
@@ -18,272 +18,157 @@
 
 package org.apache.tomee.deb
 
+import groovy.text.GStringTemplateEngine
 import org.apache.commons.codec.digest.DigestUtils
 import org.apache.commons.compress.archivers.ar.ArArchiveEntry
 import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
-import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream
-import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
-
-import java.util.zip.GZIPInputStream
 
 class PackageBuilder {
-    String targetDir
-    String tomeeVersion
-    def roots = new HashSet<String>()
-
-    private File untar(String fileName) {
-        File parent = new File(this.targetDir, 'output')
-        File outputDir = new File(parent, fileName)
-        outputDir.mkdirs()
-        File tar = new File(parent, fileName + '.tar')
-        TarArchiveInputStream input = new TarArchiveInputStream(new 
FileInputStream(tar))
-        TarArchiveEntry entry = null
-        while ((entry = (TarArchiveEntry) input.getNextEntry()) != null) {
-            if (entry.isDirectory()) {
-                new File(outputDir, entry.getName()).mkdirs()
-
-            } else {
-                byte[] content = new byte[entry.getSize()]
-                input.read(content)
-                OutputStream output = new BufferedOutputStream(new 
FileOutputStream(new File(outputDir, entry.getName())))
-                output.write(content)
-                output.close()
-            }
-        }
-        input.close()
-        tar.delete()
-        return outputDir.listFiles()[0]
-    }
+    static final TOMEE_VERSION = '1.6.1'
 
-    private def delete = { File file ->
-        file.eachDir(delete)
-        file.eachFile {
-            it.delete()
-        }
-        file.delete()
-    } as Object
-
-    private def tarRoot(String name, TarArchiveOutputStream output, String 
root) {
-        if (roots.contains(name + ':' + root)) {
-            // no-op
-            return;
-        }
-        StringBuilder builder = new StringBuilder()
-        root.split('/').each {
-            builder.append(it)
-            builder.append('/')
-
-            String path = builder.toString()
-            TarArchiveEntry entry = new TarArchiveEntry(path)
-            entry.userName = 'root'
-            entry.groupName = 'root'
-            entry.setModTime System.currentTimeMillis()
-            output.putArchiveEntry(entry)
-            output.closeArchiveEntry()
-        }
-        roots << name + ':' + root
-    }
+    def ant = new AntBuilder()
 
-    private def tarItem = { TarArchiveOutputStream output, File item, Integer 
startIndex, def dataholder ->
-        if (item.isFile()) {
-            if (item.name == 'LICENSE') {
-                // no-op the package has the license already. 
http://lintian.debian.org/tags/no-copyright-file.html
-                return
-            }
-            if (item.name.endsWith('.original')) {
-                // no-op -> skipping unused file.
-                return
-            }
-        }
-        String subPath = item.path.substring(startIndex).replaceAll("\\\\", 
"/");
-        if (item.isDirectory()) {
-            subPath = subPath + '/'
-        }
-        String root
-        String path
-        if (subPath.startsWith('/webapps') || subPath.startsWith('/work')) {
-            root = './var/lib/tomee'
-            path = root + subPath
-
-        } else if (subPath.startsWith('/conf')) {
-            root = './etc/tomee'
-            path = root + subPath.substring('/conf'.length())
-            dataholder.conffiles << path.substring(1)
-
-        } else if (subPath.startsWith('/logs')) {
-            root = './var/log/tomee'
-            path = root + subPath.substring('/logs'.length())
-
-        } else if (subPath.startsWith('/temp')) {
-            // no-op
-            return
-
-        } else {
-            root = './usr/share/tomee'
-            path = root + subPath
-        }
-        tarRoot('data', output, root)
-        TarArchiveEntry entry = new TarArchiveEntry(path, true)
-        entry.userName = 'root'
-        entry.groupName = 'root'
-        entry.setModTime(System.currentTimeMillis())
-        if (item.isFile()) {
-            dataholder.checksum.append(getCheckSumLine(path, item))
-            if (path.endsWith('.sh')) {
-                entry.mode = 0100755
-            }
-
-            long size = item.length()
-            dataholder.size = dataholder.size + size
-            entry.size = size
-            output.putArchiveEntry(entry)
-            output << item.newInputStream()
-        } else {
-            output.putArchiveEntry(entry)
-        }
-        output.closeArchiveEntry()
-        if (item.isDirectory()) {
-            File[] children = item.listFiles()
-            children.each {
-                tarItem(output, it, startIndex, dataholder)
+    String unzip(String tarPath) {
+        def outputDir = new File(new File(tarPath).parent, 'exploded')
+        outputDir.mkdirs()
+        ant.unzip(
+                src: tarPath,
+                dest: outputDir.absolutePath
+        )
+        def files = outputDir.listFiles()
+        if (files.size() > 1) {
+            return outputDir.absolutePath
+        }
+        def aux = new File(new File(tarPath).parent, 'aux')
+        files[0].renameTo(aux)
+        outputDir.delete()
+        aux.renameTo(outputDir)
+        ant.delete(includeemptydirs: true) {
+            fileset(dir: outputDir.absolutePath, includes: '**/*.exe')
+            fileset(dir: outputDir.absolutePath, includes: '**/*.bat')
+            fileset(dir: outputDir.absolutePath, includes: '**/*.original')
+            fileset(dir: outputDir.absolutePath, includes: '**/*.tmp')
+            fileset(dir: new File(outputDir, 'webapps').absolutePath) {
+                include(name: '**/*')
+                exclude(name: '**/tomee/**')
             }
         }
-    } as Object
-
-    private static String getCheckSum(String text) {
-        return getCheckSum(new ByteArrayInputStream(text.getBytes()))
+        outputDir.absolutePath
     }
 
-    private static String getCheckSum(File file) {
+    private String getCheckSum(File file) {
         return getCheckSum(new FileInputStream(file))
     }
 
-    private static String getCheckSum(InputStream input) {
+    private String getCheckSum(InputStream input) {
         String md5 = DigestUtils.md5Hex(input)
         input.close()
         return md5
     }
 
-    private static String getCheckSumLine(String name, File file) {
+    private String getCheckSumLine(File root, File file) {
         String md5 = getCheckSum(file)
-        return "${md5} ${name}\n"
-    }
-
-    private static String getCheckSumLine(String name, String text) {
-        String md5 = getCheckSum(text)
-        return "${md5} ${name}\n"
+        return "${md5} 
${file.absolutePath.substring(root.absolutePath.length() + 1)}"
     }
 
-    private def tar(File exploded) {
-        File tar = new File(exploded.parent, 'data.tar')
-        TarArchiveOutputStream output = new TarArchiveOutputStream(new 
FileOutputStream(tar))
-        output.longFileMode = TarArchiveOutputStream.LONGFILE_GNU
-        File[] items = exploded.listFiles()
-        Integer startIndex = exploded.path.length()
-        def dataholder = [
-                size: 0l,
-                checksum: new StringBuilder(),
-                conffiles: new ArrayList<String>()
-        ]
-        items.each {
-            tarItem(output, it, startIndex, dataholder)
+    String createControlDir(String dataDirPath) {
+        def dataDir = new File(dataDirPath)
+        def controlDir = new File(dataDir.parent, 'control')
+        controlDir.mkdirs()
+        new File(controlDir, 'md5sums').withWriter { BufferedWriter out ->
+            dataDir.eachFileRecurse {
+                if (it.directory) {
+                    return
+                }
+                out.writeLine(getCheckSumLine(dataDir, it))
+            }
         }
-        addCopyrightEntry(output, dataholder)
-        output.close()
-        return [
-                tar: tar,
-                checksum: dataholder.checksum.toString(),
-                size: dataholder.size,
-                conffiles: dataholder.conffiles
-        ]
-    }
-
-    private static void addTextEntry(TarArchiveOutputStream output, String 
entryName, String text) {
-        TarArchiveEntry entry = new TarArchiveEntry(entryName)
-        entry.userName = 'root'
-        entry.setSize(text.getBytes().length)
-        output.putArchiveEntry(entry)
-        output.write(text.getBytes())
-        output.closeArchiveEntry()
-    }
-
-    private void addCopyrightEntry(TarArchiveOutputStream output, def 
dataholder) {
-        tarRoot('data', output, './usr/share/doc/tomee')
-        String text = """Files: *
-Copyright: 2013 The Apache Software Foundation
-License: Apache
-"""
-        
dataholder.checksum.append(getCheckSumLine('./usr/share/doc/tomee/copyright', 
text))
-        addTextEntry(output, './usr/share/doc/tomee/copyright', text)
-    }
-
-    private void addControlEntry(TarArchiveOutputStream output, long 
installedSize) {
-        long inMB = installedSize / 1024
-        String text = """Package: tomee
-Version: ${tomeeVersion}
-Section: java
-Priority: optional
-Homepage: http://tomee.apache.org/
-Architecture: all
-Depends: openjdk-7-jre
-Installed-Size: ${inMB}
-Maintainer: devlist <[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.
-"""
-        addTextEntry(output, 'control', text)
-    }
-
-    private void addConffilesEntry(TarArchiveOutputStream output, List<String> 
conffiles) {
-        addTextEntry(output, 'conffiles', conffiles.join('\n') + '\n')
-    }
-
-    private static void addChecksum(TarArchiveOutputStream output, String 
checksum) {
-        addTextEntry(output, 'md5sums', checksum)
-    }
-
-    private File createControlTar(File exploded, def data) {
-        File tar = new File(exploded.parent, 'control.tar')
-        TarArchiveOutputStream output = new TarArchiveOutputStream(new 
FileOutputStream(tar))
-        output.longFileMode = TarArchiveOutputStream.LONGFILE_POSIX
-        addControlEntry(output, (long) data.size)
-        addConffilesEntry(output, (List<String>) data.conffiles)
-        addChecksum(output, (String) data.checksum)
-        output.close()
-        return tar
-    }
-
-    private def unzip(String fileName) {
-        File outputDir = new File(this.targetDir, 'output')
-        outputDir.mkdirs()
-        File gz = new File(this.targetDir, fileName + '.tar.gz')
-        InputStream input = new GZIPInputStream(new FileInputStream(gz))
-        OutputStream output = new FileOutputStream(new File(outputDir, 
fileName + '.tar'))
-        output << input
-        output.close()
-        input.close()
-
-        gz.delete()
+        Double installedSize = dataDir.directorySize() / 1024
+        new File(controlDir, 'control').withWriter { BufferedWriter out ->
+            def template = new GStringTemplateEngine().createTemplate(
+                    this.class.getResource('/control/control.template')
+            ).make([
+                    tomeeVersion: TOMEE_VERSION,
+                    inMB        : installedSize.longValue()
+            ])
+            out.write(template.toString())
+        }
+        new File(controlDir, 'postinst').withWriter { BufferedWriter out ->
+            out.write(this.class.getResource('/control/postinst.sh').text)
+        }
+        new File(controlDir, 'prerm').withWriter { BufferedWriter out ->
+            out.write(this.class.getResource('/control/prerm.sh').text)
+        }
+        controlDir.absolutePath
+    }
+
+    String createDataDir(String explodedPath) {
+        def exploded = new File(explodedPath)
+        def outputDir = new File(exploded.parent, 'output')
+        def dataDir = new File(outputDir, 'data')
+        dataDir.mkdirs()
+        def distributionTomeeDir = new File(dataDir, 'opt/tomee')
+        ant.move(todir: distributionTomeeDir.absolutePath) {
+            fileset(dir: explodedPath) {
+                include(name: "**/*")
+            }
+        }
+        ant.move(todir: new File(dataDir, 'etc/tomee').absolutePath) {
+            fileset(dir: new File(distributionTomeeDir, 'conf')) {
+                include(name: "**/*")
+            }
+        }
+        def initd = new File(dataDir, 'etc/init.d/')
+        initd.mkdirs()
+        new File(initd, 'tomee').withWriter { BufferedWriter out ->
+            out.write(this.class.getResource('/init/tomee.sh').text)
+        }
+        ant.move(
+                todir: new File(dataDir, 'var/lib/tomee').absolutePath,
+                file: new File(distributionTomeeDir, 'webapps').absolutePath
+        )
+        new File(dataDir, 'var/log/tomee').mkdirs()
+        new File(dataDir, 'var/tmp/tomee/temp').mkdirs()
+        new File(dataDir, 'var/tmp/tomee/work').mkdirs()
+        new File(distributionTomeeDir, 'conf').delete() // add link from 
"/usr/lib/tomee/conf" to "/etc/tomee"
+        new File(distributionTomeeDir, 'logs').delete() // add link from 
"/usr/lib/tomee/logs" to "/var/log/tomee"
+        new File(distributionTomeeDir, 'temp').delete() // add link from 
"/usr/lib/tomee/temp" to "/var/tmp/tomee/temp"
+        new File(distributionTomeeDir, 'work').delete() // add link from 
"/usr/lib/tomee/work" to "/var/tmp/tomee/work"
+        new File(distributionTomeeDir, 'webapps').delete()
+        // add link from "/usr/lib/tomee/webapps" to "/var/lib/tomee/webapps"
+        exploded.delete()
+        dataDir.absolutePath
+    }
+
+    private File createTarGz(String path) {
+        def dataDir = new File(path)
+        def tarFile = new File(dataDir.parent, "${dataDir.name}.tar")
+        def gzFile = new File(tarFile.parent, "${tarFile.name}.gz")
+        ant.with {
+            tar(destfile: tarFile) {
+                tarfileset(dir: dataDir.absolutePath, username: 'root', group: 
'root', prefix: './') {
+                    include(name: "**/*")
+                    exclude(name: "**/*.sh")
+                    exclude(name: "**/postinst")
+                    exclude(name: "**/prerm")
+                    exclude(name: "**/init.d/tomee")
+                }
+                tarfileset(dir: dataDir.absolutePath, username: 'root', group: 
'root', filemode: '755', prefix: './') {
+                    include(name: "**/*.sh")
+                    include(name: "**/postinst")
+                    include(name: "**/prerm")
+                    include(name: "**/init.d/tomee")
+                }
+            }
+            gzip(src: tarFile, destfile: gzFile)
+            delete(file: tarFile)
+        }
+        gzFile
     }
 
-    private static File gzip(File file) {
-        File gz = new File(file.parent, file.name + '.gz')
-        InputStream input = new FileInputStream(file)
-        GzipCompressorOutputStream output = new GzipCompressorOutputStream(new 
FileOutputStream(gz))
-        output << input
-        output.close()
-        input.close()
-        file.delete()
-        return gz
-    }
 
     private static void arItem(ArArchiveOutputStream output, File file) {
-        ArArchiveEntry entry = new ArArchiveEntry(file.name, file.length())
+        def entry = new ArArchiveEntry(file.name, file.length())
         output.putArchiveEntry(entry)
         output << new FileInputStream(file)
         output.closeArchiveEntry()
@@ -291,43 +176,23 @@ Description: Apache TomEE
 
     private static void arDebianBinary(ArArchiveOutputStream output) {
         byte[] text = "2.0\n".getBytes()
-        ArArchiveEntry entry = new ArArchiveEntry('debian-binary', text.length)
+        def entry = new ArArchiveEntry('debian-binary', text.length)
         output.putArchiveEntry(entry)
         output.write(text)
         output.closeArchiveEntry()
     }
 
-    private File ar(String name, File data, File control) {
-        String packageName = "apache-tomee-${name}-${tomeeVersion}.deb"
-        File ar = new File(data.parent, packageName)
-        ArArchiveOutputStream output = new ArArchiveOutputStream(new 
FileOutputStream(ar))
+    File compressFiles(String... paths) {
+        def packageName = "apache-tomee-${TOMEE_VERSION}.deb"
+        def ar = new File(new File(paths[0]).parent, packageName)
+        def output = new ArArchiveOutputStream(new FileOutputStream(ar))
         arDebianBinary(output)
-        arItem(output, control)
-        arItem(output, data)
+        paths.collect({
+            createTarGz(it)
+        }).each {
+            arItem(output, it)
+        }
         output.close()
-        return ar
-    }
-
-    def PackageBuilder(def script) {
-        this.targetDir = script.project.properties.targetDir
-        this.tomeeVersion = script.project.properties.tomeeVersion
-    }
-
-    private File packSolution(String name) {
-        unzip(name)
-        File exploded = untar(name)
-        def tarData = tar(exploded)
-        File data = gzip(tarData.tar)
-        File control = gzip(createControlTar(exploded, tarData))
-        delete exploded
-        File debFile = ar(name, data, control)
-        File result = new File(this.targetDir, debFile.name)
-        debFile.renameTo(result)
-        delete new File(this.targetDir, 'output')
-        return result
-    }
-
-    void execute() {
-        packSolution('plus')
+        ar
     }
 }

Added: tomee/sandbox/tomee-deb/src/main/java/readme.txt
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/main/java/readme.txt?rev=1580483&view=auto
==============================================================================
--- tomee/sandbox/tomee-deb/src/main/java/readme.txt (added)
+++ tomee/sandbox/tomee-deb/src/main/java/readme.txt Sun Mar 23 10:24:06 2014
@@ -0,0 +1,6 @@
+If there is at least one file (Java or not) in src/main/java,
+then all files in src/main/groovy will be found.
+If, however, src/main/java is empty, then src/main/groovy will be ignored.
+You can get around this by placing an empty file in src/main/java just so that 
src/main/groovy
+will be recognized. The same is true for src/test/java and src/test/groovy.
+This is actually a workaround for GRECLIPSE-1221.
\ No newline at end of file

Added: tomee/sandbox/tomee-deb/src/main/resources/control/control.template
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/main/resources/control/control.template?rev=1580483&view=auto
==============================================================================
--- tomee/sandbox/tomee-deb/src/main/resources/control/control.template (added)
+++ tomee/sandbox/tomee-deb/src/main/resources/control/control.template Sun Mar 
23 10:24:06 2014
@@ -0,0 +1,13 @@
+Package: tomee
+Version: ${tomeeVersion}
+Section: java
+Priority: optional
+Homepage: http://tomee.apache.org/
+Architecture: all
+Installed-Size: ${inMB}
+Maintainer: devlist <[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: tomee/sandbox/tomee-deb/src/main/resources/control/postinst.sh
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/main/resources/control/postinst.sh?rev=1580483&view=auto
==============================================================================
--- tomee/sandbox/tomee-deb/src/main/resources/control/postinst.sh (added)
+++ tomee/sandbox/tomee-deb/src/main/resources/control/postinst.sh Sun Mar 23 
10:24:06 2014
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+ln -sf /etc/tomee /opt/tomee/conf
+ln -sf /var/log/tomee /opt/tomee/logs
+ln -sf /var/tmp/tomee/temp /opt/tomee/temp
+ln -sf /var/tmp/tomee/work /opt/tomee/work
+ln -sf /var/lib/tomee/webapps /opt/tomee/webapps
+
+groupadd apachetomee
+useradd apachetomee -g apachetomee
+
+chown -R apachetomee:apachetomee /opt/tomee/
+chown -R apachetomee:apachetomee /var/log/tomee
+chown -R apachetomee:apachetomee /var/tmp/tomee/temp
+chown -R apachetomee:apachetomee /var/tmp/tomee/work
+chown -R apachetomee:apachetomee /var/lib/tomee/webapps
+
+update-rc.d tomee defaults
+echo "Reboot your machine or run 'service tomee start' to start the Apache 
TomEE server"
\ No newline at end of file

Added: tomee/sandbox/tomee-deb/src/main/resources/control/prerm.sh
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/main/resources/control/prerm.sh?rev=1580483&view=auto
==============================================================================
--- tomee/sandbox/tomee-deb/src/main/resources/control/prerm.sh (added)
+++ tomee/sandbox/tomee-deb/src/main/resources/control/prerm.sh Sun Mar 23 
10:24:06 2014
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+kill -9 $(ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | 
awk '{print $2}')
+
+rm -f /opt/tomee/conf
+rm -f /opt/tomee/logs
+rm -f /opt/tomee/temp
+rm -f /opt/tomee/work
+rm -f /opt/tomee/webapps
+
+update-rc.d -f tomee remove
\ No newline at end of file

Added: tomee/sandbox/tomee-deb/src/main/resources/init/tomee.sh
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/main/resources/init/tomee.sh?rev=1580483&view=auto
==============================================================================
--- tomee/sandbox/tomee-deb/src/main/resources/init/tomee.sh (added)
+++ tomee/sandbox/tomee-deb/src/main/resources/init/tomee.sh Sun Mar 23 
10:24:06 2014
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+CATALINA_HOME=/opt/tomee
+TOMCAT_USER=apachetomee
+
+RETVAL=0
+start(){
+   echo "Starting TomEE: "
+   su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"
+   RETVAL=$?
+   return $RETVAL
+}
+
+stop(){
+   echo "Shutting down TomEE: "
+   su - $TOMCAT_USER -c "$CATALINA_HOME/bin/shutdown.sh"
+   RETVAL=$?
+   return $RETVAL
+}
+
+case "$1" in
+   start)
+      start
+      ;;
+   stop)
+      stop
+      ;;
+   force-reload)
+      stop
+      start
+      ;;
+   *)
+      echo $"Usage: $0 {start|stop|force-reload}"
+      exit 1
+      ;;
+esac
+exit $?
\ No newline at end of file

Added: 
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/PackageBuilderTest.groovy
URL: 
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/PackageBuilderTest.groovy?rev=1580483&view=auto
==============================================================================
--- 
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/PackageBuilderTest.groovy
 (added)
+++ 
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/PackageBuilderTest.groovy
 Sun Mar 23 10:24:06 2014
@@ -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 org.apache.tomee.deb
+
+import org.junit.Test
+
+class PackageBuilderTest {
+
+    @Test
+    void testMe() {
+        def explodedPath = new 
PackageBuilder().unzip('/home/tveronezi/tomee/apache-tomee-plus-1.6.1-SNAPSHOT.zip')
+        def dataDir = new PackageBuilder().createDataDir(explodedPath)
+        def controlDir = new PackageBuilder().createControlDir(dataDir)
+        new PackageBuilder().compressFiles(controlDir, dataDir)
+    }
+
+}


Reply via email to