001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.jci.compilers;
019
020 import org.apache.commons.jci.problems.CompilationProblemHandler;
021 import org.apache.commons.jci.readers.ResourceReader;
022 import org.apache.commons.jci.stores.ResourceStore;
023
024
025 /**
026 * The general compiler interface. All compilers implementing
027 * this interface should read the resources from the reader
028 * and store the java class files into the ResourceStore.
029 *
030 * The actual compilation language does not matter. But the
031 * contract is that the result of the compilation will be a
032 * class file.
033 *
034 * If possible the compiler should notify the optional
035 * CompilationProblemHandler as soon as a problem is found.
036 *
037 * @author tcurdt
038 */
039 public interface JavaCompiler {
040
041 /**
042 * Set the the handler that gets the notification of an error
043 * or warning as soon as this information is available from
044 * the compiler.
045 * Note: Some compilers might not support this feature.
046 *
047 * @param pHandler
048 */
049 void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
050
051 /**
052 * factory method to create the underlying default settings
053 */
054 JavaCompilerSettings createDefaultSettings();
055
056 /**
057 * uses the default compiler settings and the current classloader
058 */
059 CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore );
060
061 /**
062 * uses the default compiler settings
063 */
064 CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader );
065
066 /**
067 * Compiles the java resources "some/path/to/MyJava.java"
068 * read through the ResourceReader and then stores the resulting
069 * classes in the ResourceStore under "some/path/to/MyJava.class".
070 * Note: As these are resource path you always have to use "/"
071 *
072 * The result of the compilation run including detailed error
073 * information is returned as CompilationResult. If you need to
074 * get notified already during the compilation process you can
075 * register a CompilationProblemHandler.
076 * Note: Not all compilers might support this notification mechanism.
077 *
078 * @param pResourcePaths
079 * @param pReader
080 * @param pStore
081 * @param pClassLoader
082 * @param pSettings
083 * @return always a CompilationResult
084 */
085 CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings );
086
087 }