Search in sources :

Example 46 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class GantScriptType method additionalScopeFiles.

public static List<VirtualFile> additionalScopeFiles(@NotNull GroovyFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module != null) {
        final String sdkHome = GantUtils.getSdkHomeFromClasspath(module);
        if (sdkHome != null) {
            return Collections.emptyList();
        }
    }
    final GantSettings gantSettings = GantSettings.getInstance(file.getProject());
    final VirtualFile home = gantSettings.getSdkHome();
    if (home == null) {
        return Collections.emptyList();
    }
    return gantSettings.getClassRoots();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Module(com.intellij.openapi.module.Module)

Example 47 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class GrabDependencies method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    final VirtualFile vfile = file.getOriginalFile().getVirtualFile();
    assert vfile != null;
    if (JavaPsiFacade.getInstance(project).findClass("org.apache.ivy.core.report.ResolveReport", file.getResolveScope()) == null) {
        Messages.showErrorDialog("Sorry, but IDEA cannot @Grab the dependencies without Ivy. Please add Ivy to your module dependencies and re-run the action.", "Ivy Missing");
        return;
    }
    Map<String, String> queries = prepareQueries(file);
    final Map<String, GeneralCommandLine> lines = new HashMap<>();
    for (String grabText : queries.keySet()) {
        final JavaParameters javaParameters = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
        try {
            DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module, GRAPE_RUNNER, false, true);
            javaParameters.getClassPath().add(PathUtil.getJarPathForClass(GrapeRunner.class));
            javaParameters.getProgramParametersList().add(queries.get(grabText));
            javaParameters.setUseDynamicClasspath(true);
            lines.put(grabText, javaParameters.toCommandLine());
        } catch (CantRunException e) {
            String title = "Can't run @Grab: " + ExceptionUtil.getMessage(e);
            NOTIFICATION_GROUP.createNotification(title, ExceptionUtil.getThrowableText(e), NotificationType.ERROR, null).notify(project);
            return;
        }
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Processing @Grab Annotations") {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            int jarCount = 0;
            String messages = "";
            for (Map.Entry<String, GeneralCommandLine> entry : lines.entrySet()) {
                String grabText = entry.getKey();
                indicator.setText2(grabText);
                try {
                    final GrapeProcessHandler handler = new GrapeProcessHandler(entry.getValue(), module);
                    handler.startNotify();
                    handler.waitFor();
                    jarCount += handler.jarCount;
                    messages += "<b>" + grabText + "</b>: " + handler.messages + "<p>";
                } catch (ExecutionException e) {
                    LOG.error(e);
                }
            }
            final String finalMessages = messages;
            final String title = jarCount + " Grape dependency jar" + (jarCount == 1 ? "" : "s") + " added";
            NOTIFICATION_GROUP.createNotification(title, finalMessages, NotificationType.INFORMATION, null).notify(project);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) CantRunException(com.intellij.execution.CantRunException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException)

Example 48 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class GriffonDefaultImportContributor method appendImplicitlyImportedPackages.

