source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/input/TargetInput.java@ 17581

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

made the hidden attribute work

File size: 5.7 KB
Line 
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 */
16package org.tp23.antinstaller.input;
17
18
19import org.tp23.antinstaller.InstallerContext;
20import 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 */
53public 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 boolean getHidden() {
99 return this.hidden;
100 }
101
102 public void setHidden(String hidden) {
103 this.hidden = hidden.equals("true");
104 }
105
106 public String getForce() {
107 return force;
108 }
109
110 public void setForce(String force) {
111 this.force = force;
112 }
113
114 public String getStrict() {
115 return strict;
116 }
117
118 public void setStrict(String strict) {
119 this.strict = strict;
120 }
121
122 public String getOsSpecific() {
123 return osSpecific;
124 }
125
126 public void setOsSpecific(String osSpecific) {
127 this.osSpecific = osSpecific;
128 }
129
130 public String getDiskRequirement() {
131 return diskRequirement;
132 }
133
134 /**
135 * Called to validate the user input
136 */
137 public boolean validate(InstallerContext cxt) throws ValidationException {
138 //setInputResult(target);
139 return true;
140 }
141
142
143
144 /**
145 * Used by checkConfig to validate the configuration file.
146 * Not used at runtime.
147 * @return boolean
148 */
149 public boolean validateObject() {
150 if(getDisplayText()==null){
151 System.out.println("Target:displayText must be set");
152 return false;
153 }
154 if(getTarget()==null){
155 System.out.println("Target:target must be set");
156 return false;
157 }
158// if(getTarget().equals("default")){
159// System.out.println("Target:target can not be \"default\"");
160// return false;
161// }
162 if(!InputField.optionalBoolean(getForce())){
163 System.out.println("Target:force must be true or false or null");
164 return false;
165 }
166 if(!InputField.optionalBoolean(getStrict())){
167 System.out.println("Target:strict must be true or false or null");
168 return false;
169 }
170 if(!InputField.optionalBoolean(getOsSpecific())){
171 System.out.println("Target:osSpecific must be true or false or null");
172 return false;
173 }
174 if(!InputField.requiredBoolean(getDefaultValue())){
175 System.out.println("Target:defaultValue must be true or false");
176 return false;
177 }
178 return true;
179 }
180 public int getIdx() {
181 return idx;
182 }
183 public static int getGlobalIdx() {
184 return globalIdx++;
185 }
186
187 public String getOSSpecificTarget() {
188 if(isTrue(strict)){
189 return getStrictTarget();
190 }
191 else return getLaxTarget();
192 }
193
194 private String getStrictTarget(){
195 return target + getOsSpecificSuffix();
196 }
197
198 private String getLaxTarget(){
199 return target + getLaxOsSpecificSuffix();
200 }
201
202 /**
203 * N.B. should have added a "-" but to late to change now and not important
204 * @return
205 */
206 public static String getOsSpecificSuffix(){
207 return System.getProperty("os.name");
208 }
209 public static String getLaxOsSpecificSuffix(){
210 String osName = System.getProperty("os.name").toLowerCase();
211 if(osName.indexOf("linux") != -1){
212 return "-linux";
213 }
214 if(osName.indexOf("mac") != -1){
215 return "-mac";
216 }
217 if(osName.indexOf("windows") != -1){
218 return "-win";
219 }
220 if(osName.indexOf("solaris") != -1 || osName.indexOf("sunos") != -1){
221 return "-sun";
222 }
223 return "-other";
224
225 }
226}
Note: See TracBrowser for help on using the repository browser.