[ci skip] update generated files
[scons.git] / test / Java / RMIC.py
blobb7e45f4e9ee844dc597ca7b99b240d7339fa956b
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 import os
28 import TestSCons
30 _python_ = TestSCons._python_
32 test = TestSCons.TestSCons()
34 test.file_fixture(['Java-fixture', 'myrmic.py'])
36 test.write('SConstruct', """
37 DefaultEnvironment(tools=[])
38 env = Environment(tools=['rmic'], RMIC=r'%(_python_)s myrmic.py')
39 env.RMIC(target='outdir', source='test1.java')
40 """ % locals())
42 test.write('test1.java', """\
43 test1.java
44 /*rmic*/
45 line 3
46 """)
48 test.run(arguments = '.', stderr = None)
50 test.must_match(['outdir', 'test1.class'], "test1.java\nline 3\n", mode='r')
52 if os.path.normcase('.java') == os.path.normcase('.JAVA'):
53 test.write('SConstruct', """\
54 DefaultEnvironment(tools=[])
55 env = Environment(tools=['rmic'], RMIC=r'%(_python_)s myrmic.py')
56 env.RMIC(target='outdir', source='test2.JAVA')
57 """ % locals())
59 test.write('test2.JAVA', """\
60 test2.JAVA
61 /*rmic*/
62 line 3
63 """)
65 test.run(arguments = '.', stderr = None)
67 test.must_match(['outdir', 'test2.class'], "test2.JAVA\nline 3\n", mode='r')
69 where_javac, java_version = test.java_where_javac()
70 where_rmic = test.java_where_rmic()
72 # Try to get the major/minor Java version
73 curver = (1, 0)
74 if java_version.count('.') == 1:
75 # Check Java version
76 major, minor = java_version.split('.')
77 try:
78 curver = (int(major), int(minor))
79 except ValueError:
80 pass
81 elif java_version.count('.') == 0:
82 # java 11?
83 try:
84 curver = (int(java_version), 0)
85 except ValueError:
86 pass
88 # Check the version of the found Java compiler.
89 # If it's 1.8 or higher, we skip the further RMIC test
90 # because we'll get warnings about the deprecated API...
91 # it's just not state-of-the-art anymore.
92 # Recent java versions (9 and greater) are back to being
93 # marketed as a simple version, but java_where_javac() will
94 # still return a dotted version, like 10.0. If this changes,
95 # will need to rework this rule.
96 # Note, how we allow simple version strings like "5" and
97 # "6" to successfully pass this test.
98 if curver < (1, 8):
99 test.file_fixture('wrapper_with_args.py')
101 test.write('SConstruct', """
102 DefaultEnvironment(tools=[])
103 foo = Environment(tools=['javac', 'rmic'])
104 foo.Java(target='class1', source='com/sub/foo')
105 foo.RMIC(
106 target='outdir1',
107 source=['class1/com/sub/foo/Example1.class', 'class1/com/sub/foo/Example2'],
108 JAVACLASSDIR='class1',
111 rmic = foo.Dictionary('RMIC')
112 bar = foo.Clone(RMIC=r'%(_python_)s wrapper_with_args.py ' + rmic)
113 bar_classes = bar.Java(target='class2', source='com/sub/bar')
114 # XXX This is kind of a Python brute-force way to do what Ant
115 # does with its "excludes" attribute. We should probably find
116 # a similar friendlier way to do this.
117 bar_classes = [c for c in bar_classes if 'Hello' not in str(c)]
118 bar.RMIC(target=Dir('outdir2'), source=bar_classes)
119 """ % locals() )
121 test.subdir(
122 'com',
123 ['com', 'other'],
124 ['com', 'sub'],
125 ['com', 'sub', 'foo'],
126 ['com', 'sub', 'bar'],
127 'src3a',
128 'src3b',
131 test.write(['com', 'sub', 'foo', 'Hello.java'], """\
132 package com.sub.foo;
134 import java.rmi.Remote;
135 import java.rmi.RemoteException;
137 public interface Hello extends Remote {
138 String sayHello() throws RemoteException;
140 """)
142 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
143 package com.sub.foo;
145 import java.rmi.Naming;
146 import java.rmi.RemoteException;
147 import java.lang.SecurityManager;
148 import java.rmi.server.UnicastRemoteObject;
150 public class Example1 extends UnicastRemoteObject implements Hello {
152 static final long serialVersionUID = 0;
154 public Example1() throws RemoteException {
155 super();
158 public String sayHello() {
159 return "Hello World!";
162 public static void main(String args[]) {
163 if (System.getSecurityManager() == null) {
164 System.setSecurityManager(new SecurityManager());
167 try {
168 Example1 obj = new Example1();
170 Naming.rebind("//myhost/HelloServer", obj);
172 System.out.println("HelloServer bound in registry");
173 } catch (Exception e) {
174 System.out.println("Example1 err: " + e.getMessage());
175 e.printStackTrace();
179 """)
181 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
182 package com.sub.foo;
184 import java.rmi.Naming;
185 import java.rmi.RemoteException;
186 import java.lang.SecurityManager;
187 import java.rmi.server.UnicastRemoteObject;
189 public class Example2 extends UnicastRemoteObject implements Hello {
191 static final long serialVersionUID = 0;
193 public Example2() throws RemoteException {
194 super();
197 public String sayHello() {
198 return "Hello World!";
201 public static void main(String args[]) {
202 if (System.getSecurityManager() == null) {
203 System.setSecurityManager(new SecurityManager());
206 try {
207 Example2 obj = new Example2();
209 Naming.rebind("//myhost/HelloServer", obj);
211 System.out.println("HelloServer bound in registry");
212 } catch (Exception e) {
213 System.out.println("Example2 err: " + e.getMessage());
214 e.printStackTrace();
218 """)
220 test.write(['com', 'sub', 'bar', 'Hello.java'], """\
221 package com.sub.bar;
223 import java.rmi.Remote;
224 import java.rmi.RemoteException;
226 public interface Hello extends Remote {
227 String sayHello() throws RemoteException;
229 """)
231 test.write(['com', 'sub', 'bar', 'Example3.java'], """\
232 package com.sub.bar;
234 import java.rmi.Naming;
235 import java.rmi.RemoteException;
236 import java.lang.SecurityManager;
237 import java.rmi.server.UnicastRemoteObject;
239 public class Example3 extends UnicastRemoteObject implements Hello {
241 static final long serialVersionUID = 0;
243 public Example3() throws RemoteException {
244 super();
247 public String sayHello() {
248 return "Hello World!";
251 public static void main(String args[]) {
252 if (System.getSecurityManager() == null) {
253 System.setSecurityManager(new SecurityManager());
256 try {
257 Example3 obj = new Example3();
259 Naming.rebind("//myhost/HelloServer", obj);
261 System.out.println("HelloServer bound in registry");
262 } catch (Exception e) {
263 System.out.println("Example3 err: " + e.getMessage());
264 e.printStackTrace();
268 """)
270 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
271 package com.sub.bar;
273 import java.rmi.Naming;
274 import java.rmi.RemoteException;
275 import java.lang.SecurityManager;
276 import java.rmi.server.UnicastRemoteObject;
278 public class Example4 extends UnicastRemoteObject implements Hello {
280 static final long serialVersionUID = 0;
282 public Example4() throws RemoteException {
283 super();
286 public String sayHello() {
287 return "Hello World!";
290 public static void main(String args[]) {
291 if (System.getSecurityManager() == null) {
292 System.setSecurityManager(new SecurityManager());
295 try {
296 Example4 obj = new Example4();
298 Naming.rebind("//myhost/HelloServer", obj);
300 System.out.println("HelloServer bound in registry");
301 } catch (Exception e) {
302 System.out.println("Example4 err: " + e.getMessage());
303 e.printStackTrace();
307 """)
309 test.run(arguments = '.')
311 test.must_match('wrapper.out',
312 "wrapper_with_args.py rmic -d outdir2 -classpath class2 com.sub.bar.Example3 com.sub.bar.Example4\n",
313 mode='r')
315 test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Stub.class'))
316 test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Stub.class'))
317 test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Stub.class'))
318 test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Stub.class'))
320 # We used to check for _Skel.class files as well, but they're not
321 # generated by default starting with Java 1.5, and they apparently
322 # haven't been needed for a while. Don't bother looking, even if we're
323 # running Java 1.4. If we think they're needed but they don't exist
324 # the test.up_to_date() call below will detect it.
325 #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Skel.class'))
326 #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Skel.class'))
327 #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Skel.class'))
328 #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Skel.class'))
330 test.up_to_date(arguments = '.')
332 test.pass_test()
334 # Local Variables:
335 # tab-width:4
336 # indent-tabs-mode:nil
337 # End:
338 # vim: set expandtab tabstop=4 shiftwidth=4: