Skip to content

Conversation

@mpdonova
Copy link
Contributor

@mpdonova mpdonova commented Mar 11, 2025

In this PR, I created a new method, ArtifactResolver.fetchOne(), to consolidate duplicate code across tests.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8350964: Add an ArtifactResolver.fetch(clazz) method (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23989/head:pull/23989
$ git checkout pull/23989

Update a local copy of the PR:
$ git checkout pull/23989
$ git pull https://git.openjdk.org/jdk.git pull/23989/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23989

View PR using the GUI difftool:
$ git pr show -t 23989

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23989.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 11, 2025

👋 Welcome back mdonovan! 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 bot commented Mar 11, 2025

@mpdonova 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:

8350964: Add an ArtifactResolver.fetch(clazz) method

Reviewed-by: weijun

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 54 new commits pushed to the master branch:

  • 0454406: 8351987: ProblemList the failing JFR streaming tests on macOS
  • be36b23: 8351778: JIT compiler fails when running -XX:AOTMode=create
  • 7fc776e: 8270265: LineBreakMeasurer calculates incorrect line breaks with zero-width characters
  • 3da5e3f: 8349350: Unable to print using InputSlot and OutputBin print attributes at the same time
  • aa047ee: 8319192: Remove javax.swing.plaf.synth.SynthLookAndFeel.load(URL url)
  • cd1be91: 8319055: JCMD should not buffer the whole output of commands
  • 248c373: 8351266: JFR: -XX:StartFlightRecording:report-on-exit
  • 03ef79c: 8346470: Improve WriteBarrier JMH to have old-to-young refs
  • b50fe9b: 8280818: Expand bug8033699.java to iterate over all LaFs
  • 771e160: 8351323: Parameterize compiler and linker flags for iconv
  • ... and 44 more: https://git.openjdk.org/jdk/compare/0de2cddf3a7be23f67af93972875af1235f3107e...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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 11, 2025
@openjdk
Copy link

openjdk bot commented Mar 11, 2025

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

  • security

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 security security-dev@openjdk.org label Mar 11, 2025
@mlbridge
Copy link

mlbridge bot commented Mar 11, 2025

Webrevs

} catch (ArtifactResolverException e) {
Throwable cause = e.getCause();
if (cause == null) {
// if property doesn't exist
Copy link
Member

@myankelev myankelev Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our discussion, do you think doing it in a way similar to this would be easier to read during a debug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the message.

}
}

private static Path fetchACVPServerTests(Class<?> clazz) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a point in this method? It's used in 1 spot only it seems and you can just directly call fetchOne

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It encapsulates all of the logic involved in getting the tests. Specifically, what to do if the tests can't be fetched. It could be done in main() but this is a little cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather just let ArtifactResolver.fetchOne throw the SkippedException. Is that always what we need?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a reason why a test would want to continue if the file wasn't accessible. I moved the skippedexception into thefetchOne method.

