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

com.netflix.nebula.lint.plugin.SourceCollector.groovy Maven / Gradle / Ivy

Go to download

Pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts

There is a newer version: 20.2.2
Show newest version
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