1 21 22 25 package net.sf.launch4j.config; 26 27 import java.io.File ; 28 import java.util.Arrays ; 29 import java.util.List ; 30 31 import net.sf.launch4j.binding.IValidatable; 32 import net.sf.launch4j.binding.Validator; 33 34 37 public class Config implements IValidatable { 38 39 public static final String HEADER = "header"; 41 public static final String JAR = "jar"; 42 public static final String OUTFILE = "outfile"; 43 public static final String ERR_TITLE = "errTitle"; 44 public static final String JAR_ARGS = "jarArgs"; 45 public static final String CHDIR = "chdir"; 46 public static final String CUSTOM_PROC_NAME = "customProcName"; 47 public static final String STAY_ALIVE = "stayAlive"; 48 public static final String ICON = "icon"; 49 50 public static final String DOWNLOAD_URL = "http://java.com/download"; 52 53 public static final String GUI_HEADER = "gui"; 54 public static final String CONSOLE_HEADER = "console"; 55 56 private static final String [] HEADER_TYPES = new String [] { GUI_HEADER, 57 CONSOLE_HEADER }; 58 59 private static final String [] PRIORITY_CLASS_NAMES = new String [] { "normal", 60 "idle", 61 "high" }; 62 63 private static final int[] PRIORITY_CLASSES = new int[] { 0x00000020, 64 0x00000040, 65 0x00000080 }; 66 67 private boolean dontWrapJar; 68 private String headerType = GUI_HEADER; 69 private List headerObjects; 70 private List libs; 71 private File jar; 72 private File outfile; 73 74 private String errTitle; 76 private String cmdLine; 77 private String chdir; 78 private String priority; 79 private String downloadUrl; 80 private String supportUrl; 81 private boolean customProcName; 82 private boolean stayAlive; 83 private File icon; 84 private List variables; 85 private ClassPath classPath; 86 private Jre jre; 87 private Splash splash; 88 private VersionInfo versionInfo; 89 private Msg messages; 90 91 public void checkInvariants() { 92 Validator.checkTrue(outfile != null && outfile.getPath().endsWith(".exe"), 93 "outfile", Messages.getString("Config.specify.output.exe")); 94 if (dontWrapJar) { 95 if (jar != null && !jar.getPath().equals("")) { 96 Validator.checkRelativeWinPath(jar.getPath(), "jar", 97 Messages.getString("Config.application.jar.path")); 98 } else { 99 Validator.checkTrue(classPath != null, "classPath", 100 Messages.getString("ClassPath.or.jar")); 101 } 102 } else { 103 Validator.checkFile(jar, "jar", 104 Messages.getString("Config.application.jar")); 105 } 106 if (!Validator.isEmpty(chdir)) { 107 Validator.checkRelativeWinPath(chdir, "chdir", 108 Messages.getString("Config.chdir.relative")); 109 Validator.checkFalse(chdir.toLowerCase().equals("true") 110 || chdir.toLowerCase().equals("false"), 111 "chdir", Messages.getString("Config.chdir.path")); 112 } 113 Validator.checkOptFile(icon, "icon", Messages.getString("Config.icon")); 114 Validator.checkOptString(cmdLine, Validator.MAX_BIG_STR, "jarArgs", 115 Messages.getString("Config.jar.arguments")); 116 Validator.checkOptString(errTitle, Validator.MAX_STR, "errTitle", 117 Messages.getString("Config.error.title")); 118 Validator.checkOptString(downloadUrl, 256, 119 "downloadUrl", Messages.getString("Config.download.url")); 120 Validator.checkOptString(supportUrl, 256, 121 "supportUrl", Messages.getString("Config.support.url")); 122 Validator.checkIn(getHeaderType(), HEADER_TYPES, "headerType", 123 Messages.getString("Config.header.type")); 124 Validator.checkFalse(getHeaderType().equals(CONSOLE_HEADER) && splash != null, 125 "headerType", 126 Messages.getString("Config.splash.not.impl.by.console.hdr")); 127 Validator.checkOptStrings(variables, 128 Validator.MAX_ARGS, 129 Validator.MAX_ARGS, 130 "[^=%\t]+=[^=\t]+", 131 "variables", 132 Messages.getString("Config.variables"), 133 Messages.getString("Config.variables.err")); 134 Validator.checkIn(getPriority(), PRIORITY_CLASS_NAMES, "priority", 135 Messages.getString("Config.priority")); 136 jre.checkInvariants(); 137 } 138 139 public void validate() { 140 checkInvariants(); 141 if (classPath != null) { 142 classPath.checkInvariants(); 143 } 144 if (splash != null) { 145 splash.checkInvariants(); 146 } 147 if (versionInfo != null) { 148 versionInfo.checkInvariants(); 149 } 150 } 151 152 153 public String getChdir() { 154 return chdir; 155 } 156 157 public void setChdir(String chdir) { 158 this.chdir = chdir; 159 } 160 161 162 public String getCmdLine() { 163 return cmdLine; 164 } 165 166 public void setCmdLine(String cmdLine) { 167 this.cmdLine = cmdLine; 168 } 169 170 171 public String getErrTitle() { 172 return errTitle; 173 } 174 175 public void setErrTitle(String errTitle) { 176 this.errTitle = errTitle; 177 } 178 179 180 public String getHeaderType() { 181 return headerType.toLowerCase(); 182 } 183 184 public void setHeaderType(String headerType) { 185 this.headerType = headerType; 186 } 187 188 189 public int getHeaderTypeIndex() { 190 int x = Arrays.asList(HEADER_TYPES).indexOf(getHeaderType()); 191 return x != -1 ? x : 0; 192 } 193 194 public void setHeaderTypeIndex(int headerTypeIndex) { 195 headerType = HEADER_TYPES[headerTypeIndex]; 196 } 197 198 public boolean isCustomHeaderObjects() { 199 return headerObjects != null && !headerObjects.isEmpty(); 200 } 201 202 public List getHeaderObjects() { 203 return isCustomHeaderObjects() ? headerObjects 204 : getHeaderType().equals(GUI_HEADER) 205 ? LdDefaults.GUI_HEADER_OBJECTS 206 : LdDefaults.CONSOLE_HEADER_OBJECTS; 207 } 208 209 public void setHeaderObjects(List headerObjects) { 210 this.headerObjects = headerObjects; 211 } 212 213 public boolean isCustomLibs() { 214 return libs != null && !libs.isEmpty(); 215 } 216 217 public List getLibs() { 218 return isCustomLibs() ? libs : LdDefaults.LIBS; 219 } 220 221 public void setLibs(List libs) { 222 this.libs = libs; 223 } 224 225 226 public File getIcon() { 227 return icon; 228 } 229 230 public void setIcon(File icon) { 231 this.icon = icon; 232 } 233 234 235 public File getJar() { 236 return jar; 237 } 238 239 public void setJar(File jar) { 240 this.jar = jar; 241 } 242 243 public List getVariables() { 244 return variables; 245 } 246 247 public void setVariables(List variables) { 248 this.variables = variables; 249 } 250 251 public ClassPath getClassPath() { 252 return classPath; 253 } 254 255 public void setClassPath(ClassPath classpath) { 256 this.classPath = classpath; 257 } 258 259 260 public Jre getJre() { 261 return jre; 262 } 263 264 public void setJre(Jre jre) { 265 this.jre = jre; 266 } 267 268 269 public File getOutfile() { 270 return outfile; 271 } 272 273 public void setOutfile(File outfile) { 274 this.outfile = outfile; 275 } 276 277 278 public boolean isCustomProcName() { 279 return customProcName; 280 } 281 282 public void setCustomProcName(boolean customProcName) { 283 this.customProcName = customProcName; 284 } 285 286 287 public Splash getSplash() { 288 return splash; 289 } 290 291 public void setSplash(Splash splash) { 292 this.splash = splash; 293 } 294 295 296 public boolean isStayAlive() { 297 return stayAlive; 298 } 299 300 public void setStayAlive(boolean stayAlive) { 301 this.stayAlive = stayAlive; 302 } 303 304 public VersionInfo getVersionInfo() { 305 return versionInfo; 306 } 307 308 public void setVersionInfo(VersionInfo versionInfo) { 309 this.versionInfo = versionInfo; 310 } 311 312 public boolean isDontWrapJar() { 313 return dontWrapJar; 314 } 315 316 public void setDontWrapJar(boolean dontWrapJar) { 317 this.dontWrapJar = dontWrapJar; 318 } 319 320 public int getPriorityIndex() { 321 int x = Arrays.asList(PRIORITY_CLASS_NAMES).indexOf(getPriority()); 322 return x != -1 ? x : 0; 323 } 324 325 public void setPriorityIndex(int x) { 326 priority = PRIORITY_CLASS_NAMES[x]; 327 } 328 329 public String getPriority() { 330 return Validator.isEmpty(priority) ? PRIORITY_CLASS_NAMES[0] : priority; 331 } 332 333 public void setPriority(String priority) { 334 this.priority = priority; 335 } 336 337 public int getPriorityClass() { 338 return PRIORITY_CLASSES[getPriorityIndex()]; 339 } 340 341 public String getDownloadUrl() { 342 return Validator.isEmpty(downloadUrl) ? DOWNLOAD_URL : downloadUrl; 343 } 344 345 public void setDownloadUrl(String downloadUrl) { 346 this.downloadUrl = downloadUrl; 347 } 348 349 public String getSupportUrl() { 350 return supportUrl; 351 } 352 353 public void setSupportUrl(String supportUrl) { 354 this.supportUrl = supportUrl; 355 } 356 357 public Msg getMessages() { 358 return messages; 359 } 360 361 public void setMessages(Msg messages) { 362 this.messages = messages; 363 } 364 } 365 | Popular Tags |