<commit_before>/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.standardout.gradle.plugin.include

import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.gradle.api.Project

/**
 * Extension that allows including build scripts based on methods defined in
 * such a script.
 *
 * @author <NAME>
 */
class IncludePluginExtension {
	
	private final Project project
	
	IncludePluginExtension(Project project) {
		this.project = project
	}
	
	def location(def file, Closure closure = null) {
		// determine script location
		def loc = file
		if (!(loc instanceof File)) {
			loc = project.file(loc as String)
		}
		
		// load script
		Binding binding = new Binding()
		binding.setVariable('project', project)
		CompilerConfiguration compilerConf = new CompilerConfiguration()
		compilerConf.scriptBaseClass = IncludeScript.name
		GroovyShell shell = new GroovyShell(IncludeScript.classLoader, binding, compilerConf)
		Script script = shell.parse(loc)
		
		if (closure == null) {
			closure = {
				script.run()
			}
		}
		closure.delegate = new IncludeDelegate(script)
		closure.resolveStrategy = Closure.DELEGATE_FIRST
		closure()
	}
	
	// alias for location
	def from(def file, Closure closure = null) {
		location(file, closure)
	}
	
	private class IncludeDelegate {
		private final Script script
		IncludeDelegate(Script script) {
			this.script = script
		}
		
		def invokeMethod(String name, def args) {
			// invoke script method
			InvokerHelper.invokeMethod(script, name, args)
		}
	}
	
}
<commit_msg>include: provide thisFile and thisDir variables<commit_after>/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.standardout.gradle.plugin.include

import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.gradle.api.Project

/**
 * Extension that allows including build scripts based on methods defined in
 * such a script.
 *
 * @author <NAME>
 */
class IncludePluginExtension {
	
	private final Project project
	
	IncludePluginExtension(Project project) {
		this.project = project
	}
	
	def location(def file, Closure closure = null) {
		// determine script location
		def loc = file
		if (!(loc instanceof File)) {
			loc = project.file(loc as String)
		}
		
		// load script
		Binding binding = new Binding()
		binding.setVariable('project', project)
		binding.setVariable('thisFile', loc)
		binding.setVariable('thisDir', loc.parentFile)
		CompilerConfiguration compilerConf = new CompilerConfiguration()
		compilerConf.scriptBaseClass = IncludeScript.name
		GroovyShell shell = new GroovyShell(IncludeScript.classLoader, binding, compilerConf)
		Script script = shell.parse(loc)
		
		if (closure == null) {
			closure = {
				script.run()
			}
		}
		closure.delegate = new IncludeDelegate(script)
		closure.resolveStrategy = Closure.DELEGATE_FIRST
		closure()
	}
	
	// alias for location
	def from(def file, Closure closure = null) {
		location(file, closure)
	}
	
	private class IncludeDelegate {
		private final Script script
		IncludeDelegate(Script script) {
			this.script = script
		}
		
		def invokeMethod(String name, def args) {
			// invoke script method
			InvokerHelper.invokeMethod(script, name, args)
		}
	}
	
}

{'fraction_non_alphanumeric': 0.08552036199095023, 'fraction_numerical': 0.0036199095022624436, 'mean_word_length': 3.8635863586358634, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2408671', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1183, 'n_words': 423}