View Javadoc

1   package org.alfresco.plexus.archiver;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import org.codehaus.plexus.archiver.*;
6   import org.codehaus.plexus.archiver.jar.JarArchiver;
7   import org.codehaus.plexus.archiver.zip.ZipOutputStream;
8   
9   public class AmpArchiver extends JarArchiver
10  {
11  
12      public AmpArchiver()
13      {
14          super.archiveType = "amp";
15      }
16  
17      public void setModuleProperties(File descr)
18      throws ArchiverException
19      {
20  //        deploymentDescriptor = descr;
21  //        if(!deploymentDescriptor.exists())
22  //        {
23  //            throw new ArchiverException("Deployment descriptor: " + deploymentDescriptor + " does not exist.");
24  //        } else
25  //        {
26  //            addFile(descr, "config/AMP-INF/module.properties");
27  //            return;
28  //        }
29      }
30  
31      public void addLib(File fileName)
32          throws ArchiverException
33      {
34          addDirectory(fileName.getParentFile(), "lib/", new String[] {
35              fileName.getName()
36          }, null);
37      }
38  
39      public void addLibs(File directoryName, String includes[], String excludes[])
40          throws ArchiverException
41      {
42          addDirectory(directoryName, "lib/", includes, excludes);
43      }
44  
45      public void addClass(File fileName)
46          throws ArchiverException
47      {
48          addDirectory(fileName.getParentFile(), "classes/", new String[] {
49              fileName.getName()
50          }, null);
51      }
52  
53      public void addClasses(File directoryName, String includes[], String excludes[])
54          throws ArchiverException
55      {
56          addDirectory(directoryName, "classes/", includes, excludes);
57      }
58  
59  
60      protected void initZipOutputStream(ZipOutputStream zOut)
61          throws IOException, ArchiverException
62      {
63  //        if(deploymentDescriptor == null && !isInUpdateMode())
64  //        {
65  //            throw new ArchiverException("module properies attribute is required");
66  //        } 
67  //        else
68  //        {
69              super.initZipOutputStream(zOut);
70              return;
71  //        }
72      }
73  
74      protected void zipFile(ArchiveEntry entry, ZipOutputStream zOut, String vPath, int mode)
75          throws IOException, ArchiverException
76      {
77          if(vPath.equalsIgnoreCase("config/AMP-INF/module.properties"))
78          {
79              if(deploymentDescriptor == null || !deploymentDescriptor.getCanonicalPath().equals(entry.getFile().getCanonicalPath()) || descriptorAdded)
80              {
81                  getLogger().warn("Warning: selected " + super.archiveType + " files include a config/AMP-INF/module.properites which will be ignored " + "(please use webxml attribute to " + super.archiveType + " task)");
82              } 
83              else
84              {
85                super.zipFile(entry, zOut, vPath);
86                  descriptorAdded = true;
87              }
88          } 
89          else
90          {
91              super.zipFile(entry, zOut, vPath);
92          }
93      }
94  
95      
96      protected void cleanUp()
97      {
98          descriptorAdded = false;
99          super.cleanUp();
100     }
101 
102     private File deploymentDescriptor;
103     private boolean descriptorAdded;
104     /***
105      * @see org.codehaus.plexus.archiver.AbstractArchiver#addDirectory(java.io.File, java.lang.String, java.lang.String[], java.lang.String[])
106      */
107     public void addDirectory(File pArg0, String pArg1, String[] pArg2, String[] pArg3)
108         throws ArchiverException
109     {
110         /* */
111         getLogger().info("adding directory [ '"+pArg0+"' '"+pArg1+"']");
112         super.addDirectory(pArg0, pArg1, pArg2, pArg3);
113     }
114 }