source: other-projects/trunk/realistic-books/packages/AntInstaller/src/org/tp23/antinstaller/input/TargetInput.java@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

File size: 5.4 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
65 private static int globalIdx = 1;
66
67 public TargetInput() {
68 idx = getGlobalIdx();
69 }
70
71 public String getTarget() {
72 if(isTrue(osSpecific)){
73 return getOSSpecificTarget();
74 } else {
75 return target;
76 }
77 }
78
79 /**
80 * Used to fetch the target value that was set in the config file
81 * @return
82 */
83 public String getTargetName() {
84 return target;
85 }
86
87 public void setTarget(String target) {
88 this.target = target;
89 setProperty(target);
90 }
91
92 public String getForce() {
93 return force;
94 }
95
96 public void setForce(String force) {
97 this.force = force;
98 }
99
100
101 public String getStrict() {
102 return strict;
103 }
104
105 public void setStrict(String strict) {
106 this.strict = strict;
107 }
108
109 public String getOsSpecific() {
110 return osSpecific;
111 }
112
113 public void setOsSpecific(String osSpecific) {
114 this.osSpecific = osSpecific;
115 }
116
117 /**
118 * Called to validate the user input
119 */
120 public boolean validate(InstallerContext cxt) throws ValidationException {
121 //setInputResult(target);
122 return true;
123 }
124
125
126
127 /**
128 * Used by checkConfig to validate the configuration file.
129 * Not used at runtime.
130 * @return boolean
131 */
132 public boolean validateObject() {
133 if(getDisplayText()==null){
134 System.out.println("Target:displayText must be set");
135 return false;
136 }
137 if(getTarget()==null){
138 System.out.println("Target:target must be set");
139 return false;
140 }
141// if(getTarget().equals("default")){
142// System.out.println("Target:target can not be \"default\"");
143// return false;
144// }
145 if(!InputField.optionalBoolean(getForce())){
146 System.out.println("Target:force must be true or false or null");
147 return false;
148 }
149 if(!InputField.optionalBoolean(getStrict())){
150 System.out.println("Target:strict must be true or false or null");
151 return false;
152 }
153 if(!InputField.optionalBoolean(getOsSpecific())){
154 System.out.println("Target:osSpecific must be true or false or null");
155 return false;
156 }
157 if(!InputField.requiredBoolean(getDefaultValue())){
158 System.out.println("Target:defaultValue must be true or false");
159 return false;
160 }
161 return true;
162 }
163 public int getIdx() {
164 return idx;
165 }
166 public static int getGlobalIdx() {
167 return globalIdx++;
168 }
169
170 public String getOSSpecificTarget() {
171 if(isTrue(strict)){
172 return getStrictTarget();
173 }
174 else return getLaxTarget();
175 }
176
177 private String getStrictTarget(){
178 return target + getOsSpecificSuffix();
179 }
180
181 private String getLaxTarget(){
182 return target + getLaxOsSpecificSuffix();
183 }
184
185 /**
186 * N.B. should have added a "-" but to late to change now and not important
187 * @return
188 */
189 public static String getOsSpecificSuffix(){
190 return System.getProperty("os.name");
191 }
192 public static String getLaxOsSpecificSuffix(){
193 String osName = System.getProperty("os.name").toLowerCase();
194 if(osName.indexOf("linux") != -1){
195 return "-linux";
196 }
197 if(osName.indexOf("mac") != -1){
198 return "-mac";
199 }
200 if(osName.indexOf("windows") != -1){
201 return "-win";
202 }
203 if(osName.indexOf("solaris") != -1 || osName.indexOf("sunos") != -1){
204 return "-sun";
205 }
206 return "-other";
207
208 }
209}
Note: See TracBrowser for help on using the repository browser.