Andrea Aime ha scritto:
Andrea Aime ha scritto:
Hi Gabriel,
I can't build the CQL module on trunk on windows (I need
to put it in the build to forward port the Geoserver changes
to gs trunk).

Well, it seems the problems won't be fixed in javacc 3.2,
and it's not fixed in javacc 4.0 neither, see:
https://javacc.dev.java.net/issues/show_bug.cgi?id=81
https://javacc.dev.java.net/issues/show_bug.cgi?id=135

Oh well, I rolled my own fix in our javacc plugin,
basically if the operating system is Windows, I rewrite
every generated file so that the header contains unix separators
instead of windows ones.

The module mantainer for jjtree-javacc module is Martin.
Martin, can you have a look at the attached patch?
If ok, I can apply it,
and then finally put the cql module in the build for the joy
of both windows and linux users.

Cheers
Andrea
Index: C:/progetti/geotools/trunk/gt/build/maven/jjtree-javacc/src/main/java/org/geotools/maven/JJTreeJavaCC.java
===================================================================
--- C:/progetti/geotools/trunk/gt/build/maven/jjtree-javacc/src/main/java/org/geotools/maven/JJTreeJavaCC.java	(revision 24415)
+++ C:/progetti/geotools/trunk/gt/build/maven/jjtree-javacc/src/main/java/org/geotools/maven/JJTreeJavaCC.java	(working copy)
@@ -16,7 +16,11 @@
 package org.geotools.maven;
 
 // J2SE dependencies
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
@@ -147,6 +151,9 @@
      * @throws MojoExecutionException if the plugin execution failed.
      */
     public void execute() throws MojoExecutionException, MojoFailureException {
+        // if not windows, don't rewrite file
+        boolean windowsOs = System.getProperty("os.name").indexOf("Windows") != -1;  
+        
         outputPackageDirectory = createPackageDirectory(outputDirectory);
         if (!FileUtils.fileExists(timestampDirectory)) {
             FileUtils.mkdir(timestampDirectory);
@@ -192,6 +199,12 @@
         final Set staleGrammars = searchStaleGrammars(new File(outputDirectory), ".jj");
         for (final Iterator it=staleGrammars.iterator(); it.hasNext();) {
             final File sourceFile = (File) it.next();
+            try {
+                if(windowsOs)
+                    fixHeader(sourceFile);
+            } catch (IOException e) {
+                throw new MojoExecutionException("Failed to fix header for .jj file.", e);
+            }
             final String[]   args = generateJavaCCArgumentList(sourceFile.getPath());
             final int      status;
             try {
@@ -208,6 +221,20 @@
                 throw new MojoExecutionException("Failed to copy processed .jj file.", e);
             }
         }
+        /**
+         * Reprocess generated java files so that they won't contain invalid escape characters
+         */
+        if(windowsOs) {
+            try {
+                String[] files = FileUtils.getFilesFromExtension(outputDirectory, new String[] {"java"});
+                for (int i = 0; i < files.length; i++) {
+                    System.out.println("Fixing " + files[i]);
+                    fixHeader(new File(files[i]));
+                }
+            } catch (IOException e) {
+                throw new MojoExecutionException("Failed to fix header for java file.", e);
+            }
+        }
         /*
          * Add the generated-sources directory to the compilation root for the remaining
          * maven build.
@@ -218,6 +245,36 @@
     }
 
     /**
+     * Takes a file generated from javacc, and changes the first line so that it does not
+     * contain escape characters on windows (the filename may contain things like \ u 
+     * which are invalid escape chars)
+     * @param sourceFile
+     * @throws IOException 
+     */
+    private void fixHeader(File sourceFile) throws IOException {
+        BufferedReader reader = null;
+        BufferedWriter writer = null;
+        File fixedFile = new File(sourceFile.getParentFile(), sourceFile.getName() + ".fix");
+        try {
+            reader = new BufferedReader(new FileReader(sourceFile));
+            writer = new BufferedWriter(new FileWriter(fixedFile));
+            String line;
+            while((line = reader.readLine()) != null) {
+                if(line.startsWith("/[EMAIL PROTECTED](jjtree) Generated By:JJTree:") || 
+                        line.startsWith("/* Generated By:JJTree:"))
+                    line = line.replace('\\', '/');
+                writer.write(line);
+                writer.newLine();
+            }
+        } finally {
+            if(reader != null) reader.close();
+            if(writer != null) writer.close();
+        }
+        sourceFile.delete();
+        fixedFile.renameTo(sourceFile);
+    }
+
+    /**
      * Returns the concatenation of [EMAIL PROTECTED] directory} with [EMAIL PROTECTED] #nodePackage}. This is used in
      * order to construct a directory path which include the Java package. The directory will be
      * created if it doesn't exists.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to