@@ -0,0 +1,3026 @@
+/*%0A * Copyright 2016 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.gradle.internal.classloader;%0A%0Aimport com.google.common.base.Preconditions;%0Aimport com.google.common.collect.Lists;%0Aimport org.gradle.internal.Factory;%0Aimport org.gradle.internal.Pair;%0A%0Aimport java.io.Closeable;%0Aimport java.util.List;%0A%0A/**%0A * A ClassLoader which lazily re-instantiates its parent on the next use after it's closed.%0A */%0Apublic class ReusableClassLoader extends ClassLoader implements ClassLoaderHierarchy, Closeable %7B%0A    private final Factory%3CClassLoader%3E parentFactory;%0A    private ClassLoader parent;%0A    private List%3CPair%3CString, Boolean%3E%3E loadedClasses;%0A%0A    public ReusableClassLoader(Factory%3CClassLoader%3E parentFactory) %7B%0A        this.parentFactory = Preconditions.checkNotNull(parentFactory);%0A        this.parent = null;%0A        this.loadedClasses = Lists.newArrayList();%0A    %7D%0A%0A    @Override%0A    public void close() %7B%0A        ClassLoaderUtils.tryClose(parent);%0A        parent = null;%0A    %7D%0A%0A    @Override%0A    public void visit(ClassLoaderVisitor visitor) %7B%0A        visitor.visitSpec(new CachingClassLoader.Spec());%0A        visitor.visitParent(parent);%0A    %7D%0A%0A    @Override%0A    protected Class%3C?%3E loadClass(String name, boolean resolve) throws ClassNotFoundException %7B%0A        if (parent == null) %7B%0A            parent = parentFactory.create();%0A            replay();%0A        %7D%0A%0A        Class%3C?%3E loadedClass = parent.loadClass(name);%0A        loadedClasses.add(Pair.of(name, resolve));%0A        return loadedClass;%0A    %7D%0A%0A    private void replay() throws ClassNotFoundException %7B%0A        // Reload prior classes one by one.%0A        List%3CPair%3CString, Boolean%3E%3E classesToLoad = loadedClasses;%0A        loadedClasses = Lists.newArrayList();%0A%0A        // This builds loadedClasses back up; the lists should be equal by the end of it.%0A        for (Pair%3CString, Boolean%3E replayClass : classesToLoad) %7B%0A            try %7B%0A                loadClass(replayClass.getLeft(), replayClass.getRight());%0A            %7D catch (ClassNotFoundException e) %7B%0A                // If loading fails, back out to the state before replay was called.%0A                close();%0A                loadedClasses = classesToLoad;%0A                throw e;%0A            %7D%0A        %7D%0A%0A        if (!loadedClasses.equals(classesToLoad)) %7B%0A            close();%0A            throw new IllegalStateException(%22Replayed classes (%22 + loadedClasses + %22) don't match old list of classes (%22 + classesToLoad + %22)%22);%0A        %7D%0A    %7D%0A%7D%0A

Revert "Remove ReusableClassLoader as it wasn't necessary."