com.netflix.nebula.lint.plugin.SourceCollector.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-lint-plugin Show documentation
Show all versions of gradle-lint-plugin Show documentation
Pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts
package com.netflix.nebula.lint.plugin
import org.codehaus.groovy.ast.ClassNode
import org.codehaus.groovy.ast.ModuleNode
import org.codenarc.source.SourceCode
import org.codenarc.source.SourceString
import org.gradle.api.Project
class SourceCollector {
/**
* It scans given build file for possible `apply from: 'another.gradle'` and recursively
* collect all build files which are present.
*/
static List getAllFiles(File buildFile, Project project) {
if (buildFile.exists()) {
List result = new ArrayList<>()
result.add(buildFile)
SourceCode sourceCode = new SourceString(buildFile.text)
ModuleNode ast = sourceCode.getAst()
if (ast != null && ast.getClasses() != null) {
for (ClassNode classNode : ast.getClasses()) {
AppliedFilesAstVisitor visitor = new AppliedFilesAstVisitor(project)
visitor.visitClass(classNode)
result.addAll(visitor.appliedFiles)
}
}
return result
} else {
return Collections.emptyList()
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy