Source Code Cross Referenced for WhichResource.java in  » Build » ANT » org » apache » tools » ant » taskdefs » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » ANT » org.apache.tools.ant.taskdefs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.taskdefs;
020:
021:        import org.apache.tools.ant.types.Path;
022:        import org.apache.tools.ant.Task;
023:        import org.apache.tools.ant.BuildException;
024:        import org.apache.tools.ant.Project;
025:        import org.apache.tools.ant.AntClassLoader;
026:
027:        import java.net.URL;
028:
029:        /**
030:         * Find a class or resource on the supplied classpath, or the
031:         * system classpath if none is supplied. The named property is set if
032:         * the item can be found. For example
033:         * <pre>
034:         * &lt;whichresource resource="/log4j.properties"
035:         *   property="log4j.url" &gt;
036:         * </pre>
037:         * @since Ant 1.6
038:         * @ant.attribute.group name="oneof" description="Exactly one of these two"
039:         */
040:        public class WhichResource extends Task {
041:            /**
042:             * our classpath
043:             */
044:            private Path classpath;
045:
046:            /**
047:             * class to look for
048:             */
049:            private String classname;
050:
051:            /**
052:             * resource to look for
053:             */
054:            private String resource;
055:
056:            /**
057:             * property to set
058:             */
059:            private String property;
060:
061:            /**
062:             * Set the classpath to be used for this compilation.
063:             * @param cp the classpath to be used.
064:             */
065:            public void setClasspath(Path cp) {
066:                if (classpath == null) {
067:                    classpath = cp;
068:                } else {
069:                    classpath.append(cp);
070:                }
071:            }
072:
073:            /**
074:             * Adds a path to the classpath.
075:             * @return a classpath to be configured.
076:             */
077:            public Path createClasspath() {
078:                if (classpath == null) {
079:                    classpath = new Path(getProject());
080:                }
081:                return classpath.createPath();
082:            }
083:
084:            /**
085:             * validate
086:             */
087:            private void validate() {
088:                int setcount = 0;
089:                if (classname != null) {
090:                    setcount++;
091:                }
092:                if (resource != null) {
093:                    setcount++;
094:                }
095:
096:                if (setcount == 0) {
097:                    throw new BuildException(
098:                            "One of classname or resource must be specified");
099:                }
100:                if (setcount > 1) {
101:                    throw new BuildException(
102:                            "Only one of classname or resource can be specified");
103:                }
104:                if (property == null) {
105:                    throw new BuildException("No property defined");
106:                }
107:            }
108:
109:            /**
110:             * execute it
111:             * @throws BuildException on error
112:             */
113:            public void execute() throws BuildException {
114:                validate();
115:                if (classpath != null) {
116:                    getProject().log(
117:                            "using user supplied classpath: " + classpath,
118:                            Project.MSG_DEBUG);
119:                    classpath = classpath.concatSystemClasspath("ignore");
120:                } else {
121:                    classpath = new Path(getProject());
122:                    classpath = classpath.concatSystemClasspath("only");
123:                    getProject().log("using system classpath: " + classpath,
124:                            Project.MSG_DEBUG);
125:                }
126:                AntClassLoader loader;
127:                loader = new AntClassLoader(getProject().getCoreLoader(),
128:                        getProject(), classpath, false);
129:                String loc = null;
130:                if (classname != null) {
131:                    //convert a class name into a resource
132:                    resource = classname.replace('.', '/') + ".class";
133:                }
134:
135:                if (resource == null) {
136:                    throw new BuildException(
137:                            "One of class or resource is required");
138:                }
139:
140:                if (resource.startsWith("/")) {
141:                    resource = resource.substring(1);
142:                }
143:
144:                log("Searching for " + resource, Project.MSG_VERBOSE);
145:                URL url;
146:                url = loader.getResource(resource);
147:                if (url != null) {
148:                    //set the property
149:                    loc = url.toExternalForm();
150:                    getProject().setNewProperty(property, loc);
151:                }
152:            }
153:
154:            /**
155:             * name the resource to look for
156:             * @param resource the name of the resource to look for.
157:             * @ant.attribute group="oneof"
158:             */
159:            public void setResource(String resource) {
160:                this .resource = resource;
161:            }
162:
163:            /**
164:             * name the class to look for
165:             * @param classname the name of the class to look for.
166:             * @ant.attribute group="oneof"
167:             */
168:            public void setClass(String classname) {
169:                this .classname = classname;
170:            }
171:
172:            /**
173:             * the property to fill with the URL of the resource or class
174:             * @param property the property to be set.
175:             * @ant.attribute group="required"
176:             */
177:            public void setProperty(String property) {
178:                this.property = property;
179:            }
180:
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.