DRILL-213: Test cases fail on Windows

Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/4b192494
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/4b192494
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/4b192494

Branch: refs/heads/master
Commit: 4b1924944cd7c941b088488a558dd8f56a6fb27e
Parents: ad992eb
Author: Aditya Kishore <[email protected]>
Authored: Wed Sep 4 19:43:59 2013 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Thu Sep 5 17:01:14 2013 -0700

----------------------------------------------------------------------
 .../org/apache/drill/common/util/FileUtils.java  |  4 ++++
 .../drill/exec/compile/ClassTransformer.java     | 19 ++++++++++---------
 .../drill/exec/expr/fn/FunctionConverter.java    |  5 +++--
 3 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b192494/common/src/main/java/org/apache/drill/common/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/drill/common/util/FileUtils.java 
b/common/src/main/java/org/apache/drill/common/util/FileUtils.java
index f38f9d2..455cb62 100644
--- a/common/src/main/java/org/apache/drill/common/util/FileUtils.java
+++ b/common/src/main/java/org/apache/drill/common/util/FileUtils.java
@@ -28,6 +28,10 @@ import com.google.common.io.Files;
 public class FileUtils {
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(FileUtils.class);
 
+  public static final char separatorChar = '/';
+
+  public static final String separator = "" + separatorChar;
+
   public static File getResourceAsFile(String fileName) throws IOException {
     URL u = FileUtils.class.getResource(fileName);
     if (u == null) throw new FileNotFoundException(String.format("Unable to 
find file on path %s", fileName));

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b192494/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
index d549db4..4a934f9 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/compile/ClassTransformer.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.exception.ClassTransformationException;
 import org.codehaus.commons.compiler.CompileException;
 import org.objectweb.asm.ClassReader;
@@ -114,8 +115,8 @@ public class ClassTransformer {
       final byte[] implementationClass = 
classLoader.getClassByteCode(materializedClassName, entireClass);
 
       // Get Template Class
-      final String templateClassName = 
templateDefinition.getTemplateClassName().replaceAll("\\.", File.separator);
-      final String templateClassPath = File.separator + templateClassName + 
".class";
+      final String templateClassName = 
templateDefinition.getTemplateClassName().replace('.', FileUtils.separatorChar);
+      final String templateClassPath = FileUtils.separator + templateClassName 
+ ".class";
       t1.stop();
       Stopwatch t2 = new Stopwatch().start();
       final byte[] templateClass = getClassByteCodeFromPath(templateClassPath);
@@ -125,8 +126,8 @@ public class ClassTransformer {
 
       // Setup adapters for merging, remapping class names and class writing. 
This is done in reverse order of how they
       // will be evaluated.
-      String oldTemplateSlashName = 
templateDefinition.getTemplateClassName().replace('.', '/');
-      String materializedSlashName = materializedClassName.replace('.', '/');
+      String oldTemplateSlashName = 
templateDefinition.getTemplateClassName().replace('.', FileUtils.separatorChar);
+      String materializedSlashName = materializedClassName.replace('.', 
FileUtils.separatorChar);
       RemapClasses remapper = new RemapClasses(oldTemplateSlashName, 
materializedSlashName);
       
       Stopwatch t3;
@@ -157,7 +158,7 @@ public class ClassTransformer {
       for (String s : remapper.getSubclasses()) {
         logger.debug("Setting up sub class {}", s);
         // for each sub class, remap them into the new class.
-        String subclassPath = File.separator + s + ".class";
+        String subclassPath = FileUtils.separator + s + ".class";
         final byte[] bytecode = getClassByteCodeFromPath(subclassPath);
         RemapClasses localRemapper = new RemapClasses(oldTemplateSlashName, 
materializedSlashName);
         Preconditions.checkArgument(localRemapper.getSubclasses().isEmpty(), 
"Class transformations are only supported for classes that have a single level 
of inner classes.");
@@ -166,7 +167,7 @@ public class ClassTransformer {
         ClassReader reader = new ClassReader(bytecode);
         reader.accept(remap, ClassReader.EXPAND_FRAMES);
         byte[] newByteCode = subcw.toByteArray();
-        classLoader.injectByteCode(s.replace(oldTemplateSlashName, 
materializedSlashName).replace('/', '.'), newByteCode);
+        classLoader.injectByteCode(s.replace(oldTemplateSlashName, 
materializedSlashName).replace(FileUtils.separatorChar, '.'), newByteCode);
 //        Files.write(subcw.toByteArray(), new 
File(String.format("/tmp/%d-sub-%d.class", fileNum, i)));
         i++;
       }
@@ -209,7 +210,7 @@ public class ClassTransformer {
       super(Opcodes.ASM4, cv);
       this.classToMerge = cn;
       this.templateName = templateName;
-      this.newName = newName.replace('.', '/');
+      this.newName = newName.replace('.', FileUtils.separatorChar);
       ;
 
     }
@@ -268,8 +269,8 @@ public class ClassTransformer {
         mn.instructions.resetLabels();
         // mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new
         // SimpleRemapper("org.apache.drill.exec.compile.ExampleTemplate", 
"Bunky")));
-        mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new 
SimpleRemapper(cname.replace('.', '/'),
-            classToMerge.name.replace('.', '/'))));
+        mn.accept(new RemappingMethodAdapter(mn.access, mn.desc, mv, new 
SimpleRemapper(cname.replace('.', FileUtils.separatorChar),
+            classToMerge.name.replace('.', FileUtils.separatorChar))));
       }
       super.visitEnd();
     }

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/4b192494/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
----------------------------------------------------------------------
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
index 0c1ab8a..4c51cf5 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/FunctionConverter.java
@@ -10,6 +10,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.drill.common.types.TypeProtos.MajorType;
+import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.expr.DrillFunc;
 import org.apache.drill.exec.expr.annotations.FunctionTemplate;
 import org.apache.drill.exec.expr.annotations.Output;
@@ -41,7 +42,7 @@ public class FunctionConverter {
   private CompilationUnit get(Class<?> c) throws IOException{
     String path = c.getName();
     path = path.replaceFirst("\\$.*", "");
-    path = path.replace(".", File.separator);
+    path = path.replace(".", FileUtils.separator);
     path = "/" + path + ".java";
     CompilationUnit cu = functionUnits.get(path);
     if(cu != null) return cu;
@@ -181,7 +182,7 @@ public class FunctionConverter {
   private String getClassBody(Class<?> c) throws CompileException, IOException{
     String path = c.getName();
     path = path.replaceFirst("\\$.*", "");
-    path = path.replace(".", File.separator);
+    path = path.replace(".", FileUtils.separator);
     path = "/" + path + ".java";
     URL u = Resources.getResource(c, path);
     InputSupplier<InputStream> supplier = Resources.newInputStreamSupplier(u);

Reply via email to