You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cn...@apache.org on 2013/07/18 00:14:38 UTC

svn commit: r1504303 - in /hadoop/common/branches/branch-1-win: CHANGES.branch-1-win.txt src/test/org/apache/hadoop/mapred/TestNonLocalJobJarSubmission.java

Author: cnauroth
Date: Wed Jul 17 22:14:37 2013
New Revision: 1504303

URL: http://svn.apache.org/r1504303
Log:
MAPREDUCE-5391. TestNonLocalJobJarSubmission fails on Windows due to missing classpath entries. Contributed by Chris Nauroth.

Modified:
    hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
    hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNonLocalJobJarSubmission.java

Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1504303&r1=1504302&r2=1504303&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Wed Jul 17 22:14:37 2013
@@ -313,6 +313,9 @@ Branch-hadoop-1-win (branched from branc
     HDFS-4975. Branch-1-win TestReplicationPolicy failed caused by stale data
     node handling. (Xi Fang via cnauroth)
 
+    MAPREDUCE-5391. TestNonLocalJobJarSubmission fails on Windows due to missing
+    classpath entries. (cnauroth)
+
   Merged from branch-1
 
     HDFS-385. Backport: Add support for an experimental API that allows a

Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNonLocalJobJarSubmission.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNonLocalJobJarSubmission.java?rev=1504303&r1=1504302&r2=1504303&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNonLocalJobJarSubmission.java (original)
+++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/mapred/TestNonLocalJobJarSubmission.java Wed Jul 17 22:14:37 2013
@@ -24,10 +24,14 @@ import java.io.Writer;
 import java.io.InputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Iterator;
+import java.util.jar.Attributes.Name;
+import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 import java.util.Scanner;
 
@@ -39,6 +43,7 @@ import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.util.Shell;
 
 public class TestNonLocalJobJarSubmission extends ClusterMapReduceTestCase {
   
@@ -150,7 +155,26 @@ public class TestNonLocalJobJarSubmissio
       }
       URL[] urls = ((URLClassLoader)applicationClassLoader).getURLs();
       for(URL url : urls) {
+        if (Shell.WINDOWS && url.getPath().contains("classpath") &&
+            url.getPath().endsWith(".jar")) {
+          // On Windows, classpath is packed into an intermediate jar file with
+          // a manifest containing a classpath entry to work around command line
+          // length limitation.  Unpack the individual class path entries from
+          // the intermediate jar.
+          final JarFile jf;
+          try {
+            jf = new JarFile(new File(url.toURI()));
+          } catch (URISyntaxException e) {
+            throw new IOException("unexpected URISyntaxException", e);
+          }
+          Manifest mf = jf.getManifest();
+          String classPath = mf.getMainAttributes().getValue(Name.CLASS_PATH);
+          for (String classPathEntry: classPath.split(" ")) {
+            out.collect(zero, new Text(classPathEntry));
+          }
+        } else {
           out.collect(zero, new Text(url.toString()));
+        }
       }
     }