1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package org.apache.commons.jci.compilers; 19 20 import org.apache.commons.jci.problems.CompilationProblemHandler; 21 import org.apache.commons.jci.readers.ResourceReader; 22 import org.apache.commons.jci.stores.ResourceStore; 23 24 25 /** 26 * The general compiler interface. All compilers implementing 27 * this interface should read the resources from the reader 28 * and store the java class files into the ResourceStore. 29 * 30 * The actual compilation language does not matter. But the 31 * contract is that the result of the compilation will be a 32 * class file. 33 * 34 * If possible the compiler should notify the optional 35 * CompilationProblemHandler as soon as a problem is found. 36 * 37 * @author tcurdt 38 */ 39 public interface JavaCompiler { 40 41 /** 42 * Set the the handler that gets the notification of an error 43 * or warning as soon as this information is available from 44 * the compiler. 45 * Note: Some compilers might not support this feature. 46 * 47 * @param pHandler 48 */ 49 void setCompilationProblemHandler( final CompilationProblemHandler pHandler ); 50 51 /** 52 * factory method to create the underlying default settings 53 */ 54 JavaCompilerSettings createDefaultSettings(); 55 56 /** 57 * uses the default compiler settings and the current classloader 58 */ 59 CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore ); 60 61 /** 62 * uses the default compiler settings 63 */ 64 CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader ); 65 66 /** 67 * Compiles the java resources "some/path/to/MyJava.java" 68 * read through the ResourceReader and then stores the resulting 69 * classes in the ResourceStore under "some/path/to/MyJava.class". 70 * Note: As these are resource path you always have to use "/" 71 * 72 * The result of the compilation run including detailed error 73 * information is returned as CompilationResult. If you need to 74 * get notified already during the compilation process you can 75 * register a CompilationProblemHandler. 76 * Note: Not all compilers might support this notification mechanism. 77 * 78 * @param pResourcePaths 79 * @param pReader 80 * @param pStore 81 * @param pClassLoader 82 * @param pSettings 83 * @return always a CompilationResult 84 */ 85 CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings ); 86 87 }