From e3e599548dacd37c8b7c32fb9d4aaeabee1974da Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 8 Nov 2011 19:57:15 +0100 Subject: [PATCH] use runtime classpath to allow groovyc to access indirectly referenced classes in indirect dependencies --- .../jps/incremental/groovy/GroovyBuilder.java | 9 +++++--- .../groovy/compiler/GroovyCompilerTest.groovy | 20 ++++++++++++++++ .../compiler/GroovyCompilerTestCase.java | 23 ++++++++++++++++--- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java index 23e415232550..d941d52998c7 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/groovy/GroovyBuilder.java @@ -61,7 +61,7 @@ public class GroovyBuilder extends Builder { return exitCode; } - final List cp = new ArrayList(); + final Set cp = new LinkedHashSet(); //groovy_rt.jar // IMPORTANT! must be the first in classpath cp.add(ClasspathBootstrap.getResourcePath(GroovyCompilerWrapper.class).getPath()); @@ -69,6 +69,9 @@ public class GroovyBuilder extends Builder { for (File file : context.getProjectPaths().getClasspathFiles(chunk, ClasspathKind.compile(context.isCompilingTests()), false)) { cp.add(FileUtil.toCanonicalPath(file.getPath())); } + for (File file : context.getProjectPaths().getClasspathFiles(chunk, ClasspathKind.runtime(context.isCompilingTests()), false)) { + cp.add(FileUtil.toCanonicalPath(file.getPath())); + } final File tempFile = FileUtil.createTempFile("ideaGroovyToCompile", ".txt", true); final Module representativeModule = chunk.getModules().iterator().next(); @@ -98,8 +101,8 @@ public class GroovyBuilder extends Builder { final List cmd = ExternalProcessUtil.buildJavaCommandLine( SystemProperties.getJavaHome() + "/bin/java", "org.jetbrains.groovy.compiler.rt.GroovycRunner", - Collections.emptyList(), cp, - Arrays.asList("-Xmx384m"/*, "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5858"*/), + Collections.emptyList(), new ArrayList(cp), + Arrays.asList("-Xmx384m"/*, "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5858"*/), Arrays.asList(myForStubs ? "stubs" : "groovyc", tempFile.getPath()) ); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy index 714c60732338..119b13d70285 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy @@ -284,6 +284,25 @@ public class Transf implements ASTTransformation { assertOutput("Bar", "239", dep); } + public void testIndirectDependencies() throws Exception { + myFixture.addFileToProject("dependent1/Bar1.groovy", "class Bar1 {}"); + myFixture.addFileToProject("dependent2/Bar2.groovy", "class Bar2 extends Bar1 {}"); + PsiFile main = myFixture.addFileToProject("Main.groovy", "class Main extends Bar2 {}"); + + Module dep1 = addModule('dependent1') + Module dep2 = addModule('dependent2') + addDependency dep2, dep1 + addDependency myModule, dep2 + + addGroovyLibrary(dep1); + addGroovyLibrary(dep2); + + assertEmpty(make()) + + touch(main.virtualFile) + assertEmpty(make()) + } + public void testExtendFromGroovyAbstractClass() throws Exception { myFixture.addFileToProject "Super.groovy", "abstract class Super {}" myFixture.addFileToProject "AJava.java", "public class AJava {}" @@ -436,6 +455,7 @@ class Usage { public static class JpsMode extends GroovyCompilerTest { @Override protected boolean useJps() { true } + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java index 44b985a97eaa..75fabeefee0d 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java @@ -148,18 +148,35 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC } protected Module addDependentModule() { + Module module = addModule("dependent"); + addDependency(module, myModule); + return module; + } + + protected void addDependency(final Module from, final Module to) { + new WriteCommandAction(getProject()) { + @Override + protected void run(Result result) throws Throwable { + final ModifiableRootModel model = ModuleRootManager.getInstance(from).getModifiableModel(); + model.addModuleOrderEntry(to); + model.commit(); + } + }.execute().getResultObject(); + + } + + protected Module addModule(final String name) { return new WriteCommandAction(getProject()) { @Override protected void run(Result result) throws Throwable { - final VirtualFile depRoot = myFixture.getTempDirFixture().findOrCreateDir("dependent"); + final VirtualFile depRoot = myFixture.getTempDirFixture().findOrCreateDir(name); final ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel(); - String moduleName = moduleModel.newModule(depRoot.getPath() + "/dependent.iml", StdModuleTypes.JAVA).getName(); + String moduleName = moduleModel.newModule(depRoot.getPath() + "/" + name + ".iml", StdModuleTypes.JAVA).getName(); moduleModel.commit(); final Module dep = ModuleManager.getInstance(getProject()).findModuleByName(moduleName); final ModifiableRootModel model = ModuleRootManager.getInstance(dep).getModifiableModel(); - model.addModuleOrderEntry(myModule); final ContentEntry entry = model.addContentEntry(depRoot); entry.addSourceFolder(depRoot, false); model.setSdk(ModuleRootManager.getInstance(myModule).getSdk());