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

Allow configuring other strategies for finding the Google Cloud SDK. #168

Merged
merged 7 commits into from
Jul 19, 2016

Conversation

briandealwis
Copy link
Member

@briandealwis briandealwis commented Jul 14, 2016

Currently the Eclipse Tooling has wrapper classes (CloudSdkProvider and CloudSdkPrompter) for resolving the Google Cloud SDK using a user-provided location. This solution is error-prone as all code that tries to obtain a CloudSdk instance must funnel through these wrapper classes. Failures occur if there are any code paths that uses the CloudSdk.Builder directly.

This patch extracts an interface CloudSdkResolver modelled on PathResolver. The CloudSdk instance looks up additional CloudSdkResolver classes using the standard java.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

@briandealwis
Copy link
Member Author

We could consider splitting out the PathResolver into separate resolvers:

  • Windows resolver
  • Environment variable resolver (GOOGLE_CLOUD_SDK_HOME)
  • System property resolver
    We'd need to have some way to rank and order the resolvers. CloudSdkResolver could have a method to return a priority value.

@briandealwis
Copy link
Member Author

Mentioned to João on chat:

The nice thing about these Resolver instances is that they're automatically registered.

I also wondered about turning the CloudSdkPrompter, which prompts the user to download and configure the Google Cloud SDK if required, into a last-ditch resolver:

I had wondered if we could turn the [eclipse-side] CloudSdkPrompter into the last-ditch Resolver that would prompt the user if it was running on the SWT thread and if there wasn't a some specific ThreadLocal flag to disable prompting.
Turning the [eclipse-side] Prompter into a Resolver also reduces the number of calling conventions to create / discover the SDK.

That would require some way to order the resolvers.

if (discoveredSdkPath != null) {
return discoveredSdkPath;
}
} catch (Exception ex) {
Copy link
Contributor

Choose a reason for hiding this comment

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

more specific exceptions please

Copy link
Member Author

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.

Copy link
Contributor

@elharo elharo Jul 16, 2016

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.

Copy link
Member Author

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.

@joaoandremartins
Copy link
Contributor

@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?

@briandealwis
Copy link
Member Author

@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)

@joaoandremartins
Copy link
Contributor

@briandealwis GoogleCloudPlatform/google-cloud-eclipse#335 landed, let me know when this is ready for another review.

@briandealwis
Copy link
Member Author

Please do @joaoandremartins — PTAL. It's now a priority because of gcloud-eclipse-tools#335 as you cut over CloudSdkProvider calls to Cloudsdk.Builder.build(), which breaks me ;-)

/**
* Compare two {@link CloudSdkResolver} instances by their rank.
*/
private static class ResolverComparator implements Comparator<CloudSdkResolver>, Serializable {
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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

@joaoandremartins
Copy link
Contributor

Besides the resolver order issue, LGTM.

@briandealwis
Copy link
Member Author

briandealwis commented Jul 19, 2016

@joaoandremartins Besides the resolver order issue, LGTM.

I addressed the ordering issue in d6e67b6 — do you mean the Serializable thingy?

@joaoandremartins
Copy link
Contributor

Ah, didn't see that.
LGTM

@briandealwis briandealwis merged commit 4bdcb76 into master Jul 19, 2016
@briandealwis briandealwis deleted the servicelocator branch July 19, 2016 20:04
JoeWang1127 pushed a commit that referenced this pull request Nov 29, 2023
…nes are "v2-alpha" only (#168)

* Fixes #167 - Update parameter javadocs in RunMojo to indicate which ones are v2-alpha only

* reformat javadoc to make Checkstyle happy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide hooks for locating the Google Cloud SDK in other locations
5 participants