Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8261518: jpackage looks for main module in current dir when there is no module-path #2781

Closed
wants to merge 7 commits into from

Conversation

@andyherrick
Copy link

@andyherrick andyherrick commented Mar 1, 2021

when the app modules have already been jlinked with the runtime, and there is no need for module-path, jpackage was acting as if the module-path was "." and picking up jars in the current directory.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8261518: jpackage looks for main module in current dir when there is no module-path

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2781/head:pull/2781
$ git checkout pull/2781

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Mar 1, 2021

👋 Welcome back herrick! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

@openjdk openjdk bot commented Mar 1, 2021

@andyherrick The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs label Mar 1, 2021
@openjdk openjdk bot added the rfr label Mar 1, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Mar 1, 2021

ArrayList<Path> paths = new ArrayList<Path>();
paths.add(TKit.TEST_SRC_ROOT.resolve("apps/image/Hello.java"));

// compile Hello.java again putting classes in tmpdir
new Executor()
.setToolProvider(JavaTool.JAVAC)
.addArguments("-d", tmpdir.toString())
.addPathArguments(paths)
.execute();

// make raw jar of just Hello.class from tmpdir.
new Executor()
.setToolProvider(JavaTool.JAR)
.dumpOutput()
.addArguments("-cvf", "junk.jar",
"-C", tmpdir.toString(), "Hello.class")
.execute();
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle Mar 3, 2021

Single line HelloApp.createBundle("junk.jar:Hello", tmpdir); would compile source class and put it into "junk.jar" in tmpdir folder. It can be used to replace lines from [109, 125] range.

What is the point to build "junk.jar"? I don't see how it is used in the test.

Copy link
Author

@andyherrick andyherrick Mar 3, 2021

The bug is that when --module-path option is not used in a modular app, jpackage uses a module-path with "." on it.
Having a non-modular jar in the modular path is an error.
So with this non-modular Hello.jar in the current directory the jpackage command failed before the fix, and succeeds after the fix.

I can create the non-modular Hello.jar in the current directory with one line:
HelloApp.createBundle(JavaAppDesc.parse("junk.jar:Hello"), Path.of("."))

Another precondition for the test is that Java runtime used with jpackage command should include module with app main class, right?
Test arguments are: List.of("Hello", "com.foo/com.foo.main.Aloha");. The first argument is non-modular app, it is not used with jlink. What is the point to run the test for non-modular app?

public void test() throws IOException {
final Path tmpdir = TKit.createTempDirectory("tmpdir");
try {
Files.createFile(tmpdir.resolve("tmpfile"));

Is this leftover from something or on purpose?

Copy link
Author

@andyherrick andyherrick Mar 3, 2021

yes - was leftover - removed

@alexeysemenyukoracle
Copy link
Member

@alexeysemenyukoracle alexeysemenyukoracle commented Mar 3, 2021

I don't quite understand what unit test is doing. It creates a runtime that includes app module. It builds "junk.jar". How these pieces are connected?

jlink.execute();

// create a non-modular jar in the current directory
HelloApp.createBundle(JavaAppDesc.parse("junk.jar:Hello"), Path.of("."));

Test files must be created in test work directory (TKit.workDir()) and not in the current directory. Test harness creates empty work directory for every test run. In case of running this test multiple times and if previous test execution was aborted "junk.jar" will be in the current directory from the previous test run and the next test run will fail.
Running test multiple times without running clean up is the case when the test is executed in IDE under debugger and debugging session is aborted.
If you absolutely must create "junk.jar" in the current directory, you need to remove it manually. Something like this:

Path junkJar = null;
try {
  junkJar = HelloApp.createBundle(JavaAppDesc.parse("junk.jar:Hello"), Path.of("."));
  ...
  cmd.executeAndAssertHelloAppImageCreated();
} finally {
    if (junkJar != null) {
      TKit.deleteIfExists(junkJar);
    }
}

@openjdk openjdk bot removed the rfr label Mar 4, 2021
Copy link
Member

@azuev-java azuev-java left a comment

Looks good. Please don't forget to fix the trailing whitespaces problem in the test.

@openjdk
Copy link

@openjdk openjdk bot commented Mar 4, 2021

@andyherrick This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8261518: jpackage looks for main module in current dir when there is no module-path

Reviewed-by: asemenyuk, almatvee, kizune

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 110 new commits pushed to the master branch:

  • e61a3ba: 8239386: handle ContendedPaddingWidth in vm_version_aarch64
  • f56c918: 8262837: handle split_USE correctly
  • bd1a806: 8263040: fix for JDK-8262122 fails validate-source
  • a6427c8: 8259709: Disable SHA-1 XML Signatures
  • ef5e13d: 8263030: Remove Shenandoah leftovers from ReferenceProcessor
  • 222a17e: 8262122: [TESTBUG] Shenandoah-specific variant of TestReferenceRefersTo
  • a777e82: 8254717: isAssignableFrom checks in KeyFactorySpi.engineGetKeySpec appear to be backwards
  • d2c4ed0: 8262000: jdk/jfr/event/gc/detailed/TestPromotionFailedEventWithParallelScavenge.java failed with "OutOfMemoryError: Java heap space"
  • 94f26e4: 8261450: JShell crashes with SIOOBE in tab completion
  • b817855: 8262935: Add missing logging to sun.net.httpserver.ServerImpl
  • ... and 100 more: https://git.openjdk.java.net/jdk/compare/2c99bad082c672b2f1b4dc7792c213b2e9076f57...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@andyherrick
Copy link
Author

@andyherrick andyherrick commented Mar 4, 2021

/integrate

@openjdk openjdk bot closed this Mar 4, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Mar 4, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Mar 4, 2021

@andyherrick Since your change was applied there have been 110 commits pushed to the master branch:

  • e61a3ba: 8239386: handle ContendedPaddingWidth in vm_version_aarch64
  • f56c918: 8262837: handle split_USE correctly
  • bd1a806: 8263040: fix for JDK-8262122 fails validate-source
  • a6427c8: 8259709: Disable SHA-1 XML Signatures
  • ef5e13d: 8263030: Remove Shenandoah leftovers from ReferenceProcessor
  • 222a17e: 8262122: [TESTBUG] Shenandoah-specific variant of TestReferenceRefersTo
  • a777e82: 8254717: isAssignableFrom checks in KeyFactorySpi.engineGetKeySpec appear to be backwards
  • d2c4ed0: 8262000: jdk/jfr/event/gc/detailed/TestPromotionFailedEventWithParallelScavenge.java failed with "OutOfMemoryError: Java heap space"
  • 94f26e4: 8261450: JShell crashes with SIOOBE in tab completion
  • b817855: 8262935: Add missing logging to sun.net.httpserver.ServerImpl
  • ... and 100 more: https://git.openjdk.java.net/jdk/compare/2c99bad082c672b2f1b4dc7792c213b2e9076f57...master

Your commit was automatically rebased without conflicts.

Pushed as commit 109af7b.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@andyherrick andyherrick deleted the JDK-8261518 branch Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants