@Nullable protected static VirtualFile findGroovyJar(@NotNull Module module) { final VirtualFile[] files = OrderEnumerator.orderEntries(module).getAllLibrariesAndSdkClassesRoots(); for (VirtualFile root : files) { if (root.getName().matches(GroovyConfigUtils.GROOVY_JAR_PATTERN) || GroovyConfigUtils.matchesGroovyAll(root.getName())) { return root; } } for (VirtualFile file : files) { if (file.getName().contains("groovy") && "jar".equals(file.getExtension())) { return file; } } return null; }
public boolean validateConfiguration(CompileScope compileScope) { VirtualFile[] files = compileScope.getFiles(GroovyFileType.GROOVY_FILE_TYPE, true); if (files.length == 0) return true; final Set<String> scriptExtensions = GroovyFileTypeLoader.getCustomGroovyScriptExtensions(); final CompilerManager compilerManager = CompilerManager.getInstance(myProject); Set<Module> modules = new HashSet<Module>(); for (VirtualFile file : files) { if (scriptExtensions.contains(file.getExtension()) || compilerManager.isExcludedFromCompilation(file) || CompilerConfiguration.getInstance(myProject).isResourceFile(file)) { continue; } ProjectRootManager rootManager = ProjectRootManager.getInstance(myProject); Module module = rootManager.getFileIndex().getModuleForFile(file); if (module != null) { modules.add(module); } } Set<Module> nojdkModules = new HashSet<Module>(); for (Module module : modules) { if (!GroovyUtils.isAcceptableModuleType(ModuleType.get(module))) continue; final Sdk sdk = ModuleRootManager.getInstance(module).getSdk(); if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) { 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")); ModulesConfigurator.showDialog( module.getProject(), module.getName(), ClasspathEditor.NAME); return false; } } } if (!nojdkModules.isEmpty()) { final 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")); } else { StringBuilder modulesList = new StringBuilder(); for (int i = 0; i < noJdkArray.length; i++) { if (i > 0) modulesList.append(", "); modulesList.append(noJdkArray[i].getName()); } Messages.showErrorDialog( myProject, GroovyBundle.message("cannot.compile.groovy.files.no.sdk.mult", modulesList.toString()), GroovyBundle.message("cannot.compile")); } return false; } final GroovyCompilerConfiguration configuration = GroovyCompilerConfiguration.getInstance(myProject); if (!configuration.transformsOk && needTransformCopying(compileScope)) { final 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", GroovyIcons.GROOVY_ICON_32x32); if (result == 0) { CompilerConfiguration.getInstance(myProject) .addResourceFilePattern(AST_TRANSFORM_FILE_NAME); } else { configuration.transformsOk = true; } } return true; }