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

astaddgradle.1.10.2.source-code.ModuleLoader.groovy Maven / Gradle / Ivy

There is a newer version: 1.13.3
Show newest version
import org.gradle.api.InvalidUserDataException

class ModuleLoader {
	final JastAddExtension extension

	public ModuleLoader(JastAddExtension extension) {
		this.extension = extension;
	}

	void load(project, moduleName) {
		def source = project.file(moduleName)
		def dir = source.parent
		if (source.isDirectory()) {
			source = project.file("${moduleName}/modules")
			dir = moduleName
		}
		if (!source.exists()) {
			throw new InvalidUserDataException("Could not load module definitions: ${moduleName}")
		}
		extension.addModuleSource source
		def code = source.text
		def closure = new GroovyShell().evaluate("{->${code}}")
		closure.delegate = new ModuleDefinitions(this, project, dir)
		closure.resolveStrategy = Closure.DELEGATE_ONLY
		closure()
	}

	/** Track the loaded module. */
	public void addModule(module) {
		extension.addModule module
	}

	/** Lookup an existing module. */
	def get(module) {
		extension.getModule module
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy