Remove sourceFileExtensions input
This and new KotlinCompile task inputs dedicated for scripting allowed providing proper Kotlin scripts compilation support without eager configuration dependencies resolve. ^KT-32805 In Progress
This commit is contained in:
committed by
teamcity
parent
0025bf9ed3
commit
f81e49f210
+12
@@ -122,6 +122,18 @@ abstract class KaptGenerateStubsTask @Inject constructor(
|
||||
patternFilterable.include { it.isDirectory || it.file.isSourceRootAllowed() }
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
override val scriptSources: FileCollection = objectFactory.fileCollection()
|
||||
|
||||
override val incrementalProps: List<FileCollection>
|
||||
get() = listOf(
|
||||
sources,
|
||||
javaSources,
|
||||
commonSourceSet,
|
||||
classpathSnapshotProperties.classpath,
|
||||
classpathSnapshotProperties.classpathSnapshot
|
||||
)
|
||||
|
||||
override val javaSources: FileCollection = super.javaSources
|
||||
.asFileTree
|
||||
.matching { patternFilterable ->
|
||||
|
||||
+5
-1
@@ -164,7 +164,11 @@ internal fun addSourcesToKotlinCompileTask(
|
||||
// In this call, the super-implementation of `source` adds the directories files to the roots of the union file tree,
|
||||
// so it's OK to pass just the source roots.
|
||||
setSource(Callable(sources))
|
||||
sourceFilesExtensions.addAll(sourceFileExtensions)
|
||||
with(sourceFileExtensions.toSet()) {
|
||||
if (isNotEmpty()) {
|
||||
include(flatMap { ext -> ext.fileExtensionCasePermutations().map { "**/*.$it" } })
|
||||
}
|
||||
}
|
||||
|
||||
// The `commonSourceSet` is passed to the compiler as-is, converted with toList
|
||||
commonSourceSet.from(
|
||||
|
||||
+1
-5
@@ -59,11 +59,7 @@ class DefaultKotlinSourceSet(
|
||||
val intransitiveMetadataConfigurationName: String
|
||||
get() = lowerCamelCaseName(disambiguateName(INTRANSITIVE), METADATA_CONFIGURATION_NAME_SUFFIX)
|
||||
|
||||
override val kotlin: SourceDirectorySet = createDefaultSourceDirectorySet(project, "$name Kotlin source").apply {
|
||||
filter.include("**/*.java")
|
||||
filter.include("**/*.kt")
|
||||
filter.include("**/*.kts")
|
||||
}
|
||||
override val kotlin: SourceDirectorySet = createDefaultSourceDirectorySet(project, "$name Kotlin source")
|
||||
|
||||
override val languageSettings: LanguageSettingsBuilder = DefaultLanguageSettingsBuilder()
|
||||
|
||||
|
||||
+1
-34
@@ -68,7 +68,7 @@ class ScriptingGradleSubplugin : Plugin<Project> {
|
||||
discoveryClasspathConfiguration.allDependencies.isEmpty() -> {
|
||||
// skip further checks - user did not configured any discovery sources
|
||||
}
|
||||
else -> configureScriptsExtensions(project, javaPluginConvention, task.sourceSetName.get())
|
||||
else -> task.scriptDefinitions.from(discoveryClasspathConfiguration)
|
||||
}
|
||||
} catch (e: IllegalStateException) {
|
||||
project.logger.warn("$SCRIPTING_LOG_PREFIX applied in the non-supported environment (error received: ${e.message})")
|
||||
@@ -85,39 +85,6 @@ class ScriptingGradleSubplugin : Plugin<Project> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureScriptsExtensions(
|
||||
project: Project,
|
||||
javaPluginConvention: JavaPluginConvention,
|
||||
sourceSetName: String
|
||||
) {
|
||||
javaPluginConvention.sourceSets.findByName(sourceSetName)?.let { sourceSet ->
|
||||
|
||||
val discoveryResultsConfigurationName = getDiscoveryResultsConfigurationName(sourceSetName)
|
||||
|
||||
val kotlinSourceSet = sourceSet.getConvention(KOTLIN_DSL_NAME) as? KotlinSourceSet
|
||||
if (kotlinSourceSet == null) {
|
||||
project.logger.warn("$SCRIPTING_LOG_PREFIX kotlin source set not found: $project.$sourceSet, $MISCONFIGURATION_MESSAGE_SUFFIX")
|
||||
} else {
|
||||
val extensions by lazy {
|
||||
val discoveryResultsConfiguration = project.configurations.findByName(discoveryResultsConfigurationName)
|
||||
if (discoveryResultsConfiguration == null) {
|
||||
project.logger.warn("$SCRIPTING_LOG_PREFIX discovery results not found: $project.$discoveryResultsConfigurationName, $MISCONFIGURATION_MESSAGE_SUFFIX")
|
||||
emptySet<String>()
|
||||
} else {
|
||||
discoveryResultsConfiguration.files.flatMapTo(HashSet()) {
|
||||
it.readLines().filter(String::isNotBlank)
|
||||
}.also {
|
||||
kotlinSourceSet.addCustomSourceFilesExtensions(it.toList())
|
||||
project.logger.debug("$SCRIPTING_LOG_PREFIX $project.$sourceSet: discovered script extensions: $it")
|
||||
}
|
||||
}
|
||||
}
|
||||
kotlinSourceSet.kotlin.filter.include { it.file.extension in extensions }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private const val MAIN_CONFIGURATION_NAME = "kotlinScriptDef"
|
||||
|
||||
+48
-10
@@ -18,6 +18,7 @@ import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.provider.SetProperty
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.specs.Spec
|
||||
@@ -103,12 +104,6 @@ abstract class AbstractKotlinCompileTool<T : CommonToolArguments> @Inject constr
|
||||
{ sourceFiles.asFileTree.matching(patternFilterable) }
|
||||
)
|
||||
|
||||
@Deprecated("Use PatternFilterable methods to configure sources")
|
||||
@get:Input
|
||||
val sourceFilesExtensions: ListProperty<String> = objectFactory
|
||||
.listProperty(String::class.java)
|
||||
.convention(DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS)
|
||||
|
||||
/**
|
||||
* Sets the source for this task.
|
||||
* The given source object is evaluated as per [org.gradle.api.Project.files].
|
||||
@@ -747,6 +742,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
get() = listOf(
|
||||
sources,
|
||||
javaSources,
|
||||
scriptSources,
|
||||
commonSourceSet,
|
||||
classpathSnapshotProperties.classpath,
|
||||
classpathSnapshotProperties.classpathSnapshot
|
||||
@@ -791,10 +787,47 @@ abstract class KotlinCompile @Inject constructor(
|
||||
@get:Internal
|
||||
internal abstract val jvmTargetValidationMode: Property<PropertiesProvider.JvmTargetValidationMode>
|
||||
|
||||
@get:Internal
|
||||
internal val scriptDefinitions: ConfigurableFileCollection = objectFactory.fileCollection()
|
||||
|
||||
@get:Input
|
||||
@get:Optional
|
||||
internal val scriptExtensions: SetProperty<String> = objectFactory.setPropertyWithLazyValue {
|
||||
scriptDefinitions
|
||||
.map { definitionFile ->
|
||||
definitionFile.readLines().filter(String::isNotBlank)
|
||||
}
|
||||
.flatten()
|
||||
}
|
||||
|
||||
private class ScriptFilterSpec(
|
||||
private val scriptExtensions: SetProperty<String>
|
||||
) : Spec<FileTreeElement> {
|
||||
override fun isSatisfiedBy(element: FileTreeElement): Boolean {
|
||||
val extensions = scriptExtensions.get()
|
||||
return extensions.isNotEmpty() &&
|
||||
(element.isDirectory || extensions.contains(element.file.extension))
|
||||
}
|
||||
}
|
||||
|
||||
private val scriptSourceFiles = objectFactory.fileCollection()
|
||||
|
||||
@get:InputFiles
|
||||
@get:SkipWhenEmpty
|
||||
@get:IgnoreEmptyDirectories
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
internal open val scriptSources: FileCollection = scriptSourceFiles
|
||||
.asFileTree
|
||||
.matching { patternFilterable ->
|
||||
patternFilterable.include(ScriptFilterSpec(scriptExtensions))
|
||||
}
|
||||
|
||||
init {
|
||||
incremental = true
|
||||
}
|
||||
|
||||
override fun skipCondition(): Boolean = sources.isEmpty && scriptSources.isEmpty
|
||||
|
||||
override fun createCompilerArgs(): K2JVMCompilerArguments =
|
||||
K2JVMCompilerArguments()
|
||||
|
||||
@@ -829,6 +862,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
) {
|
||||
validateKotlinAndJavaHasSameTargetCompatibility(args, kotlinSources)
|
||||
|
||||
val scriptSources = scriptSources.asFileTree.files
|
||||
val messageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
@@ -856,12 +890,14 @@ abstract class KotlinCompile @Inject constructor(
|
||||
- (classpathSnapshotProperties.classpathSnapshotDir.orNull?.asFile?.let { setOf(it) } ?: emptySet()),
|
||||
reportingSettings = reportingSettings(),
|
||||
incrementalCompilationEnvironment = icEnv,
|
||||
kotlinScriptExtensions = sourceFilesExtensions.get().toTypedArray()
|
||||
kotlinScriptExtensions = scriptExtensions.get().toTypedArray()
|
||||
)
|
||||
logger.info("Kotlin source files: ${kotlinSources.joinToString()}")
|
||||
logger.info("Java source files: ${javaSources.files.joinToString()}")
|
||||
logger.info("Script source files: ${scriptSources.joinToString()}")
|
||||
logger.info("Script file extensions: ${scriptExtensions.get().joinToString()}")
|
||||
compilerRunner.runJvmCompilerAsync(
|
||||
kotlinSources.toList(),
|
||||
(kotlinSources + scriptSources).toList(),
|
||||
commonSourceSet.toList(),
|
||||
javaSources.files, // we need here only directories where Java sources are located
|
||||
javaPackagePrefix,
|
||||
@@ -951,15 +987,17 @@ abstract class KotlinCompile @Inject constructor(
|
||||
.matching(::javaFilesPatternFilter)
|
||||
)
|
||||
|
||||
// override setSource to track Java sources as well
|
||||
// override setSource to track Java and script sources as well
|
||||
override fun setSource(source: Any) {
|
||||
javaSourceFiles.from(source)
|
||||
scriptSourceFiles.from(source)
|
||||
super.setSource(source)
|
||||
}
|
||||
|
||||
// override source to track Java sources as well
|
||||
// override source to track Java and script sources as well
|
||||
override fun setSource(vararg source: Any) {
|
||||
javaSourceFiles.from(*source)
|
||||
scriptSourceFiles.from(*source)
|
||||
super.setSource(*source)
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -15,6 +15,7 @@ import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.provider.SetProperty
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.kotlin.dsl.setProperty
|
||||
import java.io.File
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
@@ -48,6 +49,14 @@ internal inline fun <reified T : Any?> ObjectFactory.property(initialValue: T) =
|
||||
|
||||
internal inline fun <reified T : Any?> ObjectFactory.property(initialValue: Provider<T>) = property<T>().value(initialValue)
|
||||
|
||||
internal inline fun <reified T : Any?> ObjectFactory.setPropertyWithValue(
|
||||
initialValue: Provider<Iterable<T>>
|
||||
) = setProperty<T>().value(initialValue)
|
||||
|
||||
internal inline fun <reified T : Any?> ObjectFactory.setPropertyWithLazyValue(
|
||||
noinline lazyValue: () -> Iterable<T>
|
||||
) = setPropertyWithValue(providerWithLazyConvention(lazyValue))
|
||||
|
||||
internal inline fun <reified T : Any?> ObjectFactory.propertyWithConvention(
|
||||
conventionValue: Provider<T>
|
||||
) = property<T>().convention(conventionValue)
|
||||
|
||||
Reference in New Issue
Block a user