5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
35 test.write('myrmic.py', r"""
44 elif a == '-classpath':
46 elif a == '-sourcepath':
52 infile = open(file, 'rb')
53 outfile = open(os.path.join(outdir, file[:-5] + '.class'), 'wb')
54 for l in infile.readlines():
55 if l[:8] != '/*rmic*/':
60 test.write('SConstruct', """
61 env = Environment(tools = ['rmic'],
62 RMIC = r'%(_python_)s myrmic.py')
63 env.RMIC(target = 'outdir', source = 'test1.java')
66 test.write('test1.java', """\
72 test.run(arguments = '.', stderr = None)
74 test.fail_test(test.read(['outdir', 'test1.class']) != "test1.java\nline 3\n")
76 if os.path.normcase('.java') == os.path.normcase('.JAVA'):
78 test.write('SConstruct', """\
79 env = Environment(tools = ['rmic'],
80 RMIC = r'%(_python_)s myrmic.py')
81 env.RMIC(target = 'outdir', source = 'test2.JAVA')
84 test.write('test2.JAVA', """\
90 test.run(arguments = '.', stderr = None)
92 test.fail_test(test.read(['outdir', 'test2.class']) != "test2.JAVA\nline 3\n")
94 where_javac, java_version = test.java_where_javac()
95 where_rmic = test.java_where_rmic()
97 test.write("wrapper.py", """\
100 open('%s', 'ab').write("wrapper.py %%s\\n" %% " ".join(sys.argv[1:]))
101 os.system(" ".join(sys.argv[1:]))
102 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
104 test.write('SConstruct', """
105 foo = Environment(tools = ['javac', 'rmic'],
106 JAVAC = r'%(where_javac)s',
107 RMIC = r'%(where_rmic)s')
108 foo.Java(target = 'class1', source = 'com/sub/foo')
109 foo.RMIC(target = 'outdir1',
110 source = ['class1/com/sub/foo/Example1.class',
111 'class1/com/sub/foo/Example2'],
112 JAVACLASSDIR = 'class1')
114 rmic = foo.Dictionary('RMIC')
115 bar = foo.Clone(RMIC = r'%(_python_)s wrapper.py ' + rmic)
116 bar_classes = bar.Java(target = 'class2', source = 'com/sub/bar')
117 # XXX This is kind of a Python brute-force way to do what Ant
118 # does with its "excludes" attribute. We should probably find
119 # a similar friendlier way to do this.
120 bar_classes = [c for c in bar_classes if str(c).find('Hello') == -1]
121 bar.RMIC(target = Dir('outdir2'), source = bar_classes)
127 ['com', 'sub', 'foo'],
128 ['com', 'sub', 'bar'],
132 test.write(['com', 'sub', 'foo', 'Hello.java'], """\
135 import java.rmi.Remote;
136 import java.rmi.RemoteException;
138 public interface Hello extends Remote {
139 String sayHello() throws RemoteException;
143 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
146 import java.rmi.Naming;
147 import java.rmi.RemoteException;
148 import java.rmi.RMISecurityManager;
149 import java.rmi.server.UnicastRemoteObject;
151 public class Example1 extends UnicastRemoteObject implements Hello {
153 static final long serialVersionUID = 0;
155 public Example1() throws RemoteException {
159 public String sayHello() {
160 return "Hello World!";
163 public static void main(String args[]) {
164 if (System.getSecurityManager() == null) {
165 System.setSecurityManager(new RMISecurityManager());
169 Example1 obj = new Example1();
171 Naming.rebind("//myhost/HelloServer", obj);
173 System.out.println("HelloServer bound in registry");
174 } catch (Exception e) {
175 System.out.println("Example1 err: " + e.getMessage());
182 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
185 import java.rmi.Naming;
186 import java.rmi.RemoteException;
187 import java.rmi.RMISecurityManager;
188 import java.rmi.server.UnicastRemoteObject;
190 public class Example2 extends UnicastRemoteObject implements Hello {
192 static final long serialVersionUID = 0;
194 public Example2() throws RemoteException {
198 public String sayHello() {
199 return "Hello World!";
202 public static void main(String args[]) {
203 if (System.getSecurityManager() == null) {
204 System.setSecurityManager(new RMISecurityManager());
208 Example2 obj = new Example2();
210 Naming.rebind("//myhost/HelloServer", obj);
212 System.out.println("HelloServer bound in registry");
213 } catch (Exception e) {
214 System.out.println("Example2 err: " + e.getMessage());
221 test.write(['com', 'sub', 'bar', 'Hello.java'], """\
224 import java.rmi.Remote;
225 import java.rmi.RemoteException;
227 public interface Hello extends Remote {
228 String sayHello() throws RemoteException;
232 test.write(['com', 'sub', 'bar', 'Example3.java'], """\
235 import java.rmi.Naming;
236 import java.rmi.RemoteException;
237 import java.rmi.RMISecurityManager;
238 import java.rmi.server.UnicastRemoteObject;
240 public class Example3 extends UnicastRemoteObject implements Hello {
242 static final long serialVersionUID = 0;
244 public Example3() throws RemoteException {
248 public String sayHello() {
249 return "Hello World!";
252 public static void main(String args[]) {
253 if (System.getSecurityManager() == null) {
254 System.setSecurityManager(new RMISecurityManager());
258 Example3 obj = new Example3();
260 Naming.rebind("//myhost/HelloServer", obj);
262 System.out.println("HelloServer bound in registry");
263 } catch (Exception e) {
264 System.out.println("Example3 err: " + e.getMessage());
271 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
274 import java.rmi.Naming;
275 import java.rmi.RemoteException;
276 import java.rmi.RMISecurityManager;
277 import java.rmi.server.UnicastRemoteObject;
279 public class Example4 extends UnicastRemoteObject implements Hello {
281 static final long serialVersionUID = 0;
283 public Example4() throws RemoteException {
287 public String sayHello() {
288 return "Hello World!";
291 public static void main(String args[]) {
292 if (System.getSecurityManager() == null) {
293 System.setSecurityManager(new RMISecurityManager());
297 Example4 obj = new Example4();
299 Naming.rebind("//myhost/HelloServer", obj);
301 System.out.println("HelloServer bound in registry");
302 } catch (Exception e) {
303 System.out.println("Example4 err: " + e.getMessage());
310 test.run(arguments = '.')
312 test.fail_test(test.read('wrapper.out') != "wrapper.py %s -d outdir2 -classpath class2 com.sub.bar.Example3 com.sub.bar.Example4\n" % where_rmic)
314 test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Stub.class'))
315 test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Stub.class'))
316 test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Stub.class'))
317 test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Stub.class'))
319 # We used to check for _Skel.class files as well, but they're not
320 # generated by default starting with Java 1.5, and they apparently
321 # haven't been needed for a while. Don't bother looking, even if we're
322 # running Java 1.4. If we think they're needed but they don't exist
323 # the test.up_to_date() call below will detect it.
324 #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Skel.class'))
325 #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Skel.class'))
326 #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Skel.class'))
327 #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Skel.class'))
329 test.up_to_date(arguments = '.')
335 # indent-tabs-mode:nil
337 # vim: set expandtab tabstop=4 shiftwidth=4: