KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > launch4j > ant > Launch4jTask


1 /*
2     Launch4j (http://launch4j.sourceforge.net/)
3     Cross-platform Java application wrapper for creating Windows native executables.
4
5     Copyright (C) 2004, 2006 Grzegorz Kowal
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */

21
22 /*
23  * Created on May 24, 2005
24  */

25 package net.sf.launch4j.ant;
26
27 import java.io.File JavaDoc;
28
29 import net.sf.launch4j.Builder;
30 import net.sf.launch4j.BuilderException;
31 import net.sf.launch4j.Log;
32 import net.sf.launch4j.config.Config;
33 import net.sf.launch4j.config.ConfigPersister;
34 import net.sf.launch4j.config.ConfigPersisterException;
35
36 import org.apache.tools.ant.BuildException;
37 import org.apache.tools.ant.Task;
38
39 /**
40  * @author Copyright (C) 2005 Grzegorz Kowal
41  */

42 public class Launch4jTask extends Task {
43     private File JavaDoc _configFile;
44     private AntConfig _config;
45
46     // System properties
47
private File JavaDoc tmpdir; // launch4j.tmpdir
48
private File JavaDoc bindir; // launch4j.bindir
49

50     // Override configFile settings
51
private File JavaDoc jar;
52     private File JavaDoc outfile;
53     private String JavaDoc fileVersion;
54     private String JavaDoc txtFileVersion;
55     private String JavaDoc productVersion;
56     private String JavaDoc txtProductVersion;
57
58     public void execute() throws BuildException {
59         try {
60             if (tmpdir != null) {
61                 System.setProperty("launch4j.tmpdir", tmpdir.getPath());
62             }
63             if (bindir != null) {
64                 System.setProperty("launch4j.bindir", bindir.getPath());
65             }
66             if (_configFile != null && _config != null) {
67                 throw new BuildException(
68                         Messages.getString("Launch4jTask.specify.config"));
69             } else if (_configFile != null) {
70                 ConfigPersister.getInstance().load(_configFile);
71                 Config c = ConfigPersister.getInstance().getConfig();
72                 if (jar != null) {
73                     c.setJar(jar);
74                 }
75                 if (outfile != null) {
76                     c.setOutfile(outfile);
77                 }
78                 if (fileVersion != null) {
79                     c.getVersionInfo().setFileVersion(fileVersion);
80                 }
81                 if (txtFileVersion != null) {
82                     c.getVersionInfo().setTxtFileVersion(txtFileVersion);
83                 }
84                 if (productVersion != null) {
85                     c.getVersionInfo().setProductVersion(productVersion);
86                 }
87                 if (txtProductVersion != null) {
88                     c.getVersionInfo().setTxtProductVersion(txtProductVersion);
89                 }
90             } else if (_config != null) {
91                 _config.unwrap();
92                 ConfigPersister.getInstance().setAntConfig(_config,
93                         getProject().getBaseDir());
94             } else {
95                 throw new BuildException(
96                         Messages.getString("Launch4jTask.specify.config"));
97             }
98             final Builder b = new Builder(Log.getAntLog());
99             b.build();
100         } catch (ConfigPersisterException e) {
101             throw new BuildException(e);
102         } catch (BuilderException e) {
103             throw new BuildException(e);
104         }
105     }
106
107     public void setConfigFile(File JavaDoc configFile) {
108         _configFile = configFile;
109     }
110
111     public void addConfig(AntConfig config) {
112         _config = config;
113     }
114
115     public void setBindir(File JavaDoc bindir) {
116         this.bindir = bindir;
117     }
118
119     public void setTmpdir(File JavaDoc tmpdir) {
120         this.tmpdir = tmpdir;
121     }
122
123     public void setFileVersion(String JavaDoc fileVersion) {
124         this.fileVersion = fileVersion;
125     }
126
127     public void setJar(File JavaDoc jar) {
128         this.jar = jar;
129     }
130
131     public void setJarPath(String JavaDoc path) {
132         this.jar = new File JavaDoc(path);
133     }
134
135     public void setOutfile(File JavaDoc outfile) {
136         this.outfile = outfile;
137     }
138
139     public void setProductVersion(String JavaDoc productVersion) {
140         this.productVersion = productVersion;
141     }
142
143     public void setTxtFileVersion(String JavaDoc txtFileVersion) {
144         this.txtFileVersion = txtFileVersion;
145     }
146
147     public void setTxtProductVersion(String JavaDoc txtProductVersion) {
148         this.txtProductVersion = txtProductVersion;
149     }
150 }
151
Popular Tags