Changeset 429 for trunk/icedtea-web/tests/test-extensions
- Timestamp:
- Sep 24, 2014, 9:34:21 PM (11 years ago)
- Location:
- trunk/icedtea-web/tests/test-extensions
- Files:
-
- 13 edited
- 13 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/ContentReader.java
r418 r429 35 35 exception statement from your version. 36 36 */ 37 38 37 package net.sourceforge.jnlp; 39 38 … … 42 41 import java.io.InputStreamReader; 43 42 import java.io.Reader; 43 import java.util.ArrayList; 44 import java.util.List; 44 45 45 46 /** 46 * Class to read content of stdout/stderr of process, and to cooperate with its running/terminated/finished statuses. 47 * Class to read content of stdout/stderr of process, and to cooperate with its 48 * running/terminated/finished statuses. 47 49 */ 48 50 class ContentReader implements Runnable { … … 51 53 private final InputStream is; 52 54 private boolean done; 53 ContentReaderListener listener;55 final List<ContentReaderListener> listeners = new ArrayList<ContentReaderListener>(1); 54 56 55 57 public String getContent() { … … 63 65 public ContentReader(InputStream is, ContentReaderListener l) throws IOException { 64 66 this.is = is; 65 this.listener = l; 67 if (l != null) { 68 this.listeners.add(l); 69 } 66 70 } 67 71 68 public void setListener(ContentReaderListener listener) { 69 this.listener = listener; 72 public ContentReader(InputStream is, List<ContentReaderListener> l) throws IOException { 73 this.is = is; 74 if (l != null) { 75 this.listeners.addAll(l); 76 } 70 77 } 71 78 72 public ContentReaderListener getListener() { 73 return listener; 79 public void addListener(ContentReaderListener listener) { 80 this.listeners.add(listener); 81 } 82 83 public List<ContentReaderListener> getListener() { 84 return listeners; 74 85 } 75 86 … … 97 108 int s = br.read(); 98 109 if (s < 0) { 99 if (line.length() > 0 && listener != null) { 100 listener.lineReaded(line.toString()); 110 if (line.length() > 0 && listeners != null) { 111 for (ContentReaderListener listener : listeners) { 112 if (listener != null) { 113 listener.lineReaded(line.toString()); 114 } 115 } 101 116 } 102 117 break; … … 106 121 line.append(ch); 107 122 if (ch == '\n') { 108 if (listener != null) { 109 listener.lineReaded(line.toString()); 123 if (listeners != null) { 124 for (ContentReaderListener listener : listeners) { 125 if (listener != null) { 126 listener.lineReaded(line.toString()); 127 } 128 } 110 129 } 111 130 line = new StringBuilder(); 112 131 } 113 if (listener != null) { 114 listener.charReaded(ch); 132 if (listeners != null) { 133 for (ContentReaderListener listener : listeners) { 134 if (listener != null) { 135 listener.charReaded(ch); 136 } 137 } 115 138 } 116 139 } 117 //do not want to bother output with terminations 118 //mostly compaling when assassin kill the process about StreamClosed 119 //do not want to bother output with terminations 120 //mostly compaling when assassin kill the process about StreamClosed 121 } catch (Exception ex) { 140 } catch (NullPointerException ex) { 141 ex.printStackTrace(); 142 } 143 //do not want to bother output with terminations 144 //mostly compaling when assassin kill the process about StreamClosed 145 catch (Exception ex) { 122 146 // logException(ex); 147 //ex.printStackTrace(); 123 148 } finally { 124 149 try { -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/LoggingBottleneck.java
r418 r429 46 46 import java.io.Writer; 47 47 import java.lang.reflect.Method; 48 import java.util.Collections; 48 49 import java.util.HashMap; 49 50 import java.util.Map; … … 81 82 * class.testMethod.logs 82 83 */ 83 final Map<String, Map<String, TestsLogs>> processLogs = new HashMap<String, Map<String, TestsLogs>>(100);84 final Map<String, Map<String, TestsLogs>> processLogs = Collections.synchronizedMap(new HashMap<String, Map<String, TestsLogs>>(1000)); 84 85 private boolean added = false; 85 86 86 public static LoggingBottleneck getDefaultLoggingBottleneck() {87 synchronized public static LoggingBottleneck getDefaultLoggingBottleneck() { 87 88 if (loggingBottleneck == null) { 88 89 loggingBottleneck = new LoggingBottleneck(); … … 102 103 } 103 104 104 void writeXmlLog() throws FileNotFoundException, IOException {105 synchronized void writeXmlLog() throws FileNotFoundException, IOException { 105 106 writeXmlLog(DEFAULT_LOG_FILE); 106 107 } 107 108 108 void writeXmlLog(File f) throws FileNotFoundException, IOException { 109 synchronized void writeXmlLog(File f) throws FileNotFoundException, IOException { 110 writeXmlLog(f, Collections.unmodifiableMap(processLogs)); 111 } 112 113 synchronized static void writeXmlLog(File f, Map<String, Map<String, TestsLogs>> processLogs) throws FileNotFoundException, IOException { 109 114 Writer w = new OutputStreamWriter(new FileOutputStream(f)); 110 115 Set<Entry<String, Map<String, TestsLogs>>> classes = processLogs.entrySet(); … … 118 123 String testLogs = testLog.getValue().toString(); 119 124 w.write("<" + TESTLOG_ELEMENT + " " + TESTMETHOD_ATTRIBUTE + "=\"" + testName + "\" " + FULLID_ATTRIBUTE + "=\"" + className + "." + testName + "\" >"); 120 w.write( testLogs);125 w.write(clearChars(testLogs)); 121 126 w.write("</" + TESTLOG_ELEMENT + ">"); 122 127 } … … 128 133 } 129 134 130 void addToXmlLog(String message, boolean printToOut, boolean printToErr, StackTraceElement ste) {135 synchronized void addToXmlLog(String message, boolean printToOut, boolean printToErr, StackTraceElement ste) { 131 136 Map<String, TestsLogs> classLog = processLogs.get(ste.getClassName()); 132 137 if (classLog == null) { … … 158 163 } 159 164 160 public String modifyMethodWithForBrowser(String methodBrowseredName, String className) {165 synchronized public String modifyMethodWithForBrowser(String methodBrowseredName, String className) { 161 166 try { 162 Class clazz = Class.forName(className);167 Class<?> clazz = Class.forName(className); 163 168 /* 164 169 * By using this isAssignable to ensure corect class before invocation, … … 181 186 } 182 187 183 public void setLoggedBrowser(String loggedBrowser) {188 synchronized public void setLoggedBrowser(String loggedBrowser) { 184 189 this.loggedBrowser = loggedBrowser; 185 190 } 186 191 187 public void logIntoPlaintextLog(String message, boolean printToOut, boolean printToErr) {192 synchronized public void logIntoPlaintextLog(String message, boolean printToOut, boolean printToErr) { 188 193 try { 189 194 if (printToOut) { … … 202 207 DEFAULT_STDOUT_WRITER.write(idded); 203 208 DEFAULT_STDOUT_WRITER.newLine(); 209 DEFAULT_STDOUT_WRITER.flush(); 204 210 } 205 211 … … 207 213 DEFAULT_STDERR_WRITER.write(idded); 208 214 DEFAULT_STDERR_WRITER.newLine(); 215 DEFAULT_STDERR_WRITER.flush(); 209 216 } 210 217 … … 212 219 DEFAULT_STDLOGS_WRITER.write(idded); 213 220 DEFAULT_STDLOGS_WRITER.newLine(); 221 DEFAULT_STDLOGS_WRITER.flush(); 222 } 223 224 synchronized public static String clearChars(String ss) { 225 StringBuilder s = new StringBuilder(ss); 226 for (int i = 0; i < s.length(); i++) { 227 char q = s.charAt(i); 228 if (q == '\n') { 229 continue; 230 } 231 if (q == '\t') { 232 continue; 233 } 234 int iq = (int) q; 235 if ((iq <= 31 || iq > 65533)||(iq >= 64976 && iq <= 65007)) { 236 s.setCharAt(i, 'I'); 237 s.insert(i + 1, "NVALID_CHAR_" + iq); 238 i--; 239 } 240 } 241 return s.toString(); 214 242 } 215 243 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java
r418 r429 40 40 import java.util.ArrayList; 41 41 import java.util.List; 42 import net.sourceforge.jnlp.browsertesting.ReactingProcess; 42 43 43 44 /** 44 * class which timeout any ThreadedProcess. This killing of 'thread with process' replaced not working process.destroy(). 45 * class which timeout any ThreadedProcess. This killing of 'thread with 46 * process' replaced not working process.destroy(). 45 47 */ 46 class ProcessAssasin extends Thread {48 public class ProcessAssasin extends Thread { 47 49 48 50 long timeout; … … 51 53 private boolean canRun = true; 52 54 private boolean wasTerminated = false; 55 //signifies that assasin have been summoned 56 private volatile boolean killing = false; 57 //signifies that assasin have done its job 58 private volatile boolean killed = false; 53 59 /** 54 * if this is true, then process is not destroyed after timeout, but just left to its own destiny. 55 * Its stdout/err is no longer recorded, and it is leaking system resources until it dies by itself 56 * The contorl is returned to main thread with all informations recorded untill now. 57 * You will be able to listen to std out from listeners still 60 * if this is true, then process is not destroyed after timeout, but just 61 * left to its own destiny. Its stdout/err is no longer recorded, and it is 62 * leaking system resources until it dies by itself The contorl is returned 63 * to main thread with all informations recorded untill now. You will be 64 * able to listen to std out from listeners still 58 65 */ 59 66 private boolean skipInstedOfDesroy = false; 67 private ReactingProcess reactingProcess; 60 68 61 69 public ProcessAssasin(ThreadedProcess p, long timeout) { … … 98 106 return skipInstedOfDesroy; 99 107 } 108 109 void setTimeout(long timeout) { 110 this.timeout = timeout; 111 } 112 100 113 101 114 @Override … … 119 132 try { 120 133 if (!skipInstedOfDesroy) { 121 destroyProcess( p);134 destroyProcess(); 122 135 } 123 136 } catch (Throwable ex) { … … 161 174 } 162 175 163 public static void destroyProcess(ThreadedProcess pp) { 176 public void destroyProcess() { 177 try { 178 killing = true; 179 destroyProcess(p, reactingProcess); 180 } finally { 181 killed = true; 182 } 183 } 184 185 public boolean haveKilled() { 186 return killed; 187 } 188 189 public boolean isKilling() { 190 return killing; 191 } 192 193 194 195 public static void destroyProcess(ThreadedProcess pp, ReactingProcess reactingProcess) { 164 196 Process p = pp.getP(); 165 197 try { … … 167 199 f.setAccessible(true); 168 200 String pid = (f.get(p)).toString(); 201 if (reactingProcess != null) { 202 reactingProcess.beforeKill(pid); 203 }; 169 204 sigInt(pid); 170 205 //sigTerm(pid); … … 174 209 } finally { 175 210 p.destroy(); 211 if (reactingProcess != null) { 212 reactingProcess.afterKill(""); 213 }; 176 214 } 177 215 } … … 189 227 } 190 228 191 public static void kill(String pid, String signal) throws InterruptedException, Exception {229 public static void kill(String pid, String signal) throws InterruptedException, Exception { 192 230 List<String> ll = new ArrayList<String>(4); 193 231 ll.add("kill"); … … 199 237 Thread.sleep(1000); 200 238 } 239 240 void setReactingProcess(ReactingProcess reactingProcess) { 241 this.reactingProcess = reactingProcess; 242 } 243 244 public static void closeWindow(String pid) throws Exception { 245 List<String> ll = new ArrayList<String>(2); 246 ll.add(ServerAccess.getInstance().getDir().getParent() + "/softkiller"); 247 ll.add(pid); 248 ServerAccess.executeProcess(ll); //sync, but acctually release 249 //before affected application "close" 250 Thread.sleep(100); 251 252 } 253 254 public static void closeWindows(String s) throws Exception { 255 closeWindows(s, 10); 256 } 257 258 public static void closeWindows(String s, int count) throws Exception { 259 //each close closes just one tab... 260 for (int i = 0; i < count; i++) { 261 ProcessAssasin.closeWindow(s); 262 } 263 } 264 265 201 266 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
r418 r429 1 1 /* ServerAccess.java 2 Copyright (C) 2011 Red Hat, Inc.2 Copyright (C) 2011, 2012 Red Hat, Inc. 3 3 4 4 This file is part of IcedTea. … … 56 56 import java.util.ArrayList; 57 57 import java.util.List; 58 import net.sourceforge.jnlp.ProcessResult; 58 59 import net.sourceforge.jnlp.browsertesting.Browser; 59 60 import net.sourceforge.jnlp.browsertesting.BrowserFactory; 60 61 import net.sourceforge.jnlp.browsertesting.Browsers; 62 import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener; 63 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; 64 import net.sourceforge.jnlp.util.FileUtils; 65 import net.sourceforge.jnlp.util.logging.OutputController; 61 66 import org.junit.Assert; 62 67 … … 78 83 public class ServerAccess { 79 84 85 public static enum AutoClose { 86 87 CLOSE_ON_EXCEPTION, CLOSE_ON_CORRECT_END, CLOSE_ON_BOTH 88 } 89 80 90 public static final long NANO_TIME_DELIMITER=1000000l; 81 91 /** … … 132 142 } else { 133 143 int port = 44321; 134 if (args.length > 0) { 135 port=new Integer(args[0]); 144 if (args.length > 0 && args[0].equalsIgnoreCase("randomport")) { 145 port = findFreePort(); 146 } else if (args.length > 0) { 147 port = new Integer(args[0]); 136 148 } 137 149 getIndependentInstance(port); … … 157 169 } 158 170 public static final String HEADLES_OPTION="-headless"; 159 public static final String VERBOSE_OPTION="-verbose 171 public static final String VERBOSE_OPTION="-verbose"; 160 172 161 173 /** … … 260 272 List<String> l1=this.currentBrowser.getComaptibilitySwitches(); 261 273 List<String> l2=this.currentBrowser.getDefaultSwitches(); 262 List<String> l= new ArrayList ();274 List<String> l= new ArrayList<String>(); 263 275 if (l1!=null)l.addAll(l1); 264 276 if (l2!=null)l.addAll(l2); … … 409 421 * @throws IOException if connection can't be established or resource does not exist 410 422 */ 411 public static String getContentOfStream(InputStream is,String encoding) throws IOException { 412 try { 413 BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding)); 414 StringBuilder sb = new StringBuilder(); 415 while (true) { 416 String s = br.readLine(); 417 if (s == null) { 418 break; 419 } 420 sb.append(s).append("\n"); 421 422 } 423 return sb.toString(); 424 } finally { 425 is.close(); 426 } 427 423 public static String getContentOfStream(InputStream is, String encoding) throws IOException { 424 return FileUtils.getContentOfStream(is, encoding); 428 425 } 429 426 … … 436 433 */ 437 434 public static String getContentOfStream(InputStream is) throws IOException { 438 return getContentOfStream(is, "UTF-8"); 439 435 return FileUtils.getContentOfStream(is); 440 436 } 441 437 … … 483 479 */ 484 480 public static void saveFile(String content, File f) throws IOException { 485 saveFile(content, f, "utf-8");481 FileUtils.saveFile(content, f); 486 482 } 487 483 public static void saveFile(String content, File f,String encoding) throws IOException { 488 Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f),encoding)); 489 output.write(content); 490 output.flush(); 491 output.close(); 484 FileUtils.saveFile(content, f, encoding); 492 485 } 493 486 … … 546 539 return executeJavaws(null, resource,stdoutl,stderrl); 547 540 } 541 542 public net.sourceforge.jnlp.ProcessResult executeBrowser(String string, AutoClose autoClose) throws Exception { 543 ClosingListener errClosing = null; 544 ClosingListener outClosing = null; 545 if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose == AutoClose.CLOSE_ON_EXCEPTION){ 546 errClosing=new AutoErrorClosingListener(); 547 } 548 if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose == AutoClose.CLOSE_ON_CORRECT_END){ 549 outClosing=new AutoOkClosingListener(); 550 } 551 return executeBrowser(string, outClosing, errClosing); 552 } 553 554 548 555 public ProcessResult executeBrowser(String resource) throws Exception { 549 556 return executeBrowser(getBrowserParams(), resource); 550 557 } 551 558 public ProcessResult executeBrowser(String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { 559 return executeBrowser(getBrowserParams(), resource, stdoutl, stderrl); 560 } 561 562 public ProcessResult executeBrowser(String resource, List<ContentReaderListener> stdoutl, List<ContentReaderListener> stderrl) throws Exception { 552 563 return executeBrowser(getBrowserParams(), resource, stdoutl, stderrl); 553 564 } … … 572 583 573 584 public ProcessResult executeBrowser(List<String> otherargs, String resource) throws Exception { 574 return executeProcessUponURL(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource)); 575 } 576 public ProcessResult executeBrowser(List<String> otherargs, String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { 577 return executeProcessUponURL(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource),stdoutl,stderrl); 578 } 579 580 public ProcessResult executeBrowser(Browser b,List<String> otherargs, String resource) throws Exception { 581 return executeProcessUponURL(b.getBin(), otherargs, getUrlUponThisInstance(resource)); 582 } 583 public ProcessResult executeBrowser(Browser b,List<String> otherargs, String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { 584 return executeProcessUponURL(b.getBin(), otherargs, getUrlUponThisInstance(resource),stdoutl,stderrl); 585 return executeBrowser(otherargs, getUrlUponThisInstance(resource)); 586 } 587 588 public ProcessResult executeBrowser(List<String> otherargs, URL url) throws Exception { 589 ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, url); 590 rpw.setReactingProcess(getCurrentBrowser());//current browser may be null, but it does not metter 591 return rpw.execute(); 592 } 593 594 public ProcessResult executeBrowser(List<String> otherargs, String resource, ContentReaderListener stdoutl, ContentReaderListener stderrl) throws Exception { 595 ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource), stdoutl, stderrl, null); 596 rpw.setReactingProcess(getCurrentBrowser());//current browser may be null, but it does not metter 597 return rpw.execute(); 598 } 599 600 public ProcessResult executeBrowser(List<String> otherargs, String resource, List<ContentReaderListener> stdoutl, List<ContentReaderListener> stderrl) throws Exception { 601 ProcessWrapper rpw = new ProcessWrapper(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource), stdoutl, stderrl, null); 602 rpw.setReactingProcess(getCurrentBrowser());// current browser may be null, but it does not matter 603 return rpw.execute(); 604 } 605 606 public ProcessResult executeBrowser(Browser b, List<String> otherargs, String resource) throws Exception { 607 ProcessWrapper rpw = new ProcessWrapper(b.getBin(), otherargs, getUrlUponThisInstance(resource)); 608 rpw.setReactingProcess(b); 609 return rpw.execute(); 610 } 611 612 public ProcessResult executeBrowser(Browser b, List<String> otherargs, String resource, ContentReaderListener stdoutl, ContentReaderListener stderrl) throws Exception { 613 ProcessWrapper rpw = new ProcessWrapper(b.getBin(), otherargs, getUrlUponThisInstance(resource), stdoutl, stderrl, null); 614 rpw.setReactingProcess(b); 615 return rpw.execute(); 616 } 617 618 public ProcessResult executeBrowser(Browser b, List<String> otherargs, String resource, List<ContentReaderListener> stdoutl, List<ContentReaderListener> stderrl) throws Exception { 619 ProcessWrapper rpw = new ProcessWrapper(b.getBin(), otherargs, getUrlUponThisInstance(resource), stdoutl, stderrl, null); 620 rpw.setReactingProcess(b); 621 return rpw.execute(); 622 } 623 624 /** 625 * Create resource on http, on 'localhost' on port on which this cached instance is running 626 * @param resource 627 * @return 628 * @throws MalformedURLException 629 */ 630 public URL getUrlUponThisInstance(String resource) throws MalformedURLException { 631 getInstance(); 632 return getUrlUponInstance(server, resource); 585 633 } 586 634 … … 591 639 * @throws MalformedURLException 592 640 */ 593 public URL getUrlUponThisInstance(String resource) throws MalformedURLException { 594 if (!resource.startsWith("/")) { 595 resource = "/" + resource; 596 } 597 return new URL("http", server.getServerName(), getPort(), resource); 641 public static URL getUrlUponInstance(ServerLauncher instance,String resource) throws MalformedURLException { 642 return instance.getUrl(resource); 598 643 } 599 644 … … 623 668 */ 624 669 public static ProcessResult executeProcessUponURL(String toBeExecuted, List<String> otherargs, URL u) throws Exception { 625 return executeProcessUponURL(toBeExecuted, otherargs, u,null,null); 626 } 627 628 public static ProcessResult executeProcessUponURL(String toBeExecuted, List<String> otherargs, URL u,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { 629 return executeProcessUponURL(toBeExecuted, otherargs, u, stdoutl, stderrl, null); 630 } 631 public static ProcessResult executeProcessUponURL(String toBeExecuted, List<String> otherargs, URL u,ContentReaderListener stdoutl,ContentReaderListener stderrl,String[] vars) throws Exception { 632 Assert.assertNotNull(u); 633 Assert.assertNotNull(toBeExecuted); 634 Assert.assertTrue(toBeExecuted.trim().length() > 1); 635 if (otherargs == null) { 636 otherargs = new ArrayList<String>(1); 637 } 638 List<String> urledArgs = new ArrayList<String>(otherargs); 639 urledArgs.add(0, toBeExecuted); 640 urledArgs.add(u.toString()); 641 return executeProcess(urledArgs, stdoutl, stderrl,vars); 670 return new ProcessWrapper(toBeExecuted, otherargs, u).execute(); 671 } 672 673 public static ProcessResult executeProcessUponURL(String toBeExecuted, List<String> otherargs, URL u, ContentReaderListener stdoutl, ContentReaderListener stderrl) throws Exception { 674 return new ProcessWrapper(toBeExecuted, otherargs, u, stdoutl, stderrl, null).execute(); 675 } 676 677 public static ProcessResult executeProcessUponURL(String toBeExecuted, List<String> otherargs, URL u, ContentReaderListener stdoutl, ContentReaderListener stderrl, String[] vars) throws Exception { 678 return new ProcessWrapper(toBeExecuted, otherargs, u, stdoutl, stderrl, vars).execute(); 642 679 } 643 680 … … 671 708 } 672 709 673 private static String createConnectionMessage(ThreadedProcess t) {674 return "Connecting " + t.getCommandLine();675 }676 677 710 /** 678 711 * Proceed message s to logging with request to reprint to System.err … … 699 732 } 700 733 701 privatestatic void log(String message, boolean printToOut, boolean printToErr) {734 static void log(String message, boolean printToOut, boolean printToErr) { 702 735 String idded; 703 736 StackTraceElement ste = getTestMethod(); … … 726 759 } 727 760 public static void logException(Throwable t, boolean print){ 728 try{ 729 StringWriter sw = new StringWriter(); 730 PrintWriter pw = new PrintWriter(sw); 731 t.printStackTrace(pw); 732 log(sw.toString(), false, print); 733 pw.close(); 734 sw.close(); 735 }catch(Exception ex){ 736 throw new RuntimeException(ex); 737 } 761 log(OutputController.exceptionToString(t), false, print); 738 762 } 739 763 … … 744 768 private static StackTraceElement getTestMethod(StackTraceElement[] stack) { 745 769 //0 is always thread 746 //1 is net.sourceforge.jnlp.ServerAccess 770 //1 is net.sourceforge.jnlp.* 771 //we need to get out of all of classes from this package or pick last of it 747 772 StackTraceElement result = stack[1]; 748 773 String baseClass = stack[1].getClassName(); … … 750 775 for (; i < stack.length; i++) { 751 776 result = stack[i];//at least moving up 752 if (stack[i].getClassName().contains("$")){777 if (stack[i].getClassName().contains("$")) { 753 778 continue; 754 779 } 755 if (!baseClass.equals(stack[i].getClassName())) { 756 break; 780 //probablky it is necessary to get out of net.sourceforge.jnlp. 781 //package where are right now all test-extensions 782 //for now keeping exactly the three classes helping you access the log 783 try { 784 Class<?> clazz = Class.forName(stack[i].getClassName()); 785 String path = null; 786 try { 787 path = clazz.getProtectionDomain().getCodeSource().getLocation().getPath(); 788 } catch (NullPointerException ex) { 789 //silently ignoring and continuing with null path 790 } 791 if (path != null && path.contains("/tests.build/")) { 792 if (!path.contains("/test-extensions/")) { 793 break; 794 } 795 } else { 796 //running from ide 797 if (!stack[i].getClassName().startsWith("net.sourceforge.jnlp.")) { 798 break; 799 } 800 } 801 } catch (ClassNotFoundException ex) { 802 ///should not happen, searching only for already loaded class 803 ex.printStackTrace(); 757 804 } 758 805 } … … 760 807 //so the target method is the highest form it and better to return it 761 808 //rather then die to ArrayOutOfBounds 762 if (i >= stack.length){809 if (i >= stack.length) { 763 810 return result; 764 811 } 765 //now we are out of net.sourceforge.jnlp.ServerAccess812 //now we are out of test-extensions 766 813 //method we need (the test) is highest from following class 767 814 baseClass = stack[i].getClassName(); … … 783 830 784 831 } 785 public static ProcessResult executeProcess(final List<String> args, File dir, ContentReaderListener stdoutl, ContentReaderListener stderrl,String[] vars) throws Exception { 786 ThreadedProcess t = new ThreadedProcess(args, dir,vars); 787 if (PROCESS_LOG) { 788 String connectionMesaage = createConnectionMessage(t); 789 log(connectionMesaage, true, true); 790 } 791 ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT); 792 pa.start(); 793 t.start(); 794 while (t.getP() == null && t.deadlyException == null) { 795 Thread.sleep(100); 796 } 797 if (t.deadlyException != null) { 798 pa.setCanRun(false); 799 return new ProcessResult("", "", null, true, Integer.MIN_VALUE, t.deadlyException); 800 } 801 ContentReader crs = new ContentReader(t.getP().getInputStream(),stdoutl); 802 ContentReader cre = new ContentReader(t.getP().getErrorStream(),stderrl); 803 804 OutputStream out = t.getP().getOutputStream(); 805 if (out != null) { 806 out.close(); 807 } 808 809 new Thread(crs).start(); 810 new Thread(cre).start(); 811 while (t.isRunning()) { 812 Thread.sleep(100); 813 } 814 815 while (!t.isDestoyed()) { 816 Thread.sleep(100); 817 } 818 pa.setCanRun(false); 819 // ServerAccess.logOutputReprint(t.getP().exitValue()); when process is killed, this throws exception 820 821 ProcessResult pr=new ProcessResult(crs.getContent(), cre.getContent(), t.getP(), pa.wasTerminated(), t.getExitCode(), null); 822 if (PROCESS_LOG) { 823 log(pr.stdout, true, false); 824 log(pr.stderr, false, true); 825 } 826 return pr; 827 } 828 829 /** 830 * this is temprary solution until refactoring is fully done 831 * Use net.sourceforge.jnlp.ProcessResult instead 832 */ 833 @Deprecated 834 public static class ProcessResult extends net.sourceforge.jnlp.ProcessResult { 835 836 public ProcessResult(String stdout, String stderr, Process process, boolean wasTerminated, Integer r, Throwable deadlyException) { 837 super(stdout, stderr, process, wasTerminated, r, deadlyException); 838 } 839 } 840 } 832 public static ProcessResult executeProcess(final List<String> args, File dir, ContentReaderListener stdoutl, ContentReaderListener stderrl, String[] vars) throws Exception { 833 return new ProcessWrapper(args, dir, stdoutl, stderrl, vars).execute(); 834 } 835 836 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/ServerLauncher.java
r418 r429 57 57 private final Integer port; 58 58 private final File dir; 59 private ServerSocket serverSocket; 60 private boolean supportingHeadRequest = true; 59 61 62 public void setSupportingHeadRequest(boolean supportsHead) { 63 this.supportingHeadRequest = supportsHead; 64 } 65 66 public boolean isSupportingHeadRequest() { 67 return supportingHeadRequest; 68 } 69 70 71 60 72 public String getServerName() { 61 73 return serverName; … … 100 112 running = true; 101 113 try { 102 ServerSocket s= new ServerSocket(port);114 serverSocket = new ServerSocket(port); 103 115 while (running) { 104 new TinyHttpdImpl(s.accept(), dir, port); 116 TinyHttpdImpl server = new TinyHttpdImpl(serverSocket.accept(), dir, false); 117 server.setSupportingHeadRequest(isSupportingHeadRequest()); 118 server.start(); 105 119 } 106 120 } catch (Exception e) { 107 e.printStackTrace();121 ServerAccess.logException(e); 108 122 } finally { 109 123 running = false; … … 112 126 113 127 public URL getUrl(String resource) throws MalformedURLException { 128 if (resource == null) { 129 resource = ""; 130 } 131 if (resource.trim().length() > 0 && !resource.startsWith("/")) { 132 resource = "/" + resource; 133 } 114 134 return new URL("http", getServerName(), getPort(), resource); 115 135 } … … 118 138 return getUrl(""); 119 139 } 140 141 public void stop() { 142 this.running = false; 143 if (serverSocket != null) { 144 try { 145 serverSocket.close(); 146 } catch (Exception ex) { 147 ServerAccess.logException(ex); 148 } 149 } 150 } 120 151 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java
r418 r429 46 46 * Process builder caused some unexpected and weird behavior :/ 47 47 */ 48 class ThreadedProcess extends Thread {48 public class ThreadedProcess extends Thread { 49 49 50 50 Process p = null; … … 60 60 */ 61 61 private boolean destoyed = false; 62 private ProcessAssasin assasin; 62 63 63 64 public boolean isDestoyed() { … … 118 119 } catch (Exception ex) { 119 120 ex.printStackTrace(); 120 } finally {121 return commandLine;122 121 } 122 return commandLine; 123 123 } 124 124 … … 144 144 exitCode = p.waitFor(); 145 145 Thread.sleep(500); //this is giving to fast done proecesses's e/o readers time to read all. I would like to know better solution :-/ 146 while(assasin.isKilling() && !assasin.haveKilled()){ 147 Thread.sleep(100); 148 }; 146 149 } finally { 147 150 destoyed = true; … … 164 167 } 165 168 } 169 170 void setAssasin(ProcessAssasin pa) { 171 this.assasin=pa; 172 } 166 173 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/TinyHttpdImpl.java
r418 r429 43 43 import java.io.FileInputStream; 44 44 import java.io.InputStreamReader; 45 import java.io.UnsupportedEncodingException; 46 import java.net.HttpURLConnection; 45 47 import java.net.Socket; 46 48 import java.net.SocketException; … … 56 58 * is returned, but its delivery is delayed 57 59 */ 58 class TinyHttpdImpl extends Thread { 59 60 Socket c; 61 private final File dir; 62 private final int port; 60 public class TinyHttpdImpl extends Thread { 61 62 private static final String CRLF = "\r\n"; 63 private static final String HTTP_NOT_IMPLEMENTED = "HTTP/1.0 " + HttpURLConnection.HTTP_NOT_IMPLEMENTED + " Not Implemented" + CRLF; 64 private static final String HTTP_NOT_FOUND = "HTTP/1.0 " + HttpURLConnection.HTTP_NOT_FOUND + " Not Found" + CRLF; 65 private static final String HTTP_OK = "HTTP/1.0 " + HttpURLConnection.HTTP_OK + " OK" + CRLF; 66 private static final String XSX = "/XslowX"; 67 68 private Socket socket; 69 private final File testDir; 63 70 private boolean canRun = true; 64 private static final String XSX = "/XslowX"; 65 66 public TinyHttpdImpl(Socket s, File f, int port) { 67 c = s; 68 this.dir = f; 69 this.port = port; 70 start(); 71 private boolean supportingHeadRequest = true; 72 73 public TinyHttpdImpl(Socket socket, File dir) { 74 this(socket, dir, true); 75 } 76 77 public TinyHttpdImpl(Socket socket, File dir, boolean start) { 78 this.socket = socket; 79 this.testDir = dir; 80 if (start) { 81 start(); 82 } 71 83 } 72 84 … … 75 87 } 76 88 89 public void setSupportingHeadRequest(boolean supportsHead) { 90 this.supportingHeadRequest = supportsHead; 91 } 92 93 public boolean isSupportingHeadRequest() { 94 return this.supportingHeadRequest; 95 } 96 77 97 public int getPort() { 78 return port;98 return this.socket.getPort(); 79 99 } 80 100 … … 82 102 public void run() { 83 103 try { 84 BufferedReader i = new BufferedReader(new InputStreamReader(c.getInputStream()));85 DataOutputStream o = new DataOutputStream(c.getOutputStream());104 BufferedReader reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); 105 DataOutputStream writer = new DataOutputStream(this.socket.getOutputStream()); 86 106 try { 87 107 while (canRun) { 88 String s = i.readLine();89 if ( s.length() < 1) {108 String line = reader.readLine(); 109 if (line.length() < 1) { 90 110 break; 91 111 } 92 if (s.startsWith("GET")) { 93 StringTokenizer t = new StringTokenizer(s, " "); 94 t.nextToken(); 95 String op = t.nextToken(); 96 String p = op; 97 if (p.startsWith(XSX)) { 98 p = p.replace(XSX, "/"); 99 } 100 ServerAccess.logNoReprint("Getting: " + p); 101 p = URLDecoder.decode(p, "UTF-8"); 102 ServerAccess.logNoReprint("Serving: " + p); 103 p = (".".concat((p.endsWith("/")) ? p.concat("index.html") : p)).replace('/', File.separatorChar); 104 File pp = new File(dir, p); 105 int l = (int) pp.length(); 106 byte[] b = new byte[l]; 107 FileInputStream f = new FileInputStream(pp); 108 f.read(b); 109 String content = ""; 110 String ct = "Content-Type: "; 111 if (p.toLowerCase().endsWith(".jnlp")) { 112 content = ct + "application/x-java-jnlp-file\n"; 113 } else if (p.toLowerCase().endsWith(".html")) { 114 content = ct + "text/html\n"; 115 } else if (p.toLowerCase().endsWith(".jar")) { 116 content = ct + "application/x-jar\n"; 117 } 118 o.writeBytes("HTTP/1.0 200 OK\nConten" + "t-Length:" + l + "\n" + content + "\n"); 119 if (op.startsWith(XSX)) { 120 byte[][] bb = splitArray(b, 10); 112 113 StringTokenizer t = new StringTokenizer(line, " "); 114 String request = t.nextToken(); 115 116 boolean isHeadRequest = request.equals("HEAD"); 117 boolean isGetRequest = request.equals("GET"); 118 119 if (isHeadRequest && !isSupportingHeadRequest()) { 120 ServerAccess.logOutputReprint("Received HEAD request but not supported"); 121 writer.writeBytes(HTTP_NOT_IMPLEMENTED); 122 continue; 123 } 124 125 if (!isHeadRequest && !isGetRequest) { 126 ServerAccess.logOutputReprint("Received unknown request type " + request); 127 continue; 128 } 129 130 String filePath = t.nextToken(); 131 boolean slowSend = filePath.startsWith(XSX); 132 133 if (slowSend) { 134 filePath = filePath.replace(XSX, "/"); 135 } 136 137 ServerAccess.logOutputReprint("Getting- " + request + ": " + filePath); 138 filePath = urlToFilePath(filePath); 139 140 File resource = new File(this.testDir, filePath); 141 142 if (!(resource.isFile() && resource.canRead())) { 143 ServerAccess.logOutputReprint("Could not open file " + filePath); 144 writer.writeBytes(HTTP_NOT_FOUND); 145 continue; 146 } 147 ServerAccess.logOutputReprint("Serving- " + request + ": " + filePath); 148 149 int resourceLength = (int) resource.length(); 150 byte[] buff = new byte[resourceLength]; 151 FileInputStream fis = new FileInputStream(resource); 152 fis.read(buff); 153 fis.close(); 154 155 String contentType = "Content-Type: "; 156 if (filePath.toLowerCase().endsWith(".jnlp")) { 157 contentType += "application/x-java-jnlp-file"; 158 } else if (filePath.toLowerCase().endsWith(".jar")) { 159 contentType += "application/x-jar"; 160 } else { 161 contentType += "text/html"; 162 } 163 writer.writeBytes(HTTP_OK + "Content-Length:" + resourceLength + CRLF + contentType + CRLF + CRLF); 164 165 if (isGetRequest) { 166 if (slowSend) { 167 byte[][] bb = splitArray(buff, 10); 121 168 for (int j = 0; j < bb.length; j++) { 122 169 Thread.sleep(2000); 123 170 byte[] bs = bb[j]; 124 o.write(bs, 0, bs.length);171 writer.write(bs, 0, bs.length); 125 172 } 126 173 } else { 127 o.write(b, 0, l);174 writer.write(buff, 0, resourceLength); 128 175 } 129 176 } … … 132 179 ServerAccess.logException(e, false); 133 180 } catch (Exception e) { 134 o.writeBytes("HTTP/1.0 404 ERROR\n\n\n");181 writer.writeBytes(HTTP_NOT_FOUND); 135 182 ServerAccess.logException(e, false); 183 } finally { 184 reader.close(); 185 writer.close(); 136 186 } 137 o.close();138 187 } catch (Exception e) { 139 188 ServerAccess.logException(e, false); … … 172 221 return array; 173 222 } 223 224 /** 225 * This function transforms a request URL into a path to a file which the server 226 * will return to the requester. 227 * @param url - the request URL 228 * @return a String representation of the local path to the file 229 * @throws UnsupportedEncodingException 230 */ 231 public static String urlToFilePath(String url) throws UnsupportedEncodingException { 232 url = URLDecoder.decode(url, "UTF-8"); // Decode URL encoded charaters, eg "%3B" becomes ';' 233 if (url.startsWith(XSX)) { 234 url = url.replace(XSX, "/"); 235 } 236 url = url.replaceAll("\\?.*", ""); // Remove query string from URL 237 url = ".".concat(url); // Change path into relative path 238 if (url.endsWith("/")) { 239 url += "index.html"; 240 } 241 url = url.replace('/', File.separatorChar); // If running on Windows, replace '/' in path with "\\" 242 url = stripHttpPathParams(url); 243 return url; 244 } 245 246 /** 247 * This function removes the HTTP Path Parameter from a given JAR URL, assuming that the 248 * path param delimiter is a semicolon 249 * @param url - the URL from which to remove the path parameter 250 * @return the URL with the path parameter removed 251 */ 252 public static String stripHttpPathParams(String url) { 253 if (url == null) { 254 return null; 255 } 256 257 // If JNLP specifies JAR URL with .JAR extension (as it should), then look for any semicolons 258 // after this position. If one is found, remove it and any following characters. 259 int fileExtension = url.toUpperCase().lastIndexOf(".JAR"); 260 if (fileExtension != -1) { 261 int firstSemiColon = url.indexOf(';', fileExtension); 262 if (firstSemiColon != -1) { 263 url = url.substring(0, firstSemiColon); 264 } 265 } 266 return url; 267 } 174 268 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/annotations/KnownToFail.java
r418 r429 42 42 import java.lang.annotation.RetentionPolicy; 43 43 import java.lang.annotation.Target; 44 import net.sourceforge.jnlp.browsertesting.Browsers; 44 45 45 46 /** … … 53 54 * implemented. 54 55 * </p> 56 * <p> 57 * The meaning of optional parameter failsIn is either a list of 58 * browsers where the test fails, or a default value - an empty array {}, 59 * default value means that the test fails always. 60 * </p> 55 61 */ 56 62 … … 58 64 @Retention(RetentionPolicy.RUNTIME) 59 65 public @interface KnownToFail { 60 66 public Browsers[] failsIn() default {}; 61 67 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/browsertesting/Browser.java
r418 r429 43 43 * interface which represents individual browsers 44 44 */ 45 public interface Browser {45 public interface Browser extends ReactingProcess{ 46 46 public String getDefaultBin(); 47 47 public String getDefaultPluginExpectedLocation(); … … 53 53 public List<String> getDefaultSwitches(); 54 54 55 56 55 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/browsertesting/browsers/Epiphany.java
r418 r429 35 35 exception statement from your version. 36 36 */ 37 38 37 package net.sourceforge.jnlp.browsertesting.browsers; 39 38 39 import java.util.Arrays; 40 import java.util.List; 40 41 import net.sourceforge.jnlp.browsertesting.Browsers; 41 42 42 43 public class Epiphany extends MozillaFamilyLinuxBrowser { 44 45 46 String[] cs = {}; 43 47 44 48 public Epiphany(String bin) { … … 47 51 48 52 @Override 53 public List<String> getComaptibilitySwitches() { 54 return Arrays.asList(cs); 55 } 56 57 @Override 49 58 public Browsers getID() { 50 59 return Browsers.epiphany; 51 60 } 52 53 54 55 61 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/browsertesting/browsers/Firefox.java
r418 r429 35 35 exception statement from your version. 36 36 */ 37 38 37 package net.sourceforge.jnlp.browsertesting.browsers; 39 38 40 39 import java.util.Arrays; 41 40 import java.util.List; 41 import net.sourceforge.jnlp.ProcessAssasin; 42 import net.sourceforge.jnlp.ServerAccess; 42 43 import net.sourceforge.jnlp.browsertesting.Browsers; 44 import net.sourceforge.jnlp.browsertesting.browsers.firefox.FirefoxProfilesOperator; 43 45 44 46 public class Firefox extends MozillaFamilyLinuxBrowser { 47 48 private static final FirefoxProfilesOperator firefoxProfilesOperatorSingleton = new FirefoxProfilesOperator(); 45 49 46 50 public Firefox(String bin) { 47 51 super(bin); 48 52 } 49 50 String[] cs={"-new-tab"}; 53 String[] cs = {"-new-tab"}; 51 54 52 55 @Override … … 60 63 } 61 64 65 @Override 66 public void beforeProcess(String s) { 67 try { 68 firefoxProfilesOperatorSingleton.backupProfiles(); //assuming firefox is not in safemode already 69 } catch (Exception ex) { 70 throw new RuntimeException("Firefox profile backup failed", ex); 71 } 72 } 62 73 74 @Override 75 public void afterProcess(String s) { 76 } 63 77 78 @Override 79 public void beforeKill(String s) { 80 try { 81 ProcessAssasin.closeWindows(s); 82 } catch (Exception ex) { 83 throw new RuntimeException(ex); 84 } 85 } 64 86 65 87 @Override 88 public void afterKill(String s) { 89 try { 90 firefoxProfilesOperatorSingleton.restoreProfiles(); 91 } catch (Exception ex) { 92 throw new RuntimeException("Firefox profile restoration failed", ex); 93 } 94 95 } 66 96 } -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/browsertesting/browsers/LinuxBrowser.java
r418 r429 93 93 } 94 94 95 @Override 96 public void beforeProcess(String s) { 97 98 } 99 100 @Override 101 public void afterProcess(String s) { 102 103 } 104 105 @Override 106 public void beforeKill(String s) { 107 108 } 109 110 @Override 111 public void afterKill(String s) { 112 113 } 95 114 96 115 -
trunk/icedtea-web/tests/test-extensions/net/sourceforge/jnlp/browsertesting/browsers/Midory.java
r418 r429 51 51 } 52 52 53 53 54 54 55 55 }
Note:
See TracChangeset
for help on using the changeset viewer.