[Help] antclipse enhancement

SourceForge.net <[email protected]> Fri, 16 Dec 2011 10:02:49 -0800
Newsgroups gmane.comp.java.ant-contrib.devel
Message-ID <[email protected]>
The following forum message was posted by duccio1969 at http://sourceforge.net/projects/ant-contrib/forums/forum/113701/topic/4886029:

I,
recently I had to modify the antclipse code of version [b]1.0b3[/b]: I would
like to explain here what I did and why.

I'm working on a quite big project that has been split into subprojects: the
structure of the main folders is like this:

|-- gsd_base/.classpath
|-- ...
`-- gsd_ef/.classpath

the content of gsd_base/.classpath is 
[code]
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="[b]src[/b]" path="src/java"/>
    <classpathentry kind="[b]src[/b]" path="src/conf"/>
    <classpathentry kind="[b]src[/b]" output="target/test-classes"
path="src/test"/>
    <classpathentry exported="true" kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry exported="true" kind="var"
path="MAVEN_REPO/junit/jars/junit-4.10.jar"
sourcepath="/MAVEN_REPO/junit/jars/junit-4.10-src.jar"/>
...
    <classpathentry kind="output" path="target/classes"/>
</classpath>
[/code]

while the content of gsd_ef/.classpath is
[code]
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/java"/>
    <classpathentry kind="src" path="src/conf"/>
...
    <classpathentry kind="lib"
path="/home/duccio/.maven/repository/xerces/jars/xml-apis-2.5.0.jar"/>
    <classpathentry kind="lib"
path="/home/duccio/.maven/repository/xmlunit/jars/xmlunit-1.3.jar"/>
    [b]<classpathentry combineaccessrules="false" kind="src"
path="/gsd_base"/>[/b]
    <classpathentry kind="output" path="target/classes"/>
</classpath>
[/code]

in this case,  antclipse did not work for me, because it did not understand
the "src" kind and the "inter project" classpath entry (in bold). I was able
to make antclipse working patching the file ClassPathTask.java (for [b]1.0b3[/b]
version), here is the output of the [i]diff[/i] command:

[code]
17a18,19
> import java.util.ArrayList;
> import java.util.List;
51a54
> 	protected List recursivePaths = new ArrayList(); //modified by d.v.: avoid
double-processing
180a184
> 		protected static final String ATTR_VAR = "var"; //by d.v.: I need to manage
also eclipse variables
376a381,402
> 				
> 				/* d.v.: do variable replacement: into my ANT build.xml file I use a <property
file="" /> tag
>                  * to set the variable's values */
>                 if (kind.equalsIgnoreCase(ATTR_VAR)) {
>                     
>                     kind = ATTR_LIB; //change type: after variable substitution
this tag is like a "lib" tag...
>                     String[] pathSplit = path.split("/");
>                     StringBuilder newPath = new StringBuilder();
>                     for (int i = 0; i < pathSplit.length; i++) {
>                         if (i == 0){ //I assume the VARIABLE is used just
as a PREFIX in the file path
>                             String propertyName =pathSplit[i];
>                             String propertyValue
= getProject().getProperty(propertyName);
>                             if (propertyValue == null) {
>                                 throw new  BuildException("property must be
defined: " + propertyName);
>                             }
>                             newPath.append(propertyValue);
>                         } else {
>                             newPath.append("/").append(pathSplit[i]);
>                         }
>                     }
>                     path = newPath.toString();
>                 }
409,413c435,453
< 						//THIS is the only specific code
< 						if (verbose)
< 							System.out.println("Adding  " + path + " to classpath " +
idContainer);
< 						PathElement element = this.path.createPathElement();
< 						element.setLocation(new File(path));
---
> 					    /* modified by d.v. -- start */
>                         if (kind.equalsIgnoreCase(ATTR_SRC)
&& path.startsWith("/")) {
>                             // I'm including a project -> recursion is
needed...
>                             // I assume that the name of the project and its
path on disk are equals
>                             File classpath = new
File(getProject().getBaseDir().getParentFile(), path + "/.classpath");
>                             if
(!recursivePaths.contains(classpath.getAbsolutePath())) { //avoid
double-processing
>                             
recursivePaths.add(classpath.getAbsolutePath());
>                                 if (verbose) 
>                                     System.out.println("parsing
" + classpath);
>                                 new ClassPathParser().parse(classpath, this);
>                             }
>                         } else { //d.v: this is the "default" behaviour
>                             // THIS is the only specific code
>                             if (verbose)
>                                 System.out.println("Adding  " + path + " to
classpath " + idContaine

------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure