name.remal.gradle_plugins.toolkit.build_logic.check-source-dirs.gradle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of build-logic Show documentation
Show all versions of build-logic Show documentation
Remal Gradle plugins: toolkit: build-logic
The newest version!
import static java.util.stream.Collectors.toSet
import java.util.stream.Stream
allprojects {
pluginManager.withPlugin('java') {
TaskProvider checkSourceDirs = tasks.register('checkSourceDirs') { Task task ->
task.group = 'verification'
File baseSourceDir = project.file('src')
SetProperty allSourceDirs = project.objects.setProperty(File).value(provider {
project.sourceSets.stream()
.flatMap { SourceSet sourceSet -> sourceSet.allSource.srcDirs.stream() }
.map { File file -> file.canonicalFile }
.flatMap { File file -> Stream.of(file, file.parentFile) }
.filter { it != null }
.collect(toSet())
}).with { it.finalizeValueOnRead(); it }
task.doLast {
List invalidSourceDirs = []
Closure> getSubDirs = { File file ->
return file.listFiles()?.collect()?.findAll { it.directory } ?: []
}
List sourceSetsBaseDirs = getSubDirs(baseSourceDir)
for (File sourceSetsBaseDir : sourceSetsBaseDirs) {
sourceSetsBaseDir = sourceSetsBaseDir.canonicalFile
if (!allSourceDirs.get().contains(sourceSetsBaseDir)) {
invalidSourceDirs.add(sourceSetsBaseDir)
break
}
List sourceDirs = getSubDirs(sourceSetsBaseDir)
for (File sourceDir : sourceDirs) {
sourceDir = sourceDir.canonicalFile
if (!allSourceDirs.get().contains(sourceDir)) {
invalidSourceDirs.add(sourceDir)
}
}
}
if (!invalidSourceDirs.isEmpty()) {
throw new GradleException("There are source directories that are not a part of any source sets:\n ${invalidSourceDirs.join('\n ')}")
}
}
}
tasks.named('check').configure { dependsOn(checkSourceDirs) }
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy