<commit_before>/*
 * Copyright 2010 Grails Plugin Collective
 *
 * 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 grails.plugin.fixtures.files

import org.springframework.context.ApplicationContext
import grails.plugin.fixtures.files.shell.FixtureBuildingShell
import grails.plugin.fixtures.exception.*

class FixtureFileLoader {
	
	protected loading = false
	
	final fixture 
	final inners
	final builder
	
	final fileResolver
	final shell
	
	def fixtureNameStack = []
	def currentLoadPattern
	
	final posts = []
	
	FixtureFileLoader(fixture, inners, builder) {
		this.fixture = fixture
		this.inners = inners
		this.builder = builder
		
		this.fileResolver = new FixtureFilePatternResolver(fixture.grailsApplication, fixture.applicationContext)
		this.shell = new FixtureBuildingShell(this)
	}
	
	ApplicationContext load(String[] patterns) {
		loading = true
		doLoad(*patterns)
		loading = false
		builder.createApplicationContext()
	}
	
	void include(String[] includes) {
		if (!loading)
			throw new IllegalStateException("Can not include unless loading")
		
		doLoad(includes)
	}
	
	void addPost(Closure post) {
		posts << post
	}
	
	protected doLoad(String[] locationPatterns) {
		locationPatterns.each { locationPattern ->
			currentLoadPattern = locationPattern
			fileResolver.resolve(locationPattern).each { fixtureResource ->
				def fixtureName = fixtureResource.filename
				fixtureNameStack.push(fixtureName)
				try {
					shell.evaluate(fixtureResource.inputStream, fixtureName)
				} catch (Throwable e) {
					throw new FixtureException("Failed to evaluate ${fixtureName} (pattern: '$locationPattern')", e)
				}
				fixtureNameStack.pop()
			}
			currentLoadPattern = null
		}
	}

	def getCurrentlyLoadingFixtureName() {
		fixtureNameStack ? fixtureNameStack.last() : null
	}
}<commit_msg>Invalid use of the spread operator in FixtureFileLoader was causing a compiler exception in Groovy 1.8-RC4, although Groovy 1.7.x allowed it. In fact, the spread operator isn't required in this case at all, so I removed it.<commit_after>/*
 * Copyright 2010 Grails Plugin Collective
 *
 * 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 grails.plugin.fixtures.files

import org.springframework.context.ApplicationContext
import grails.plugin.fixtures.files.shell.FixtureBuildingShell
import grails.plugin.fixtures.exception.*

class FixtureFileLoader {
	
	protected loading = false
	
	final fixture 
	final inners
	final builder
	
	final fileResolver
	final shell
	
	def fixtureNameStack = []
	def currentLoadPattern
	
	final posts = []
	
	FixtureFileLoader(fixture, inners, builder) {
		this.fixture = fixture
		this.inners = inners
		this.builder = builder
		
		this.fileResolver = new FixtureFilePatternResolver(fixture.grailsApplication, fixture.applicationContext)
		this.shell = new FixtureBuildingShell(this)
	}
	
	ApplicationContext load(String[] patterns) {
		loading = true
		doLoad(patterns)
		loading = false
		builder.createApplicationContext()
	}
	
	void include(String[] includes) {
		if (!loading)
			throw new IllegalStateException("Can not include unless loading")
		
		doLoad(includes)
	}
	
	void addPost(Closure post) {
		posts << post
	}
	
	protected doLoad(String[] locationPatterns) {
		locationPatterns.each { locationPattern ->
			currentLoadPattern = locationPattern
			fileResolver.resolve(locationPattern).each { fixtureResource ->
				def fixtureName = fixtureResource.filename
				fixtureNameStack.push(fixtureName)
				try {
					shell.evaluate(fixtureResource.inputStream, fixtureName)
				} catch (Throwable e) {
					throw new FixtureException("Failed to evaluate ${fixtureName} (pattern: '$locationPattern')", e)
				}
				fixtureNameStack.pop()
			}
			currentLoadPattern = null
		}
	}

	def getCurrentlyLoadingFixtureName() {
		fixtureNameStack ? fixtureNameStack.last() : null
	}
}

{'fraction_non_alphanumeric': 0.0800082270670506, 'fraction_numerical': 0.0043192102015631425, 'mean_word_length': 4.2290322580645165, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2403847', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1305, 'n_words': 420}