/*
 * Copyright 2019 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.api.plugins;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.internal.component.external.model.ProjectTestFixtures;
import org.gradle.api.tasks.SourceSet;

import static org.gradle.api.plugins.internal.JavaPluginsHelper.addApiToSourceSet;
import static org.gradle.internal.component.external.model.TestFixturesSupport.*;

public class JavaTestFixturesPlugin implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getPluginManager().withPlugin("java", plugin -> {
            JavaPluginConvention convention = findJavaConvention(project);
            JavaPluginExtension extension = findJavaPluginExtension(project);
            SourceSet testFixtures = convention.getSourceSets().create(TEST_FIXTURE_SOURCESET_NAME);
            extension.registerFeature(TEST_FIXTURES_FEATURE_NAME, featureSpec -> featureSpec.usingSourceSet(testFixtures));
            addApiToSourceSet(project, testFixtures, project.getConfigurations());
            createImplicitTestFixturesDependencies(project, convention);
        });
    }

    private void createImplicitTestFixturesDependencies(Project project, JavaPluginConvention convention) {
        DependencyHandler dependencies = project.getDependencies();
        dependencies.add(TEST_FIXTURES_API, dependencies.create(project));
        ProjectDependency testDependency = (ProjectDependency) dependencies.add(findTestSourceSet(convention).getImplementationConfigurationName(), dependencies.create(project));
        testDependency.capabilities(new ProjectTestFixtures(project));
    }

    private SourceSet findTestSourceSet(JavaPluginConvention convention) {
        return convention.getSourceSets().getByName("test");
    }

    private JavaPluginExtension findJavaPluginExtension(Project project) {
        return project.getExtensions().getByType(JavaPluginExtension.class);
    }

    private JavaPluginConvention findJavaConvention(Project project) {
        return (JavaPluginConvention) project.getConvention().getPlugins().get("java");
    }

}

@@ -642,16 +642,50 @@
 ugins;%0A%0A
+import org.gradle.api.Incubating;%0A
 import o
@@ -843,16 +843,55 @@
 andler;%0A
+import org.gradle.api.tasks.SourceSet;%0A
 import o
@@ -955,23 +955,31 @@
 xtures;%0A
+%0A
 import 
+static 
 org.grad
@@ -977,38 +977,75 @@
  org.gradle.api.
-tasks.
+plugins.internal.JavaPluginsHelper.addApiTo
 SourceSet;%0A%0Aimpo
@@ -1039,17 +1039,16 @@
 rceSet;%0A
-%0A
 import s
@@ -1068,148 +1068,684 @@
 dle.
-api.plugins.internal.JavaPluginsHelper.addApiToSourceSet;%0Aimport static org.gradle.internal.component.external.model.TestFixturesSupport.*;%0A
+internal.component.external.model.TestFixturesSupport.TEST_FIXTURES_API;%0Aimport static org.gradle.internal.component.external.model.TestFixturesSupport.TEST_FIXTURES_FEATURE_NAME;%0Aimport static org.gradle.internal.component.external.model.TestFixturesSupport.TEST_FIXTURE_SOURCESET_NAME;%0A%0A/**%0A * Adds support for producing test fixtures. This plugin will automatically%0A * create a %60testFixtures%60 source set, and wires the tests to use those%0A * test fixtures automatically.%0A *%0A * Other projects may consume the test fixtures of the current project by%0A * declaring a dependency using the %7B@link DependencyHandler#testFixtures(Object)%7D%0A * method.%0A *%0A * @since 5.6%0A */%0A@Incubating
 %0Apub

Add missing javadocs