1 | /*
|
---|
2 | * Copyright 2005 Paul Hinds
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 | package org.tp23.antinstaller.input;
|
---|
17 |
|
---|
18 |
|
---|
19 | import org.tp23.antinstaller.InstallerContext;
|
---|
20 | import org.tp23.antinstaller.ValidationException;
|
---|
21 |
|
---|
22 |
|
---|
23 | /**
|
---|
24 | *
|
---|
25 | * <p>Input type to select targets to install </p>
|
---|
26 | * If the osSpecific flag is set the OS of the current system will
|
---|
27 | * be appended to the name of the target actually by ant run so that different
|
---|
28 | * Targets can be run according to the target platform.
|
---|
29 | * This feature goes against the principles of
|
---|
30 | * building cross platform installers, but is provided so that common installer
|
---|
31 | * tasks such as creating icons and shortcuts can be run on Windows for
|
---|
32 | * all those useless users who can't run a command script ;)
|
---|
33 | * <br>
|
---|
34 | * Currently there are two modes strict and not strict (lax).</p>
|
---|
35 | * <p>Strict target will return the target name plus the exact String in the
|
---|
36 | * System Property "os.name" this means you will have to provide targets for
|
---|
37 | * every possible OS version. See
|
---|
38 | * <a href="http://lopica.sourceforge.net/os.html">this page</a> for a list of possible values
|
---|
39 | * There are a great many but you may not want to consider some of the options.</p>
|
---|
40 | * <p>Lax target will return one of the following strings only
|
---|
41 | * <ul>
|
---|
42 | * <li>"[target-name]-linux" - Linux </li>
|
---|
43 | * <li>"[target-name]-mac" - Mac OS and Mac OS X</li>
|
---|
44 | * <li>"[target-name]-sun" - SunOS and Solaris</li>
|
---|
45 | * <li>"[target-name]-win" - Windows *</li>
|
---|
46 | * <li>"[target-name]-other" - any thing else</li>
|
---|
47 | * </ul></p> so you only have to create 5 ant targets to support all the cases.
|
---|
48 | * <p>Copyright: Copyright (c) 2004</p>
|
---|
49 | * <p>Company: tp23</p>
|
---|
50 | * @author Paul Hinds
|
---|
51 | * @version $Id: TargetInput.java,v 1.3 2006/12/07 02:42:22 teknopaul Exp $
|
---|
52 | */
|
---|
53 | public class TargetInput
|
---|
54 | extends InputField
|
---|
55 | implements Target{
|
---|
56 |
|
---|
57 |
|
---|
58 | private String target;
|
---|
59 | private String force;
|
---|
60 | private String osSpecific;
|
---|
61 | private String strict;
|
---|
62 | //targets are ordered
|
---|
63 | private int idx;
|
---|
64 | private String diskRequirement;
|
---|
65 | private boolean hidden;
|
---|
66 |
|
---|
67 | private static int globalIdx = 1;
|
---|
68 |
|
---|
69 | public TargetInput() {
|
---|
70 | idx = getGlobalIdx();
|
---|
71 | }
|
---|
72 |
|
---|
73 | public String getTarget() {
|
---|
74 | if(isTrue(osSpecific)){
|
---|
75 | return getOSSpecificTarget();
|
---|
76 | } else {
|
---|
77 | return target;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Used to fetch the target value that was set in the config file
|
---|
83 | * @return
|
---|
84 | */
|
---|
85 | public String getTargetName() {
|
---|
86 | return target;
|
---|
87 | }
|
---|
88 |
|
---|
89 | public void setTarget(String target) {
|
---|
90 | this.target = target;
|
---|
91 | setProperty(target);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void setDiskRequirement(String diskRequirement) {
|
---|
95 | this.diskRequirement = diskRequirement;
|
---|
96 | }
|
---|
97 |
|
---|
98 | public void setHidden(String hidden) {
|
---|
99 | this.hidden = hidden.equals("true");
|
---|
100 | }
|
---|
101 |
|
---|
102 | public String getForce() {
|
---|
103 | return force;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void setForce(String force) {
|
---|
107 | this.force = force;
|
---|
108 | }
|
---|
109 |
|
---|
110 | public String getStrict() {
|
---|
111 | return strict;
|
---|
112 | }
|
---|
113 |
|
---|
114 | public void setStrict(String strict) {
|
---|
115 | this.strict = strict;
|
---|
116 | }
|
---|
117 |
|
---|
118 | public String getOsSpecific() {
|
---|
119 | return osSpecific;
|
---|
120 | }
|
---|
121 |
|
---|
122 | public void setOsSpecific(String osSpecific) {
|
---|
123 | this.osSpecific = osSpecific;
|
---|
124 | }
|
---|
125 |
|
---|
126 | public String getDiskRequirement() {
|
---|
127 | return diskRequirement;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Called to validate the user input
|
---|
132 | */
|
---|
133 | public boolean validate(InstallerContext cxt) throws ValidationException {
|
---|
134 | //setInputResult(target);
|
---|
135 | return true;
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Used by checkConfig to validate the configuration file.
|
---|
142 | * Not used at runtime.
|
---|
143 | * @return boolean
|
---|
144 | */
|
---|
145 | public boolean validateObject() {
|
---|
146 | if(getDisplayText()==null){
|
---|
147 | System.out.println("Target:displayText must be set");
|
---|
148 | return false;
|
---|
149 | }
|
---|
150 | if(getTarget()==null){
|
---|
151 | System.out.println("Target:target must be set");
|
---|
152 | return false;
|
---|
153 | }
|
---|
154 | // if(getTarget().equals("default")){
|
---|
155 | // System.out.println("Target:target can not be \"default\"");
|
---|
156 | // return false;
|
---|
157 | // }
|
---|
158 | if(!InputField.optionalBoolean(getForce())){
|
---|
159 | System.out.println("Target:force must be true or false or null");
|
---|
160 | return false;
|
---|
161 | }
|
---|
162 | if(!InputField.optionalBoolean(getStrict())){
|
---|
163 | System.out.println("Target:strict must be true or false or null");
|
---|
164 | return false;
|
---|
165 | }
|
---|
166 | if(!InputField.optionalBoolean(getOsSpecific())){
|
---|
167 | System.out.println("Target:osSpecific must be true or false or null");
|
---|
168 | return false;
|
---|
169 | }
|
---|
170 | if(!InputField.requiredBoolean(getDefaultValue())){
|
---|
171 | System.out.println("Target:defaultValue must be true or false");
|
---|
172 | return false;
|
---|
173 | }
|
---|
174 | return true;
|
---|
175 | }
|
---|
176 | public int getIdx() {
|
---|
177 | return idx;
|
---|
178 | }
|
---|
179 | public static int getGlobalIdx() {
|
---|
180 | return globalIdx++;
|
---|
181 | }
|
---|
182 |
|
---|
183 | public String getOSSpecificTarget() {
|
---|
184 | if(isTrue(strict)){
|
---|
185 | return getStrictTarget();
|
---|
186 | }
|
---|
187 | else return getLaxTarget();
|
---|
188 | }
|
---|
189 |
|
---|
190 | private String getStrictTarget(){
|
---|
191 | return target + getOsSpecificSuffix();
|
---|
192 | }
|
---|
193 |
|
---|
194 | private String getLaxTarget(){
|
---|
195 | return target + getLaxOsSpecificSuffix();
|
---|
196 | }
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * N.B. should have added a "-" but to late to change now and not important
|
---|
200 | * @return
|
---|
201 | */
|
---|
202 | public static String getOsSpecificSuffix(){
|
---|
203 | return System.getProperty("os.name");
|
---|
204 | }
|
---|
205 | public static String getLaxOsSpecificSuffix(){
|
---|
206 | String osName = System.getProperty("os.name").toLowerCase();
|
---|
207 | if(osName.indexOf("linux") != -1){
|
---|
208 | return "-linux";
|
---|
209 | }
|
---|
210 | if(osName.indexOf("mac") != -1){
|
---|
211 | return "-mac";
|
---|
212 | }
|
---|
213 | if(osName.indexOf("windows") != -1){
|
---|
214 | return "-win";
|
---|
215 | }
|
---|
216 | if(osName.indexOf("solaris") != -1 || osName.indexOf("sunos") != -1){
|
---|
217 | return "-sun";
|
---|
218 | }
|
---|
219 | return "-other";
|
---|
220 |
|
---|
221 | }
|
---|
222 | }
|
---|