1 | /*
|
---|
2 | * Copyright 2003-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs;
|
---|
19 |
|
---|
20 | import org.apache.tools.ant.AntClassLoader;
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 | import org.apache.tools.ant.types.Path;
|
---|
24 | import org.apache.tools.ant.types.Reference;
|
---|
25 | import org.apache.tools.ant.util.ClasspathUtils;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Base class for Definitions
|
---|
29 | * handling uri and class loading.
|
---|
30 | * (This was part of Definer)
|
---|
31 | *
|
---|
32 | * @since Ant 1.6
|
---|
33 | */
|
---|
34 | public abstract class DefBase extends AntlibDefinition {
|
---|
35 | private ClassLoader createdLoader;
|
---|
36 | private ClasspathUtils.Delegate cpDelegate;
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * @param reverseLoader if true a delegated loader will take precedence over
|
---|
40 | * the parent
|
---|
41 | * @deprecated stop using this attribute
|
---|
42 | * @ant.attribute ignore="true"
|
---|
43 | */
|
---|
44 | public void setReverseLoader(boolean reverseLoader) {
|
---|
45 | getDelegate().setReverseLoader(reverseLoader);
|
---|
46 | log("The reverseloader attribute is DEPRECATED. It will be removed",
|
---|
47 | Project.MSG_WARN);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @return the classpath for this definition
|
---|
52 | */
|
---|
53 | public Path getClasspath() {
|
---|
54 | return getDelegate().getClasspath();
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * @return the reverse loader attribute of the classpath delegate.
|
---|
59 | */
|
---|
60 | public boolean isReverseLoader() {
|
---|
61 | return getDelegate().isReverseLoader();
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Returns the loader id of the class path Delegate.
|
---|
66 | * @return the loader id
|
---|
67 | */
|
---|
68 | public String getLoaderId() {
|
---|
69 | return getDelegate().getClassLoadId();
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Returns the class path id of the class path delegate.
|
---|
74 | * @return the class path id
|
---|
75 | */
|
---|
76 | public String getClasspathId() {
|
---|
77 | return getDelegate().getClassLoadId();
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Set the classpath to be used when searching for component being defined
|
---|
82 | *
|
---|
83 | * @param classpath an Ant Path object containing the classpath.
|
---|
84 | */
|
---|
85 | public void setClasspath(Path classpath) {
|
---|
86 | getDelegate().setClasspath(classpath);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Create the classpath to be used when searching for component being
|
---|
91 | * defined
|
---|
92 | * @return the classpath of the this definition
|
---|
93 | */
|
---|
94 | public Path createClasspath() {
|
---|
95 | return getDelegate().createClasspath();
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * reference to a classpath to use when loading the files.
|
---|
100 | * To actually share the same loader, set loaderref as well
|
---|
101 | * @param r the reference to the classpath
|
---|
102 | */
|
---|
103 | public void setClasspathRef(Reference r) {
|
---|
104 | getDelegate().setClasspathref(r);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Use the reference to locate the loader. If the loader is not
|
---|
109 | * found, taskdef will use the specified classpath and register it
|
---|
110 | * with the specified name.
|
---|
111 | *
|
---|
112 | * This allow multiple taskdef/typedef to use the same class loader,
|
---|
113 | * so they can be used together. It eliminate the need to
|
---|
114 | * put them in the CLASSPATH.
|
---|
115 | *
|
---|
116 | * @param r the reference to locate the loader.
|
---|
117 | * @since Ant 1.5
|
---|
118 | */
|
---|
119 | public void setLoaderRef(Reference r) {
|
---|
120 | getDelegate().setLoaderRef(r);
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * create a classloader for this definition
|
---|
125 | * @return the classloader from the cpDelegate
|
---|
126 | */
|
---|
127 | protected ClassLoader createLoader() {
|
---|
128 | if (getAntlibClassLoader() != null && cpDelegate == null) {
|
---|
129 | return getAntlibClassLoader();
|
---|
130 | }
|
---|
131 | if (cpDelegate == null) {
|
---|
132 | cpDelegate = ClasspathUtils.getDelegate(this);
|
---|
133 | }
|
---|
134 | if (createdLoader == null) {
|
---|
135 | createdLoader = cpDelegate.getClassLoader();
|
---|
136 | // need to load Task via system classloader or the new
|
---|
137 | // task we want to define will never be a Task but always
|
---|
138 | // be wrapped into a TaskAdapter.
|
---|
139 | ((AntClassLoader) createdLoader)
|
---|
140 | .addSystemPackageRoot("org.apache.tools.ant");
|
---|
141 | }
|
---|
142 | return createdLoader;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * @see org.apache.tools.ant.Task#init()
|
---|
147 | * @since Ant 1.6
|
---|
148 | */
|
---|
149 | public void init() throws BuildException {
|
---|
150 | super.init();
|
---|
151 | }
|
---|
152 |
|
---|
153 | private ClasspathUtils.Delegate getDelegate() {
|
---|
154 | if (cpDelegate == null) {
|
---|
155 | cpDelegate = ClasspathUtils.getDelegate(this);
|
---|
156 | }
|
---|
157 | return cpDelegate;
|
---|
158 | }
|
---|
159 | }
|
---|