All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.api.reporting.dependencies.HtmlDependencyReportTaskIntegrationTest.groovy Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2013 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.dependencies

import groovy.json.JsonSlurper
import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import org.gradle.test.fixtures.file.TestFile
import org.jsoup.Jsoup
import spock.lang.Issue

/**
 * Integration tests for the HTML dependency report generation task
 */
class HtmlDependencyReportTaskIntegrationTest extends AbstractIntegrationSpec {
    def setup() {
        executer.requireOwnGradleUserHomeDir()
    }

    def "renders graph"() {
        given:
        mavenRepo.module("foo", "bar", "1.0").publish()
        mavenRepo.module("foo", "qix", "1.0").publish()
        mavenRepo.module("foo", "baz", "1.0").dependsOn("foo", "bar", "1.0").dependsOn("foo", "qix", "1.0").publish()

        file("settings.gradle") << """
            rootProject.name = 'fooProject'
        """

        file("build.gradle") << """
            apply plugin : 'project-report'
            description = 'dummy description'
            repositories {
                maven { url "${mavenRepo.uri}" }
            }
            configurations { compile }
            configurations { testCompile }
            dependencies {
              compile 'foo:baz:1.0'
              testCompile 'foo:bar:1.0'
            }
        """

        when:
        run "htmlDependencyReport"
        def json = readGeneratedJson("root")

        then:
        json.generationDate != null
        json.gradleVersion != null
        json.project.name == "fooProject"
        json.project.description == "dummy description"
        json.project.configurations.size() == 2
        json.project.configurations[0].name == "compile"
        json.project.configurations[0].dependencies.size() == 1
        json.project.configurations[0].dependencies[0].module == "foo:baz"
        json.project.configurations[0].dependencies[0].name == "foo:baz:1.0"
        json.project.configurations[0].dependencies[0].resolvable == 'RESOLVED'
        json.project.configurations[0].dependencies[0].alreadyRendered == false
        json.project.configurations[0].dependencies[0].hasConflict == false
        json.project.configurations[0].dependencies[0].children.size() == 2

        json.project.configurations[0].dependencies[0].children[0].module == "foo:bar"
        json.project.configurations[0].dependencies[0].children[0].name == "foo:bar:1.0"
        json.project.configurations[0].dependencies[0].children[0].resolvable == 'RESOLVED'
        json.project.configurations[0].dependencies[0].children[0].alreadyRendered == false
        json.project.configurations[0].dependencies[0].children[0].hasConflict == false
        json.project.configurations[0].dependencies[0].children[0].children.empty

        json.project.configurations[0].dependencies[0].children[1].module == "foo:qix"
        json.project.configurations[0].dependencies[0].children[1].name == "foo:qix:1.0"
        json.project.configurations[0].dependencies[0].children[1].resolvable == 'RESOLVED'
        json.project.configurations[0].dependencies[0].children[1].alreadyRendered == false
        json.project.configurations[0].dependencies[0].children[1].hasConflict == false
        json.project.configurations[0].dependencies[0].children[1].children.empty

        json.project.configurations[1].name == "testCompile"
        json.project.configurations[1].dependencies.size() == 1
        json.project.configurations[1].dependencies[0].module == "foo:bar"
        json.project.configurations[1].dependencies[0].name == "foo:bar:1.0"
        json.project.configurations[1].dependencies[0].resolvable == 'RESOLVED'
        json.project.configurations[1].dependencies[0].alreadyRendered == false
        json.project.configurations[1].dependencies[0].hasConflict == false
        json.project.configurations[1].dependencies[0].children.empty
    }

    def "already rendered dependencies are marked as such"() {
        given:
        mavenRepo.module("foo", "bar", "1.0").publish()
        mavenRepo.module("foo", "qix", "1.0").dependsOn("foo", "bar", "1.0").publish()
        mavenRepo.module("foo", "baz", "1.0").dependsOn("foo", "qix", "1.0").publish()

        file("settings.gradle") << """
            rootProject.name = 'fooProject'
        """

        file("build.gradle") << """
            apply plugin : 'project-report'
            repositories {
                maven { url "${mavenRepo.uri}" }
            }
            configurations { compile }
            dependencies {
              compile 'foo:qix:1.0'
              compile 'foo:baz:1.0'
            }
        """

        when:
        run "htmlDependencyReport"
        def json = readGeneratedJson("root")

        then:
        json.project.configurations[0].dependencies.size() == 2
        json.project.configurations[0].dependencies[0].name == "foo:qix:1.0"
        json.project.configurations[0].dependencies[0].children[0].name == "foo:bar:1.0"

        json.project.configurations[0].dependencies[1].name == "foo:baz:1.0"
        json.project.configurations[0].dependencies[1].children[0].name == "foo:qix:1.0"
        json.project.configurations[0].dependencies[1].children[0].alreadyRendered == true
        json.project.configurations[0].dependencies[1].children[0].children.empty
    }

