KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > AntX


1 /**
2  * $Id: AntX.java 187 2007-03-25 17:59:16Z ssmc $
3  * Copyright 2002-2004,2007 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 as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * 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 (GNU Lesser General Public License) 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 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://antxtras.sf.net/ EMAIL- jware[at]users[dot]sourceforge[dot]net
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx;
30
31 import org.apache.tools.ant.Main;
32
33 import com.idaremedia.apis.BundleStringManager;
34 import com.idaremedia.apis.UIStringManager;
35 import com.idaremedia.antx.helpers.Strings;
36 import com.idaremedia.antx.helpers.Tk;
37
38 /**
39  * Collection of common AntX properties and constants.
40  *
41  * @since JWare/AntX 0.1
42  * @author ssmc, &copy;2002-2004,2007 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
43  * @version 0.5.1
44  * @.safety multiple
45  * @.group impl,helper
46  **/

47
48 public final class AntX
49 {
50 //----------------------------------------------------------------------------------------
51
// Package and configuration identifiers
52
//----------------------------------------------------------------------------------------
53
/**
54      * A fallback name of <i>AntX</i> package(s) when buildstrs and other localized
55      * resource information is unavailable. Useful for diagnostics.
56      **/

57     public static final String JavaDoc ANTX_FALLBACK_NAME =
58         "JWare.AntX";
59
60
61     /**
62      * The standard package prefix for this <i>AntX</i> implementation.
63      * Defined as "<i>com.idaremedia.antx</i>".
64      **/

65     public static final String JavaDoc ANTX_PACKAGE_PREFIX=
66         "com.idaremedia.antx";
67
68
69     /**
70      * The default prefix for <i>AntX</i> configuration properties; usually
71      * "<i>jware.antx</i>". Properties within class-specific files are not
72      * required to have this prefix. However, if the property can be specified
73      * on the command-line it must have this identifying prefix.
74      **/

75     public static final String JavaDoc ANTX_CONFIG_ID =
76         "jware.antx";
77
78
79     /**
80      * The default prefix for internal <i>AntX</i> configuration properties.
81      * These properties are between AntX class implementations; they should
82      * not be defined or modified by user scripts.
83      **/

84     public static final String JavaDoc ANTX_INTERNAL_ID =
85         ANTX_CONFIG_ID+".internal_.";
86
87
88 //----------------------------------------------------------------------------------------
89
// AntX configuration properties (all fully qualified property names)
90
//----------------------------------------------------------------------------------------
91

92     /** Property for default AntX noise-level. **/
93     public final static String JavaDoc DEFAULT_NOISELEVEL_PROP =
94         ANTX_CONFIG_ID+".noiselevel";
95
96
97     /** Property for default AntX logging category id. **/
98     public final static String JavaDoc DEFAULT_ROOT_CATEGORY_PROP =
99         ANTX_CONFIG_ID+".root.category";
100
101
102     /** Property for a default root UIStringManager's bundle. **/
103     public final static String JavaDoc DEFAULT_UISTRS_BUNDLE_PROP =
104         ANTX_CONFIG_ID+".default.messages.bundle";
105
106
107     /** Property for whether properties checked for msgids. **/
108     public final static String JavaDoc PROPERTY_MSGIDS_PROP =
109         ANTX_CONFIG_ID+".allow.property.msgids";
110
111
112     /** Property for default AntX temporary file-system object prefix. **/
113     public final static String JavaDoc DEFAULT_TEMPOBJECT_PREFIX_PROP =
114         ANTX_CONFIG_ID+".tempobject.prefix";
115
116
117     /** Property for default false &lt;prefer&gt; warnings. **/
118     public final static String JavaDoc PROPERTY_FALSE_PREFER_NOISELEVEL_PROP =
119         ANTX_CONFIG_ID+".noiselevel.false.prefers";
120
121
122     /** Property to control whether AntX tasks verify content on load. **/
123     public final static String JavaDoc STRICT_SCRIPTCHECK_PROP=
124         ANTX_CONFIG_ID+".strict.scriptcheck.enabled";
125
126
127 //----------------------------------------------------------------------------------------
128
// AntX defaults for required configuration properties (source shouldn't use other)
129
//----------------------------------------------------------------------------------------
130

131     /** The default diagnostics and other message noise level (<i>info</i>). **/
132     public final static String JavaDoc DEFAULT_NOISELEVEL = "info";
133
134     /** The default <em>client</em> UIStrings resource bundle name. **/
135     public final static String JavaDoc DEFAULT_UISTRS_RESOURCEBUNDLE =
136         ANTX_CONFIG_ID+".UIStrings";
137
138     /** The default delimiter used in delimited string lists. **/
139     public final static String JavaDoc DEFAULT_DELIMITER= ",";
140
141
142 //----------------------------------------------------------------------------------------
143
// AntX Tracing/Assertion categories
144
//----------------------------------------------------------------------------------------
145

146     /** Top of JWare's AntX namespace for error messages and assertions. **/
147     public final static String JavaDoc AntX= ANTX_FALLBACK_NAME+".";
148
149     /** AntX's "no-package" module identifier. **/
150     public final static String JavaDoc nopackage= AntX+"core";
151
152     /** AntX's UISM sub-module identifier. **/
153     public final static String JavaDoc uism= AntX+"uism.";
154
155     /** AntX's rules sub-module identifier. **/
156     public final static String JavaDoc rules= AntX+"rules.";
157
158     /** AntX's rules conditions sub-module identifier. **/
159     public final static String JavaDoc conditions= rules+"conditions.";
160     
161     /** AntX's rules capture module identifier.
162      * @since JWare/AntX 0.5
163      **/

164     public final static String JavaDoc capture= rules+"capture.";
165
166     /** AntX's flow-control module identifier. **/
167     public final static String JavaDoc flow= AntX+"flowcontrol.";
168
169     /** AntX's print sub-module identifier. **/
170     public final static String JavaDoc print= AntX+"print.";
171
172     /** AntX's mktemp helpers sub-module identifier. **/
173     public final static String JavaDoc mktemp= AntX+"mktemp.";
174
175     /** AntX's starters sub-module identifier. **/
176     public final static String JavaDoc starters= AntX+"starters.";
177
178     /** AntX's feedback (emit) module identifier. **/
179     public final static String JavaDoc feedback= AntX+"feedback.";
180
181     /** AntX's general utilities group identifier.
182      * @since JWare/AntX 0.4
183      **/

184     public final static String JavaDoc utilities= AntX+"helpers.";
185
186     /** AntX's general fixture element group identifier.
187      * @since JWare/AntX 0.5
188      **/

189     public final static String JavaDoc fixture= AntX+"fixture.";
190
191     /** AntX's artifacts module identifier.
192      * @since JWare/AntX 0.4
193      **/

194     public final static String JavaDoc artifacts= AntX+"artifacts.";
195
196
197 //----------------------------------------------------------------------------------------
198
// AntX (project) fixed UI-Strings
199
//----------------------------------------------------------------------------------------
200

201     private static UIStringManager sm_UISM=
202         new BundleStringManager(ANTX_PACKAGE_PREFIX+".uistrs.UIStrings");
203
204
205     /**
206      * Returns instance of the <em>internal JWare/AntX</em> UIStringManager.
207      * This manager is <em>not</em> controlled by any task's 'msgid' attribute
208      * or otherwise. The underlying bundle is part of the AntX class package.
209      **/

210     public static final UIStringManager uistrs()
211     {
212         return sm_UISM;
213     }
214
215
216
217     /**
218      * Msgid of common "clone is really broken" associated with Cloneables
219      * capturing a CloneNotSupportedException. Should never happen, but&#46;&#46;&#46;
220      **/

221     public static final String JavaDoc CLONE_BROKEN_MSGID= "cv.clone.broken";
222
223
224
225     /**
226      * True if AntX tasks should verify themselves (or their contents)
227      * as they're being created instead of just before they're executed.
228      * Defaults <i>false</i>. This property is to counteract Ant 1.6+
229      * mapping of <em>all</em> script elements to UnknownElement
230      * placeholders until just before execution or referenced.
231      * @since JWare/AntX 0.4
232      * @see #STRICT_SCRIPTCHECK_PROP
233      **/

234     public static final boolean STRICT_SCRIPTS;
235     
236     /**
237      * True if the current Ant runtime is pre-1&#46;7 (a 1&#46;6 variant).
238      * @since JWare/AntXtras 0.5.1
239      */

240     public static final boolean ANT_PRE17;
241     
242     /**
243      * Contains the current Ant runtime's version string as best we can
244      * determine with explicitly reading the version information ourselves.
245      * @since JWare/AntXtras 0.5.1
246      */

247     public static final String JavaDoc ANT_VERSIONSTRING;
248
249     static {
250         //NB:This is fracking hack to deal with Ant's inability to make up its
251
// mind regarding build file parsing and component initialization!
252
boolean pre17=false;
253         String JavaDoc versionstring= Strings.UNDEFINED;
254         String JavaDoc av = Main.getAntVersion();
255         if (av.indexOf("version 1.6")>0) {
256             pre17 = true;
257         }
258         final int _0 = av.indexOf("Ant version ");
259         final int _n = av.indexOf(" compiled");
260         if (_0>=0 && _n>0) {
261             versionstring = av.substring(_0+"Ant version ".length(),_n);
262         }
263         String JavaDoc s = System.getProperty(STRICT_SCRIPTCHECK_PROP);
264         if (s!=null) {
265             STRICT_SCRIPTS = Tk.booleanFrom(s);
266         } else {
267             STRICT_SCRIPTS = true; //Ant 1.6,1.7
268
}
269         ANT_PRE17 = pre17;
270         ANT_VERSIONSTRING = versionstring;
271     }
272
273
274
275     /**
276      * Throws an illegal argument exception if a pre-condition
277      * is not met.
278      * @param c the pre-condition
279      * @param msg [optional] failure message (if not met)
280      * @throws IllegalArgumentException if condition not met
281      * @since JWare/AntX 0.4
282      **/

283     public static final void require_(boolean c, String JavaDoc iam, String JavaDoc msg)
284     {
285         if (!c) {
286             String JavaDoc ermsg = uistrs().get("cv.require",iam,msg);
287             throw new IllegalArgumentException JavaDoc(ermsg);
288         }
289     }
290
291
292
293
294     /**
295      * Throws an illegal state exception if condition is not met.
296      * Used for block and invariant verification.
297      * @param c condition
298      * @param msg [optional] failure message (if not met)
299      * @throws IllegalStateException if condition not met
300      * @since JWare/AntX 0.4
301      **/

302     public static final void verify_(boolean c, String JavaDoc iam, String JavaDoc msg)
303     {
304         if (!c) {
305             String JavaDoc ermsg = uistrs().get("cv.verify",iam,msg);
306             throw new IllegalStateException JavaDoc(ermsg);
307         }
308     }
309
310
311
312     /** -- nope nope -- prevent construction of any instances -- **/
313     private AntX() { }
314 }
315
316 /* end-of-AntX.java */
317
Popular Tags