// Path: core/src/main/java/org/apache/commons/jci2/problems/CompilationProblem.java
// public interface CompilationProblem {
// 
//     /**
//      * is the problem an error and compilation cannot continue
//      * or just a warning and compilation can proceed
//      *
//      * @return true if the problem is an error
//      */
//     boolean isError();
// 
//     /**
//      * name of the file where the problem occurred
//      *
//      * @return name of the file where the problem occurred
//      */
//     String getFileName();
// 
//     /**
//      * position of where the problem starts in the source code
//      *
//      * @return position of where the problem starts in the source code
//      */
//     int getStartLine();
//     int getStartColumn();
// 
//     /**
//      * position of where the problem stops in the source code
//      *
//      * @return position of where the problem stops in the source code
//      */
//     int getEndLine();
//     int getEndColumn();
// 
//     /**
//      * the description of the problem
//      *
//      * @return the description of the problem
//      */
//     String getMessage();
// 
// }
// 
// Path: core/src/main/java/org/apache/commons/jci2/readers/ResourceReader.java
// public interface ResourceReader {
// 
//     boolean isAvailable( final String pResourceName );
//     byte[] getBytes( final String pResourceName );
// 
// }
// 
// Path: core/src/main/java/org/apache/commons/jci2/stores/ResourceStore.java
// public interface ResourceStore {
// 
//     void write( final String pResourceName, final byte[] pResourceData );
//     byte[] read( final String pResourceName );
//     //FIXME: return the result of the remove
//     void remove( final String pResourceName );
// }


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.jci2.problems.CompilationProblem;
import org.apache.commons.jci2.readers.ResourceReader;
import org.apache.commons.jci2.stores.ResourceStore;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.commons.compiler.CompileException;
import org.codehaus.commons.compiler.LocatedException;
import org.codehaus.commons.compiler.Location;
import org.codehaus.janino.ClassLoaderIClassLoader;
import org.codehaus.janino.Compiler;
import org.codehaus.janino.FilterWarningHandler;
import org.codehaus.janino.UnitCompiler.ErrorHandler;
import org.codehaus.janino.WarningHandler;
import org.codehaus.janino.util.StringPattern;
import org.codehaus.janino.util.resource.Resource;
import org.codehaus.janino.util.resource.ResourceCreator;
import org.codehaus.janino.util.resource.ResourceFinder;
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.commons.jci2.compilers;



/**
 * @author tcurdt
 */
public final class JaninoJavaCompiler extends AbstractJavaCompiler {

    private final Log log = LogFactory.getLog(JaninoJavaCompiler.class);

    private final JaninoJavaCompilerSettings defaultSettings;

    public JaninoJavaCompiler() {
    	this(new JaninoJavaCompilerSettings());
    }

    public JaninoJavaCompiler( final JaninoJavaCompilerSettings pSettings ) {
    	defaultSettings = pSettings;
    }

    private final static class JciResource implements Resource {

    	private final String name;
    	private final byte[] bytes;

    	public JciResource( final String pName, final byte[] pBytes ) {
    		name = pName;
    		bytes = pBytes;
    	}

		public String getFileName() {
			return name;
		}

		public long lastModified() {
			return 0;
		}

		public InputStream open() throws IOException {
			return new ByteArrayInputStream(bytes);
		}
    }

// Path: core/src/main/java/org/apache/commons/jci2/problems/CompilationProblem.java
// public interface CompilationProblem {
// 
//     /**
//      * is the problem an error and compilation cannot continue
//      * or just a warning and compilation can proceed
//      *
//      * @return true if the problem is an error
//      */
//     boolean isError();
// 
//     /**
//      * name of the file where the problem occurred
//      *
//      * @return name of the file where the problem occurred
//      */
//     String getFileName();
// 
//     /**
//      * position of where the problem starts in the source code
//      *
//      * @return position of where the problem starts in the source code
//      */
//     int getStartLine();
//     int getStartColumn();
// 
//     /**
//      * position of where the problem stops in the source code
//      *
//      * @return position of where the problem stops in the source code
//      */
//     int getEndLine();
//     int getEndColumn();
// 
//     /**
//      * the description of the problem
//      *
//      * @return the description of the problem
//      */
//     String getMessage();
// 
// }
// 
// Path: core/src/main/java/org/apache/commons/jci2/readers/ResourceReader.java
// public interface ResourceReader {
// 
//     boolean isAvailable( final String pResourceName );
//     byte[] getBytes( final String pResourceName );
// 
// }
// 
// Path: core/src/main/java/org/apache/commons/jci2/stores/ResourceStore.java
// public interface ResourceStore {
// 
//     void write( final String pResourceName, final byte[] pResourceData );
//     byte[] read( final String pResourceName );
//     //FIXME: return the result of the remove
//     void remove( final String pResourceName );
// }


// Path: compilers/janino/src/main/java/org/apache/commons/jci2/compilers/JaninoJavaCompiler.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.jci2.problems.CompilationProblem;
import org.apache.commons.jci2.readers.ResourceReader;
import org.apache.commons.jci2.stores.ResourceStore;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.commons.compiler.CompileException;
import org.codehaus.commons.compiler.LocatedException;
import org.codehaus.commons.compiler.Location;
import org.codehaus.janino.ClassLoaderIClassLoader;
import org.codehaus.janino.Compiler;
import org.codehaus.janino.FilterWarningHandler;
import org.codehaus.janino.UnitCompiler.ErrorHandler;
import org.codehaus.janino.WarningHandler;
import org.codehaus.janino.util.StringPattern;
import org.codehaus.janino.util.resource.Resource;
import org.codehaus.janino.util.resource.ResourceCreator;
import org.codehaus.janino.util.resource.ResourceFinder;

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.commons.jci2.compilers;



/**
 * @author tcurdt
 */
public final class JaninoJavaCompiler extends AbstractJavaCompiler {

    private final Log log = LogFactory.getLog(JaninoJavaCompiler.class);

    private final JaninoJavaCompilerSettings defaultSettings;

    public JaninoJavaCompiler() {
    	this(new JaninoJavaCompilerSettings());
    }

    public JaninoJavaCompiler( final JaninoJavaCompilerSettings pSettings ) {
    	defaultSettings = pSettings;
    }

    private final static class JciResource implements Resource {

    	private final String name;
    	private final byte[] bytes;

    	public JciResource( final String pName, final byte[] pBytes ) {
    		name = pName;
    		bytes = pBytes;
    	}

		public String getFileName() {
			return name;
		}

		public long lastModified() {
			return 0;
		}

		public InputStream open() throws IOException {
			return new ByteArrayInputStream(bytes);
		}
    }

    private final static class JciOutputStream extends ByteArrayOutputStream {