    def "non-resolved dependencies are marked as such"() {
        given:
        mavenRepo.module("foo", "bar", "1.0").dependsOn("foo", "qix", "1.0").publish()

        file("settings.gradle") << """
            rootProject.name = 'fooProject'
        """

        file("build.gradle") << """
            apply plugin : 'project-report'
            repositories {
                maven { url "${mavenRepo.uri}" }
            }
            configurations { compile }
            dependencies {
              compile 'foo:bar:1.0'
              compile 'grr:bzz:1.0'
            }
        """

        when:
        run "htmlDependencyReport"
        def json = readGeneratedJson("root")

        then:
        json.project.configurations[0].dependencies.size() == 2
        json.project.configurations[0].dependencies[0].name == "foo:bar:1.0"
        json.project.configurations[0].dependencies[0].children[0].name == "foo:qix:1.0"
        json.project.configurations[0].dependencies[0].children[0].resolvable == 'FAILED'
        json.project.configurations[0].dependencies[1].name == "grr:bzz:1.0"
        json.project.configurations[0].dependencies[1].resolvable == 'FAILED'
    }

    def "conflicting dependencies are marked as such"() {
        given:
        mavenRepo.module("foo", "bar", "1.0").publish()
        mavenRepo.module("foo", "bar", "2.0").publish()
        mavenRepo.module("foo", "baz", "1.0").dependsOn("foo", "bar", "1.0").publish()

        file("build.gradle") << """
            apply plugin : 'project-report'
            repositories {
                maven { url "${mavenRepo.uri}" }
            }
            configurations { compile }
            dependencies {
              compile 'foo:baz:1.0'
              compile 'foo:bar:2.0'
            }
        """

        when:
        run "htmlDependencyReport"
        def json = readGeneratedJson("root")

        then:
        json.project.configurations[0].dependencies.size() == 2
        json.project.configurations[0].dependencies[0].name == "foo:baz:1.0"
        json.project.configurations[0].dependencies[0].children[0].name == "foo:bar:1.0 \u27A1 2.0"
        json.project.configurations[0].dependencies[0].children[0].hasConflict == true
        json.project.configurations[0].dependencies[1].name == "foo:bar:2.0"
    }

    def "generates report for multiple projects"() {
        given:
        createDirs("a", "b")
        file("settings.gradle") << """
            rootProject.name = 'fooProject'
            include 'a', 'b'
        """
        file("build.gradle") << """
            apply plugin : 'project-report'

            htmlDependencyReport {
                projects = [project(':a'), project(':b')]
            }
        """

        when:
        run "htmlDependencyReport"
        def jsonA = readGeneratedJson("root.a")
        def jsonB = readGeneratedJson("root.b")

        then:
        jsonA.project.name == "a"
        jsonB.project.name == "b"
    }

    def "copies necessary css, images and js files"() {
        given:
        file("build.gradle") << """
            apply plugin : 'project-report'
            configurations { compile }
        """

        when:
        run "htmlDependencyReport"

        then:
        file("build/reports/project/dependencies/images/d.gif").assertExists()
        file("build/reports/project/dependencies/images/d.png").assertExists()
        file("build/reports/project/dependencies/js/jquery.jstree.js").assertExists()
        file("build/reports/project/dependencies/js/jquery.min-3.5.1.js").assertExists()
        file("build/reports/project/dependencies/js/script.js").assertExists()
        file("build/reports/project/dependencies/css/style.css").assertExists()
        file("build/reports/project/dependencies/images/throbber.gif").assertExists()
        file("build/reports/project/dependencies/css/tree.css").assertExists()

        file("build/reports/project/dependencies/root.html").getText().contains('