BuildEnvironment (final @Nullable BuildEnvironment buildEnvironment) { if (buildEnvironment == null || buildEnvironment instanceof InternalBuildEnvironment) { return buildEnvironment; } return new InternalBuildEnvironment( () -> { BuildIdentifier buildIdentifier = buildEnvironment.getBuildIdentifier(); return new InternalBuildIdentifier(buildIdentifier.getRootDir()); }, () -> { GradleEnvironment gradle = buildEnvironment.getGradle(); return gradle.getGradleUserHome(); }, () -> { GradleEnvironment gradle = buildEnvironment.getGradle(); return gradle.getGradleVersion(); }, () -> { JavaEnvironment java = buildEnvironment.getJava(); return new InternalJavaEnvironment(java.getJavaHome(), java.getJvmArguments()); } ); }