<commit_before>/*
 * Copyright (c) 2002-2009 "Neo Technology,"
 *     Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 * 
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.shell.apps.extra;

import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.Map;

import org.neo4j.shell.Output;
import org.neo4j.shell.ShellException;

/**
 * Executes groovy scripts purely via reflection
 */
public class GshExecutor extends ScriptExecutor
{
	private static final String BINDING_CLASS = "groovy.lang.Binding";
	
	private static final String ENGINE_CLASS = "groovy.util.GroovyScriptEngine";
	
	@Override
	protected String getPathKey()
	{
		return "GSH_PATH";
	}

	@Override
	protected void runScript( Object groovyScriptEngine,
		String scriptName, Map<String, Object> properties, String[] paths )
		throws ShellException
	{
		try
		{
			properties.put( "out",
				new GshOutput( ( Output ) properties.get( "out" ) ) );
			Object binding = this.newGroovyBinding( properties );
			Method runMethod = groovyScriptEngine.getClass().getMethod(
				"run", String.class, binding.getClass() );
			runMethod.invoke( groovyScriptEngine, scriptName + ".groovy",
				binding );
		}
		catch ( Exception e )
		{
			// Don't pass the exception on because the client most certainly
			// doesn't have groovy in the classpath.
			throw new ShellException( "Groovy exception: " +
				this.findProperMessage( e ) + "\n" +
				"\n----------[ACTUAL EXCEPTION]----------" + "\n" +
				this.stackTraceAsString( e ) +
				"----------[END OF ACTUAL EXCEPTION]----------\n" );
		}
	}<commit_msg>Added a default path src/main/groovy<commit_after>/*
 * Copyright (c) 2002-2009 "Neo Technology,"
 *     Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 * 
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.shell.apps.extra;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import java.util.Map;

import org.neo4j.shell.Output;
import org.neo4j.shell.ShellException;

/**
 * Executes groovy scripts purely via reflection
 */
public class GshExecutor extends ScriptExecutor
{
	private static final String BINDING_CLASS = "groovy.lang.Binding";
	
	private static final String ENGINE_CLASS = "groovy.util.GroovyScriptEngine";
	
	@Override
    protected String getDefaultPaths()
    {
	    return super.getDefaultPaths() + ":" +
	            "src" + File.separator + "main" + File.separator + "groovy";
    }

    @Override
	protected String getPathKey()
	{
		return "GSH_PATH";
	}

	@Override
	protected void runScript( Object groovyScriptEngine,
		String scriptName, Map<String, Object> properties, String[] paths )
		throws ShellException
	{
		try
		{
			properties.put( "out",
				new GshOutput( ( Output ) properties.get( "out" ) ) );
			Object binding = this.newGroovyBinding( properties );
			Method runMethod = groovyScriptEngine.getClass().getMethod(
				"run", String.class, binding.getClass() );
			runMethod.invoke( groovyScriptEngine, scriptName + ".groovy",
				binding );
		}
		catch ( Exception e )
		{
			// Don't pass the exception on because the client most certainly
			// doesn't have groovy in the classpath.
			throw new ShellException( "Groovy exception: " +
				this.findProperMessage( e ) + "\n" +
				"\n----------[ACTUAL EXCEPTION]----------" + "\n" +
				this.stackTraceAsString( e ) +
				"----------[END OF ACTUAL EXCEPTION]----------\n" );
		}
	}
{'fraction_non_alphanumeric': 0.11413934426229508, 'fraction_numerical': 0.005737704918032787, 'mean_word_length': 3.433242506811989, 'pattern_counts': {'":': 1, '<': 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': '1886886', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1393, 'n_words': 497}