@@ -0,0 +1,3311 @@
+/*%0A * Copyright 2014 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.api.internal.plugins;%0A%0Aimport org.gradle.api.Nullable;%0Aimport org.gradle.api.Plugin;%0Aimport org.gradle.api.plugins.PluginAware;%0Aimport org.gradle.model.internal.core.ModelRuleRegistration;%0Aimport org.gradle.model.internal.inspect.ModelRuleInspector;%0Aimport org.gradle.model.internal.inspect.ModelRuleSourceDetector;%0Aimport org.gradle.model.internal.inspect.RuleSourceDependencies;%0Aimport org.gradle.model.internal.registry.ModelRegistryScope;%0A%0Aimport java.util.List;%0A%0Apublic class RuleBasedPluginApplicator%3CT extends ModelRegistryScope & PluginAware%3E implements PluginApplicator %7B%0A%0A    private final ModelRuleInspector inspector;%0A    private final T target;%0A    private final ModelRuleSourceDetector modelRuleSourceDetector;%0A    private final PluginApplicator imperativeApplicator;%0A%0A    public RuleBasedPluginApplicator(T target, ModelRuleInspector inspector, ModelRuleSourceDetector modelRuleSourceDetector) %7B%0A        this.target = target;%0A        this.inspector = inspector;%0A        this.modelRuleSourceDetector = modelRuleSourceDetector;%0A        this.imperativeApplicator = new ImperativeOnlyPluginApplicator%3CT%3E(target);%0A    %7D%0A%0A    public void applyImperative(@Nullable String pluginId, Plugin%3C?%3E plugin) %7B%0A        imperativeApplicator.applyImperative(pluginId, plugin);%0A    %7D%0A%0A    public void applyRules(@Nullable String pluginId, Class%3C?%3E clazz) %7B%0A        for (Class%3C?%3E source : modelRuleSourceDetector.getDeclaredSources(clazz)) %7B%0A            List%3CModelRuleRegistration%3E registrations = inspector.inspect(source, new RuleSourceDependencies() %7B%0A                public void add(Class%3C?%3E source) %7B%0A                    target.getPluginManager().apply(source);%0A                %7D%0A            %7D);%0A            for (ModelRuleRegistration registration : registrations) %7B%0A                // TODO catch %E2%80%9Cstrange%E2%80%9D exceptions thrown here and wrap with some context on the rule being registered%0A                // If the thrown exception doesn't provide any %E2%80%9Cmodel rule%E2%80%9D context, it will be more or less impossible for a user%0A                // to work out what happened because the stack trace won't reveal any info about which rule was being registered.%0A                // However, a %E2%80%9Cwrap everything%E2%80%9D%C2%A0strategy doesn't quite work because the thrown exception may already have enough context%0A                // and do a better job of explaining what went wrong than what we can do at this level.%0A                registration.applyTo(target.getModelRegistry());%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void applyImperativeRulesHybrid(@Nullable String pluginId, Plugin%3C?%3E plugin) %7B%0A        applyImperative(pluginId, plugin);%0A        applyRules(pluginId, plugin.getClass());%0A    %7D%0A%0A%7D%0A

Add file left out of previous commit