ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc JavaCC.java JJTree.java
Date Tue, 12 Mar 2002 09:11:59 GMT
sbailliez    02/03/12 01:11:59

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/javacc
                        JavaCC.java JJTree.java
  Log:
  Enhance lookup path so that it works automagically with 1.x and 2.x versions...
  
  Revision  Changes    Path
  1.12      +27 -5     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
  
  Index: JavaCC.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- JavaCC.java	10 Jan 2002 13:59:36 -0000	1.11
  +++ JavaCC.java	12 Mar 2002 09:11:59 -0000	1.12
  @@ -239,12 +239,9 @@
           }
           cmdl.createArgument().setValue(target.getAbsolutePath());
   
  -        if (javaccHome == null || !javaccHome.isDirectory()) {
  -            throw new BuildException("Javacchome not set.");
  -        }
           final Path classpath = cmdl.createClasspath(project);
  -        classpath.createPathElement().setPath(javaccHome.getAbsolutePath() +
  -                                                  "/JavaCC.zip");
  +        final File javaccJar = JavaCC.getArchiveFile(javaccHome);
  +        classpath.createPathElement().setPath( javaccJar.getAbsolutePath() );
           classpath.addJavaRuntime();
   
           final Commandline.Argument arg = cmdl.createVmArgument();
  @@ -252,6 +249,31 @@
           arg.setValue("-Dinstall.root="+javaccHome.getAbsolutePath());
   
           Execute.runCommand(this, cmdl.getCommandline());
  +    }
  +
  +    /**
  +     * Helper class to retrieve the path used to store the JavaCC.zip which is
  +     * different from versions.
  +     * @param home the javacc home path directory.
  +     * @throws BuildException thrown if the home directory is invalid or if the archive
  +     * could not be found despite attemps to do so.
  +     * @return the file object pointing to the JavaCC archive.
  +     */
  +    protected static File getArchiveFile(File home) throws BuildException {
  +        if (home == null || !home.isDirectory()) {
  +            throw new BuildException("JavaCC home must be a valid directory.");
  +        }
  +        // javacc prior to 2.0
  +        File f = new File(home, "JavaCC.zip");
  +        if ( f.exists() ){
  +          return f;
  +        }
  +        // javacc install 2.0+
  +        f = new File(home, "bin/lib/JavaCC.zip");
  +        if ( f.exists() ){
  +          return f;
  +        }
  +        throw new BuildException("Could not find a path to JavaCC.zip from '" + home +
"'.");
       }
   
       /**
  
  
  
  1.8       +3 -6      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java
  
  Index: JJTree.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JJTree.java	10 Jan 2002 13:59:36 -0000	1.7
  +++ JJTree.java	12 Mar 2002 09:11:59 -0000	1.8
  @@ -196,12 +196,9 @@
           }
           cmdl.createArgument().setValue(target.getAbsolutePath());
   
  -        if (javaccHome == null || !javaccHome.isDirectory()) {
  -            throw new BuildException("Javacchome not set.");
  -        }
           final Path classpath = cmdl.createClasspath(project);
  -        classpath.createPathElement().setPath(javaccHome.getAbsolutePath() +
  -                                                  "/JavaCC.zip");
  +        final File javaccJar = JavaCC.getArchiveFile(javaccHome);
  +        classpath.createPathElement().setPath( javaccJar.getAbsolutePath() );
           classpath.addJavaRuntime();
   
           final Commandline.Argument arg = cmdl.createVmArgument();
  @@ -222,7 +219,7 @@
               }
           }
           catch (IOException e) {
  -            throw new BuildException("Failed to launch JJTree: " + e);
  +            throw new BuildException("Failed to launch JJTree", e);
           }
       }
   }
  
  
  

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


Mime
View raw message