KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > common > launch > DirectLauncher


1 package org.jacorb.test.common.launch;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 2005 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301, USA.
22  */

23
24 import java.util.*;
25 import java.io.*;
26
27 /**
28  * Launches a JacORB process by direct invocation of a JVM
29  * with appropriate arguments.
30  *
31  * @author Andre Spiegel spiegel@gnu.org
32  * @version $Id: DirectLauncher.java,v 1.1 2005/05/10 13:58:29 andre.spiegel Exp $
33  */

34 public class DirectLauncher extends JacORBLauncher
35 {
36     public DirectLauncher(String JavaDoc jacorbHome, boolean coverage)
37     {
38         super(jacorbHome, coverage);
39     }
40
41     public Process JavaDoc launch(String JavaDoc classpath,
42                           Properties props,
43                           String JavaDoc mainClass,
44                           String JavaDoc[] args)
45     {
46         Runtime JavaDoc rt = Runtime.getRuntime();
47
48         List cmdList = new ArrayList();
49         
50         String JavaDoc javaHome = System.getProperty("java.home");
51         String JavaDoc javaCommand = javaHome + "/bin/java";
52         cmdList.add (javaCommand);
53         cmdList.add ("-classpath");
54         cmdList.add (classpath + ":" + getJacORBLibraryPath());
55         cmdList.add ("-Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB");
56         cmdList.add ("-Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton");
57         cmdList.addAll (propsToArgList(props));
58         cmdList.add ("-Djacorb.home=" + jacorbHome);
59         cmdList.add (mainClass);
60         cmdList.addAll (Arrays.asList(args));
61         
62         String JavaDoc[] envp = new String JavaDoc[]
63         {
64             "JACORB_HOME=" + jacorbHome
65         };
66         
67         try
68         {
69             String JavaDoc[] cmd = toStringArray(cmdList);
70             //System.out.print ("exec: ");
71
//for (int i=0; i<cmd.length; i++)
72
//{
73
// System.out.print (cmd[i]);
74
// if (i<cmd.length-1) System.out.print (" ");
75
//}
76
//System.out.println();
77
return rt.exec (cmd, envp);
78         }
79         catch (IOException ex)
80         {
81             throw new RuntimeException JavaDoc(ex);
82         }
83     }
84     
85     public String JavaDoc getJacORBLibraryPath()
86     {
87         return getJacORBPath() + ":"
88              + jacorbHome + "/lib/logkit-1.2.jar:"
89              + jacorbHome + "/lib/avalon-framework-4.1.5.jar:"
90              + jacorbHome + "/lib/concurrent-1.3.2.jar:"
91              + jacorbHome + "/lib/antlr-2.7.2.jar:"
92              + jacorbHome + "/lib/picocontainer-1.2-021105.jar";
93     }
94         
95     public String JavaDoc getJacORBPath()
96     {
97         File result = null;
98         if (coverage)
99         {
100             result = new File (jacorbHome, "classes-instrumented");
101             if (!result.exists())
102                 System.out.println ("WARNING: JacORB installation "
103                                     + jacorbHome
104                                     + " is not instrumented; coverage "
105                                     + " will not be available");
106             else
107                 return result.toString() + ":"
108                      + jacorbHome + "/classes:"
109                      + jacorbHome + "/test/regression/lib/emma.jar";
110         }
111         result = new File (jacorbHome, "classes/org");
112         if (result.exists())
113             return new File (jacorbHome, "classes").toString();
114         else
115             return new File (jacorbHome, "lib/jacorb.jar").toString();
116     }
117 }
118
Popular Tags