changeset 310:1f74d3de726c

reproducers engine can now handle files and directories with spaces
author Jiri Vanek <jvanek@redhat.com>
date Fri, 11 Nov 2011 14:33:29 +0100
parents 5860a2cbe221
children dc34e82d88d4
files Makefile.am NEW_LINE_IFS tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java
diffstat 4 files changed, 57 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Thu Nov 10 20:57:36 2011 +0100
+++ b/Makefile.am	Fri Nov 11 14:33:29 2011 +0100
@@ -473,22 +473,24 @@
 stamps/netx-dist-tests-prepare-reproducers.stamp: stamps/junit-jnlp-dist-dirs
 	types=(simple signed); \
 	for which in "$${types[@]}" ; do \
+	  . $(abs_top_builddir)/NEW_LINE_IFS ; \
 	  simpleReproducers=(`cat $(abs_top_builddir)/junit-jnlp-dist-$$which.txt `); \
+	  IFS="$$IFS_BACKUP" ; \
 	  for dir in "$${simpleReproducers[@]}" ; do \
 	    echo "processing: $$dir" ; \
-	    mkdir -p $(JNLP_TESTS_DIR)/$$dir ; \
+	    mkdir -p "$(JNLP_TESTS_DIR)/$$dir" ; \
 	    d=`pwd` ; \
-	    cd $(JNLP_TESTS_SRCDIR)/$$which/$$dir/srcs/ ; \
+	    cd "$(JNLP_TESTS_SRCDIR)/$$which/$$dir/srcs/" ; \
 	    srcFiles=`find . -mindepth 1 -type f -name "*.java" | sed "s/.\/*//"` ; \
 	    notSrcFiles=`find . -mindepth 1 -type f \! -name "*.java" | sed "s/.\/*//"` ; \
-	    $(BOOT_DIR)/bin/javac -d  $(JNLP_TESTS_DIR)/$$dir/ $$srcFiles ; \
+	    $(BOOT_DIR)/bin/javac -d  "$(JNLP_TESTS_DIR)/$$dir/" $$srcFiles ; \
 	    if [ -n "$$notSrcFiles" ] ; then \
-	      cp -R --parents $$notSrcFiles $(JNLP_TESTS_DIR)/$$dir/ ; \
+	      cp -R --parents "$$notSrcFiles" "$(JNLP_TESTS_DIR)/$$dir/" ; \
 	    fi ; \
