Search in sources :

Example 76 with Module

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

the class GenerateGroovyDocAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    if (module == null)
        return;
    GroovyDocConfiguration configuration = new GroovyDocConfiguration();
    final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
    if (files.length == 1) {
        configuration.INPUT_DIRECTORY = files[0].getPath();
    }
    final GenerateGroovyDocDialog dialog = new GenerateGroovyDocDialog(project, configuration);
    if (!dialog.showAndGet()) {
        return;
    }
    generateGroovydoc(configuration, project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GenerateGroovyDocDialog(org.jetbrains.plugins.groovy.doc.GenerateGroovyDocDialog) Module(com.intellij.openapi.module.Module) GroovyDocConfiguration(org.jetbrains.plugins.groovy.doc.GroovyDocConfiguration)

Example 77 with Module

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

the class GroovyCompilerConfigurable method createExcludedConfigurable.

private ExcludedEntriesConfigurable createExcludedConfigurable(final Project project) {
    final ExcludesConfiguration configuration = myConfig.getExcludeFromStubGeneration();
    final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && !index.isExcluded(file);
        }
    };
    descriptor.setRoots(ContainerUtil.concat(ContainerUtil.map(ModuleManager.getInstance(project).getModules(), new Function<Module, List<VirtualFile>>() {

        @Override
        public List<VirtualFile> fun(final Module module) {
            return ModuleRootManager.getInstance(module).getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
        }
    })));
    return new ExcludedEntriesConfigurable(project, descriptor, configuration);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExcludedEntriesConfigurable(com.intellij.openapi.compiler.options.ExcludedEntriesConfigurable) ExcludesConfiguration(com.intellij.openapi.compiler.options.ExcludesConfiguration) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) List(java.util.List) Module(com.intellij.openapi.module.Module)

Example 78 with Module

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

the class ModuleChooserUtil method selectModule.

public static void selectModule(@NotNull Project project, final Collection<Module> suitableModules, final Function<Module, String> versionProvider, final Consumer<Module> callback, @Nullable DataContext context) {
    final List<Module> modules = new ArrayList<>();
    final Map<Module, String> versions = new HashMap<>();
    for (Module module : suitableModules) {
        modules.add(module);
        versions.put(module, versionProvider.fun(module));
    }
    if (modules.size() == 1) {
        callback.consume(modules.get(0));
        return;
    }
    Collections.sort(modules, ModulesAlphaComparator.INSTANCE);
    BaseListPopupStep<Module> step = new BaseListPopupStep<Module>("Which module to use classpath of?", modules, PlatformIcons.CONTENT_ROOT_ICON_CLOSED) {

        @NotNull
        @Override
        public String getTextFor(Module value) {
            return String.format("%s (%s)", value.getName(), versions.get(value));
        }

        @Override
        public String getIndexedString(Module value) {
            return value.getName();
        }

        @Override
        public boolean isSpeedSearchEnabled() {
            return true;
        }

        @Override
        public PopupStep onChosen(Module selectedValue, boolean finalChoice) {
            PropertiesComponent.getInstance(selectedValue.getProject()).setValue(GROOVY_LAST_MODULE, selectedValue.getName());
            callback.consume(selectedValue);
            return null;
        }
    };
    final String lastModuleName = PropertiesComponent.getInstance(project).getValue(GROOVY_LAST_MODULE);
    if (lastModuleName != null) {
        int defaultOption = ContainerUtil.indexOf(modules, new Condition<Module>() {

            @Override
            public boolean value(Module module) {
                return module.getName().equals(lastModuleName);
            }
        });
        if (defaultOption >= 0) {
            step.setDefaultOptionIndex(defaultOption);
        }
    }
    final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
    if (context == null) {
        listPopup.showCenteredInCurrentWindow(project);
    } else {
        listPopup.showInBestPositionFor(context);
    }
}
Also used : BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Module(com.intellij.openapi.module.Module)

Example 79 with Module

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

the class MavenExternalParameters method dumpModulesPaths.

private static File dumpModulesPaths(@NotNull Project project) throws IOException {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    Properties res = new Properties();
    MavenProjectsManager manager = MavenProjectsManager.getInstance(project);
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        if (manager.isMavenizedModule(module)) {
            MavenProject mavenProject = manager.findProject(module);
            if (mavenProject != null && !manager.isIgnored(mavenProject)) {
                res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":pom" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getFile().getPath());
                res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ':' + mavenProject.getPackaging() + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getOutputDirectory());
                res.setProperty(mavenProject.getMavenId().getGroupId() + ':' + mavenProject.getMavenId().getArtifactId() + ":test-jar" + ':' + mavenProject.getMavenId().getVersion(), mavenProject.getTestOutputDirectory());
                addArtifactFileMapping(res, mavenProject, "sources");
                addArtifactFileMapping(res, mavenProject, "test-sources");
                addArtifactFileMapping(res, mavenProject, "javadoc");
                addArtifactFileMapping(res, mavenProject, "test-javadoc");
            }
        }
    }
    File file = new File(PathManager.getSystemPath(), "Maven/idea-projects-state-" + project.getLocationHash() + ".properties");
    FileUtil.ensureExists(file.getParentFile());
    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    try {
        res.store(out, null);
    } finally {
        out.close();
    }
    return file;
}
Also used : MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ZipOutputStream(java.util.zip.ZipOutputStream) Module(com.intellij.openapi.module.Module)

Example 80 with Module

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

the class MavenExternalParameters method getJdk.

@NotNull
private static Sdk getJdk(@Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
    String name = runnerSettings.getJreName();
    if (name.equals(MavenRunnerSettings.USE_INTERNAL_JAVA)) {
        return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
    }
    if (name.equals(MavenRunnerSettings.USE_PROJECT_JDK)) {
        if (project != null) {
            Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
            if (res != null) {
                return res;
            }
            Module[] modules = ModuleManager.getInstance(project).getModules();
            for (Module module : modules) {
                Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
                if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
                    return sdk;
                }
            }
        }
        if (project == null) {
            Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
            if (recent != null)
                return recent;
            return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
        }
        throw new ProjectJdkSettingsOpenerExecutionException("Project JDK is not specified. <a href=''>Configure</a>", project);
    }
    if (name.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
        final String javaHome = System.getenv("JAVA_HOME");
        if (StringUtil.isEmptyOrSpaces(javaHome)) {
            throw new ExecutionException(RunnerBundle.message("maven.java.home.undefined"));
        }
        final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
        if (jdk == null) {
            throw new ExecutionException(RunnerBundle.message("maven.java.home.invalid", javaHome));
        }
        return jdk;
    }
    for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
        if (projectJdk.getName().equals(name)) {
            return projectJdk;
        }
    }
    if (isGlobalRunnerSettings) {
        throw new ExecutionException(RunnerBundle.message("maven.java.not.found.default.config", name));
    } else {
        throw new ExecutionException(RunnerBundle.message("maven.java.not.found", name));
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

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