KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > deploy > Deploy


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.deliver.portal.deploy;
24
25 import java.io.BufferedInputStream JavaDoc;
26 import java.io.BufferedOutputStream JavaDoc;
27 import java.io.ByteArrayInputStream JavaDoc;
28 import java.io.File JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.io.FileNotFoundException JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.io.InputStream JavaDoc;
34 import java.io.OutputStream JavaDoc;
35 import java.net.URL JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.Vector JavaDoc;
38 import java.util.jar.JarEntry JavaDoc;
39 import java.util.jar.JarFile JavaDoc;
40 import java.util.jar.JarOutputStream JavaDoc;
41 import java.util.zip.ZipEntry JavaDoc;
42 import java.util.zip.ZipOutputStream JavaDoc;
43
44 import org.apache.commons.logging.Log;
45 import org.apache.commons.logging.LogFactory;
46 import org.apache.pluto.PortletContainerServices;
47 import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
48 import org.apache.pluto.descriptors.services.WebAppDescriptorService;
49 import org.apache.pluto.descriptors.services.impl.AbstractWebAppDescriptorService;
50 import org.apache.pluto.descriptors.services.impl.StreamPortletAppDescriptorServiceImpl;
51 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
52 import org.apache.pluto.portalImpl.om.portlet.impl.PortletApplicationDefinitionImpl;
53 import org.apache.pluto.portalImpl.services.ServiceManager;
54 import org.apache.xerces.parsers.DOMParser;
55 import org.exolab.castor.mapping.Mapping;
56 import org.exolab.castor.xml.Unmarshaller;
57 import org.infoglue.deliver.portal.ServletConfigContainer;
58 import org.w3c.dom.Document JavaDoc;
59 import org.xml.sax.InputSource JavaDoc;
60
61 /**
62  * Slightly modified version of jakarta-plutos deploy target. This utility
63  * requires that portletdefinitionmapping.xml and servletdefinitionmapping.xml
64  * are located somewhere in the classpath.
65  */

66 public class Deploy {
67     
68     public static class StreamWebAppDescriptorServiceImpl extends AbstractWebAppDescriptorService {
69
70         private InputStream JavaDoc in;
71         private OutputStream JavaDoc out;
72
73         public StreamWebAppDescriptorServiceImpl(String JavaDoc contextPath,
74                                                  InputStream JavaDoc in,
75                                                  OutputStream JavaDoc out) {
76             super(contextPath);
77             this.in = in;
78             this.out = out;
79         }
80
81         protected InputStream JavaDoc getInputStream() throws IOException JavaDoc {
82             return in;
83         }
84
85         protected OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
86             return out;
87         }
88     }
89
90     private static final Log log = LogFactory.getLog(Deploy.class);
91
92     private static final int MAX_POLL_DEPLOY = 30;
93
94     private static final String JavaDoc PORTLET_XML = "WEB-INF/portlet.xml";
95
96     private static final String JavaDoc WEB_XML = "WEB-INF/web.xml";
97
98     private static final String JavaDoc PORTLET_MAPPING = "portletdefinitionmapping.xml";
99
100     private static final String JavaDoc SERVLET_MAPPING = "servletdefinitionmapping.xml";
101
102     /**
103      * Deploy a portlet. Creates a .war-file in webapps and waits until it is
104      * deployed by the servlet container (max 30 seconds).
105      *
106      * @param webappsDir
107      * webapps directory
108      * @param warName
109      * name of .war-file (portlet)
110      * @param is
111      * stream of .war-file
112      * @param containerName
113      * name of portlet container to be updated
114      * @return true if portlet was deployed
115      * @throws FileNotFoundException
116      * in case webapps directory not found
117      * @throws IOException
118      */

