Hi,

Thiago, do you know where the tomcat package is done?

maybe that's easier to simply enrich the config and libs as we do to
package tomee.

*Romain Manni-Bucau*
*Twitter: @rmannibucau <https://twitter.com/rmannibucau>*
*Blog: **http://rmannibucau.wordpress.com/*<http://rmannibucau.wordpress.com/>
*LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
*Github: https://github.com/rmannibucau*



---------- Forwarded message ----------
From: <[email protected]>
Date: 2013/3/11
Subject: svn commit: r1455127 - in /tomee/sandbox/tomee-deb: ./ src/
src/main/ src/main/groovy/ src/main/groovy/org/ src/main/groovy/org/apache/
src/main/groovy/org/apache/tomee/ src/main/groovy/org/apache/tomee/deb/
src/test/ src/test/groovy/ src/test/groovy/o...
To: [email protected]


Author: tveronezi
Date: Mon Mar 11 13:07:15 2013
New Revision: 1455127

URL: http://svn.apache.org/r1455127
Log:
https://issues.apache.org/jira/browse/TOMEE-245
-Creating debian package for tomee plus. We still need to properly split
the directories in order to follow the linux directory standards (
http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)

Added:
    tomee/sandbox/tomee-deb/pom.xml
    tomee/sandbox/tomee-deb/src/
    tomee/sandbox/tomee-deb/src/main/
    tomee/sandbox/tomee-deb/src/main/groovy/
    tomee/sandbox/tomee-deb/src/main/groovy/org/
    tomee/sandbox/tomee-deb/src/main/groovy/org/apache/
    tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/
    tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/

tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy
    tomee/sandbox/tomee-deb/src/test/
    tomee/sandbox/tomee-deb/src/test/groovy/
    tomee/sandbox/tomee-deb/src/test/groovy/org/
    tomee/sandbox/tomee-deb/src/test/groovy/org/apache/
    tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/
    tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/

tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/TestPlaceholder.groovy

Added: tomee/sandbox/tomee-deb/pom.xml
URL:
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/pom.xml?rev=1455127&view=auto
==============================================================================
--- tomee/sandbox/tomee-deb/pom.xml (added)
+++ tomee/sandbox/tomee-deb/pom.xml Mon Mar 11 13:07:15 2013
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed 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";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.tomee</groupId>
+    <artifactId>tomee-deb</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>jar</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>
+
+        <commons.compress>1.5-SNAPSHOT</commons.compress>
+        <commons.io>2.5-SNAPSHOT</commons.io>
+        <commons.codec>1.8-SNAPSHOT</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>
+</project>

Added:
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=1455127&view=auto
==============================================================================
---
tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy
(added)
+++
tomee/sandbox/tomee-deb/src/main/groovy/org/apache/tomee/deb/PackageBuilder.groovy
Mon Mar 11 13:07:15 2013
@@ -0,0 +1,277 @@
+/**
+ *
+ * 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.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
+
+    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]
+    }
+
+    private def delete = { File file ->
+        file.eachDir(delete)
+        file.eachFile {
+            it.delete()
+        }
+        file.delete()
+    } as Object
+
+    private def tarRoot(TarArchiveOutputStream output, String... pathList)
{
+        StringBuilder builder = new StringBuilder()
+        pathList.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()
+        }
+    }
+
+    private def tarItem = { TarArchiveOutputStream output, File item,
Integer startIndex, def dataholder ->
+        String subPath =
item.path.substring(startIndex).replaceAll("\\\\", "/");
+        if (item.isDirectory()) {
+            subPath = subPath + '/'
+        }
+
+        String path = './usr/share/tomee' + subPath
+        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') || path.endsWith('.sh.original')) {
+                entry.mode = 754
+            }
+
+            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)
+            }
+        }
+    } as Object
+
+    private String getCheckSumLine(String name, File file) throws
IOException {
+        FileInputStream fis = new FileInputStream(file)
+        String md5 = DigestUtils.md5Hex(fis)
+        fis.close()
+        return "${md5} ${name}\n"
+    }
+
+    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()
+        ]
+
+        tarRoot(output, '.', 'usr', 'share', 'tomee')
+        items.each {
+            tarItem(output, it, startIndex, dataholder)
+        }
+        output.close()
+        return [
+                tar: tar,
+                checksum: dataholder.checksum.toString(),
+                size: dataholder.size
+        ]
+    }
+
+    private 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 addControlEntry(TarArchiveOutputStream output, long
installedSize) {
+        long inMB = installedSize / 1024
+        String text = """Package: tomee
+Version: ${tomeeVersion}
+Section: admin
+Priority: optional
+Architecture: i386
+Depends:
+Suggests:
+Conflicts:
+Replaces:
+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 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)
+        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()
+    }
+
+    private 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 void arItem(ArArchiveOutputStream output, File file) {
+        ArArchiveEntry entry = new ArArchiveEntry(file.name, file.length())
+        output.putArchiveEntry(entry)
+        output << new FileInputStream(file)
+        output.closeArchiveEntry()
+    }
+
+    private void arDebianBinary(ArArchiveOutputStream output) {
+        byte[] text = "2.0\n".getBytes()
+        ArArchiveEntry entry = new ArArchiveEntry('debian-binary',
text.length)
+        output.putArchiveEntry(entry)
+        output.write(text)
+        output.closeArchiveEntry()
+    }
+
+    private File ar(String name, File data, File control) {
+        File ar = new File(data.parent,
"apache-tomee-${name}-${tomeeVersion}.deb")
+        ArArchiveOutputStream output = new ArArchiveOutputStream(new
FileOutputStream(ar))
+
+        arDebianBinary(output)
+        arItem(output, control)
+        arItem(output, data)
+
+        output.close()
+        //data.delete()
+        //control.delete()
+        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')
+    }
+}

Added:
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/TestPlaceholder.groovy
URL:
http://svn.apache.org/viewvc/tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/TestPlaceholder.groovy?rev=1455127&view=auto
==============================================================================
---
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/TestPlaceholder.groovy
(added)
+++
tomee/sandbox/tomee-deb/src/test/groovy/org/apache/tomee/deb/TestPlaceholder.groovy
Mon Mar 11 13:07:15 2013
@@ -0,0 +1,35 @@
+/**
+ *
+ * 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.Before
+import org.junit.Test
+
+class TestPlaceholder {
+
+    @Before
+    public void setUp() throws Exception {
+
+    }
+
+    @Test
+    void testCreateUser() {
+
+    }
+}

Reply via email to