antclipse enhancement

Help
2011-12-16
2013-04-24
  • Duccio Vigolo
    Duccio Vigolo
    2011-12-16

    I,
    recently I had to modify the antclipse code of version 1.0b3: 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

    <?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>
    

    while the content of gsd_ef/.classpath is

    <?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>
    

    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 1.0b3 version), here is the output of the diff command:

    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 " + idContainer);
    >                             PathElement element = this.path.createPathElement();
    >                             element.setLocation(new File(path));
    >                         }
    >                         /* modified by d.v. -- end */
    

    Any suggestions would be greatly appreciated.

    Regards,
    Duccio Vigolo