119     public static boolean deployArchive(String JavaDoc webappsDir, String JavaDoc warName, InputStream JavaDoc is,
120             String JavaDoc containerName) throws FileNotFoundException JavaDoc, IOException JavaDoc {
121         File JavaDoc webapps = new File JavaDoc(webappsDir);
122         if (!webapps.exists() || !webapps.isDirectory()) {
123             throw new FileNotFoundException JavaDoc("Webapps directory not found: " + webappsDir);
124         }
125         String JavaDoc appName = warName;
126         int dot = appName.lastIndexOf(".");
127         if (dot > 0) {
128             appName = appName.substring(0, dot);
129         } else {
130             warName += ".war";
131         }
132
133         // Create .war-file in webapps
134
File JavaDoc war = new File JavaDoc(webapps, warName);
135         if (war.exists()) {
136             // .war-file already exists - skip?
137
log.info(".war-file already exists: " + war.getAbsolutePath());
138         } else {
139             FileOutputStream JavaDoc os = new FileOutputStream JavaDoc(war);
140             BufferedOutputStream JavaDoc bos = new BufferedOutputStream JavaDoc(os);
141             int num = copyStream(is, bos);
142             bos.close();
143             os.close();
144             log.info(num + " bytes written to " + war.getAbsolutePath());
145         }
146
147         // Expand .war-file into application directory (NOT necessary in Tomcat
148
// 4.1. others?)
149
/*
150          * File appDir = new File(webapps, appName); if (appDir.exists()) { //
151          * app dir already exists - skip? log.warn("Application directory
152          * already exists: " + appDir.getAbsolutePath()); return false; } if
153          * (!appDir.mkdirs()) { throw new IOException( "Unable to create
154          * application directory: " + appDir.getAbsolutePath()); } int numFiles =
155          * expandArchive(war, appDir); log.warn(numFiles + " files extracted to " +
156          * appDir.getAbsolutePath());
157          */

158
159         // Wait until portlet is deployed in servlet container
160
File JavaDoc appDir = new File JavaDoc(webapps, appName);
161         File JavaDoc webInfDir = new File JavaDoc(appDir, "WEB-INF");
162         File JavaDoc portletXml = new File JavaDoc(webInfDir, "portlet.xml");
163         for (int i = 0; !portletXml.exists() && i < MAX_POLL_DEPLOY; i++) {
164             log.debug("Waiting for servlet container to deploy portlet, try " + i + "/"
165                     + MAX_POLL_DEPLOY);
166             try {
167                 Thread.sleep(1000);
168             } catch (InterruptedException JavaDoc e) {
169                 log.warn("Deployment paus interrupted", e);
170             }
171         }
172         if (!portletXml.exists()) {
173             log.error("Failed to deploy portlet: " + war.getAbsolutePath());
174         }
175
176         // Update pluto service manager
177
log.info("Updating pluto service manager: " + containerName);
178         try {
179             PortletContainerServices.prepare(containerName);
180             ServiceManager.init(ServletConfigContainer.getContainer().getServletConfig());
181         } catch (Exception JavaDoc e) {
182             log.error("Error during update of pluto service manager", e);
183         }
184         return true;
185     }
186
187     /**
188      * Prepare a portlet according to Pluto (switch web.xml)
189      *
190      * @param file .war to prepare
191      * @param tmp the resulting updated .war
192      * @param appName name of application (context name)
193      * @return the portlet application definition (portlet.xml)
194      * @throws IOException
195      */

196     public static PortletApplicationDefinition prepareArchive(File JavaDoc file, File JavaDoc tmp, String JavaDoc appName) throws IOException JavaDoc
197     {
198         PortletApplicationDefinitionImpl portletApp = null;
199         try
200         {
201             Mapping pdmXml = new Mapping();
202             try
203             {
204                 URL JavaDoc url = Deploy.class.getResource("/" + PORTLET_MAPPING);
205                 pdmXml.loadMapping(url);
206             }
207             catch (Exception JavaDoc e)
208             {
209                 throw new IOException JavaDoc("Failed to load mapping file " + PORTLET_MAPPING);
210             }
211              
212             // Open the jar file.
213
JarFile JavaDoc jar = new JarFile JavaDoc(file);
214
215             // Extract and parse portlet.xml
216
ZipEntry JavaDoc portletEntry = jar.getEntry(PORTLET_XML);
217             if (portletEntry == null)
218             {
219                 throw new IOException JavaDoc("Unable to find portlet.xml");
220             }
221             
222             InputStream JavaDoc pisDebug = jar.getInputStream(portletEntry);
223             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
224             int i;
225             while((i = pisDebug.read()) > -1)
226             {
227                 sb.append((char)i);
228             }
229             pisDebug.close();
230             
231             InputSource JavaDoc xmlSource = new InputSource JavaDoc(new ByteArrayInputStream JavaDoc(sb.toString().getBytes("UTF-8")));
232             DOMParser parser = new DOMParser();
233             parser.parse(xmlSource);
234             Document JavaDoc portletDocument = parser.getDocument();
235             
236             //InputStream pis = jar.getInputStream(portletEntry);
237
//Document portletDocument = XmlParser.parsePortletXml(pis);
238
//pis.close();
239
InputStream JavaDoc pis = jar.getInputStream(portletEntry);
240             
241             ZipEntry JavaDoc webEntry = jar.getEntry(WEB_XML);
242             InputStream JavaDoc wis = null;
243             if (webEntry != null)
244             {
245                 wis = jar.getInputStream(webEntry);
246                 /* webDocument = XmlParser.parseWebXml(wis);
247                 wis.close();
248                 */

249             }
250             
251             Unmarshaller unmarshaller = new Unmarshaller(pdmXml);
252             unmarshaller.setWhitespacePreserve(true);
253             unmarshaller.setIgnoreExtraElements(true);
254             unmarshaller.setIgnoreExtraAttributes(true);
255
256             portletApp = (PortletApplicationDefinitionImpl) unmarshaller.unmarshal(portletDocument);
257
258             // refill structure with necessary information
259
Vector JavaDoc structure = new Vector JavaDoc();
260             structure.add(appName);
261             structure.add(null);
262             structure.add(null);
263             portletApp.preBuild(structure);
264
265             /*
266             // now generate web part
267             WebApplicationDefinitionImpl webApp = null;
268             if (webDocument != null) {
269                 Unmarshaller unmarshallerWeb = new Unmarshaller(sdmXml);
270
271                 // modified by YCLI: START :: to ignore extra elements and
272                 // attributes
273                 unmarshallerWeb.setWhitespacePreserve(true);
274                 unmarshallerWeb.setIgnoreExtraElements(true);
275                 unmarshallerWeb.setIgnoreExtraAttributes(true);
276                 // modified by YCLI: END
277
278                 webApp = (WebApplicationDefinitionImpl) unmarshallerWeb.unmarshal(webDocument);
279             } else {
280                 webApp = new WebApplicationDefinitionImpl();
281                 DisplayNameImpl dispName = new DisplayNameImpl();
282                 dispName.setDisplayName(appName);
283                 dispName.setLocale(Locale.ENGLISH);
284                 DisplayNameSetImpl dispSet = new DisplayNameSetImpl();
285                 dispSet.add(dispName);
286                 webApp.setDisplayNames(dispSet);
287                 DescriptionImpl desc = new DescriptionImpl();
288                 desc.setDescription("Automated generated Application Wrapper");
289                 desc.setLocale(Locale.ENGLISH);
290                 DescriptionSetImpl descSet = new DescriptionSetImpl();
291                 descSet.add(desc);
292                 webApp.setDescriptions(descSet);
293             }
294
295             org.apache.pluto.om.ControllerFactory controllerFactory = new org.apache.pluto.portalImpl.om.ControllerFactoryImpl();
296
297             ServletDefinitionListCtrl servletDefinitionSetCtrl = (ServletDefinitionListCtrl) controllerFactory
298                     .get(webApp.getServletDefinitionList());
299             Collection servletMappings = webApp.getServletMappings();
300
301             Iterator portlets = portletApp.getPortletDefinitionList().iterator();
302             while (portlets.hasNext()) {
303
304                 PortletDefinition portlet = (PortletDefinition) portlets.next();
305
306                 // check if already exists
307                 ServletDefinition servlet = webApp.getServletDefinitionList()
308                         .get(portlet.getName());
309                 if (servlet != null) {
310                     ServletDefinitionCtrl _servletCtrl = (ServletDefinitionCtrl) controllerFactory
311                             .get(servlet);
312                     _servletCtrl.setServletClass("org.apache.pluto.core.PortletServlet");
313                 } else {
314                     servlet = servletDefinitionSetCtrl.add(portlet.getName(),
315                             "org.apache.pluto.core.PortletServlet");
316                 }
317
318                 ServletDefinitionCtrl servletCtrl = (ServletDefinitionCtrl) controllerFactory
319                         .get(servlet);
320
321                 DisplayNameImpl dispName = new DisplayNameImpl();
322                 dispName.setDisplayName(portlet.getName() + " Wrapper");
323                 dispName.setLocale(Locale.ENGLISH);
324                 DisplayNameSetImpl dispSet = new DisplayNameSetImpl();
325                 dispSet.add(dispName);
326                 servletCtrl.setDisplayNames(dispSet);
327                 DescriptionImpl desc = new DescriptionImpl();
328                 desc.setDescription("Automated generated Portlet Wrapper");
329                 desc.setLocale(Locale.ENGLISH);
330                 DescriptionSetImpl descSet = new DescriptionSetImpl();
331                 descSet.add(desc);
332                 servletCtrl.setDescriptions(descSet);
333                 ParameterSet parameters = servlet.getInitParameterSet();
334
335                 ParameterSetCtrl parameterSetCtrl = (ParameterSetCtrl) controllerFactory
336                         .get(parameters);
337
338                 Parameter parameter1 = parameters.get("portlet-class");
339                 if (parameter1 == null) {
340                     parameterSetCtrl.add("portlet-class", portlet.getClassName());
341                 } else {
342                     ParameterCtrl parameterCtrl = (ParameterCtrl) controllerFactory.get(parameter1);
343                     parameterCtrl.setValue(portlet.getClassName());
344
345                 }
346                 Parameter parameter2 = parameters.get("portlet-guid");
347                 if (parameter2 == null) {
348                     parameterSetCtrl.add("portlet-guid", portlet.getId().toString());
349                 } else {
350                     ParameterCtrl parameterCtrl = (ParameterCtrl) controllerFactory.get(parameter2);
351                     parameterCtrl.setValue(portlet.getId().toString());
352
353                 }
354
355                 boolean found = false;
356                 Iterator mappings = servletMappings.iterator();
357                 while (mappings.hasNext()) {
358                     ServletMappingImpl servletMapping = (ServletMappingImpl) mappings.next();
359                     if (servletMapping.getServletName().equals(portlet.getName())) {
360                         found = true;
361                         servletMapping.setUrlPattern("/" + portlet.getName().replace(' ', '_')
362                                 + "/*");
363                     }
364                 }
365                 if (!found) {
366                     ServletMappingImpl servletMapping = new ServletMappingImpl();
367                     servletMapping.setServletName(portlet.getName());
368                     servletMapping.setUrlPattern("/" + portlet.getName().replace(' ', '_') + "/*");
369                     servletMappings.add(servletMapping);
370                 }
371
372                 SecurityRoleRefSet servletSecurityRoleRefs = ((ServletDefinitionImpl) servlet)
373                         .getInitSecurityRoleRefSet();
374
375                 SecurityRoleRefSetCtrl servletSecurityRoleRefSetCtrl = (SecurityRoleRefSetCtrl) controllerFactory
376                         .get(servletSecurityRoleRefs);
377
378                 SecurityRoleSet webAppSecurityRoles = webApp.getSecurityRoles();
379
380                 SecurityRoleRefSet portletSecurityRoleRefs = portlet.getInitSecurityRoleRefSet();
381
382                 Iterator p = portletSecurityRoleRefs.iterator();
383                 while (p.hasNext()) {
384                     SecurityRoleRef portletSecurityRoleRef = (SecurityRoleRef) p.next();
385
386                     if (portletSecurityRoleRef.getRoleLink() == null
387                             && webAppSecurityRoles.get(portletSecurityRoleRef.getRoleName()) == null) {
388                         System.out
389                                 .println("Note: The web application has no security role defined which matches the role name \""
390                                         + portletSecurityRoleRef.getRoleName()
391                                         + "\" of the security-role-ref element defined for the wrapper-servlet with the name '"
392                                         + portlet.getName() + "'.");
393                         break;
394                     }
395                     SecurityRoleRef servletSecurityRoleRef = servletSecurityRoleRefs
396                             .get(portletSecurityRoleRef.getRoleName());
397                     if (null != servletSecurityRoleRef) {
398                         System.out
399                                 .println("Note: Replaced already existing element of type <security-role-ref> with value \""
400                                         + portletSecurityRoleRef.getRoleName()
401                                         + "\" for subelement of type <role-name> for the wrapper-servlet with the name '"
402                                         + portlet.getName() + "'.");
403                         servletSecurityRoleRefSetCtrl.remove(servletSecurityRoleRef);
404                     }
405                     servletSecurityRoleRefSetCtrl.add(portletSecurityRoleRef);
406                 }
407
408             }
409             */

410
411             /*
412              * TODO is this necessary? TagDefinitionImpl portletTagLib = new
413              * TagDefinitionImpl(); Collection taglibs =
414              * webApp.getCastorTagDefinitions(); taglibs.add(portletTagLib);
415              */

416         
417
418             // Duplicate jar-file with replaced web.xml
419
FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(tmp);
420             JarOutputStream JavaDoc tempJar = new JarOutputStream JavaDoc(fos);
421             byte[] buffer = new byte[1024];
422             int bytesRead;
423             for (Enumeration JavaDoc entries = jar.entries(); entries.hasMoreElements();)
424             {
425                 JarEntry JavaDoc entry = (JarEntry JavaDoc) entries.nextElement();
426                 //System.out.println("entry:" + entry.getName());
427
JarEntry JavaDoc newEntry = new JarEntry JavaDoc(entry.getName());
428                 tempJar.putNextEntry(newEntry);
429                 
430                 if (entry.getName().equals(WEB_XML)) {
431                     // Swap web.xml
432
/*
433                     log.debug("Swapping web.xml");
434                     OutputFormat of = new OutputFormat();
435                     of.setIndenting(true);
436                     of.setIndent(4); // 2-space indention
437                     of.setLineWidth(16384);
438                     of.setDoctype(Constants.WEB_PORTLET_PUBLIC_ID, Constants.WEB_PORTLET_DTD);
439
440                     XMLSerializer serializer = new XMLSerializer(tempJar, of);
441                     Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
442                     marshaller.setMapping(sdmXml);
443                     marshaller.marshal(webApp);
444                     */

445                     
446                     PortletAppDescriptorService portletAppDescriptorService = new StreamPortletAppDescriptorServiceImpl(appName, pis, null);
447                     File JavaDoc tmpf = File.createTempFile("infoglue-web-xml", null);
448                     WebAppDescriptorService webAppDescriptorService = new StreamWebAppDescriptorServiceImpl(appName, wis, new FileOutputStream JavaDoc(tmpf));
449                     
450                     org.apache.pluto.driver.deploy.Deploy d = new org.apache.pluto.driver.deploy.Deploy(webAppDescriptorService, portletAppDescriptorService);
451                     d.updateDescriptors();
452                     FileInputStream JavaDoc fis = new FileInputStream JavaDoc(tmpf);
453                     while ((bytesRead = fis.read(buffer)) != -1)
454                     {
455                         tempJar.write(buffer, 0, bytesRead);
456                     }
457                     tmpf.delete();
458                 }
459                 else
460                 {
461                     InputStream JavaDoc entryStream = jar.getInputStream(entry);
462                     if(entryStream != null)
463                     {
464                         while ((bytesRead = entryStream.read(buffer)) != -1)
465                         {
466                             tempJar.write(buffer, 0, bytesRead);
467                         }
468                     }
469                 }
470             }
471             tempJar.flush();
472             tempJar.close();
473             fos.flush();
474             fos.close();
475             /*
476              * String strTo = dirDelim + "WEB-INF" + dirDelim + "tld" + dirDelim +
477              * "portlet.tld"; String strFrom = "webapps" + dirDelim + strTo;
478              *
479              * copy(strFrom, webAppsDir + webModule + strTo);
480              */

481         } catch (Exception JavaDoc e) {
482             log.error("Failed to prepare archive", e);
483             throw new IOException JavaDoc(e.getMessage());
484         }
485
486         return portletApp;
487     }
488
489     private static void copy(String JavaDoc from, String JavaDoc to) throws IOException JavaDoc {
490         File JavaDoc f = new File JavaDoc(to);
491         f.getParentFile().mkdirs();
492
493         InputStream JavaDoc fis = new FileInputStream JavaDoc(from);
494         FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(f);
495         copyStream(fis, fos);
496         fos.close();
497     }
498
499     private static int copyStream(InputStream JavaDoc is, OutputStream JavaDoc os) throws IOException JavaDoc {
500         int total = 0;
501         byte[] buffer = new byte[1024];
502         int length = 0;
503
504         while ((length = is.read(buffer)) >= 0) {
505             os.write(buffer, 0, length);
506             total += length;
507         }
508         os.flush();
509         return total;
510     }
511
512     private static int expandArchive(File JavaDoc warFile, File JavaDoc destDir) throws IOException JavaDoc {
513         int numEntries = 0;
514
515         if (!destDir.exists()) {
516             destDir.mkdirs();
517         }
518         JarFile JavaDoc jarFile = new JarFile JavaDoc(warFile);
519         Enumeration JavaDoc files = jarFile.entries();
520         while (files.hasMoreElements()) {
521             JarEntry JavaDoc entry = (JarEntry JavaDoc) files.nextElement();
522             String JavaDoc fileName = entry.getName();
523
524             File JavaDoc file = new File JavaDoc(destDir, fileName);
525             File JavaDoc dirF = new File JavaDoc(file.getParent());
526             dirF.mkdirs();
527
528             if (entry.isDirectory()) {
529                 file.mkdirs();
530             } else {
531                 InputStream JavaDoc fis = jarFile.getInputStream(entry);
532                 FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(file);
533                 copyStream(fis, fos);
534                 fos.close();
535             }
536             numEntries++;
537         }
538         return numEntries;
539     }
540
541     private static int createArchive(File JavaDoc dir, File JavaDoc archive) throws IOException JavaDoc {
542         int BUFFER = 2048;
543         BufferedInputStream JavaDoc origin = null;
544         FileOutputStream JavaDoc dest = new FileOutputStream JavaDoc(archive);
545         ZipOutputStream JavaDoc out = new ZipOutputStream JavaDoc(new BufferedOutputStream JavaDoc(dest));
546         //out.setMethod(ZipOutputStream.DEFLATED);
547
byte data[] = new byte[BUFFER];
548         // get a list of files from current directory
549
File JavaDoc files[] = dir.listFiles();
550
551         for (int i = 0; i < files.length; i++) {
552             File JavaDoc curr = files[i];
553             if (curr.isDirectory()) {
554                 // TODO
555
} else {
556                 FileInputStream JavaDoc fi = new FileInputStream JavaDoc(curr);
557                 origin = new BufferedInputStream JavaDoc(fi, BUFFER);
558                 ZipEntry JavaDoc entry = new ZipEntry JavaDoc(curr.getName());
559                 out.putNextEntry(entry);
560                 int count;
561                 while ((count = origin.read(data, 0, BUFFER)) != -1) {
562                     out.write(data, 0, count);
563                 }
564                 origin.close();
565             }
566         }
567         out.close();
568         return files.length;
569     }
570
571     private static void removeAll(File JavaDoc file) {
572         if (file.isDirectory()) {
573             File JavaDoc[] files = file.listFiles();
574             for (int i = 0; i < files.length; i++) {
575                 removeAll(files[i]);
576             }
577         }
578         file.delete();
579     }
580
581     public static void main(String JavaDoc[] args) {
582         try {
583             File JavaDoc file = new File JavaDoc("c:\\infoglueHome\\RssPortlet.war");
584             File JavaDoc tmp = new File JavaDoc("c:\\infoglueHome\\RssPortlet2.war");
585             prepareArchive(file, tmp, "test-portlet.war");
586         } catch (IOException JavaDoc e) {
587             // TODO Auto-generated catch block
588
e.printStackTrace();
589         }
590     }
591 }
Popular Tags