/*
 * Copyright 2014 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.reporting.components;

import org.gradle.api.DefaultTask;
import org.gradle.api.Incubating;
import org.gradle.api.Project;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.api.reporting.components.internal.ComponentReportRenderer;
import org.gradle.api.reporting.components.internal.TypeAwareBinaryRenderer;
import org.gradle.api.tasks.TaskAction;
import org.gradle.language.base.ProjectSourceSet;
import org.gradle.logging.StyledTextOutput;
import org.gradle.logging.StyledTextOutputFactory;
import org.gradle.model.ModelMap;
import org.gradle.model.internal.registry.ModelRegistry;
import org.gradle.model.internal.type.ModelType;
import org.gradle.platform.base.BinarySpec;
import org.gradle.platform.base.ComponentSpec;
import org.gradle.platform.base.ComponentSpecContainer;
import org.gradle.platform.base.test.TestSuiteContainer;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;

import static org.gradle.model.internal.type.ModelTypes.modelMap;

/**
 * Displays some details about the software components produced by the project.
 */
@Incubating
public class ComponentReport extends DefaultTask {
    @Inject
    protected StyledTextOutputFactory getTextOutputFactory() {
        throw new UnsupportedOperationException();
    }

    @Inject
    protected FileResolver getFileResolver() {
        throw new UnsupportedOperationException();
    }

    @Inject
    protected ModelRegistry getModelRegistry() {
        throw new UnsupportedOperationException();
    }

    @Inject
    protected TypeAwareBinaryRenderer getBinaryRenderer() {
        throw new UnsupportedOperationException();
    }

    @TaskAction
    public void report() {
        Project project = getProject();

        StyledTextOutput textOutput = getTextOutputFactory().create(ComponentReport.class);
        ComponentReportRenderer renderer = new ComponentReportRenderer(getFileResolver(), getBinaryRenderer());
        renderer.setOutput(textOutput);

        renderer.startProject(project);

        Collection<ComponentSpec> components = new ArrayList<ComponentSpec>();
        ComponentSpecContainer componentSpecs = find("components", ComponentSpecContainer.class);
        if (componentSpecs != null) {
            components.addAll(componentSpecs.values());
        }

        TestSuiteContainer testSuites = find("testSuites", TestSuiteContainer.class);
        if (testSuites != null) {
            components.addAll(testSuites.values());
        }

        renderer.renderComponents(components);

        ProjectSourceSet sourceSets = find("sources", ProjectSourceSet.class);
        if (sourceSets != null) {
            renderer.renderSourceSets(sourceSets);
        }
        ModelMap<BinarySpec> binaries = find("binaries", modelMap(BinarySpec.class));
        if (binaries != null) {
            renderer.renderBinaries(binaries);
        }

        renderer.completeProject(project);
        renderer.complete();
    }

    private <T> T find(String path, Class<T> clazz) {
        return find(path, ModelType.of(clazz));
    }

    private <T> T find(String path, ModelType<T> modelType) {
        return getModelRegistry().find(path, modelType);
    }
}

@@ -2790,20 +2790,28 @@
 Specs = 
-find
+modelElement
 (%22compon
@@ -2993,20 +2993,28 @@
 uites = 
-find
+modelElement
 (%22testSu
@@ -3230,20 +3230,28 @@
 eSets = 
-find
+modelElement
 (%22source
@@ -3414,20 +3414,28 @@
 aries = 
-find
+modelElement
 (%22binari
@@ -3647,36 +3647,44 @@
   private %3CT%3E T 
-find
+modelElement
 (String path, Cl
@@ -3718,39 +3718,44 @@
 urn 
-find(path, ModelType.of(
+getModelRegistry().find(path, 
 clazz)
-)
 ;%0A  
@@ -3777,20 +3777,28 @@
 e %3CT%3E T 
-find
+modelElement
 (String 

Rename explaining method