-	    cd $(JNLP_TESTS_DIR)/$$dir/ ; \
-	    $(BOOT_DIR)/bin/jar cf $(JNLP_TESTS_SERVER_DEPLOYDIR)/$$dir.jar * ; \
-	    cd $$d ; \
-	    cp -R $(JNLP_TESTS_SRCDIR)/$$which/$$dir/resources/*  $(JNLP_TESTS_SERVER_DEPLOYDIR)/ ; \
+	    cd "$(JNLP_TESTS_DIR)/$$dir/" ; \
+	    $(BOOT_DIR)/bin/jar cf "$(JNLP_TESTS_SERVER_DEPLOYDIR)/$$dir.jar" * ; \
+	    cd "$$d" ; \
+	    cp -R "$(JNLP_TESTS_SRCDIR)/$$which/$$dir/resources/"*  $(JNLP_TESTS_SERVER_DEPLOYDIR)/ ; \
 	  done ; \
 	done ; \
 	mkdir -p stamps && \
@@ -499,9 +501,11 @@
 	keystore=$(abs_top_builddir)/$(KEYSTORE_NAME); \
 	pass=123456789; \
 	$(BOOT_DIR)/bin/keytool -genkey -alias $$alias -keystore $$keystore -keypass $$pass -storepass $$pass -dname "cn=$$alias, ou=$$alias, o=$$alias, c=$$alias" ; \
+	  . $(abs_top_builddir)/NEW_LINE_IFS ; \
 	signedReproducers=(`cat $(abs_top_builddir)/junit-jnlp-dist-signed.txt `); \
+	  IFS="$$IFS_BACKUP" ; \
 	for dir in "$${signedReproducers[@]}" ; do \
-	 $(BOOT_DIR)/bin/jarsigner -keystore $$keystore -storepass $$pass -keypass $$pass  $(JNLP_TESTS_SERVER_DEPLOYDIR)/$$dir.jar  $$alias ; \
+	 $(BOOT_DIR)/bin/jarsigner -keystore $$keystore -storepass $$pass -keypass $$pass  "$(JNLP_TESTS_SERVER_DEPLOYDIR)/$$dir.jar"  $$alias ; \
  	done ; \
  	mkdir -p stamps && \
  	touch $@
@@ -522,12 +526,14 @@
  netx-dist-tests-source-files.txt stamps/netx-dist-tests-compile.stamp
 	types=(simple signed); \
 	for which in "$${types[@]}" ; do \
+	  . $(abs_top_builddir)/NEW_LINE_IFS ; \
 	  simpleReproducers=(`cat $(abs_top_builddir)/junit-jnlp-dist-$$which.txt `); \
+	  IFS="$$IFS_BACKUP" ; \
 	  for dir in "$${simpleReproducers[@]}" ; do \
 	    $(BOOT_DIR)/bin/javac $(IT_JAVACFLAGS) \
 	    -d $(JNLP_TESTS_ENGINE_DIR) \
 	    -classpath $(JUNIT_JAR):$(NETX_DIR)/lib/classes.jar:$(JNLP_TESTS_ENGINE_DIR) \
-	    $(JNLP_TESTS_SRCDIR)/$$which/$$dir/testcases/* ; \
+	    "$(JNLP_TESTS_SRCDIR)/$$which/$$dir/testcases/"* ; \
 	  done ; \
 	done ; \
 	mkdir -p stamps && \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NEW_LINE_IFS	Fri Nov 11 14:33:29 2011 +0100
@@ -0,0 +1,8 @@
+#!/bin/sh
+NEW_LINE_IFS="
+"
+
+IFS_BACKUP="$IFS"; 
+#echo "1xx""$IFS""xx" ; 
+IFS="$NEW_LINE_IFS" ; 
+#echo "2xx""$IFS""xx" ; 
--- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java	Thu Nov 10 20:57:36 2011 +0100
+++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java	Fri Nov 11 14:33:29 2011 +0100
@@ -38,6 +38,7 @@
 
 import java.io.File;
 import java.io.FileFilter;
+import java.net.URI;
 import org.junit.Assert;
 
 import org.junit.Test;
@@ -45,7 +46,6 @@
 public class ResourcesTest {
 
     private static ServerAccess server = new ServerAccess();
-    
 
     @Test
     public void testResourcesExists() throws Exception {
@@ -64,9 +64,15 @@
 
         for (int i = 0; i < simpleContent.length; i++) {
             File file = simpleContent[i];
-            System.err.println(file.getName());
+            System.err.print(file.getName());
+            //server port have in fact no usage in converting filename to uri-like-filename.
+            //But if there is null, instead if some number, then nullpointer exception is thrown (Integer->int).
+            //So I'm using "real" currently used port, instead of some random value.
+            URI u = new URI((String)null,(String)null,(String)null,server.getPort(),file.getName(),(String)null,null);
+            System.err.println(" ("+u.toString()+")");
+            String fname=u.toString();
             if (file.getName().toLowerCase().endsWith(".jnlp")) {
-                String c = server.getResourceAsString("/" + file.getName());
+                String c = server.getResourceAsString("/" + fname);
                 Assert.assertTrue(c.contains("<"));
                 Assert.assertTrue(c.contains(">"));
                 Assert.assertTrue(c.contains("jnlp"));
@@ -74,7 +80,7 @@
                 Assert.assertTrue(c.replaceAll("\\s*", "").contains("</jnlp>"));
 
             } else {
-                byte[] c = server.getResourceAsBytes("/" + file.getName()).toByteArray();
+                byte[] c = server.getResourceAsBytes("/" + fname).toByteArray();
                 Assert.assertEquals(c.length, file.length());
             }
 
--- a/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java	Thu Nov 10 20:57:36 2011 +0100
+++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java	Fri Nov 11 14:33:29 2011 +0100
@@ -53,7 +53,9 @@
 import java.net.MalformedURLException;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.URI;
 import java.net.URL;
+import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -134,6 +136,7 @@
         findPortTestingSocket.close();
         return port;
     }
+    public static final  String HEADLES_OPTION="-headless";
 
     /**
      * we would like to have an singleton instance asap
@@ -454,7 +457,7 @@
             otherargs = new ArrayList<String>(1);
         }
         List<String> headlesList = new ArrayList<String>(otherargs);
-        headlesList.add("-headless");
+        headlesList.add(HEADLES_OPTION);
         return executeJavaws(headlesList, resource);
     }
 
@@ -515,6 +518,9 @@
         return executeProcess(urledArgs);
     }
 
+     public static ProcessResult executeProcess(final List<String> args) throws Exception {
+         return  executeProcess(args, null);
+     }
     /**
      * utility method to lunch process, get its stdou/stderr, its return value and to kill it if runing to long (@see PROCESS_TIMEOUT)
      *
@@ -527,12 +533,13 @@
      * Construct result from readed stdout, stderr, process return value, assasin sucessfulity
      *
      * @param args binary with args to be executed
+     * @param dir optional, directory where this process will run
      * @return what left from process - proces sitself, its stdout, stderr and return value and weather it was terminated by assasin.
      * @throws Exception
      */
-    public static ProcessResult executeProcess(final List<String> args) throws Exception {
+    public static ProcessResult executeProcess(final List<String> args,File dir) throws Exception {
 
-        ThreadedProcess t = new ThreadedProcess(args);
+        ThreadedProcess t = new ThreadedProcess(args,dir);
         ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT);
         pa.start();
         t.start();
@@ -569,6 +576,7 @@
         List<String> args;
         Integer exitCode;
         Boolean running;
+        File dir;
 
         public Boolean isRunning() {
             return running;
@@ -581,6 +589,10 @@
         public ThreadedProcess(List<String> args) {
             this.args = args;
         }
+         public ThreadedProcess(List<String> args,File dir) {
+            this.args = args;
+            this.dir=dir;
+        }
 
         public String getCommandLine() {
             String commandLine = "unknown command";
@@ -608,7 +620,11 @@
             try {
                 running = true;
                 Runtime r = Runtime.getRuntime();
-                p = r.exec(args.toArray(new String[0]));
+                if (dir==null){
+                    p = r.exec(args.toArray(new String[0]));
+                }else{
+                    p = r.exec(args.toArray(new String[0]),new String[0], dir);
+                }
                 exitCode = p.waitFor();
             } catch (Exception ex) {
                 if (ex instanceof InterruptedException) {
@@ -744,6 +760,9 @@
                                 StringTokenizer t = new StringTokenizer(s, " ");
                                 t.nextToken();
                                 String p = t.nextToken();
+                                System.err.println("Getting: "+p);
+                                p=URLDecoder.decode(p, "UTF-8");
+                                System.err.println("Serving: "+p);
                                 p = (".".concat(((p.endsWith("/")) ? p.concat(
                                         "index.html") : p))).replace('/', File.separatorChar);
                                 File pp = new File(dir, p);