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 | */
|
---|
25 | package net.sf.launch4j.config;
|
---|
26 |
|
---|
27 | import net.sf.launch4j.binding.IValidatable;
|
---|
28 | import net.sf.launch4j.binding.Validator;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * @author Copyright (C) 2005 Grzegorz Kowal
|
---|
32 | */
|
---|
33 | public class Jre implements IValidatable {
|
---|
34 | public static final String VERSION_PATTERN = "(\\d\\.){2}\\d(_\\d+)?"; //$NON-NLS-1$
|
---|
35 | public static final String PATH = "jrepath"; //$NON-NLS-1$
|
---|
36 | public static final String MIN_VERSION = "javamin"; //$NON-NLS-1$
|
---|
37 | public static final String MAX_VERSION = "javamax"; //$NON-NLS-1$
|
---|
38 | public static final String ARGS = "jvmArgs"; //$NON-NLS-1$
|
---|
39 |
|
---|
40 | private String path;
|
---|
41 | private String minVersion;
|
---|
42 | private String maxVersion;
|
---|
43 | private int initialHeapSize;
|
---|
44 | private int maxHeapSize;
|
---|
45 | private String args;
|
---|
46 |
|
---|
47 | public void checkInvariants() {
|
---|
48 | Validator.checkOptString(minVersion, 10, VERSION_PATTERN,
|
---|
49 | "jre.minVersion", Messages.getString("Jre.min.version")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
50 | Validator.checkOptString(maxVersion, 10, VERSION_PATTERN,
|
---|
51 | "jre.maxVersion", Messages.getString("Jre.max.version")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
52 | if (Validator.isEmpty(path)) {
|
---|
53 | Validator.checkFalse(Validator.isEmpty(minVersion),
|
---|
54 | "jre.path", Messages.getString("Jre.specify.jre.path.min.version")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
55 | } else {
|
---|
56 | Validator.checkString(path, Validator.MAX_PATH,
|
---|
57 | "jre.path", Messages.getString("Jre.embedded.path")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
58 | }
|
---|
59 | if (!Validator.isEmpty(maxVersion)) {
|
---|
60 | Validator.checkFalse(Validator.isEmpty(minVersion),
|
---|
61 | "jre.minVersion", Messages.getString("Jre.specify.min.version")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
62 | Validator.checkTrue(minVersion.compareTo(maxVersion) < 0,
|
---|
63 | "jre.maxVersion", Messages.getString("Jre.max.greater.than.min")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
64 | }
|
---|
65 | Validator.checkTrue(initialHeapSize >= 0, "jre.initialHeapSize", //$NON-NLS-1$
|
---|
66 | Messages.getString("Jre.initial.heap")); //$NON-NLS-1$
|
---|
67 | Validator.checkTrue(maxHeapSize == 0 || initialHeapSize <= maxHeapSize,
|
---|
68 | "jre.maxHeapSize", Messages.getString("Jre.max.heap")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
69 | Validator.checkOptString(args, 512, "jre.args", Messages.getString("Jre.jvm.args")); //$NON-NLS-1$ //$NON-NLS-2$
|
---|
70 | if (!Validator.isEmpty(args)) {
|
---|
71 | Validator.checkTrue(args.matches("[^\"]*|([^\"]*\"[^\"]*\"[^\"]*)*"),
|
---|
72 | "jre.args", Messages.getString("Jre.jvm.args.unclosed.quotation"));
|
---|
73 | Validator.checkTrue(args.matches("[^%]*|([^%]*\"([^%]*%[^%]+%[^%]*)+\"[^%]*)*"),
|
---|
74 | "jre.args", Messages.getString("Jre.jvm.args.variable"));
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | /** JVM arguments: XOptions, system properties. */
|
---|
79 | public String getArgs() {
|
---|
80 | return args;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void setArgs(String args) {
|
---|
84 | this.args = args;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /** Max Java version (x.x.x) */
|
---|
88 | public String getMaxVersion() {
|
---|
89 | return maxVersion;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public void setMaxVersion(String maxVersion) {
|
---|
93 | this.maxVersion = maxVersion;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /** Min Java version (x.x.x) */
|
---|
97 | public String getMinVersion() {
|
---|
98 | return minVersion;
|
---|
99 | }
|
---|
100 |
|
---|
101 | public void setMinVersion(String minVersion) {
|
---|
102 | this.minVersion = minVersion;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /** JRE path */
|
---|
106 | public String getPath() {
|
---|
107 | return path;
|
---|
108 | }
|
---|
109 |
|
---|
110 | public void setPath(String path) {
|
---|
111 | this.path = path;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /** Initial heap size in MB */
|
---|
115 | public int getInitialHeapSize() {
|
---|
116 | return initialHeapSize;
|
---|
117 | }
|
---|
118 |
|
---|
119 | public void setInitialHeapSize(int initialHeapSize) {
|
---|
120 | this.initialHeapSize = initialHeapSize;
|
---|
121 | }
|
---|
122 |
|
---|
123 | /** Max heap size in MB */
|
---|
124 | public int getMaxHeapSize() {
|
---|
125 | return maxHeapSize;
|
---|
126 | }
|
---|
127 |
|
---|
128 | public void setMaxHeapSize(int maxHeapSize) {
|
---|
129 | this.maxHeapSize = maxHeapSize;
|
---|
130 | }
|
---|
131 | }
|
---|