KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > tests > CallTestGeneric


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.editor.app.tests;
20
21 import java.io.PrintStream JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import java.security.PermissionCollection JavaDoc;
24 import java.security.Permissions JavaDoc;
25 import java.security.AllPermission JavaDoc;
26
27 import java.lang.reflect.Method JavaDoc;
28 import java.lang.reflect.Constructor JavaDoc;
29 import org.netbeans.test.editor.app.Main;
30
31 import org.netbeans.test.editor.app.util.WriterOutputStream;
32 //import org.openide.execution.NbClassLoader;
33
import org.openide.filesystems.Repository;
34
35
36 public class CallTestGeneric {
37
38     private static final boolean debug = true;
39     
40     private PrintWriter JavaDoc log = null;
41     
42     protected void log(String JavaDoc what) {
43         if (log != null) {
44             log.println(what);
45             log.flush();
46         } else {
47             System.err.println(what);
48             System.err.flush();
49         }
50     }
51     
52     public void runTest(String JavaDoc[] args, final PrintWriter JavaDoc log, final PrintWriter JavaDoc ref) throws Exception JavaDoc {
53         PrintStream JavaDoc oout = System.out;
54         PrintStream JavaDoc oerr = System.err;
55         
56         try {
57             if (debug)
58                 System.err.println("Testing internal execution!");
59             if (Repository.getDefault() == null) {
60                 throw new IllegalStateException JavaDoc("Repository.getDefault() == null, probably not internal execution.");
61             }
62             
63             if (debug)
64                 System.err.println("Redirecting System.err and System.out.");
65             System.setErr(new PrintStream JavaDoc(new WriterOutputStream(log)));
66             System.setOut(new PrintStream JavaDoc(new WriterOutputStream(ref)));
67             
68             System.err.println("Before trying to execute:");
69             Main.main(args);
70 /* NbClassLoader cl = new NbClassLoader();
71             System.err.println("Class loader parent: "+cl.getParent());
72             PermissionCollection pcoll = new Permissions();
73             pcoll.add(new AllPermission());
74             cl.setDefaultPermissions(pcoll);
75  
76             Class callTest = cl.loadClass("org.netbeans.test.editor.app.Main");
77             Method method = callTest.getMethod("main", new Class[] {args.getClass()});
78  
79             System.err.println(method.getReturnType());
80  
81             Object obj = method.invoke(null, new Object[] {args});*/

82         } catch (Exception JavaDoc e) {
83             e.printStackTrace(log);
84             throw e;
85         } finally {
86             System.err.flush();
87             System.out.flush();
88             System.setOut(oout);
89             System.setErr(oerr);
90         }
91     }
92     
93     public static final void main(String JavaDoc[] args) throws Exception JavaDoc {
94         String JavaDoc[] arguments = new String JavaDoc[] {
95             "/org/netbeans/test/editor/app/tests/javadoc_test.xml",
96             "Javadoc_writting.Common_Java_settings",
97             "/org/netbeans/test/editor/app/tests/javadoc_test.xml",
98             "Javadoc_writting.JavaDoc_inside",
99         };
100         PrintWriter JavaDoc log = new PrintWriter JavaDoc(System.err);
101         PrintWriter JavaDoc ref = new PrintWriter JavaDoc(System.out);
102         
103         new CallTestGeneric().runTest(arguments, log, ref);
104         
105         log.close();
106         ref.close();
107     }
108 }
109
Popular Tags