Package com.illumon.compilertools
Class CompilerTools
java.lang.Object
com.illumon.compilertools.CompilerTools
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Class<?>compile(@NotNull String className, @NotNull String classBody, @NotNull String packageNameRoot, @Nullable StringBuilder codeLog, @NotNull Map<String, Class<?>> parameterClasses) Compile a class.static Class<?>static Class<?>compile(String className, String classBody, String packageNameRoot, StringBuilder codeLog) static Class<?>compile(String className, String classBody, String packageNameRoot, Map<String, Class<?>> parameterClasses) static StringcreateEscapedJoinedString(String originalString) Transform a string into the corresponding Java source code that compiles into that string.static StringcreateEscapedJoinedString(String originalString, int maxStringLength) static <RETURN_TYPE>
RETURN_TYPEdoWithContext(@NotNull CompilerTools.Context context, @NotNull Supplier<RETURN_TYPE> action) static CompilerTools.Contextstatic StringRetrieve the java class path from our existing Java class path, and IntelliJ/TeamCity environment variables.static voidstatic voidstatic voidsetContext(@Nullable CompilerTools.Context context) static booleansetLogEnabled(boolean logEnabled) Enables or disables compilation logging.tryCompile(File basePath, Collection<File> javaFiles) Try to compile the set of files, returning a pair of success and compiler output.static voidwriteClass(File destinationDirectory, String className, byte[] data) static voidwriteClass(File destinationDirectory, String className, byte[] data, String message)
-
Field Details
-
FORMULA_PREFIX
- See Also:
-
DYNAMIC_GROOVY_CLASS_PREFIX
- See Also:
-
-
Constructor Details
-
CompilerTools
public CompilerTools()
-
-
Method Details
-
setLogEnabled
public static boolean setLogEnabled(boolean logEnabled) Enables or disables compilation logging.- Parameters:
logEnabled- Whether or not logging should be enabled- Returns:
- The value of
logEnabledbefore calling this method.
-
writeClass
public static void writeClass(File destinationDirectory, String className, byte[] data) throws IOException - Throws:
IOException
-
writeClass
public static void writeClass(File destinationDirectory, String className, byte[] data, String message) throws IOException - Throws:
IOException
-
resetContext
public static void resetContext() -
setContext
-
getContext
-
doWithContext
public static <RETURN_TYPE> RETURN_TYPE doWithContext(@NotNull @NotNull CompilerTools.Context context, @NotNull @NotNull Supplier<RETURN_TYPE> action) -
compile
-
compile
-
compile
public static Class<?> compile(String className, String classBody, String packageNameRoot, StringBuilder codeLog) -
compile
public static Class<?> compile(@NotNull @NotNull String className, @NotNull @NotNull String classBody, @NotNull @NotNull String packageNameRoot, @Nullable @Nullable StringBuilder codeLog, @NotNull @NotNull Map<String, Class<?>> parameterClasses) Compile a class.- Parameters:
className- Class nameclassBody- Class body, before update with "$CLASS_NAME$" replacement and package name prefixingpackageNameRoot- Package name prefixcodeLog- Optional "log" for final class codeparameterClasses- Generic parameters, empty if none required- Returns:
- The compiled class
-
createEscapedJoinedString
Transform a string into the corresponding Java source code that compiles into that string. This involves escaping special characters, surrounding it with quotes, and (if the string is larger than the max string length for Java literals), splitting it into substrings and constructing a call to String.join() that combines those substrings. -
createEscapedJoinedString
-
tryCompile
public static com.fishlib.base.Pair<Boolean,String> tryCompile(File basePath, Collection<File> javaFiles) throws IOException Try to compile the set of files, returning a pair of success and compiler output.- Parameters:
basePath- the base path for the java classesjavaFiles- the java source files- Returns:
- a Pair of success, and the compiler output
- Throws:
IOException
-
getJavaClassPath
Retrieve the java class path from our existing Java class path, and IntelliJ/TeamCity environment variables.- Returns:
-
main
-