ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc JJDoc.java JJTree.java JavaCC.java
Date Fri, 30 Jul 2004 10:55:34 GMT
bodewig     2004/07/30 03:55:34

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/javacc
                        JJDoc.java JJTree.java JavaCC.java
  Log:
  Base version decision on classpath instead of archive names, this allows Gump to effectivly
ignore javacchome
  
  Revision  Changes    Path
  1.10      +3 -3      ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java
  
  Index: JJDoc.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JJDoc.java	9 Mar 2004 16:48:29 -0000	1.9
  +++ JJDoc.java	30 Jul 2004 10:55:34 -0000	1.10
  @@ -132,13 +132,13 @@
   
           cmdl.createArgument().setValue(target.getAbsolutePath());
   
  -        cmdl.setClassname(JavaCC.getMainClass(javaccHome,
  -                                              JavaCC.TASKDEF_TYPE_JJDOC));
  -
           final Path classpath = cmdl.createClasspath(getProject());
           final File javaccJar = JavaCC.getArchiveFile(javaccHome);
           classpath.createPathElement().setPath(javaccJar.getAbsolutePath());
           classpath.addJavaRuntime();
  +        
  +        cmdl.setClassname(JavaCC.getMainClass(classpath,
  +                                              JavaCC.TASKDEF_TYPE_JJDOC));
   
           final Commandline.Argument arg = cmdl.createVmArgument();
           arg.setValue("-mx140M");
  
  
  
  1.33      +3 -3      ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java
  
  Index: JJTree.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- JJTree.java	9 Mar 2004 16:48:29 -0000	1.32
  +++ JJTree.java	30 Jul 2004 10:55:34 -0000	1.33
  @@ -235,13 +235,13 @@
   
           cmdl.createArgument().setValue(target.getAbsolutePath());
   
  -        cmdl.setClassname(JavaCC.getMainClass(javaccHome,
  -                                              JavaCC.TASKDEF_TYPE_JJTREE));
  -
           final Path classpath = cmdl.createClasspath(getProject());
           final File javaccJar = JavaCC.getArchiveFile(javaccHome);
           classpath.createPathElement().setPath(javaccJar.getAbsolutePath());
           classpath.addJavaRuntime();
  +
  +        cmdl.setClassname(JavaCC.getMainClass(classpath,
  +                                              JavaCC.TASKDEF_TYPE_JJTREE));
   
           final Commandline.Argument arg = cmdl.createVmArgument();
           arg.setValue("-mx140M");
  
  
  
  1.31      +61 -52    ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
  
  Index: JavaCC.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- JavaCC.java	9 Mar 2004 16:48:29 -0000	1.30
  +++ JavaCC.java	30 Jul 2004 10:55:34 -0000	1.31
  @@ -18,10 +18,12 @@
   package org.apache.tools.ant.taskdefs.optional.javacc;
   
   import java.io.File;
  +import java.io.InputStream;
   import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.zip.ZipFile;
  +import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
  @@ -307,14 +309,14 @@
           }
           cmdl.createArgument().setValue(target.getAbsolutePath());
   
  -        cmdl.setClassname(JavaCC.getMainClass(javaccHome,
  -                                              JavaCC.TASKDEF_TYPE_JAVACC));
  -
           final Path classpath = cmdl.createClasspath(getProject());
           final File javaccJar = JavaCC.getArchiveFile(javaccHome);
           classpath.createPathElement().setPath(javaccJar.getAbsolutePath());
           classpath.addJavaRuntime();
   
  +        cmdl.setClassname(JavaCC.getMainClass(classpath,
  +                                              JavaCC.TASKDEF_TYPE_JAVACC));
  +
           final Commandline.Argument arg = cmdl.createVmArgument();
           arg.setValue("-mx140M");
           arg.setValue("-Dinstall.root=" + javaccHome.getAbsolutePath());
  @@ -347,15 +349,33 @@
       protected static String getMainClass(File home, int type)
           throws BuildException {
   
  -        int majorVersion = getMajorVersionNumber(home);
  +        Path p = new Path(null);
  +        p.createPathElement().setLocation(getArchiveFile(home));
  +        p.addJavaRuntime();
  +        return getMainClass(p, type);
  +    }
  +
  +    /**
  +     * Helper method to retrieve main class which is different from versions.
  +     * @param path classpath to search in.
  +     * @param type the taskdef.
  +     * @throws BuildException thrown if the home directory is invalid
  +     * or if the archive could not be found despite attempts to do so.
  +     * @return the main class for the taskdef.
  +     * @since Ant 1.7
  +     */
  +    protected static String getMainClass(Path path, int type)
  +        throws BuildException {
           String packagePrefix = null;
           String mainClass = null;
   
  -        switch (majorVersion) {
  -        case 1:
  -        case 2:
  +        AntClassLoader l = new AntClassLoader();
  +        l.setClassPath(path.concatSystemClasspath("ignore"));
  +        String javaccClass = COM_PACKAGE + COM_JAVACC_CLASS;
  +        InputStream is = l.getResourceAsStream(javaccClass.replace('.', '/')
  +                                               + ".class");
  +        if (is != null) {
               packagePrefix = COM_PACKAGE;
  -
               switch (type) {
               case TASKDEF_TYPE_JAVACC:
                   mainClass = COM_JAVACC_CLASS;
  @@ -372,58 +392,47 @@
   
                   break;
               }
  -
  -            break;
  -
  -        case 3:
  -            /*
  -             * This is where the fun starts, JavaCC 3.0 uses
  -             * org.netbeans.javacc, 3.1 uses org.javacc - I wonder
  -             * which version is going to use net.java.javacc.
  -             *
  -             * Look into to the archive to pick up the best
  -             * package.
  -             */
  -            ZipFile zf = null;
  -            try {
  -                zf = new ZipFile(getArchiveFile(home));
  -                if (zf.getEntry(ORG_PACKAGE_3_0.replace('.', '/')) != null) {
  +        } else {
  +            javaccClass = ORG_PACKAGE_3_1 + ORG_JAVACC_CLASS;
  +            is = l.getResourceAsStream(javaccClass.replace('.', '/')
  +                                       + ".class");
  +            if (is != null) {
  +                packagePrefix = ORG_PACKAGE_3_1;
  +            } else {
  +                javaccClass = ORG_PACKAGE_3_0 + ORG_JAVACC_CLASS;
  +                is = l.getResourceAsStream(javaccClass.replace('.', '/')
  +                                           + ".class");
  +                if (is != null) {
                       packagePrefix = ORG_PACKAGE_3_0;
  -                } else {
  -                    packagePrefix = ORG_PACKAGE_3_1;
  -                }
  -            } catch (IOException e) {
  -                throw new BuildException("Error reading javacc.jar", e);
  -            } finally {
  -                if (zf != null) {
  -                    try {
  -                        zf.close();
  -                    } catch (IOException e) {
  -                        throw new BuildException(e);
  -                    }
                   }
               }
   
  -            switch (type) {
  -            case TASKDEF_TYPE_JAVACC:
  -                mainClass = ORG_JAVACC_CLASS;
  -
  -                break;
  -
  -            case TASKDEF_TYPE_JJTREE:
  -                mainClass = ORG_JJTREE_CLASS;
  -
  -                break;
  -
  -            case TASKDEF_TYPE_JJDOC:
  -                mainClass = ORG_JJDOC_CLASS;
  -
  +            if (is != null) {
  +                switch (type) {
  +                case TASKDEF_TYPE_JAVACC:
  +                    mainClass = ORG_JAVACC_CLASS;
  +                    
                   break;
  +                
  +                case TASKDEF_TYPE_JJTREE:
  +                    mainClass = ORG_JJTREE_CLASS;
  +                    
  +                    break;
  +
  +                case TASKDEF_TYPE_JJDOC:
  +                    mainClass = ORG_JJDOC_CLASS;
  +                    
  +                    break;
  +                }
               }
  -
  -            break;
           }
   
  +        if (packagePrefix == null) {
  +            throw new BuildException("failed to load JavaCC");
  +        }
  +        if (mainClass == null) {
  +            throw new BuildException("unknown task type " + type);
  +        }
           return packagePrefix + mainClass;
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message