@NotNull
@Override
public List<String> appendImplicitlyImportedPackages(@NotNull GroovyFile file) {
    Module module = ModuleUtilCore.findModuleForPsiElement(file);
    MvcFramework framework = MvcFramework.getInstance(module);
    if (framework instanceof GriffonFramework) {
        ArrayList<String> result = new ArrayList<>();
        result.add("griffon.core");
        result.add("griffon.util");
        VirtualFile griffonApp = framework.findAppDirectory(file);
        if (griffonApp != null) {
            VirtualFile models = griffonApp.findChild("models");
            VirtualFile views = griffonApp.findChild("views");
            VirtualFile vFile = file.getOriginalFile().getVirtualFile();
            assert vFile != null;
            assert module != null;
            if (models != null && VfsUtilCore.isAncestor(models, vFile, true)) {
                result.addAll(getDefaultImports(module).first);
            } else if (views != null && VfsUtilCore.isAncestor(views, vFile, true)) {
                result.addAll(getDefaultImports(module).second);
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) MvcFramework(org.jetbrains.plugins.groovy.mvc.MvcFramework) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 49 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class SceneBuilderImpl method isCompatibleLanguageLevel.

private static boolean isCompatibleLanguageLevel(@NotNull PsiClass aClass, @Nullable LanguageLevel targetLevel) {
    if (targetLevel == null)
        return true;
    final Project project = aClass.getProject();
    final VirtualFile vFile = PsiUtilCore.getVirtualFile(aClass);
    if (vFile == null)
        return true;
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vFile);
    if (module == null) {
        final OrderEntry entry = LibraryUtil.findLibraryEntry(vFile, project);
        if (entry != null) {
            module = entry.getOwnerModule();
        }
    }
    Sdk jdk = module != null ? ModuleRootManager.getInstance(module).getSdk() : null;
    if (jdk == null) {
        jdk = ProjectRootManager.getInstance(project).getProjectSdk();
    }
    if (jdk == null)
        return true;
    final String versionString = jdk.getVersionString();
    if (versionString != null) {
        final JavaSdkVersion jdkVersion = JdkVersionUtil.getVersion(versionString);
        if (jdkVersion != null) {
            return targetLevel.isAtLeast(jdkVersion.getMaxLanguageLevel());
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 50 with Module

use of com.intellij.openapi.module.Module in project intellij-community by JetBrains.

the class JavaFxArtifactProperties method onBuildFinished.

@Override
public void onBuildFinished(@NotNull final Artifact artifact, @NotNull final CompileContext compileContext) {
    if (!(artifact.getArtifactType() instanceof JavaFxApplicationArtifactType)) {
        return;
    }
    final Project project = compileContext.getProject();
    final Set<Module> modules = ReadAction.compute(() -> ArtifactUtil.getModulesIncludedInArtifacts(Collections.singletonList(artifact), project));
    if (modules.isEmpty()) {
        return;
    }
    Sdk fxCompatibleSdk = null;
    for (Module module : modules) {
        final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
        if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
            if (((JavaSdk) sdk.getSdkType()).isOfVersionOrHigher(sdk, JavaSdkVersion.JDK_1_7)) {
                fxCompatibleSdk = sdk;
                break;
            }
        }
    }
    if (fxCompatibleSdk == null) {
        compileContext.addMessage(CompilerMessageCategory.ERROR, "Java version 7 or higher is required to build JavaFX package", null, -1, -1);
        return;
    }
    final JavaFxArtifactProperties properties = (JavaFxArtifactProperties) artifact.getProperties(JavaFxArtifactPropertiesProvider.getInstance());
    final JavaFxPackager javaFxPackager = new JavaFxPackager(artifact, properties, project) {

        @Override
        protected void registerJavaFxPackagerError(String message) {
            compileContext.addMessage(CompilerMessageCategory.ERROR, message, null, -1, -1);
        }
    };
    javaFxPackager.buildJavaFxArtifact(fxCompatibleSdk.getHomePath());
}
Also used : Project(com.intellij.openapi.project.Project) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1893 VirtualFile (com.intellij.openapi.vfs.VirtualFile)585 Project (com.intellij.openapi.project.Project)379 NotNull (org.jetbrains.annotations.NotNull)330 Nullable (org.jetbrains.annotations.Nullable)267 File (java.io.File)185 PsiFile (com.intellij.psi.PsiFile)147 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)134 ArrayList (java.util.ArrayList)118 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)112 Sdk (com.intellij.openapi.projectRoots.Sdk)95 PsiElement (com.intellij.psi.PsiElement)89 PsiDirectory (com.intellij.psi.PsiDirectory)77 ModuleManager (com.intellij.openapi.module.ModuleManager)65 PsiClass (com.intellij.psi.PsiClass)65 IOException (java.io.IOException)61 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)57 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)57 List (java.util.List)57 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)51