KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > tools > jbiplugin > PackageAbstractMojo


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: PackageAssemblyMojo.java 16:56:43 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.tools.jbiplugin;
23
24 import java.io.DataInputStream JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileInputStream JavaDoc;
27 import java.util.zip.ZipEntry JavaDoc;
28 import java.util.zip.ZipOutputStream JavaDoc;
29
30 /**
31  * Make a JBI Archive
32  *
33  * @author cdeneux - Capgemini Sud
34  */

35 public abstract class PackageAbstractMojo extends JBIAbstractMojo {
36
37     /**
38      * JBI sources directory
39      *
40      * @parameter expression="${basedir}/src/main/jbi/"
41      * @required
42      * @description Path of the JBI sources directory
43      */

44     protected File JavaDoc jbiDirectory;
45
46     /**
47      * Recurse a directory to add its content to a zip file
48      *
49      * @param zipOutputStream
50      * zip file
51      * @param directory
52      * directory to recurse
53      * @param entryDirectoryName
54      * directory to put the content in the zip
55      * @throws Exception
56      */

57     protected void recurseDirectory(ZipOutputStream JavaDoc zipOutputStream,
58         File JavaDoc directory, String JavaDoc entryDirectoryName) throws Exception JavaDoc {
59         for (File JavaDoc file : directory.listFiles()) {
60             if (file.isFile()) {
61                 if (verbose) {
62                     System.out.println(" "
63                         + entryDirectoryName + File.separator + file.getName() + " added to JBI Service Assembly archive");
64                 }
65                 ZipEntry JavaDoc zipEntry = new ZipEntry JavaDoc(("".equals(entryDirectoryName)) ? file.getName() : (entryDirectoryName
66                     + File.separator + file.getName()));
67                 DataInputStream JavaDoc dis = new DataInputStream JavaDoc(
68                     new FileInputStream JavaDoc(file));
69                 byte[] content = new byte[dis.available()];
70                 dis.readFully(content);
71                 zipOutputStream.putNextEntry(zipEntry);
72                 zipOutputStream.write(content);
73                 zipOutputStream.closeEntry();
74             } else {
75                 if (!file.getName().startsWith(".")) {
76                     // Avoid to add the .svn directory
77
recurseDirectory(zipOutputStream, file, ("".equals(entryDirectoryName)) ? file.getName() : (entryDirectoryName
78                             + File.separator + file.getName()));
79                 }
80             }
81         }
82     }
83 }
84
Popular Tags