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:
James Strachan
2012-03-03 06:34:26 +00:00
parent 4274a4abac
commit ffa2b7b085
3 changed files with 14 additions and 10 deletions
@@ -181,6 +181,8 @@ public class CompileEnvironment {
final String directory = new File(moduleScriptFile).getParent(); final String directory = new File(moduleScriptFile).getParent();
for (Module moduleBuilder : modules) { for (Module moduleBuilder : modules) {
CompileEnvironment compileEnvironment = new CompileEnvironment(myFileNameTransformer, myMessageRenderer); CompileEnvironment compileEnvironment = new CompileEnvironment(myFileNameTransformer, myMessageRenderer);
// copy across any compiler plugins
compileEnvironment.getMyEnvironment().getCompilerPlugins().addAll(myEnvironment.getCompilerPlugins());
ClassFileFactory moduleFactory = compileEnvironment.compileModule(moduleBuilder, directory); ClassFileFactory moduleFactory = compileEnvironment.compileModule(moduleBuilder, directory);
if (moduleFactory == null) { if (moduleFactory == null) {
return false; return false;
@@ -208,7 +210,7 @@ public class CompileEnvironment {
if (!scriptCompileSession.analyze(myErrorStream, myMessageRenderer)) { if (!scriptCompileSession.analyze(myErrorStream, myMessageRenderer)) {
return null; return null;
} }
final ClassFileFactory factory = scriptCompileSession.generate(); final ClassFileFactory factory = scriptCompileSession.generate(true);
return runDefineModules(moduleFile, factory); return runDefineModules(moduleFile, factory);
} }
@@ -267,7 +269,7 @@ public class CompileEnvironment {
if (!moduleCompileSession.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) { if (!moduleCompileSession.analyze(myErrorStream, myMessageRenderer) && !ignoreErrors) {
return null; return null;
} }
return moduleCompileSession.generate(); return moduleCompileSession.generate(false);
} }
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) { public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) {
@@ -355,7 +357,7 @@ public class CompileEnvironment {
return null; return null;
} }
ClassFileFactory factory = session.generate(); ClassFileFactory factory = session.generate(false);
return new GeneratedClassLoader(factory); return new GeneratedClassLoader(factory);
} }
@@ -380,7 +382,7 @@ public class CompileEnvironment {
return false; return false;
} }
ClassFileFactory factory = session.generate(); ClassFileFactory factory = session.generate(false);
if (jar != null) { if (jar != null) {
try { try {
writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime); writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
@@ -209,16 +209,18 @@ public class CompileSession {
} }
@NotNull @NotNull
public ClassFileFactory generate() { public ClassFileFactory generate(boolean module) {
Project project = myEnvironment.getProject(); Project project = myEnvironment.getProject();
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), myFileNameTransformer); GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), myFileNameTransformer);
generationState.compileCorrectFiles(myBindingContext, mySourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true); generationState.compileCorrectFiles(myBindingContext, mySourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true);
ClassFileFactory answer = generationState.getFactory(); ClassFileFactory answer = generationState.getFactory();
List<CompilerPlugin> fileProcessors = myEnvironment.getCompilerPlugins(); List<CompilerPlugin> plugins = myEnvironment.getCompilerPlugins();
if (fileProcessors != null) { if (!module) {
for (CompilerPlugin processor : fileProcessors) { if (plugins != null) {
processor.processFiles(myBindingContext, getSourceFileNamespaces()); for (CompilerPlugin plugin : plugins) {
plugin.processFiles(myBindingContext, getSourceFileNamespaces());
}
} }
} }
return answer; return answer;
@@ -89,7 +89,7 @@ public class TestlibTest extends CodegenTestCase {
throw new RuntimeException("There were compilation errors"); throw new RuntimeException("There were compilation errors");
} }
ClassFileFactory classFileFactory = session.generate(); ClassFileFactory classFileFactory = session.generate(false);
final GeneratedClassLoader loader = new GeneratedClassLoader( final GeneratedClassLoader loader = new GeneratedClassLoader(
classFileFactory, classFileFactory,