KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > antutils > AntProject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.output.antutils;
21
22 import java.io.File JavaDoc;
23 import org.apache.tools.ant.module.spi.AntEvent;
24 import org.netbeans.modules.junit.output.antutils.FileUtils;
25 import org.openide.filesystems.FileUtil;
26
27 /**
28  *
29  * @author Marian Petras
30  */

31 public final class AntProject {
32
33     /** {@code AntEvent} which serves for evaluation of Ant properties */
34     private final AntEvent event;
35     /** project's base directory. */
36     private final File JavaDoc baseDir;
37     
38     /**
39      * Constructor used only in tests.
40      */

41     AntProject() {
42         event = null;
43         baseDir = null;
44     }
45
46     /**
47      */

48     public AntProject(AntEvent event) {
49         this.event = event;
50         String JavaDoc baseDirName = getProperty("basedir"); //NOI18N
51
if (baseDirName == null) {
52             baseDirName = "."; //NOI18N
53
}
54         baseDir = FileUtil.normalizeFile(new File JavaDoc(baseDirName));
55     }
56
57     /**
58      */

59     public String JavaDoc getProperty(String JavaDoc propertyName) {
60         return event.getProperty(propertyName);
61     }
62
63     /**
64      */

65     public String JavaDoc replaceProperties(String JavaDoc value) {
66         return event.evaluate(value);
67     }
68
69     /**
70      */

71     public File JavaDoc resolveFile(String JavaDoc fileName) {
72         return FileUtils.resolveFile(baseDir, fileName);
73     }
74
75     /**
76      * Return the boolean equivalent of a string, which is considered
77      * {@code true} if either {@code "on"}, {@code "true"},
78      * or {@code "yes"} is found, ignoring case.
79      *
80      * @param s string to convert to a boolean value
81      *
82      * @return {@code true} if the given string is {@code "on"}, {@code "true"}
83      * or {@code "yes"}; or {@ code false} otherwise.
84      */

85     public static boolean toBoolean(String JavaDoc s) {
86         return ("on".equalsIgnoreCase(s) //NOI18N
87
|| "true".equalsIgnoreCase(s) //NOI18N
88
|| "yes".equalsIgnoreCase(s)); //NOI18N
89
}
90
91 }
92
Popular Tags