View Javadoc

1   /*
2    * 
3    * 
4    */
5   
6   package earutils.ant;
7   
8   import org.apache.tools.ant.Task;
9   import org.apache.tools.ant.BuildException;
10  import earutils.expander.*;
11  
12  /***
13   * 
14   * @author Sean C. Sullivan
15   *  
16   */
17  public class EarExpanderTask extends Task
18  {
19  	private String earFilename;
20  	private String destDirectory;
21  	private boolean verbose = false;
22  
23  	public void setEarFilename(String name)
24  	{
25  		earFilename = name;
26  	}
27  
28  	public void execute() throws BuildException
29  	{
30  		validate();
31  
32  		expandEAR();
33  	}
34  
35  	public void setVerbose(boolean b)
36  	{
37  		verbose = b;
38  	}
39  	
40  	protected void expandEAR()
41  	{
42  		Expander expander = new Expander();
43  
44  		if (verbose)
45  		{
46  			expander.addExpanderListener(new SimpleExpanderListener(verbose));
47  		}
48  		
49  		try
50  		{
51  			expander.expand(earFilename);
52  			
53  		}
54  		catch (Exception ex)
55  		{
56  			throw new BuildException(ex);
57  		}
58  	}
59  	
60  	public void setDestDir(String name)
61  	{
62  		destDirectory = name;
63  	}
64  
65  	protected void validate() throws BuildException
66  	{
67  		if ((earFilename == null) || (earFilename.length() < 1))
68  		{
69  			throw new BuildException("earfilename is required");
70  		}
71  		
72  
73  		if ((destDirectory == null) || (destDirectory.length() < 1))
74  		{
75  			throw new BuildException("destdir is required");
76  		}
77  	}
78  
79  }