Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jetbrains.plugins.groovy.impl.compiler;

import com.intellij.java.language.impl.JavaClassFileType;
Expand All @@ -23,28 +22,29 @@
import consulo.compiler.resourceCompiler.ResourceCompilerConfiguration;
import consulo.compiler.scope.CompileScope;
import consulo.content.bundle.Sdk;
import consulo.groovy.localize.GroovyLocalize;
import consulo.groovy.module.extension.GroovyModuleExtension;
import consulo.ide.setting.ShowSettingsUtil;
import consulo.java.language.module.extension.JavaModuleExtension;
import consulo.language.psi.scope.GlobalSearchScope;
import consulo.language.psi.search.FilenameIndex;
import consulo.language.util.ModuleUtilCore;
import consulo.logging.Logger;
import consulo.module.Module;
import consulo.module.content.ProjectFileIndex;
import consulo.module.content.ProjectRootManager;
import consulo.project.Project;
import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.awt.Messages;
import consulo.ui.ex.awt.UIUtil;
import consulo.util.lang.StringUtil;
import consulo.virtualFileSystem.VirtualFile;
import consulo.virtualFileSystem.fileType.FileType;
import jakarta.annotation.Nonnull;
import jakarta.inject.Inject;
import org.jetbrains.plugins.groovy.GroovyBundle;
import org.jetbrains.plugins.groovy.GroovyFileType;
import org.jetbrains.plugins.groovy.config.GroovyConfigUtils;
import org.jetbrains.plugins.groovy.util.LibrariesUtil;

