1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
|
#!/usr/bin/env python
#
# MIT License
#
# Copyright The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
Test Jar builder.
These tests require a findable/working Java subsystem.
"""
import os
import TestSCons
_python_ = TestSCons._python_
test = TestSCons.TestSCons()
where_javac, java_version = test.java_where_javac()
where_jar = test.java_where_jar()
test.file_fixture('wrapper_with_args.py')
test.write('SConstruct', """\
DefaultEnvironment(tools=[])
foo = Environment(tools=['javac', 'jar'])
# jar = foo.Dictionary('JAR')
bar = foo.Clone(JAR=r'%(_python_)s wrapper_with_args.py jar')
foo.Java(target='classes', source='com/sub/foo')
bar.Java(target='classes', source='com/sub/bar')
foo.Jar(target='foo', source='classes/com/sub/foo')
bar.Jar(target='bar', source=Dir('classes/com/sub/bar'))
""" % locals())
test.subdir('com', ['com', 'sub'], ['com', 'sub', 'foo'], ['com', 'sub', 'bar'])
test.write(['com', 'sub', 'foo', 'Example1.java'], """\
package com.sub.foo;
public class Example1
{
public static void main(String[] args)
{
}
}
""")
test.write(['com', 'sub', 'foo', 'Example2.java'], """\
package com.sub.foo;
public class Example2
{
public static void main(String[] args)
{
}
}
""")
test.write(['com', 'sub', 'foo', 'Example3.java'], """\
package com.sub.foo;
public class Example3
{
public static void main(String[] args)
{
}
}
""")
test.write(['com', 'sub', 'bar', 'Example4.java'], """\
package com.sub.bar;
public class Example4
{
public static void main(String[] args)
{
}
}
""")
test.write(['com', 'sub', 'bar', 'Example5.java'], """\
package com.sub.bar;
public class Example5
{
public static void main(String[] args)
{
}
}
""")
test.write(['com', 'sub', 'bar', 'Example6.java'], """\
package com.sub.bar;
public class Example6
{
public static void main(String[] args)
{
}
}
""")
test.run(arguments = '.')
expected_wrapper_out = "wrapper_with_args.py jar cf bar.jar classes/com/sub/bar\n"
expected_wrapper_out = expected_wrapper_out.replace('/', os.sep)
test.must_match('wrapper.out', expected_wrapper_out % locals(), mode='r')
test.must_exist('foo.jar')
test.must_exist('bar.jar')
test.up_to_date(arguments='.')
#######
# test java source files as source to Jar builder
# make some directories to test in
test.subdir('testdir2',
['testdir2', 'com'],
['testdir2', 'com', 'javasource'])
# simple SConstruct which passes the 3 .java as source
# and extracts the jars back to classes
test.write(['testdir2', 'SConstruct'], """
DefaultEnvironment(tools=[])
foo = Environment()
foo.Jar(
target='foobar',
source=[
'com/javasource/JavaFile1.java',
'com/javasource/JavaFile2.java',
'com/javasource/JavaFile3.java',
],
)
foo.Jar(
target=['foo', 'bar'],
source=[
'com/javasource/JavaFile1.java',
'com/javasource/JavaFile2.java',
'com/javasource/JavaFile3.java',
],
)
foo.Command("foobarTest", [], Mkdir("foobarTest"))
foo.Command(
'foobarTest/com/javasource/JavaFile3.java',
'foobar.jar',
foo['JAR'] + ' xvf ../foobar.jar',
chdir='foobarTest',
)
foo.Command("fooTest", [], Mkdir("fooTest"))
foo.Command(
'fooTest/com/javasource/JavaFile3.java',
'foo.jar',
foo['JAR'] + ' xvf ../foo.jar',
chdir='fooTest',
)
foo.Command("barTest", [], Mkdir("barTest"))
foo.Command(
'barTest/com/javasource/JavaFile3.java',
'bar.jar',
foo['JAR'] + ' xvf ../bar.jar',
chdir='barTest',
)
""")
test.write(['testdir2', 'com', 'javasource', 'JavaFile1.java'], """\
package com.javasource;
public class JavaFile1
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir2', 'com', 'javasource', 'JavaFile2.java'], """\
package com.javasource;
public class JavaFile2
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir2', 'com', 'javasource', 'JavaFile3.java'], """\
package com.javasource;
public class JavaFile3
{
public static void main(String[] args)
{
}
}
""")
# check the output and make sure the java files got converted to classes
# use regex . for dirsep so this will work on both windows and other platforms.
expect = ".*jar cf foo.jar -C com.javasource.JavaFile1 com.javasource.JavaFile1.class -C com.javasource.JavaFile2 com.javasource.JavaFile2.class -C com.javasource.JavaFile3 com.javasource.JavaFile3.class.*"
test.run(chdir='testdir2', match=TestSCons.match_re_dotall, stdout=expect)
#test single target jar
test.must_exist(['testdir2','foobar.jar'])
test.must_exist(['testdir2', 'foobarTest', 'com', 'javasource', 'JavaFile1.class'])
test.must_exist(['testdir2', 'foobarTest', 'com', 'javasource', 'JavaFile2.class'])
test.must_exist(['testdir2', 'foobarTest', 'com', 'javasource', 'JavaFile3.class'])
# make sure there are class in the jar
test.must_exist(['testdir2','foo.jar'])
test.must_exist(['testdir2', 'fooTest', 'com', 'javasource', 'JavaFile1.class'])
test.must_exist(['testdir2', 'fooTest', 'com', 'javasource', 'JavaFile2.class'])
test.must_exist(['testdir2', 'fooTest', 'com', 'javasource', 'JavaFile3.class'])
# make sure both jars got createds
test.must_exist(['testdir2','bar.jar'])
test.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile1.class'])
test.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile2.class'])
test.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile3.class'])
#######
# test list of lists
# make some directories to test in
test.subdir(
'listOfLists',
['manifest_dir'],
['listOfLists', 'src'],
['listOfLists', 'src', 'com'],
['listOfLists', 'src', 'com', 'javasource'],
['listOfLists', 'src', 'com', 'resource'],
)
# test varient dir and lists of lists
test.write(['listOfLists', 'SConstruct'], """
DefaultEnvironment(tools=[])
foo = Environment()
foo.VariantDir('build', 'src', duplicate=0)
foo.VariantDir('test', '../manifest_dir', duplicate=0)
sourceFiles = [
"src/com/javasource/JavaFile1.java",
"src/com/javasource/JavaFile2.java",
"src/com/javasource/JavaFile3.java",
]
list_of_class_files = foo.Java('build', source=sourceFiles)
resources = ['build/com/resource/resource1.txt', 'build/com/resource/resource2.txt']
for resource in resources:
foo.Command(
resource, list_of_class_files, Copy(resource, resource.replace('build', 'src'))
)
contents = [list_of_class_files, resources]
foo.Jar(target='lists', source=contents + ['test/MANIFEST.mf'], JARCHDIR='build')
foo.Command("listsTest", [], Mkdir("listsTest"))
foo.Command(
'listsTest/src/com/javasource/JavaFile3.java',
'lists.jar',
foo['JAR'] + ' xvf ../lists.jar',
chdir='listsTest',
)
""")
test.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile1.java'], """\
package com.javasource;
public class JavaFile1
{
public static void main(String[] args)
{
}
}
""")
test.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile2.java'], """\
package com.javasource;
public class JavaFile2
{
public static void main(String[] args)
{
}
}
""")
test.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile3.java'], """\
package com.javasource;
public class JavaFile3
{
public static void main(String[] args)
{
}
}
""")
test.write(['manifest_dir','MANIFEST.mf'],
"""Manifest-Version: 1.0
MyManifestTest: Test
""")
test.write(['listOfLists', 'src', 'com', 'resource', 'resource1.txt'], """\
this is a resource file
""")
test.write(['listOfLists', 'src', 'com', 'resource', 'resource2.txt'], """\
this is another resource file
""")
test.run(chdir='listOfLists')
#test single target jar
test.must_exist(['listOfLists','lists.jar'])
# make sure there are class in the jar
test.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile1.class'])
test.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile2.class'])
test.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile3.class'])
test.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource1.txt'])
test.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource2.txt'])
test.must_exist(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF'])
test.must_contain(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF'], b"MyManifestTest: Test" )
#######
# test different style of passing in dirs
# make some directories to test in
test.subdir(
'testdir3',
['testdir3', 'com'],
['testdir3', 'com', 'sub'],
['testdir3', 'com', 'sub', 'foo'],
['testdir3', 'com', 'sub', 'bar'],
)
# Create the jars then extract them back to check contents
test.write(['testdir3', 'SConstruct'], """
DefaultEnvironment(tools=[])
foo = Environment()
foo_cls = foo.Java(target='classes', source='com/sub/foo')
foo_res = 'classes/com/sub/foo/NonJava.txt'
foo_res_src = 'com/sub/foo/NonJava.txt'
foo.Command(foo_res, foo_cls, Copy(foo_res, foo_res_src))
foo.Jar(target='foo', source='classes/com/sub/foo', JARCHDIR='classes')
foo.Command("fooTest", 'foo.jar', Mkdir("fooTest"))
foo.Command('doesnt_exist1', "fooTest", foo['JAR'] + ' xvf ../foo.jar', chdir='fooTest')
bar = foo.Clone()
bar_cls = bar.Java(target='classes', source='com/sub/bar')
bar_res = 'classes/com/sub/bar/NonJava.txt'
bar_res_src = 'com/sub/bar/NonJava.txt'
bar.Command(bar_res, bar_cls, Copy(bar_res, bar_res_src))
bar.Jar(target='bar', source=Dir('classes/com/sub/bar'), JARCHDIR='classes')
bar.Command("barTest", 'bar.jar', Mkdir("barTest"))
bar.Command('doesnt_exist2', 'barTest', bar['JAR'] + ' xvf ../bar.jar', chdir='barTest')
""")
test.write(['testdir3', 'com', 'sub', 'foo', 'Example1.java'], """\
package com.sub.foo;
public class Example1
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir3', 'com', 'sub', 'foo', 'Example2.java'], """\
package com.sub.foo;
public class Example2
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir3', 'com', 'sub', 'foo', 'Example3.java'], """\
package com.sub.foo;
public class Example3
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir3', 'com', 'sub', 'foo', 'NonJava.txt'], """\
testfile
""")
test.write(['testdir3', 'com', 'sub', 'bar', 'Example4.java'], """\
package com.sub.bar;
public class Example4
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir3', 'com', 'sub', 'bar', 'Example5.java'], """\
package com.sub.bar;
public class Example5
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir3', 'com', 'sub', 'bar', 'Example6.java'], """\
package com.sub.bar;
public class Example6
{
public static void main(String[] args)
{
}
}
""")
test.write(['testdir3', 'com', 'sub', 'bar', 'NonJava.txt'], """\
testfile
""")
test.run(chdir='testdir3')
# check the output and make sure the java files got converted to classes
# make sure there are class in the jar
test.must_exist(['testdir3','foo.jar'])
test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example1.class'])
test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example2.class'])
test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example3.class'])
# TODO: determine expected behavior with resource files, should they be
# automatically copied in or specified in seperate commands
test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'NonJava.txt'])
# make sure both jars got createds
test.must_exist(['testdir3','bar.jar'])
test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example4.class'])
test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example5.class'])
test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example6.class'])
# TODO: determine expected behavior with resource files, should they be
# automatically copied in or specified in seperate commands
test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'NonJava.txt'])
test.pass_test()
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|