added a flag to indicate whether or not the module is being compiled or not (so we can defer compiler plugins until after the module is built)
This commit is contained in:
@@ -181,6 +181,8 @@ public class CompileEnvironment {
|
||||
final String directory = new File(moduleScriptFile).getParent();
|
||||
for (Module moduleBuilder : modules) {
|
||||
CompileEnvironment compileEnvironment = new CompileEnvironment(myFileNameTransformer, myMessageRenderer);
|
||||
// copy across any compiler plugins
|
||||
compileEnvironment.getMyEnvironment().getCompilerPlugins().addAll(myEnvironment.getCompilerPlugins());
|
||||
ClassFileFactory moduleFactory = compileEnvironment.compileModule(moduleBuilder, directory);
|
||||
if (moduleFactory == null) {
|
||||
return false;
|
||||
@@ -208,7 +210,7 @@ public class CompileEnvironment {
|
||||
if (!scriptCompileSession.analyze(myErrorStream, myMessageRenderer)) {
|
||||
return null;
|
||||
}
|
||||
final ClassFileFactory factory = scriptCompileSession.generate();
|
||||
final ClassFileFactory factory = scriptCompileSession.generate(true);
|
||||
|
||||
return runDefineModules(moduleFile, factory);
|
||||
}
|
||||
@@ -267,7 +269,7 @@ public class CompileEnvironment {
|
||||
if (!moduleCompileSession.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) {
|
||||
return null;
|
||||
}
|
||||
return moduleCompileSession.generate();
|
||||
return moduleCompileSession.generate(false);
|
||||
}
|
||||
|
||||
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) {
|
||||
@@ -355,7 +357,7 @@ public class CompileEnvironment {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassFileFactory factory = session.generate();
|
||||
ClassFileFactory factory = session.generate(false);
|
||||
return new GeneratedClassLoader(factory);
|
||||
}
|
||||
|
||||
@@ -380,7 +382,7 @@ public class CompileEnvironment {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClassFileFactory factory = session.generate();
|
||||
ClassFileFactory factory = session.generate(false);
|
||||
if (jar != null) {
|
||||
try {
|
||||
writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
|
||||
|
||||
@@ -209,16 +209,18 @@ public class CompileSession {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassFileFactory generate() {
|
||||
public ClassFileFactory generate(boolean module) {
|
||||
Project project = myEnvironment.getProject();
|
||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), myFileNameTransformer);
|
||||
generationState.compileCorrectFiles(myBindingContext, mySourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true);
|
||||
ClassFileFactory answer = generationState.getFactory();
|
||||
|
||||
List<CompilerPlugin> fileProcessors = myEnvironment.getCompilerPlugins();
|
||||
if (fileProcessors != null) {
|
||||
for (CompilerPlugin processor : fileProcessors) {
|
||||
processor.processFiles(myBindingContext, getSourceFileNamespaces());
|
||||
List<CompilerPlugin> plugins = myEnvironment.getCompilerPlugins();
|
||||
if (!module) {
|
||||
if (plugins != null) {
|
||||
for (CompilerPlugin plugin : plugins) {
|
||||
plugin.processFiles(myBindingContext, getSourceFileNamespaces());
|
||||
}
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
|
||||
@@ -89,7 +89,7 @@ public class TestlibTest extends CodegenTestCase {
|
||||
throw new RuntimeException("There were compilation errors");
|
||||
}
|
||||
|
||||
ClassFileFactory classFileFactory = session.generate();
|
||||
ClassFileFactory classFileFactory = session.generate(false);
|
||||
|
||||
final GeneratedClassLoader loader = new GeneratedClassLoader(
|
||||
classFileFactory,
|
||||
|
||||
Reference in New Issue
Block a user