View Javadoc

1   package net.sf.jpkgmk.ant;
2   
3   import java.io.File;
4   import java.io.IOException;
5   
6   import net.sf.jpkgmk.FileHandler;
7   import net.sf.jpkgmk.PkgMk;
8   
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.apache.tools.ant.BuildException;
12  import org.apache.tools.ant.Project;
13  import org.apache.tools.ant.Task;
14  
15  /**
16   * Ant interface to access the functionality of jpkgmk through ant.
17   * @author gommma (gommma AT users.sourceforge.net)
18   * @author Last changed by: $Author: gommma $
19   * @version $Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
20   * @since 1.0
21   */
22  public class JPkgMkTask extends Task {
23      /**
24       * Logger for this class
25       */
26      private static final Log logger = LogFactory.getLog(JPkgMkTask.class);
27      
28      /**
29       * The directory where the package sources are located
30       */
31      private File sourceDir;
32      
33      /**
34       * The directory where the package files will be created
35       */
36      private File targetDir;
37  
38  
39      public File getSourceDir() {
40  		return sourceDir;
41  	}
42  
43  	public void setSourceDir(File sourceDir) {
44  		this.sourceDir = sourceDir;
45  	}
46  
47  	public File getTargetDir() {
48  		return targetDir;
49  	}
50  
51  	public void setTargetDir(File targetDir) {
52  		this.targetDir = targetDir;
53  	}
54  
55  	/**
56       * Create the package using the given source directory
57       */
58      @Override
59  	public void execute() throws BuildException
60      {
61          logger.debug("execute() - start");
62  
63          try {
64  			log("Creating package from directory " + this.sourceDir, Project.MSG_INFO);
65  			PkgMk pkgMk = new PkgMk(this.sourceDir, this.targetDir);
66  			pkgMk.create();
67  			File tarGzFile = pkgMk.getGzipFile();
68  			log("Created package: " + tarGzFile.getAbsolutePath(), Project.MSG_INFO);
69  		} catch (IOException e) {
70  			throw new BuildException("Exception during package creation", e);
71  		}
72      }
73  
74  }