Skip to content

Conversation

@rjernst
Copy link
Member

@rjernst rjernst commented Apr 22, 2020

At one time, all uses of java home were found through the getJavaHome
utility method on BuildPlugin. However, that was changed many
refactorings ago, but the complex support for registering a java home
version needed that fails at configuration time still exists. The only
remaining use of grabbing java home is within bwc tests, and must be at
runtime since that is when we have the checkout and know what version is
needed.

This commit consolidates the java home finding method into a utility
unassociated with BuildPlugin.

At one time, all uses of java home were found through the getJavaHome
utility method on BuildPlugin. However, that was changed many
refactorings ago, but the complex support for registering a java home
version needed that fails at configuration time still exists. The only
remaining use of grabbing java home is within bwc tests, and must be at
runtime since that is when we have the checkout and know what version is
needed.

This commit consolidates the java home finding method into a utility
unassociated with BuildPlugin.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Build)

@rjernst rjernst requested a review from mark-vieira April 22, 2020 23:38
@mark-vieira
Copy link
Contributor

The only remaining use of grabbing java home is within bwc tests, and must be at runtime since that is when we have the checkout and know what version is needed.

Doesn't this now mean that if you try to run one of these BWC tasks and don't have the correct environment variable set you won't get an error until task execution time? Before we'd error at graph calculation time, giving folks and opportunity to fix the issue before the build kicked off and failed late.

@rjernst
Copy link
Member Author

rjernst commented Apr 23, 2020

Before we'd error at graph calculation time, giving folks and opportunity to fix the issue before the build kicked off and failed late.

We did long ago, but we dont' anymore. Notice that the method is called from within a doFirst.

@rjernst
Copy link
Member Author

rjernst commented Apr 23, 2020

Note that this changed when we moved from hardcoding the java version to use inside bwc/build.gradle to extracting the version from the bwc checkout.

Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

Couple minor comments, otherwise LGTM. Thanks for moving this out of BuildPlugin. We will soon wrangle this beast.

if (java.isEmpty()) {
throw new GradleException("JAVA" + version + "_HOME required to run task " + task.getPath());
}
return java.get().getJavaHome().get().getAbsolutePath();
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be simplified to java.orElseThrow(() -> new GradleException("message"))

public class JavaUtil {

/** A convenience method for getting java home for a version of java and requiring that version for the given task to execute */
static String getJavaHome(final Task task, final int version) {
Copy link
Contributor

@mark-vieira mark-vieira Apr 23, 2020

Choose a reason for hiding this comment

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

Give we are ditching all the task graph stuff I think we can even just avoid the Task parameter here. If this blows up at runtime in a task action the exception cause chain will include the failing task so no need to have it here just for the purpose of including it in the exception message.

@rjernst rjernst merged commit 6cb17a3 into elastic:master Apr 27, 2020
@rjernst rjernst deleted the buildsplit1 branch April 27, 2020 19:42
rjernst added a commit that referenced this pull request Apr 27, 2020
* Simplify java home verification

At one time, all uses of java home were found through the getJavaHome
utility method on BuildPlugin. However, that was changed many
refactorings ago, but the complex support for registering a java home
version needed that fails at configuration time still exists. The only
remaining use of grabbing java home is within bwc tests, and must be at
runtime since that is when we have the checkout and know what version is
needed.

This commit consolidates the java home finding method into a utility
unassociated with BuildPlugin.

* fix checkstyle

* address feedback
rjernst added a commit that referenced this pull request Apr 27, 2020
* Simplify java home verification

At one time, all uses of java home were found through the getJavaHome
utility method on BuildPlugin. However, that was changed many
refactorings ago, but the complex support for registering a java home
version needed that fails at configuration time still exists. The only
remaining use of grabbing java home is within bwc tests, and must be at
runtime since that is when we have the checkout and know what version is
needed.

This commit consolidates the java home finding method into a utility
unassociated with BuildPlugin.

* fix checkstyle

* address feedback
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Delivery/Build Build or test infrastructure >refactoring Team:Delivery Meta label for Delivery team v7.8.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants