View | Details | Raw Unified | Return to bug 40522
Collapse All | Expand All

(-)src/main/org/apache/tools/ant/AntClassLoader.java (-2 / +2 lines)
Lines 261-267 Link Here
261
     *                elements are set up to start with.
261
     *                elements are set up to start with.
262
     */
262
     */
263
    public AntClassLoader(Project project, Path classpath) {
263
    public AntClassLoader(Project project, Path classpath) {
264
        setParent(null);
264
        setParent(project.getCoreLoader());
265
        setProject(project);
265
        setProject(project);
266
        setClassPath(classpath);
266
        setClassPath(classpath);
267
    }
267
    }
Lines 307-313 Link Here
307
     */
307
     */
308
    public AntClassLoader(Project project, Path classpath,
308
    public AntClassLoader(Project project, Path classpath,
309
                          boolean parentFirst) {
309
                          boolean parentFirst) {
310
        this(null, project, classpath, parentFirst);
310
        this(project.getCoreLoader(), project, classpath, parentFirst);
311
    }
311
    }
312
312
313
    /**
313
    /**
(-)src/main/org/apache/tools/ant/ComponentHelper.java (+16 lines)
Lines 264-269 Link Here
264
    }
264
    }
265
265
266
    /**
266
    /**
267
     * Reset the classloaders for those types that have
268
     * not yet been instaniated.
269
     */
270
    protected void resetCoreLoader(
271
        ClassLoader oldLoader, ClassLoader newLoader) {
272
        for (Iterator i = antTypeTable.values().iterator(); i.hasNext();) {
273
            AntTypeDefinition def = (AntTypeDefinition) i.next();
274
            Class clazz = def.getClazz();
275
            ClassLoader loader = def.getClassLoader();
276
            if (clazz == null && (loader == oldLoader)) {
277
                def.setClassLoader(newLoader);
278
            }
279
        }
280
    }
281
    
282
    /**
267
     * This method is initialization code implementing the original ant component
283
     * This method is initialization code implementing the original ant component
268
     * loading from /org/apache/tools/ant/taskdefs/default.properties
284
     * loading from /org/apache/tools/ant/taskdefs/default.properties
269
     * and /org/apache/tools/ant/types/default.properties.
285
     * and /org/apache/tools/ant/types/default.properties.
(-)src/main/org/apache/tools/ant/Project.java (-4 / +20 lines)
Lines 163-172 Link Here
163
    private Vector listeners = new Vector();
163
    private Vector listeners = new Vector();
164
164
165
    /**
165
    /**
166
     * The Ant core classloader--may be <code>null</code> if using
166
     * The Ant core classloader.
167
     * parent classloader.
167
     * This is used for loading in tasks and types.
168
     */
168
     */
169
    private ClassLoader coreLoader = null;
169
    private ClassLoader coreLoader = Project.class.getClassLoader();
170
170
171
    /** Records the latest task to be executed on a thread. */
171
    /** Records the latest task to be executed on a thread. */
172
    private Map/*<Thread,Task>*/ threadTasks = Collections.synchronizedMap(new WeakHashMap());
172
    private Map/*<Thread,Task>*/ threadTasks = Collections.synchronizedMap(new WeakHashMap());
Lines 316-322 Link Here
316
     */
316
     */
317
    public AntClassLoader createClassLoader(Path path) {
317
    public AntClassLoader createClassLoader(Path path) {
318
        return new AntClassLoader(
318
        return new AntClassLoader(
319
            getClass().getClassLoader(), this, path);
319
            getCoreLoader(), this, path);
320
    }
320
    }
321
321
322
    /**
322
    /**
Lines 337-347 Link Here
337
     * Set the core classloader for the project. If a <code>null</code>
337
     * Set the core classloader for the project. If a <code>null</code>
338
     * classloader is specified, the parent classloader should be used.
338
     * classloader is specified, the parent classloader should be used.
339
     *
339
     *
340
     * The coreLoader *must* be able to loader *this* Project class.
340
     * @param coreLoader The classloader to use for the project.
341
     * @param coreLoader The classloader to use for the project.
341
     *                   May be <code>null</code>.
342
     *                   May be <code>null</code>.
342
     */
343
     */
343
    public void setCoreLoader(ClassLoader coreLoader) {
344
    public void setCoreLoader(ClassLoader coreLoader) {
345
        if (coreLoader == null) {
346
            coreLoader = getClass().getClassLoader();
347
        }
348
        try {
349
            Class cl = coreLoader.loadClass(getClass().getName());
350
            if (cl != getClass()) {
351
                throw new BuildException(
352
                    "Invalid coreLoader - it "
353
                    + "returns an incorrect Project.class");
354
            }
355
        } catch (Exception ex) {
356
            throw new BuildException("unable to use coreloader", ex);
357
        }
358
        ComponentHelper.getComponentHelper(this)
359
            .resetCoreLoader(this.coreLoader, coreLoader);
344
        this.coreLoader = coreLoader;
360
        this.coreLoader = coreLoader;
345
    }
361
    }
346
362
(-)src/main/org/apache/tools/ant/taskdefs/Classloader.java (-6 / +8 lines)
Lines 167-173 Link Here
167
            }
167
            }
168
168
169
            AntClassLoader acl = (AntClassLoader) obj;
169
            AntClassLoader acl = (AntClassLoader) obj;
170
171
            if (acl == null) {
170
            if (acl == null) {
172
                // Construct a new class loader
171
                // Construct a new class loader
173
                Object parent = null;
172
                Object parent = null;
Lines 197-204 Link Here
197
196
198
                if (name == null) {
197
                if (name == null) {
199
                    // This allows the core loader to load optional tasks
198
                    // This allows the core loader to load optional tasks
200
                    // without delegating
199
                    // and types without delegating
201
                    acl.addLoaderPackageRoot("org.apache.tools.ant.taskdefs.optional");
200
                    acl.addLoaderPackageRoot(
201
                        "org.apache.tools.ant.taskdefs.optional");
202
                    acl.addLoaderPackageRoot(
203
                        "org.apache.tools.ant.types.optional");
204
                    acl.addLoaderPackageRoot(
205
                        "org.apache.tools.ant.util.optional");
202
                    getProject().setCoreLoader(acl);
206
                    getProject().setCoreLoader(acl);
203
                }
207
                }
204
            }
208
            }
Lines 214-223 Link Here
214
                }
218
                }
215
            }
219
            }
216
220
217
            // XXX add exceptions
218
219
        } catch (Exception ex) {
221
        } catch (Exception ex) {
220
            ex.printStackTrace();
222
            throw new BuildException(ex);
221
        }
223
        }
222
    }
224
    }
223
}
225
}
(-)src/main/org/apache/tools/ant/AntTypeDefinition.java (+7 lines)
Lines 56-62 Link Here
56
    }
56
    }
57
57
58
    /**
58
    /**
59
     * Return the current value of clazz.
60
     */
61
    protected Class getClazz() {
62
        return clazz;
63
    }
64
65
    /**
59
     * Set the class of the definition.
66
     * Set the class of the definition.
60
     * As a side-effect may set the classloader and classname.
67
     * As a side-effect may set the classloader and classname.
61
     * @param clazz the class of this definition.
68
     * @param clazz the class of this definition.
62
69

Return to bug 40522