-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8350964: Add an ArtifactResolver.fetch(clazz) method #23989
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
Conversation
|
👋 Welcome back mdonovan! A progress list of the required criteria for merging this PR into |
|
@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: 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
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 |
Webrevs
|
| } catch (ArtifactResolverException e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause == null) { | ||
| // if property doesn't exist |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| try { | ||
| String opensslPath = OpensslArtifactFetcher.getOpensslPath(); | ||
| // if the current version of openssl is available, perform all | ||
| // keytool <-> openssl interop tests | ||
| generateInitialKeystores(opensslPath); | ||
| testWithJavaCommands(); | ||
| testWithOpensslCommands(opensslPath); |
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good thanks
|
LGTM |
| } | ||
|
|
||
| private static Path fetchNssLib(String osId, Path libraryName) { | ||
| private static Path fetchNssLib(String osId, Path libraryName) throws IOException { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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."; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright year.
|
/integrate |
|
Going to push as commit e62becc.
Your commit was automatically rebased without conflicts. |
In this PR, I created a new method,
ArtifactResolver.fetchOne(), to consolidate duplicate code across tests.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23989/head:pull/23989$ git checkout pull/23989Update a local copy of the PR:
$ git checkout pull/23989$ git pull https://git.openjdk.org/jdk.git pull/23989/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23989View PR using the GUI difftool:
$ git pr show -t 23989Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23989.diff
Using Webrev
Link to Webrev Comment