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

org.gradle.integtests.resolve.transform.CrashingBuildsArtifactTransformIntegrationTest.groovy Maven / Gradle / Ivy

There is a newer version: 8.6
Show newest version
/*
 * Copyright 2017 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.integtests.resolve.transform

import org.gradle.integtests.fixtures.AbstractDependencyResolutionTest
import org.gradle.integtests.fixtures.ToBeFixedForInstantExecution

class CrashingBuildsArtifactTransformIntegrationTest extends AbstractDependencyResolutionTest {
    @ToBeFixedForInstantExecution
    def "cleans up cached output after build process crashes during transform"() {
        given:
        buildFile << """

enum Color { Red, Green, Blue }
def type = Attribute.of("artifactType", String)

abstract class ToColor implements TransformAction {
    interface Parameters extends TransformParameters {
        @Input
        Property getColor()
    }

    @InputArtifact
    abstract Provider getInputArtifact()

    void transform(TransformOutputs outputs) {
        def input = inputArtifact.get().asFile
        def color = parameters.color.get()
        def one = outputs.file("one")
        def outputDirectory = one.parentFile
        assert outputDirectory.directory && outputDirectory.list().length == 0
        println "Transforming \$input.name to \$color"
        one.text = "one"
        // maybe killed here
        if (System.getProperty("crash")) {
            Runtime.runtime.halt(1)
        }
        def two = outputs.file("two")
        two.text = "two"
    }
}

dependencies {
    registerTransform(ToColor) {
        from.attribute(type, "jar")
        to.attribute(type, "red")
        parameters {
            color = Color.Red
        }
    }
}

configurations { 
    compile
}
dependencies {
    def f = file("thing.jar")
    f.text = "not-really-a-jar"
    compile files(f)
}

task redThings {
    doLast {
        configurations.compile.incoming.artifactView {
            attributes { it.attribute(type, "red") }
        }.files.files
    }
}
"""
        // Ensure build scripts compiled
        run("help")

        when:
        def build1 = executer.withTasks("redThings").withArgument("-Dcrash=true").start()
        build1.waitForFailure()

        run("redThings")

        then:
        output.count("Transforming") == 1
        output.count("Transforming thing.jar to Red") == 1
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy