KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > phoenix > tools > tasks > Sar


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.phoenix.tools.tasks;
9
10 import java.io.File JavaDoc;
11 import org.apache.tools.ant.BuildException;
12 import org.apache.tools.ant.taskdefs.Jar;
13 import org.apache.tools.ant.types.ZipFileSet;
14
15 /**
16  * Creates a Sar archive.
17  *
18  * @author <a HREF="mailto:peter at apache.org">Peter Donald</a>
19  * @author <a HREF="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
20  */

21 public class Sar
22     extends Jar
23 {
24     private File JavaDoc m_config;
25     private File JavaDoc m_assembly;
26     private File JavaDoc m_environment;
27
28     public Sar()
29     {
30         archiveType = "sar";
31         emptyBehavior = "fail";
32     }
33
34     public void setSarfile( final File JavaDoc file )
35     {
36         setDestFile( file );
37     }
38
39     public void setConfig( final File JavaDoc config )
40     {
41         m_config = config;
42
43         if( !m_config.exists() )
44         {
45             throw new BuildException( "Config descriptor: " + m_config + " does not exist." );
46         }
47
48         if( !m_config.isFile() )
49         {
50             throw new BuildException( "Config descriptor: " + m_config + " is not a file." );
51         }
52     }
53
54     public void setAssembly( final File JavaDoc assembly )
55     {
56         m_assembly = assembly;
57
58         if( !m_assembly.exists() )
59         {
60             throw new BuildException( "Assembly descriptor: " + m_assembly + " does not exist." );
61         }
62
63         if( !m_assembly.isFile() )
64         {
65             throw new BuildException( "Assembly descriptor: " + m_assembly + " is not a file." );
66         }
67     }
68
69     public void setServer( final File JavaDoc server )
70     {
71         System.err.println( "DEPRECATED: Server attribute of sar task is deprecated" );
72         setEnvironment( server );
73     }
74
75     public void setEnvironment( final File JavaDoc environment )
76     {
77         m_environment = environment;
78
79         if( !m_environment.exists() )
80         {
81             final String JavaDoc message = "Environment descriptor: "
82                 + m_environment + " does not exist.";
83             throw new BuildException( message );
84         }
85
86         if( !m_environment.isFile() )
87         {
88             final String JavaDoc message = "Environment descriptor: "
89                 + m_environment + " is not a file.";
90             throw new BuildException( message );
91         }
92     }
93
94     public void addLib( final ZipFileSet zipFileSet )
95     {
96         zipFileSet.setPrefix( "SAR-INF/lib" );
97         super.addFileset( zipFileSet );
98     }
99
100     public void addClasses( final ZipFileSet zipFileSet )
101     {
102         zipFileSet.setPrefix( "SAR-INF/classes" );
103         super.addFileset( zipFileSet );
104     }
105
106     public void execute()
107         throws BuildException
108     {
109         if( null == m_config )
110         {
111             throw new BuildException( "config attribute is required", location );
112         }
113         if( null == m_assembly )
114         {
115             throw new BuildException( "assembly attribute is required", location );
116         }
117         if( null == m_environment )
118         {
119             throw new BuildException( "environment attribute is required", location );
120         }
121
122         pushFile( "SAR-INF/config.xml", m_config );
123         pushFile( "SAR-INF/assembly.xml", m_assembly );
124         pushFile( "SAR-INF/environment.xml", m_environment );
125
126         super.execute();
127     }
128
129     private void pushFile( final String JavaDoc path, final File JavaDoc file )
130     {
131         final ZipFileSet zipFileSet = new ZipFileSet();
132         zipFileSet.setDir( new File JavaDoc( file.getParent() ) );
133         zipFileSet.setIncludes( file.getName() );
134         zipFileSet.setFullpath( path );
135         super.addFileset( zipFileSet );
136     }
137
138     protected void cleanUp()
139     {
140         super.cleanUp();
141
142         m_config = null;
143         m_assembly = null;
144         m_environment = null;
145     }
146 }
147
Popular Tags