diff --git a/plugins/groovy/jps-plugin/src/META-INF/services/org.jetbrains.jps.incremental.groovy.GroovyBuilderExtension b/plugins/groovy/jps-plugin/src/META-INF/services/org.jetbrains.jps.incremental.groovy.GroovyBuilderExtension new file mode 100644 index 000000000000..6b76ac35e269 --- /dev/null +++ b/plugins/groovy/jps-plugin/src/META-INF/services/org.jetbrains.jps.incremental.groovy.GroovyBuilderExtension @@ -0,0 +1 @@ +org.jetbrains.jps.incremental.groovy.GriffonBuilderExtension \ No newline at end of file diff --git a/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GriffonBuilderExtension.java b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GriffonBuilderExtension.java new file mode 100644 index 000000000000..87edd9b980a4 --- /dev/null +++ b/plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/GriffonBuilderExtension.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.jps.incremental.groovy; + +import com.intellij.openapi.application.PathManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jps.ModuleChunk; +import org.jetbrains.jps.incremental.CompileContext; +import org.jetbrains.jps.model.module.JpsModule; +import org.jetbrains.jps.util.JpsPathUtil; + +import java.io.File; +import java.util.Collection; +import java.util.Collections; + +/** + * @author peter + */ +public class GriffonBuilderExtension implements GroovyBuilderExtension { + + @NotNull + @Override + public Collection getCompilationClassPath(@NotNull CompileContext context, @NotNull ModuleChunk chunk) { + return Collections.emptyList(); + } + + @NotNull + @Override + public Collection getCompilationUnitPatchers(@NotNull CompileContext context, @NotNull ModuleChunk chunk) { + for (JpsModule module : chunk.getModules()) { + if (shouldInjectGriffon(module)) { + return Collections.singleton("org.jetbrains.groovy.compiler.rt.GriffonInjector"); + } + } + return Collections.emptyList(); + } + + private static boolean shouldInjectGriffon(JpsModule module) { + for (String rootUrl : module.getContentRootsList().getUrls()) { + File root = JpsPathUtil.urlToFile(rootUrl); + if (new File(root, "griffon-app").isDirectory() && + new File(root, "application.properties").isFile()) { + return true; + } + } + + return false; + } + +} diff --git a/plugins/groovy/rt/groovy_rt.iml b/plugins/groovy/rt/groovy_rt.iml index dd7338a70348..14e756131a5d 100644 --- a/plugins/groovy/rt/groovy_rt.iml +++ b/plugins/groovy/rt/groovy_rt.iml @@ -11,6 +11,19 @@ + + + + + + + + + + + + + diff --git a/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GriffonInjector.java b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GriffonInjector.java new file mode 100644 index 000000000000..975751e9cdbe --- /dev/null +++ b/plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GriffonInjector.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.groovy.compiler.rt; + +import groovy.lang.GroovyResourceLoader; +import org.codehaus.griffon.cli.CommandLineConstants; +import org.codehaus.griffon.compiler.DefaultImportCompilerCustomizer; +import org.codehaus.griffon.compiler.GriffonCompilerContext; +import org.codehaus.groovy.control.CompilationUnit; + +import java.io.File; + +/** + * @author aalmiray + * @author peter + */ +public class GriffonInjector extends CompilationUnitPatcher { + @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod") + public void patchCompilationUnit(CompilationUnit compilationUnit, GroovyResourceLoader resourceLoader, File[] srcFiles) { + File baseDir = guessBaseDir(srcFiles); + if (baseDir == null) { + return; + } + + GriffonCompilerContext.basedir = baseDir.getPath(); + GriffonCompilerContext.projectName = "IntelliJIDEARulezzzzz"; + GriffonCompilerContext.setup(); + if (!GriffonCompilerContext.getConfigOption(CommandLineConstants.KEY_DISABLE_AUTO_IMPORTS)) { + DefaultImportCompilerCustomizer customizer = new DefaultImportCompilerCustomizer(); + customizer.collectDefaultImportsPerArtifact(); + compilationUnit.addPhaseOperation(customizer, customizer.getPhase().getPhaseNumber()); + } + } + + private static File guessBaseDir(File srcFile) { + File each = srcFile; + while (each != null) { + if (new File(each, "griffon-app").exists()) { + return each; + } + each = each.getParentFile(); + } + return null; + } + + private static File guessBaseDir(File[] srcFiles) { + for (File file : srcFiles) { + File home = guessBaseDir(file); + if (home != null) { + return home; + } + } + return null; + } +} 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 2a353993bb56..cfba5cdecddd 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTestCase.java @@ -72,6 +72,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReference; /** + * @author aalmiray * @author peter */ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase { diff --git a/plugins/groovy/testdata/griffon/griffon-cli-1.1.0.jar b/plugins/groovy/testdata/griffon/griffon-cli-1.1.0.jar new file mode 100644 index 000000000000..06eb1d884ef6 Binary files /dev/null and b/plugins/groovy/testdata/griffon/griffon-cli-1.1.0.jar differ diff --git a/plugins/groovy/testdata/griffon/griffon-rt-1.1.0.jar b/plugins/groovy/testdata/griffon/griffon-rt-1.1.0.jar new file mode 100644 index 000000000000..fc92ba0ace72 Binary files /dev/null and b/plugins/groovy/testdata/griffon/griffon-rt-1.1.0.jar differ diff --git a/plugins/groovy/testdata/griffon/slf4j-api-1.7.1.jar b/plugins/groovy/testdata/griffon/slf4j-api-1.7.1.jar new file mode 100644 index 000000000000..97ca6570cae0 Binary files /dev/null and b/plugins/groovy/testdata/griffon/slf4j-api-1.7.1.jar differ diff --git a/plugins/groovy/testdata/griffon/slf4j-simple-1.7.1.jar b/plugins/groovy/testdata/griffon/slf4j-simple-1.7.1.jar new file mode 100644 index 000000000000..ede53d319d15 Binary files /dev/null and b/plugins/groovy/testdata/griffon/slf4j-simple-1.7.1.jar differ