1
16package org.tp23.antinstaller.input;
17
18
19import org.tp23.antinstaller.InstallerContext;
20import org.tp23.antinstaller.ValidationException;
21
22
23
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 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
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
00
01 public String getStrict() {
02 return strict;
03 }
04
05 public void setStrict(String strict) {
06 this.strict = strict;
07 }
08
09 public String getOsSpecific() {
10 return osSpecific;
11 }
12
13 public void setOsSpecific(String osSpecific) {
14 this.osSpecific = osSpecific;
15 }
16
17
20 public boolean validate(InstallerContext cxt) throws ValidationException {
21 return true;
23 }
24
25
26
27
32 public boolean validateObject() {
33 if(getDisplayText()==null){
34 System.out.println("Target:displayText must be set");
35 return false;
36 }
37 if(getTarget()==null){
38 System.out.println("Target:target must be set");
39 return false;
40 }
41 if(!InputField.optionalBoolean(getForce())){
46 System.out.println("Target:force must be true or false or null");
47 return false;
48 }
49 if(!InputField.optionalBoolean(getStrict())){
50 System.out.println("Target:strict must be true or false or null");
51 return false;
52 }
53 if(!InputField.optionalBoolean(getOsSpecific())){
54 System.out.println("Target:osSpecific must be true or false or null");
55 return false;
56 }
57 if(!InputField.requiredBoolean(getDefaultValue())){
58 System.out.println("Target:defaultValue must be true or false");
59 return false;
60 }
61 return true;
62 }
63 public int getIdx() {
64 return idx;
65 }
66 public static int getGlobalIdx() {
67 return globalIdx++;
68 }
69
70 public String getOSSpecificTarget() {
71 if(isTrue(strict)){
72 return getStrictTarget();
73 }
74 else return getLaxTarget();
75 }
76
77 private String getStrictTarget(){
78 return target + getOsSpecificSuffix();
79 }
80
81 private String getLaxTarget(){
82 return target + getLaxOsSpecificSuffix();
83 }
84
85
89 public static String getOsSpecificSuffix(){
90 return System.getProperty("os.name");
91 }
92 public static String getLaxOsSpecificSuffix(){
93 String osName = System.getProperty("os.name").toLowerCase();
94 if(osName.indexOf("linux") != -1){
95 return "-linux";
96 }
97 if(osName.indexOf("mac") != -1){
98 return "-mac";
99 }
00 if(osName.indexOf("windows") != -1){
01 return "-win";
02 }
03 if(osName.indexOf("solaris") != -1 || osName.indexOf("sunos") != -1){
04 return "-sun";
05 }
06 return "-other";
07
08 }
09}
10