Comment on lines 84 to 90
try {
String opensslPath = OpensslArtifactFetcher.getOpensslPath();
// if the current version of openssl is available, perform all
// keytool <-> openssl interop tests
generateInitialKeystores(opensslPath);
testWithJavaCommands();
testWithOpensslCommands(opensslPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should only try catch the Artifact fetching line, as other test methods could potentially throw an IOException and it could get hidden with a SkippedException

Suggested change
try {
String opensslPath = OpensslArtifactFetcher.getOpensslPath();
// if the current version of openssl is available, perform all
// keytool <-> openssl interop tests
generateInitialKeystores(opensslPath);
testWithJavaCommands();
testWithOpensslCommands(opensslPath);
String opensslPath;
try {
opensslPath = OpensslArtifactFetcher.getOpensslPath();
} catch (IOException exc) {
String exMsg = "Can't find the version: "
+ OpensslArtifactFetcher.getTestOpensslBundleVersion()
+ " of openssl binary on this machine, please install"
+ " and set openssl path with property 'test.openssl.path'";
throw new SkippedException(exMsg);
}
// if the current version of openssl is available, perform all
// keytool <-> openssl interop tests
generateInitialKeystores(opensslPath);
testWithJavaCommands();
testWithOpensslCommands(opensslPath);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good thanks

@myankelev
Copy link
Member

LGTM

}

private static Path fetchNssLib(String osId, Path libraryName) {
private static Path fetchNssLib(String osId, Path libraryName) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the IOException caught later and wrapped as a SkippedException?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed ArtifactResolver.fetchOne() to throw a SkippedException but this method still throws an IOException if the nss directory/artifact doesn't contain the necessary files. That case is handled by different tests and I didn't want to change it.

}
}

private static Path fetchACVPServerTests(Class<?> clazz) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather just let ArtifactResolver.fetchOne throw the SkippedException. Is that always what we need?

if (artifact != null) {
message = "Cannot find the artifact " + artifact.name();
} else {
message = "Class " + klass.getName() + " missing @Artifact annotation.";
Copy link
Contributor

@wangweij wangweij Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it's a bug if klass is not annotated with @Artifact. I'd rather throw an NPE here so we can notice it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to just assume artifact is never null and let the NPE be thrown if it is?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to reflect that.

import jdk.test.lib.json.JSONValue;
import jtreg.SkippedException;

import java.io.IOException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless now. The import jtreg.SkippedException is also useless.

testWithJavaCommands();
testWithOpensslCommands(opensslPath);
} else {
if (opensslPath == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we modify OpensslArtifactFetcher.getOpensslPath() so that the SkippedException is thrown inside it when the version check fails at the last line? You are already throwing this exception when fetchOpenssl is called there.

This makes sure the return value is never null, and it's consistent to ArtifactResolver.fetchOne. You can add a @throws javadoc there for clarity.


import jtreg.SkippedException;

import java.io.IOException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless now.

* Retrieve an artifact/library/file from a repository or local file system.
* <p>
* Artifacts are defined with the {@link jdk.test.lib.artifacts.Artifact}
* annotation. The file name should have the format ARTIFACT_NAME-VERSION.EXT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be a directory, right? So maybe path name is more precise.

Also, you haven't defined what each piece in ARTIFACT_NAME-VERSION.EXT is. On the other hand, the names in Artifact are name, revision, and extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't really belong here anyway so I removed it entirely

* annotation. The file name should have the format ARTIFACT_NAME-VERSION.EXT
* <p>
* If you have a local version of a dependency that you want to use, you can
* specify that by setting the System property:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to capitalize system.

* @param klass a class annotated with {@link jdk.test.lib.artifacts.Artifact}
* @return the local path to the artifact. If the artifact is a compressed
* file that gets unpacked, this path will point to the root
* directory of the uncompressed file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe file(s)?

package jdk.test.lib.security;

import java.io.File;
import java.io.IOException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless now.

return path;
private static Path fetchNssLib(Class<?> clazz, Path libraryName) throws IOException {
Path p = ArtifactResolver.fetchOne(clazz);
return findNSSLibrary(p, libraryName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this method should never return null. Can we change fetchNssLib(String osId, Path libraryName) to also never return null (default throws SkippedException)? Then inside getNSSLibPath(String library) there is no need for the null check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, i removed the unnecessary null-checks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import jtreg.SkippedException; is useless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 useless imports now:

import java.nio.file.Paths;
import jdk.test.lib.artifacts.ArtifactResolverException;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Mar 13, 2025
@mpdonova
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 17, 2025

Going to push as commit e62becc.
Since your change was applied there have been 73 commits pushed to the master branch:

  • dbf47d6: 8351876: RISC-V: enable and fix some float round tests
  • d207ed3: 8352066: JVM.commit() and JVM.flush() exhibit race conditions against JFR epochs
  • 0450ba9: 8351999: JFR: Incorrect scaling of throttled values
  • e5666f5: 8351976: assert(vthread_epoch == current_epoch) failed: invariant
  • 2eecf15: 8351967: JFR: AnnotationIterator should handle num_annotations = 0
  • c8913d2: 8345555: Improve layout of search results
  • e29d405: 8352110: [BACKOUT] C2: Print compilation bailouts with PrintCompilation compile command
  • 9f8d833: 8346194: Improve G1 pre-barrier C2 cost estimate
  • 2672c40: 8351167: ZGC: Lazily initialize livemap
  • 63bf791: 8351992: JFR: Improve robustness of the SettingControl examples
  • ... and 63 more: https://git.openjdk.org/jdk/compare/0de2cddf3a7be23f67af93972875af1235f3107e...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Mar 17, 2025
@openjdk openjdk bot closed this Mar 17, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 17, 2025
@openjdk
Copy link

openjdk bot commented Mar 17, 2025

@mpdonova Pushed as commit e62becc.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated security security-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

4 participants