/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gradle.launcher.daemon.context;

import org.gradle.util.Jvm;
import org.gradle.api.internal.Factory;

import java.io.File;

/**
 * Builds a daemon context, reflecting the current environment.
 * <p>
 * The builder itself has properties for different context values, that allow you to override
 * what would be set based on the environment. This is primarily to aid in testing.
 */
public class DaemonContextBuilder implements Factory<DaemonContext> {

    private final Jvm jvm = Jvm.current();

    private File javaHome;

    public DaemonContextBuilder() {
        javaHome = jvm.getJavaHome().getCanonicalFile();
    }

    public File getJavaHome() {
        return javaHome;
    }

    public void setJavaHome(File javaHome) {
        this.javaHome = javaHome;
    }

    /**
     * Creates a new daemon context, based on the current state of this builder.
     */
    public DaemonContext create() {
        return new DefaultDaemonContext(javaHome);
    }
}
@@ -682,16 +682,60 @@
 il.Jvm;%0A
+import org.gradle.api.UncheckedIOException;%0A
 import o
@@ -787,16 +787,44 @@
 io.File;
+%0Aimport java.io.IOException;
 %0A%0A/**%0A *
@@ -1249,24 +1249,42 @@
 Builder() %7B%0A
+        try %7B%0A    
         java
@@ -1328,16 +1328,165 @@
 File();%0A
+        %7D catch (IOException e) %7B%0A            throw new UncheckedIOException(%22Unable to canonicalise JAVA_HOME '%22 + jvm.getJavaHome(), e);%0A        %7D%0A
     %7D%0A%0A 

add missing catch for potential io error when canonicalising the java home of the daemon context.