[^andres] IDEA-69920 Support additional imports added by the Griffon compiler

This commit is contained in:
peter
2012-11-13 17:20:28 +01:00
parent 561b7c8c1e
commit fb52a87ab6
9 changed files with 146 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.jps.incremental.groovy.GriffonBuilderExtension
@@ -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<String> getCompilationClassPath(@NotNull CompileContext context, @NotNull ModuleChunk chunk) {
return Collections.emptyList();
}
@NotNull
@Override
public Collection<String> 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;
}
}
+13
View File
@@ -11,6 +11,19 @@
<orderEntry type="module" module-name="jps-builders" />
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="module" module-name="groovy-rt-constants" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/../testdata/griffon" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$MODULE_DIR$/../testdata/griffon" />
</SOURCES>
<jarDirectory url="file://$MODULE_DIR$/../testdata/griffon" recursive="false" />
<jarDirectory url="file://$MODULE_DIR$/../testdata/griffon" recursive="false" type="SOURCES" />
</library>
</orderEntry>
</component>
</module>
@@ -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;
}
}
@@ -72,6 +72,7 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
* @author aalmiray
* @author peter
*/
public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase {
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.