source: release-kits/shared/launch4j/src/net/sf/launch4j/config/Config.java@ 15024

Last change on this file since 15024 was 15024, checked in by oranfry, 16 years ago

putting launch4j in the shared area

File size: 6.6 KB
Line 
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 Apr 21, 2005
24 */
25package net.sf.launch4j.config;
26
27import java.io.File;
28
29import net.sf.launch4j.binding.IValidatable;
30import net.sf.launch4j.binding.Validator;
31
32/**
33 * @author Copyright (C) 2005 Grzegorz Kowal
34 */
35public class Config implements IValidatable {
36
37 public static final String HEADER = "header"; //$NON-NLS-1$
38 public static final String JAR = "jar"; //$NON-NLS-1$
39 public static final String OUTFILE = "outfile"; //$NON-NLS-1$
40 public static final String ERR_TITLE = "errTitle"; //$NON-NLS-1$
41 public static final String JAR_ARGS = "jarArgs"; //$NON-NLS-1$
42 public static final String CHDIR = "chdir"; //$NON-NLS-1$
43 public static final String CUSTOM_PROC_NAME = "customProcName"; //$NON-NLS-1$
44 public static final String STAY_ALIVE = "stayAlive"; //$NON-NLS-1$
45 public static final String ICON = "icon"; //$NON-NLS-1$
46
47 public static final int GUI_HEADER = 0;
48 public static final int CONSOLE_HEADER = 1;
49
50 private boolean dontWrapJar;
51 private int headerType;
52 private String[] headerObjects;
53 private String[] libs;
54 private File jar;
55 private File outfile;
56
57 // runtime configuration
58 private String errTitle;
59 private String jarArgs;
60 private String chdir;
61 private boolean customProcName;
62 private boolean stayAlive;
63 private File icon;
64 private Jre jre;
65 private Splash splash;
66 private VersionInfo versionInfo;
67
68 public void checkInvariants() {
69 Validator.checkTrue(outfile != null && outfile.getPath().endsWith(".exe"), //$NON-NLS-1$
70 "outfile", Messages.getString("Config.specify.output.exe")); //$NON-NLS-1$ //$NON-NLS-2$
71 if (dontWrapJar) {
72 Validator.checkRelativeWinPath(jar.getPath(), "jar", Messages.getString("Config.application.jar.path"));
73 } else {
74 Validator.checkFile(jar, "jar", Messages.getString("Config.application.jar")); //$NON-NLS-1$ //$NON-NLS-2$
75 }
76 if (!Validator.isEmpty(chdir)) {
77 Validator.checkRelativeWinPath(chdir,
78 "chdir", Messages.getString("Config.chdir.relative")); //$NON-NLS-1$ //$NON-NLS-2$
79 Validator.checkFalse(chdir.toLowerCase().equals("true") //$NON-NLS-1$
80 || chdir.toLowerCase().equals("false"), //$NON-NLS-1$
81 "chdir", Messages.getString("Config.chdir.path")); //$NON-NLS-1$ //$NON-NLS-2$
82 }
83 Validator.checkOptFile(icon, "icon", Messages.getString("Config.icon")); //$NON-NLS-1$ //$NON-NLS-2$
84 Validator.checkOptString(jarArgs, 16384, "jarArgs", Messages.getString("Config.jar.arguments")); //$NON-NLS-1$ //$NON-NLS-2$
85 Validator.checkOptString(errTitle, 128, "errTitle", Messages.getString("Config.error.title")); //$NON-NLS-1$ //$NON-NLS-2$
86 Validator.checkRange(headerType, GUI_HEADER, CONSOLE_HEADER,
87 "headerType", Messages.getString("Config.invalid.header.type")); //$NON-NLS-1$ //$NON-NLS-2$
88 Validator.checkTrue(headerType != CONSOLE_HEADER || splash == null,
89 "headerType", Messages.getString("Config.splash.not.impl.by.console.hdr")); //$NON-NLS-1$ //$NON-NLS-2$
90 jre.checkInvariants();
91 }
92
93 public void validate() {
94 checkInvariants();
95 if (splash != null) {
96 splash.checkInvariants();
97 }
98 if (versionInfo != null) {
99 versionInfo.checkInvariants();
100 }
101 }
102
103 /** Change current directory to EXE location. */
104 public String getChdir() {
105 return chdir;
106 }
107
108 public void setChdir(String chdir) {
109 this.chdir = chdir;
110 }
111
112 /** Constant command line arguments passed to application jar. */
113 public String getJarArgs() {
114 return jarArgs;
115 }
116
117 public void setJarArgs(String jarArgs) {
118 this.jarArgs = jarArgs;
119 }
120
121 /** Optional, error message box title. */
122 public String getErrTitle() {
123 return errTitle;
124 }
125
126 public void setErrTitle(String errTitle) {
127 this.errTitle = errTitle;
128 }
129
130 /** launch4j header file. */
131 public int getHeaderType() {
132 return headerType;
133 }
134
135 public void setHeaderType(int headerType) {
136 this.headerType = headerType;
137 }
138
139 public boolean isCustomHeaderObjects() {
140 return headerObjects != null && headerObjects.length > 0;
141 }
142
143 public String[] getHeaderObjects() {
144 return isCustomHeaderObjects() ? headerObjects
145 : headerType == GUI_HEADER
146 ? LdDefaults.getInstance().getGuiHeaderObjects()
147 : LdDefaults.getInstance().getConsoleHeaderObjects();
148 }
149
150 public void setHeaderObjects(String[] headerObjects) {
151 this.headerObjects = headerObjects;
152 }
153
154 public boolean isCustomLibs() {
155 return libs != null && libs.length > 0;
156 }
157
158 public String[] getLibs() {
159 return isCustomLibs() ? libs : LdDefaults.getInstance().getLibs();
160 }
161
162 public void setLibs(String[] libs) {
163 this.libs = libs;
164 }
165
166 /** ICO file. */
167 public File getIcon() {
168 return icon;
169 }
170
171 public void setIcon(File icon) {
172 this.icon = icon;
173 }
174
175 /** Jar to wrap. */
176 public File getJar() {
177 return jar;
178 }
179
180 public void setJar(File jar) {
181 this.jar = jar;
182 }
183
184 /** JRE configuration */
185 public Jre getJre() {
186 return jre;
187 }
188
189 public void setJre(Jre jre) {
190 this.jre = jre;
191 }
192
193 /** Output EXE file. */
194 public File getOutfile() {
195 return outfile;
196 }
197
198 public void setOutfile(File outfile) {
199 this.outfile = outfile;
200 }
201
202 /** Custom process name as the output EXE file name. */
203 public boolean isCustomProcName() {
204 return customProcName;
205 }
206
207 public void setCustomProcName(boolean customProcName) {
208 this.customProcName = customProcName;
209 }
210
211 /** Splash screen configuration. */
212 public Splash getSplash() {
213 return splash;
214 }
215
216 public void setSplash(Splash splash) {
217 this.splash = splash;
218 }
219
220 /** Stay alive after launching the application. */
221 public boolean isStayAlive() {
222 return stayAlive;
223 }
224
225 public void setStayAlive(boolean stayAlive) {
226 this.stayAlive = stayAlive;
227 }
228
229 public VersionInfo getVersionInfo() {
230 return versionInfo;
231 }
232
233 public void setVersionInfo(VersionInfo versionInfo) {
234 this.versionInfo = versionInfo;
235 }
236
237 public boolean isDontWrapJar() {
238 return dontWrapJar;
239 }
240
241 public void setDontWrapJar(boolean dontWrapJar) {
242 this.dontWrapJar = dontWrapJar;
243 }
244}
Note: See TracBrowser for help on using the repository browser.