<commit_before>/*
 * Copyright (C) 2006-2019 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */

package jolie;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.stream.Stream;
import jolie.lang.parse.ParserException;


/** Starter class of the Interpreter.
 * @author <NAME>
 */
public class Jolie
{
	private static final long TERMINATION_TIMEOUT = 100; // 0.1 seconds
	
	static {
		JolieURLStreamHandlerFactory.registerInVM();
	}
	
	private Jolie() {}
	
	private static void printErr( Throwable t, boolean printStackTraces )
	{
		String mesg;
		if ( printStackTraces ) {
			ByteArrayOutputStream bs = new ByteArrayOutputStream();
			t.printStackTrace( new PrintStream( bs ) );
			mesg = bs.toString();
		} else {
			mesg = t.getMessage();
		}
		System.err.println( mesg );
	}

	/** 
	 * Entry point of program execution.
	 * @param args the command line arguments
	 * TODO Standardize the exit codes.
	 */
	public static void main( String[] args )
	{
		int exitCode = 0;
		// TODO: remove this hack by extracting CommandLineParser here
		boolean printStackTraces = Stream.of( args ).anyMatch( s -> s.equals( "--stackTraces" ) );

		try {
			final Interpreter interpreter = new Interpreter( args, Jolie.class.getClassLoader(), null );
			Thread.currentThread().setContextClassLoader( interpreter.getClassLoader() );
			Runtime.getRuntime().addShutdownHook( new Thread() {
				@Override
				public void run()
				{
					interpreter.exit( TERMINATION_TIMEOUT );
				}
			} );
			interpreter.run();
		} catch( CommandLineException cle ) {
			printErr( cle, printStackTraces );
		} catch( FileNotFoundException fe ) {
			printErr( fe, printStackTraces );
			exitCode = 1;
		} catch( IOException ioe ) {
			printErr( ioe, printStackTraces );
			exitCode = 2;
		} catch( InterpreterException ie ) {
			if ( ie.getCause() instanceof ParserException ) {<commit_msg>FileNotFoundException error report more informative in Jolie.java<commit_after>/*
 * Copyright (C) 2006-2019 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 */

package jolie;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.stream.Stream;
import jolie.lang.parse.ParserException;


/** Starter class of the Interpreter.
 * @author <NAME>
 */
public class Jolie
{
	private static final long TERMINATION_TIMEOUT = 100; // 0.1 seconds

	static {
		JolieURLStreamHandlerFactory.registerInVM();
	}

	private Jolie() {}

	private static void printErr( Throwable t, boolean printStackTraces )
	{
		String mesg;
		if ( printStackTraces ) {
			ByteArrayOutputStream bs = new ByteArrayOutputStream();
			t.printStackTrace( new PrintStream( bs ) );
			mesg = bs.toString();
		} else {
			mesg = t.getMessage();
		}
		System.err.println( mesg );
	}

	/**
	 * Entry point of program execution.
	 * @param args the command line arguments
	 * TODO Standardize the exit codes.
	 */
	public static void main( String[] args )
	{
		int exitCode = 0;
		// TODO: remove this hack by extracting CommandLineParser here
		boolean printStackTraces = Stream.of( args ).anyMatch( s -> s.equals( "--stackTraces" ) );

		try {
			final Interpreter interpreter = new Interpreter( args, Jolie.class.getClassLoader(), null );
			Thread.currentThread().setContextClassLoader( interpreter.getClassLoader() );
			Runtime.getRuntime().addShutdownHook( new Thread() {
				@Override
				public void run()
				{
					interpreter.exit( TERMINATION_TIMEOUT );
				}
			} );
			interpreter.run();
		} catch( CommandLineException cle ) {
			printErr( cle, printStackTraces );
		} catch( FileNotFoundException fe ) {
			printErr( new FileNotFoundException( "File not found " + fe.getMessage() ), printStackTraces );
			exitCode = 1;
		} catch( IOException ioe ) {
			printErr( ioe, printStackTraces );
			exitCode = 2;
		} catch( InterpreterException ie ) {
			if ( ie.getCause() instanceof ParserException ) {
{'fraction_non_alphanumeric': 0.09618908024917552, 'fraction_numerical': 0.010626603151337486, 'mean_word_length': 3.7928007023705006, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7642363', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1555, 'n_words': 563}