KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > go > IffOs


1 /**
2  * $Id: IffOs.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2004-2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.go;
30
31 import java.util.List JavaDoc;
32
33 import org.apache.tools.ant.Project;
34 import org.apache.tools.ant.taskdefs.condition.Os;
35
36 import com.idaremedia.antx.helpers.Tk;
37
38 /**
39  * Implementation of the general <i>if-os</i> test for all conditional components.
40  * The <span class="src">IffOs</span> criteria passes if the current Ant runtime's
41  * operating system definition matches the given selection criteria. The selection
42  * criteria is based on the standard Ant <span class="src">&lt;os&gt;</span> condition.
43  *
44  * @since JWare/AntX 0.4
45  * @author ssmc, &copy;2004-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
46  * @version 0.5
47  * @.safety multiple
48  * @.group impl,helper
49  * @.pattern GoF.Strategy
50  * @see Go
51  * @see IffAnt
52  * @see com.idaremedia.antx.parameters.PlatformConditional PlatformConditional
53  **/

54
55 public final class IffOs
56 {
57     /**
58      * Returns <i>true</i> if the current Ant runtime's operating
59      * system definition matches the selection criteria. The general form
60      * of the input string is:
61      * <span class="src">[family|*],[name|*],[arch|*],[version|*]</span>.
62      * Allows selectors like: <pre>
63      * ifOs="windows,*,*,5.0.0.1"
64      * ifOs="unix,*,SunOS"
65      * </pre>
66      * @param string comma-delimited list of selection fields in order
67      * @param P project from which properties read
68      * @param ifNot <i>true</i> if test should be for no-match
69      **/

70     public static boolean pass(String JavaDoc string, Project P, boolean ifNot)
71     {
72         if (Tk.isWhitespace(string)) {
73             return false;
74         }
75
76         string = Tk.resolveString(P,string);
77
78         List JavaDoc l= Tk.splitList(string);
79         String JavaDoc family = l.get(0).toString();
80
81         String JavaDoc next;
82         String JavaDoc name = null;
83         if (l.size()>1) {
84             next = l.get(1).toString();
85             if (!ignore(next)) {
86                 name= next;
87             }
88         }
89         String JavaDoc arch = null;
90         if (l.size()>2) {
91             next= l.get(2).toString();
92             if (!ignore(next)) {
93                 arch = next;
94             }
95         }
96         String JavaDoc vers = null;
97         if (l.size()>3) {
98             next = l.get(3).toString();
99             if (!ignore(next)) {
100                 vers = next;
101             }
102         }
103         boolean is= false;
104         try {
105             is=Os.isOs(family,name,arch,vers);
106         } catch(Exception JavaDoc unknownOS) {
107             /*burp => unknown => isNot */
108         }
109         return ifNot ? !is : is;
110     }
111
112
113     /**
114      * Execute test for an "if-os" conditional parameter.
115      * @since JWare/AntX 0.4
116      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
117      * @version 0.5
118      * @.safety single
119      * @.group impl,helper
120      **/

121     public static final class Is extends Go.TestSkeleton {
122         public Is() {
123         }
124         public Is(String JavaDoc choice) {
125             super(choice);
126         }
127         public boolean pass(Project P) {
128             verifyInited();
129             return IffOs.pass(getParameter(),P,false);
130         }
131         public String JavaDoc getParameterName() {
132             return "ifOS";
133         }
134     }
135
136
137
138     /**
139      * Execute test for an "unless-os" conditional parameter.
140      * @since JWare/AntX 0.4
141      * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
142      * @version 0.5
143      * @.safety single
144      * @.group impl,helper
145      **/

146     public static final class IsNot extends Go.TestSkeleton {
147         public IsNot() {
148         }
149         public IsNot(String JavaDoc choice) {
150             super(choice);
151         }
152         public boolean pass(Project P) {
153             verifyInited();
154             return IffOs.pass(getParameter(),P,true);
155         }
156         public String JavaDoc getParameterName() {
157             return "unlessOS";
158         }
159     }
160
161
162     private static boolean ignore(String JavaDoc s)
163     {
164         return Tk.isWhitespace(s) || "*".equals(s.trim());
165     }
166
167
168     /**
169      * Prevent; only helpers public.
170      **/

171     private IffOs() {
172     }
173 }
174
175 /* end-of-IffOs.java */
176
Popular Tags