org.gradle.api.internal.tasks.properties.PropertyValidationAccessTest.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* 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.api.internal.tasks.properties
import com.google.common.collect.ImmutableMap
import org.gradle.api.DefaultTask
import org.gradle.api.Named
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTree
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import spock.lang.Specification
import java.nio.file.Path
class PropertyValidationAccessTest extends Specification {
static class TaskWithFileInput extends DefaultTask {
@Input
File file
@Input
Path filePath
@Input
FileCollection fileCollection
@Input
FileTree fileTree
}
def "warns about @Input being used on File and FileCollection properties"() {
expect:
assertHasValidationProblems(TaskWithFileInput, [
"property 'file' has @Input annotation used on property of type $File.name",
"property 'fileCollection' has @Input annotation used on property of type $FileCollection.name",
"property 'filePath' has @Input annotation used on property of type $Path.name",
"property 'fileTree' has @Input annotation used on property of type $FileTree.name"
])
}
@CacheableTask
static class CacheableTaskWithoutPathSensitivity extends DefaultTask {
@InputFile
File inputFile
@InputFiles
FileCollection inputFiles
@OutputFile
File outputFile
}
def "warns about missing @PathSensitive annotation for @CacheableTask"() {
expect:
assertHasValidationProblems(CacheableTaskWithoutPathSensitivity, [
"property 'inputFile' is missing a normalization annotation, defaulting to PathSensitivity.ABSOLUTE",
"property 'inputFiles' is missing a normalization annotation, defaulting to PathSensitivity.ABSOLUTE"
])
}
static class TaskWithNestedIterable extends DefaultTask {
@Nested
Iterable beans
@Nested
List beanList
}
static class NestedBeanWithNonAnnotatedProperty {
@Input
String input
String nonAnnotated
}
def "analyzes type arguments of Iterables"() {
expect:
assertHasValidationProblems(TaskWithNestedIterable, [
"property 'beans*.nonAnnotated' is not annotated with an input or output annotation",
"property 'beanList*.nonAnnotated' is not annotated with an input or output annotation"
])
}
static class TaskWithNestedIterableOfNamed extends DefaultTask {
@Nested
Iterable namedBeans
}
static class NamedBean implements Named {
@Input
input
String nonAnnotated
@Override
@Internal
String getName() {
return null
}
}
def "analyzes type arguments of Iterables of Named"() {
expect:
assertHasValidationProblems(TaskWithNestedIterableOfNamed, [
"property 'namedBeans..nonAnnotated' is not annotated with an input or output annotation",
])
}
static class TaskWithNestedMap extends DefaultTask {
@Nested
Map beans
@Nested
ImmutableMap
© 2015 - 2025 Weber Informatics LLC | Privacy Policy