/*
 * Copyright 2010 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.groovy.scripts.internal;

import com.google.common.collect.Maps;
import groovy.lang.Script;
import org.codehaus.groovy.ast.ClassNode;
import org.gradle.api.Action;
import org.gradle.groovy.scripts.ScriptSource;
import org.gradle.internal.Cast;

import java.util.*;

public class CachingScriptClassCompiler implements ScriptClassCompiler {
    private final Map<Collection<Object>, CompiledScript<?, ?>> cachedCompiledScripts = Maps.newHashMap();
    private final ScriptClassCompiler scriptClassCompiler;

    public CachingScriptClassCompiler(ScriptClassCompiler scriptClassCompiler) {
        this.scriptClassCompiler = scriptClassCompiler;
    }

    @Override
    public <T extends Script, M> CompiledScript<T, M> compile(ScriptSource source, ClassLoader classLoader, MetadataExtractingTransformer<M> extractingTransformer, String classpathClosureName, Class<T> scriptBaseClass, Action<? super ClassNode> verifier) {
        List<Object> key = Arrays.asList(source.getClassName(), classLoader, extractingTransformer.getTransformer().getId(), scriptBaseClass.getName());
        CompiledScript<T, M> compiledScript = Cast.uncheckedCast(cachedCompiledScripts.get(key));
        if (compiledScript == null) {
            compiledScript = scriptClassCompiler.compile(source, classLoader, extractingTransformer, classpathClosureName, scriptBaseClass, verifier);
            cachedCompiledScripts.put(key, compiledScript);
        }
        return compiledScript;
    }

}

@@ -890,17 +890,19 @@
 va.util.
-*
+Map
 ;%0A%0Apubli
@@ -995,26 +995,11 @@
 Map%3C
-Collection%3CObject%3E
+Key
 , Co
@@ -1548,40 +1548,25 @@
     
-List%3CObject%3E key = Arrays.asList
+Key key = new Key
 (sou
@@ -2031,16 +2031,16 @@
       %7D%0A
-
         
@@ -2069,10 +2069,1354 @@
 %0A    %7D%0A%0A
+    private static class Key %7B%0A        private final String className;%0A        private final ClassLoader classLoader;%0A        private final String transformerId;%0A        private final String baseClassName;%0A%0A        public Key(String className, ClassLoader classLoader, String transformerId, String baseClassName) %7B%0A            this.className = className;%0A            this.classLoader = classLoader;%0A            this.transformerId = transformerId;%0A            this.baseClassName = baseClassName;%0A        %7D%0A%0A        @Override%0A        public boolean equals(Object o) %7B%0A            if (this == o) %7B%0A                return true;%0A            %7D%0A            if (o == null %7C%7C getClass() != o.getClass()) %7B%0A                return false;%0A            %7D%0A%0A            Key key = (Key) o;%0A%0A            return baseClassName.equals(key.baseClassName)%0A                    && classLoader.equals(key.classLoader)%0A                    && className.equals(key.className)%0A                    && transformerId.equals(key.transformerId);%0A        %7D%0A%0A        @Override%0A        public int hashCode() %7B%0A            int result = className.hashCode();%0A            result = 31 * result + classLoader.hashCode();%0A            result = 31 * result + transformerId.hashCode();%0A            result = 31 * result + baseClassName.hashCode();%0A            return result;%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Use an explicit key type for in memory compiled script caching, instead of using a list.