338 .assertSuccess(); |
338 .assertSuccess(); |
339 jar("-p", |
339 jar("-p", |
340 "--file=" + modularJar.toString()) |
340 "--file=" + modularJar.toString()) |
341 .assertSuccess() |
341 .assertSuccess() |
342 .resultChecker(r -> { |
342 .resultChecker(r -> { |
343 // Expect similar output: "Name:bar, Requires: foo,... |
343 // Expect similar output: "bar, requires mandated foo, ... |
344 // Conceals: jdk.test.foo, jdk.test.foo.internal" |
344 // conceals jdk.test.foo, conceals jdk.test.foo.internal" |
345 Pattern p = Pattern.compile("\\s+Name:\\s+bar\\s+Requires:\\s+foo"); |
345 Pattern p = Pattern.compile("\\s+bar\\s+requires\\s++foo"); |
346 assertTrue(p.matcher(r.output).find(), |
346 assertTrue(p.matcher(r.output).find(), |
347 "Expecting to find \"Name: bar, Requires: foo,...\"", |
347 "Expecting to find \"bar, requires foo,...\"", |
348 "in output, but did not: [" + r.output + "]"); |
348 "in output, but did not: [" + r.output + "]"); |
349 p = Pattern.compile( |
349 p = Pattern.compile( |
350 "Conceals:\\s+jdk.test.foo\\s+jdk.test.foo.internal"); |
350 "conceals\\s+jdk.test.foo\\s+conceals\\s+jdk.test.foo.internal"); |
351 assertTrue(p.matcher(r.output).find(), |
351 assertTrue(p.matcher(r.output).find(), |
352 "Expecting to find \"Conceals: jdk.test.foo,...\"", |
352 "Expecting to find \"conceals jdk.test.foo,...\"", |
353 "in output, but did not: [" + r.output + "]"); |
353 "in output, but did not: [" + r.output + "]"); |
354 }); |
354 }); |
355 } |
355 } |
356 |
356 |
357 @Test |
357 @Test |
358 public void dependencesFooBar() throws IOException { |
358 public void hashBarInFooModule() throws IOException { |
359 Path mp = Paths.get("dependencesFooBar"); |
359 Path mp = Paths.get("dependencesFooBar"); |
360 createTestDir(mp); |
360 createTestDir(mp); |
361 |
361 |
362 Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
362 Path modClasses = MODULE_CLASSES.resolve(BAR.moduleName); |
363 Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
363 Path modularJar = mp.resolve(BAR.moduleName + ".jar"); |
364 jar("--create", |
|
365 "--file=" + modularJar.toString(), |
|
366 "--main-class=" + FOO.mainClass, |
|
367 "--module-version=" + FOO.version, |
|
368 "--no-manifest", |
|
369 "-C", modClasses.toString(), ".") |
|
370 .assertSuccess(); |
|
371 |
|
372 modClasses = MODULE_CLASSES.resolve(BAR.moduleName); |
|
373 modularJar = mp.resolve(BAR.moduleName + ".jar"); |
|
374 jar("--create", |
364 jar("--create", |
375 "--file=" + modularJar.toString(), |
365 "--file=" + modularJar.toString(), |
376 "--main-class=" + BAR.mainClass, |
366 "--main-class=" + BAR.mainClass, |
377 "--module-version=" + BAR.version, |
367 "--module-version=" + BAR.version, |
|
368 "--no-manifest", |
|
369 "-C", modClasses.toString(), ".") |
|
370 .assertSuccess(); |
|
371 |
|
372 modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
373 modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
374 jar("--create", |
|
375 "--file=" + modularJar.toString(), |
|
376 "--main-class=" + FOO.mainClass, |
|
377 "--module-version=" + FOO.version, |
378 "--modulepath=" + mp.toString(), |
378 "--modulepath=" + mp.toString(), |
379 "--hash-dependencies=" + "foo", // dependency on foo |
379 "--hash-modules=" + "bar", |
380 "--no-manifest", |
380 "--no-manifest", |
381 "-C", modClasses.toString(), ".") |
381 "-C", modClasses.toString(), ".") |
382 .assertSuccess(); |
382 .assertSuccess(); |
383 |
383 |
384 java(mp, BAR.moduleName + "/" + BAR.mainClass, |
384 java(mp, BAR.moduleName + "/" + BAR.mainClass, |
390 assertTrue(received.hashes != null, "Expected non-null hashes value."); |
390 assertTrue(received.hashes != null, "Expected non-null hashes value."); |
391 }); |
391 }); |
392 } |
392 } |
393 |
393 |
394 @Test |
394 @Test |
395 public void badDependencyFooBar() throws IOException { |
395 public void invalidHashInFooModule() throws IOException { |
396 Path mp = Paths.get("badDependencyFooBar"); |
396 Path mp = Paths.get("badDependencyFooBar"); |
397 createTestDir(mp); |
397 createTestDir(mp); |
398 |
|
399 Path fooClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
400 Path fooJar = mp.resolve(FOO.moduleName + ".jar"); |
|
401 jar("--create", |
|
402 "--file=" + fooJar.toString(), |
|
403 "--main-class=" + FOO.mainClass, |
|
404 "--module-version=" + FOO.version, |
|
405 "--no-manifest", |
|
406 "-C", fooClasses.toString(), ".").assertSuccess(); |
|
407 |
398 |
408 Path barClasses = MODULE_CLASSES.resolve(BAR.moduleName); |
399 Path barClasses = MODULE_CLASSES.resolve(BAR.moduleName); |
409 Path barJar = mp.resolve(BAR.moduleName + ".jar"); |
400 Path barJar = mp.resolve(BAR.moduleName + ".jar"); |
410 jar("--create", |
401 jar("--create", |
411 "--file=" + barJar.toString(), |
402 "--file=" + barJar.toString(), |
412 "--main-class=" + BAR.mainClass, |
403 "--main-class=" + BAR.mainClass, |
413 "--module-version=" + BAR.version, |
404 "--module-version=" + BAR.version, |
|
405 "--no-manifest", |
|
406 "-C", barClasses.toString(), ".").assertSuccess(); |
|
407 |
|
408 Path fooClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
409 Path fooJar = mp.resolve(FOO.moduleName + ".jar"); |
|
410 jar("--create", |
|
411 "--file=" + fooJar.toString(), |
|
412 "--main-class=" + FOO.mainClass, |
|
413 "--module-version=" + FOO.version, |
414 "--modulepath=" + mp.toString(), |
414 "--modulepath=" + mp.toString(), |
415 "--hash-dependencies=" + "foo", // dependency on foo |
415 "--hash-modules=" + "bar", |
|
416 "--no-manifest", |
|
417 "-C", fooClasses.toString(), ".").assertSuccess(); |
|
418 |
|
419 // Rebuild bar.jar with a change that will cause its hash to be different |
|
420 FileUtils.deleteFileWithRetry(barJar); |
|
421 jar("--create", |
|
422 "--file=" + barJar.toString(), |
|
423 "--main-class=" + BAR.mainClass, |
|
424 "--module-version=" + BAR.version + ".1", // a newer version |
416 "--no-manifest", |
425 "--no-manifest", |
417 "-C", barClasses.toString(), ".").assertSuccess(); |
426 "-C", barClasses.toString(), ".").assertSuccess(); |
418 |
|
419 // Rebuild foo.jar with a change that will cause its hash to be different |
|
420 FileUtils.deleteFileWithRetry(fooJar); |
|
421 jar("--create", |
|
422 "--file=" + fooJar.toString(), |
|
423 "--main-class=" + FOO.mainClass, |
|
424 "--module-version=" + FOO.version + ".1", // a newer version |
|
425 "--no-manifest", |
|
426 "-C", fooClasses.toString(), ".").assertSuccess(); |
|
427 |
427 |
428 java(mp, BAR.moduleName + "/" + BAR.mainClass, |
428 java(mp, BAR.moduleName + "/" + BAR.mainClass, |
429 "-XaddExports:java.base/jdk.internal.module=bar") |
429 "-XaddExports:java.base/jdk.internal.module=bar") |
430 .assertFailure() |
430 .assertFailure() |
431 .resultChecker(r -> { |
431 .resultChecker(r -> { |
432 // Expect similar output: "java.lang.module.ResolutionException: Hash |
432 // Expect similar output: "java.lang.module.ResolutionException: Hash |
433 // of foo (WdktSIQSkd4+CEacpOZoeDrCosMATNrIuNub9b5yBeo=) differs to |
433 // of bar (WdktSIQSkd4+CEacpOZoeDrCosMATNrIuNub9b5yBeo=) differs to |
434 // expected hash (iepvdv8xTeVrFgMtUhcFnmetSub6qQHCHc92lSaSEg0=)" |
434 // expected hash (iepvdv8xTeVrFgMtUhcFnmetSub6qQHCHc92lSaSEg0=)" |
435 Pattern p = Pattern.compile(".*Hash of foo.*differs to expected hash.*"); |
435 Pattern p = Pattern.compile(".*Hash of bar.*differs to expected hash.*"); |
436 assertTrue(p.matcher(r.output).find(), |
436 assertTrue(p.matcher(r.output).find(), |
437 "Expecting error message containing \"Hash of foo ... differs to" |
437 "Expecting error message containing \"Hash of bar ... differs to" |
438 + " expected hash...\" but got: [", r.output + "]"); |
438 + " expected hash...\" but got: [", r.output + "]"); |
439 }); |
439 }); |
440 } |
440 } |
441 |
441 |
442 @Test |
442 @Test |