import jakarta.annotation.Nonnull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -55,7 +55,6 @@
*/
@ExtensionImpl(id = "groovy-compile", order = "after groovy-stub-generator")
public class GroovyCompiler extends GroovyCompilerBase {
private static final Logger LOG = Logger.getInstance("#org.jetbrains.plugins.groovy.compiler.GroovyCompiler");
private static final String AST_TRANSFORM_FILE_NAME = "org.codehaus.groovy.transform.ASTTransformation";

@Inject
Expand All @@ -64,6 +63,7 @@ public GroovyCompiler(Project project) {
}

@Nonnull
@Override
public String getDescription() {
return "groovy compiler";
}
Expand All @@ -80,8 +80,10 @@ protected void compileFiles(CompileContext context,
runGroovycCompiler(context, module, toCompile, false, getMainOutput(context, module, tests), sink, tests);
}

@Override
@RequiredUIAccess
public boolean validateConfiguration(CompileScope compileScope) {
VirtualFile[] files = compileScope.getFiles(GroovyFileType.GROOVY_FILE_TYPE);
VirtualFile[] files = compileScope.getFiles(GroovyFileType.INSTANCE);
if (files.length == 0) {
return true;
}
Expand All @@ -103,33 +105,38 @@ public boolean validateConfiguration(CompileScope compileScope) {
}
}

Set<Module> nojdkModules = new HashSet<>();
Set<Module> noJdkModules = new HashSet<>();
for (Module module : modules) {
Sdk sdk = ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
if (sdk == null) {
nojdkModules.add(module);
noJdkModules.add(module);
continue;
}

if (!LibrariesUtil.hasGroovySdk(module)) {
if (!GroovyConfigUtils.getInstance().tryToSetUpGroovyFacetOnTheFly(module)) {
Messages.showErrorDialog(myProject,
GroovyBundle.message("cannot.compile.groovy.files.no.facet", module.getName()),
GroovyBundle.message("cannot.compile"));
ShowSettingsUtil.getInstance()
.showProjectStructureDialog(module.getProject(),
projectStructureSelector -> projectStructureSelector.selectOrderEntry(module, null));
Messages.showErrorDialog(
myProject,
GroovyLocalize.cannotCompileGroovyFilesNoFacet(module.getName()).get(),
GroovyLocalize.cannotCompile().get()
);
ShowSettingsUtil.getInstance().showProjectStructureDialog(
module.getProject(),
projectStructureSelector -> projectStructureSelector.selectOrderEntry(module, null)
);
return false;
}
}
}

if (!nojdkModules.isEmpty()) {
Module[] noJdkArray = nojdkModules.toArray(new Module[nojdkModules.size()]);
if (!noJdkModules.isEmpty()) {
Module[] noJdkArray = noJdkModules.toArray(new Module[noJdkModules.size()]);
if (noJdkArray.length == 1) {
Messages.showErrorDialog(myProject,
GroovyBundle.message("cannot.compile.groovy.files.no.sdk", noJdkArray[0].getName()),
GroovyBundle.message("cannot.compile"));
Messages.showErrorDialog(
myProject,
GroovyLocalize.cannotCompileGroovyFilesNoSdk(noJdkArray[0].getName()).get(),
GroovyLocalize.cannotCompile().get()
);
}
else {
StringBuilder modulesList = new StringBuilder();
Expand All @@ -139,24 +146,27 @@ public boolean validateConfiguration(CompileScope compileScope) {
}
modulesList.append(noJdkArray[i].getName());
}
Messages.showErrorDialog(myProject,
GroovyBundle.message("cannot.compile.groovy.files.no.sdk.mult", modulesList.toString()),
GroovyBundle.message("cannot.compile"));
Messages.showErrorDialog(
myProject,
GroovyLocalize.cannotCompileGroovyFilesNoSdkMult(modulesList.toString()).get(),
GroovyLocalize.cannotCompile().get()
);
}
return false;
}

GroovyCompilerConfiguration configuration = GroovyCompilerConfiguration.getInstance(myProject);
if (!configuration.transformsOk && needTransformCopying(compileScope)) {
int result = Messages.showYesNoDialog(myProject,
"You seem to have global Groovy AST transformations defined in your project,\n" + "but they won't be applied to your code because " +
"they are not marked as compiler resources.\n" + "Do you want to add them to compiler resource list?\n" + "(you can do it yourself later in Settings | Compiler | Resource " +
"patterns)",
"AST Transformations Found",
Messages.getQuestionIcon());
int result = Messages.showYesNoDialog(myProject,
"You seem to have global Groovy AST transformations defined in your project,\n" +
"but they won't be applied to your code because they are not marked as compiler resources.\n" +
"Do you want to add them to compiler resource list?\n" +
"(you can do it yourself later in Settings | Compiler | Resource patterns)",
"AST Transformations Found",
UIUtil.getQuestionIcon()
);
if (result == 0) {
ResourceCompilerConfiguration.getInstance(myProject)
.addResourceFilePattern(AST_TRANSFORM_FILE_NAME);
ResourceCompilerConfiguration.getInstance(myProject).addResourceFilePattern(AST_TRANSFORM_FILE_NAME);
}
else {
configuration.transformsOk = true;
Expand All @@ -168,7 +178,7 @@ public boolean validateConfiguration(CompileScope compileScope) {

@Override
public void registerCompilableFileTypes(@Nonnull Consumer<FileType> fileTypeConsumer) {
fileTypeConsumer.accept(GroovyFileType.GROOVY_FILE_TYPE);
fileTypeConsumer.accept(GroovyFileType.INSTANCE);
}

private boolean needTransformCopying(CompileScope compileScope) {
Expand All @@ -189,7 +199,7 @@ private boolean needTransformCopying(CompileScope compileScope) {
@Override
public FileType[] getInputFileTypes() {
return new FileType[]{
GroovyFileType.GROOVY_FILE_TYPE,
GroovyFileType.INSTANCE,
JavaClassFileType.INSTANCE
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jetbrains.plugins.groovy.impl.compiler;

import consulo.annotation.component.ComponentScope;
Expand All @@ -26,7 +25,6 @@
import consulo.component.persist.StoragePathMacros;
import consulo.disposer.Disposable;
import consulo.disposer.Disposer;
import consulo.application.Application;
import consulo.project.Project;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand All @@ -53,6 +51,7 @@ public GroovyCompilerConfiguration(Project project, GroovyCompilerWorkspaceConfi
workspaceConfiguration.myExcludeFromStubGeneration.removeAllExcludeEntryDescriptions();
}

@Override
public JpsGroovySettings getState() {
JpsGroovySettings bean = new JpsGroovySettings();
bean.heapSize = myHeapSize;
Expand All @@ -70,6 +69,7 @@ public ExcludedEntriesConfiguration getExcludeFromStubGeneration() {
return myExcludeFromStubGeneration;
}

@Override
public void loadState(JpsGroovySettings state) {
myHeapSize = state.heapSize;
myInvokeDynamic = state.invokeDynamic;
Expand Down Expand Up @@ -98,8 +98,8 @@ public void setInvokeDynamic(boolean invokeDynamic) {
myInvokeDynamic = invokeDynamic;
}

@Override
public void dispose() {
Disposer.dispose(myExcludeFromStubGeneration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jetbrains.plugins.groovy.impl.compiler;

import consulo.annotation.component.ComponentScope;
Expand All @@ -36,30 +35,32 @@
@ServiceImpl
@Singleton
public class GroovyCompilerWorkspaceConfiguration implements PersistentStateComponent<JpsGroovySettings>, Disposable {
String myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();

public JpsGroovySettings getState() {
JpsGroovySettings bean = new JpsGroovySettings();
bean.heapSize = myHeapSize;
bean.invokeDynamic = myInvokeDynamic;
bean.transformsOk = transformsOk;
myExcludeFromStubGeneration.writeExternal(bean.excludes);
return bean;
}
String myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();

public void loadState(JpsGroovySettings state) {
myHeapSize = state.heapSize;
myInvokeDynamic = state.invokeDynamic;
transformsOk = state.transformsOk;
@Override
public JpsGroovySettings getState() {
JpsGroovySettings bean = new JpsGroovySettings();
bean.heapSize = myHeapSize;
bean.invokeDynamic = myInvokeDynamic;
bean.transformsOk = transformsOk;
myExcludeFromStubGeneration.writeExternal(bean.excludes);
return bean;
}

myExcludeFromStubGeneration.readExternal(state.excludes);
}
@Override
public void loadState(JpsGroovySettings state) {
myHeapSize = state.heapSize;
myInvokeDynamic = state.invokeDynamic;
transformsOk = state.transformsOk;

public void dispose() {
Disposer.dispose(myExcludeFromStubGeneration);
}
myExcludeFromStubGeneration.readExternal(state.excludes);
}

@Override
public void dispose() {
Disposer.dispose(myExcludeFromStubGeneration);
}
}
Loading
Loading