-
Notifications
You must be signed in to change notification settings - Fork 26
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
Allow configuring other strategies for finding the Google Cloud SDK. #168
Conversation
We could consider splitting out the PathResolver into separate resolvers:
|
Mentioned to João on chat:
I also wondered about turning the
That would require some way to order the resolvers. |
if (discoveredSdkPath != null) { | ||
return discoveredSdkPath; | ||
} | ||
} catch (Exception ex) { |
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.
more specific exceptions please
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 is to prevent inadvertent exceptions from breaking the flow (e.g., IOException
or IllegalArgumentException
). Perhaps I should just trap Throwable.
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.
Catching java.lang.Exception is highly discouraged. (See Bloch, Effective Java). Catching Throwable is worse. In some cases it's OK to catch RuntimeException, but I'm not sure this is one of them. Usually you only want to do that when you don't know what code might be invoked. Here we should only catch what getCloudSdkPath might plausibly throw.
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.
You're right, it should be RuntimeException
. An exception here indicates a programming error in and should be treated as if the code had returned null
— it didn't find an SDK in some other location.
@briandealwis I noticed you assigned this issue to me. Did you just want me to review this PR or do you expect me to follow up on your work here? |
@joaoandremartins to review, please — I've done the follow-on work in GoogleCloudPlatform/google-cloud-eclipse#362 (to be modified once GoogleCloudPlatform/google-cloud-eclipse#335 lands) |
For example, from a user-supplied preference setting.
1b93b73
to
955f927
Compare
@briandealwis GoogleCloudPlatform/google-cloud-eclipse#335 landed, let me know when this is ready for another review. |
Please do @joaoandremartins — PTAL. It's now a priority because of gcloud-eclipse-tools#335 as you cut over |
/** | ||
* Compare two {@link CloudSdkResolver} instances by their rank. | ||
*/ | ||
private static class ResolverComparator implements Comparator<CloudSdkResolver>, Serializable { |
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.
why does this need to be serializable?
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.
Good question but Findbugs failed the build without it :-S
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.
we should remove that check from our FindBugs config. It's not relevant to us.
http://findbugs.sourceforge.net/bugDescriptions.html#SE_COMPARATOR_SHOULD_BE_SERIALIZABLE
Besides the resolver order issue, LGTM. |
I addressed the ordering issue in d6e67b6 — do you mean the Serializable thingy? |
Ah, didn't see that. |
This reverts commit 507d587.
Currently the Eclipse Tooling has wrapper classes (
CloudSdkProvider
andCloudSdkPrompter
) for resolving the Google Cloud SDK using a user-provided location. This solution is error-prone as all code that tries to obtain aCloudSdk
instance must funnel through these wrapper classes. Failures occur if there are any code paths that uses theCloudSdk.Builder
directly.This patch extracts an interface
CloudSdkResolver
modelled on PathResolver. TheCloudSdk
instance looks up additionalCloudSdkResolver
classes using the standardjava.util.ServiceLoader
mechanism. To support registering resolvers under Eclipse, where we have separate class loaders, we register the bundle using the Eclipse Buddy Policy; additional resolvers can also be contributed using OSGi fragments.Update: Fixes #169