ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Portier <...@outerthought.org>
Subject Cleanup for ClasspathUtils
Date Fri, 18 Apr 2003 11:52:55 GMT
Hi there again,

(more background reading in
- http://marc.theaimsgroup.com/?l=ant-dev&m=105006876127852&w=2
- http://issues.apache.org/bugzilla/show_bug.cgi?id=18906)

I'm finally finding the time to get into more of the proposed 
(promised) refactoring of the classloading stuff...

I know there is reworks in that area expected for 1.6 but I'm 
just assuming that work will be easier after some rationalisation 
and refactoring.

This mail is mainly there to let you know what I'm thinking off 
doing (so you get the chance to stop me :-))


1. ClasspathUtils duplicates (i.e. stole) some code from the 
o.a.t.a.taskdefs.Definer: the least I should do is refactor that 
one to now use what is in the ClasspathUtils.


2. ClasspathUtils currently advises people to use it like this:
public void setClasspathRef(Reference r) {
     this.classpathId = r.getRefId();
     createClasspath().setRefid(r);
}
public Path createClasspath() {
     if (this.classpath == null) {
         this.classpath = new Path(getProject());
     }
     return this.classpath.createPath();
}
public void setClassname(String fqcn) {
     this.classname = fqcn;
}

when you actually need the classloading you can just:</p>
ClassLoader cl = ClasspathUtils.getClassLoaderForPath(
                         this.classpath, this.classpathId);
Object o = ClasspathUtils.newInstance(this.classname, cl);


While this is not that much of code I still would like to add to 
this some Helper that does all of this for you, so you're custom 
task or type that needs classloading would just

ClasspathUtil.Helper cpHelper;
public void init(){
     this.cpHelper = ClasspathUtil.getHelper(this);
}
public void setClasspathRef(Reference r) {
     this.cpHelper.setClasspathRef(r);
}
public Path createClasspath() {
     return this.cpHelper.createClasspath();
}
public void setClassname(String fqcn) {
     this.cpHelper.setClassname(fqcn);
}

so when you need the particular instance you just do a

Object o = this.cpHelper.newInstance();


3. Will do a scan of where related stuff is going on
grepping for "ant.reuse.loader" and setClasspath(ref)

$ find -name *.java -exec grep -H ant.reuse.loader {} \;
./proposal/embed/src/java/org/apache/tools/ant/taskdefs/Taskdef2.java
./src/main/org/apache/tools/ant/taskdefs/Definer.java

$ find -name *.java -exec grep -H 'void setClasspath' {} \;
./proposal/embed/src/java/org/apache/tools/ant/taskdefs/SystemPath.java: 
 
./proposal/embed/src/java/org/apache/tools/ant/taskdefs/Taskdef2.java: 
 
./proposal/sandbox/antlib/src/main/org/apache/tools/ant/taskdefs/Antlib.java: 
    ./src/main/org/apache/tools/ant/taskdefs/Available.java: 
./src/main/org/apache/tools/ant/taskdefs/Classloader.java: 
./src/main/org/apache/tools/ant/taskdefs/Definer.java:
./src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java:
./src/main/org/apache/tools/ant/taskdefs/Java.java:
./src/main/org/apache/tools/ant/taskdefs/Javac.java:
./src/main/org/apache/tools/ant/taskdefs/Javadoc.java:
./src/main/org/apache/tools/ant/taskdefs/JDBCTask.java:
./src/main/org/apache/tools/ant/taskdefs/optional/depend/Depend.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/DDCreator.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/Ejbc.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLRun.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/ejb/WLStop.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/IContract.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java: 
    ./src/main/org/apache/tools/ant/taskdefs/optional/Javah.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/jsp/JspC.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/NetRexxC.java: 
 
./src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java: 
    ./src/main/org/apache/tools/ant/taskdefs/Property.java:
./src/main/org/apache/tools/ant/taskdefs/Rmic.java:
./src/main/org/apache/tools/ant/taskdefs/WhichResource.java: 
./src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java: 
./src/main/org/apache/tools/ant/types/AntFilterReader.java: 
./src/main/org/apache/tools/ant/types/Mapper.java: 
./src/main/org/apache/tools/ant/types/selectors/ExtendSelector.java: 
    ./src/main/org/apache/tools/ant/types/XMLCatalog.java:


offering me quite some work-list, but I assume not all of them 
need the same treatement...
(what about these ./proposal things?)


Finally some practical stuff:
- I take it the prefered patch format is cvs -q diff -u -N ?
- tests are currently not working in cvs head (I see a failure on 
the


diving in...
-marc=
-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at              http://radio.weblogs.com/0116284/
mpo@outerthought.org                              mpo@apache.org


Mime
View raw message