Search in sources :

Example 21 with ModuleManager

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

the class ImportModuleFromImlFileAction method getModuleNames.

private static List<VirtualFile> getModuleNames(AnActionEvent e) {
    final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    final Project project = getEventProject(e);
    if (project == null || files == null || files.length == 0) {
        return Collections.emptyList();
    }
    List<VirtualFile> modulesFiles = new ArrayList<>();
    for (VirtualFile file : files) {
        if (!file.getFileType().equals(StdFileTypes.IDEA_MODULE)) {
            return Collections.emptyList();
        }
        modulesFiles.add(file);
    }
    final ModuleManager moduleManager = ModuleManager.getInstance(project);
    for (Module module : moduleManager.getModules()) {
        modulesFiles.remove(module.getModuleFile());
    }
    return modulesFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 22 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project intellij-plugins by JetBrains.

the class OsgiRunConfiguration method getModules.

@NotNull
@Override
public Module[] getModules() {
    List<Module> modules = new ArrayList<>();
    ModuleManager moduleManager = ModuleManager.getInstance(getProject());
    for (SelectedBundle selectedBundle : getBundlesToDeploy()) {
        if (selectedBundle.isModule()) {
            Module module = moduleManager.findModuleByName(selectedBundle.getName());
            if (module != null) {
                modules.add(module);
            } else {
                LOG.error("no module [" + selectedBundle.getName() + "]");
            }
        }
    }
    return modules.toArray(new Module[modules.size()]);
}
Also used : SelectedBundle(org.osmorc.run.ui.SelectedBundle) Module(com.intellij.openapi.module.Module) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project intellij-plugins by JetBrains.

the class OsgiRunState method getSelectedBundles.

/**
   * Here we got the magic. All libs are turned into bundles sorted and returned.
   */
private List<SelectedBundle> getSelectedBundles() throws ExecutionException {
    final Ref<List<SelectedBundle>> result = Ref.create();
    final Ref<ExecutionException> error = Ref.create();
    ProgressManager.getInstance().run(new Task.Modal(myRunConfiguration.getProject(), "Preparing bundles...", false) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(false);
            AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
            try {
                Set<SelectedBundle> selectedBundles = new HashSet<>();
                // the bundles are module names, by now we try to find jar files in the output directory which we can then install
                ModuleManager moduleManager = ModuleManager.getInstance(myRunConfiguration.getProject());
                BundleCompiler bundleCompiler = new BundleCompiler(progressIndicator);
                int bundleCount = myRunConfiguration.getBundlesToDeploy().size();
                for (int i = 0; i < bundleCount; i++) {
                    progressIndicator.setFraction((double) i / bundleCount);
                    SelectedBundle selectedBundle = myRunConfiguration.getBundlesToDeploy().get(i);
                    if (selectedBundle.isModule()) {
                        // use the output jar name if it is a module
                        String name = selectedBundle.getName();
                        Module module = moduleManager.findModuleByName(name);
                        if (module == null) {
                            throw new CantRunException("Module '" + name + "' no longer exists. Please check your run configuration.");
                        }
                        OsmorcFacet facet = OsmorcFacet.getInstance(module);
                        if (facet == null) {
                            throw new CantRunException("Module '" + name + "' has no OSGi facet. Please check your run configuration.");
                        }
                        selectedBundle.setBundlePath(facet.getConfiguration().getJarFileLocation());
                        selectedBundles.add(selectedBundle);
                        // add all the library dependencies of the bundle
                        List<String> paths = bundleCompiler.bundlifyLibraries(module);
                        for (String path : paths) {
                            selectedBundles.add(new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "Dependency", path));
                        }
                    } else {
                        if (selectedBundles.contains(selectedBundle)) {
                            // if the user selected a dependency as runnable library, we need to replace the dependency with
                            // the runnable library part
                            selectedBundles.remove(selectedBundle);
                        }
                        selectedBundles.add(selectedBundle);
                    }
                }
                // filter out bundles which have the same symbolic name
                Map<String, SelectedBundle> filteredBundles = new HashMap<>();
                for (SelectedBundle selectedBundle : selectedBundles) {
                    String path = selectedBundle.getBundlePath();
                    if (path != null) {
                        String name = CachingBundleInfoProvider.getBundleSymbolicName(path);
                        String version = CachingBundleInfoProvider.getBundleVersion(path);
                        String key = name + version;
                        if (!filteredBundles.containsKey(key)) {
                            filteredBundles.put(key, selectedBundle);
                        }
                    }
                }
                List<SelectedBundle> sortedBundles = ContainerUtil.newArrayList(filteredBundles.values());
                Collections.sort(sortedBundles, START_LEVEL_COMPARATOR);
                result.set(sortedBundles);
            } catch (CantRunException e) {
                error.set(e);
            } catch (OsgiBuildException e) {
                LOG.warn(e);
                error.set(new CantRunException(e.getMessage()));
            } catch (Throwable t) {
                LOG.error(t);
                error.set(new CantRunException("Internal error: " + t.getMessage()));
            } finally {
                token.finish();
            }
        }
    });
    if (!result.isNull()) {
        return result.get();
    } else {
        throw error.get();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) SelectedBundle(org.osmorc.run.ui.SelectedBundle) ModuleManager(com.intellij.openapi.module.ModuleManager) CantRunException(com.intellij.execution.CantRunException) OsmorcFacet(org.osmorc.facet.OsmorcFacet) BundleCompiler(org.osmorc.make.BundleCompiler) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AccessToken(com.intellij.openapi.application.AccessToken) OsgiBuildException(org.jetbrains.osgi.jps.build.OsgiBuildException) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module)

Example 24 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project intellij-plugins by JetBrains.

the class FacetDetectionTest method testDetectBundlorFacet.

@Test
public void testDetectBundlorFacet() {
    ModuleManager moduleManager = ModuleManager.getInstance(myFixture.getProject());
    Module t2 = moduleManager.findModuleByName("t2");
    assertNotNull(t2);
    OsmorcFrameworkDetector detector = new OsmorcFrameworkDetector();
    ElementPattern<FileContent> filter = detector.createSuitableFilePattern();
    VirtualFile manifestFile = myTempDirFixture.getFile("t2/src/META-INF/template.mf");
    assertThat(filter.accepts(FileContentImpl.createByFile(manifestFile)), equalTo(true));
    OsmorcFacetConfiguration facetConfiguration = detector.createConfiguration(Collections.singletonList(manifestFile));
    assertNotNull(facetConfiguration);
    assertThat(facetConfiguration.getManifestLocation(), equalTo(manifestFile.getPath()));
    assertThat(facetConfiguration.isUseProjectDefaultManifestFileLocation(), equalTo(false));
    OsmorcFacet facet = OsmorcFacetType.getInstance().createFacet(t2, "OSGi", facetConfiguration, null);
    ModifiableRootModel model = ModuleRootManager.getInstance(t2).getModifiableModel();
    try {
        detector.setupFacet(facet, model);
        assertThat(facetConfiguration.getManifestLocation(), equalTo(""));
        assertThat(facetConfiguration.getBundlorFileLocation(), equalTo("src/META-INF/template.mf"));
        assertThat(facetConfiguration.isUseBundlorFile(), equalTo(true));
    } finally {
        model.dispose();
    }
}
Also used : FileContent(com.intellij.util.indexing.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) Test(org.junit.Test)

Example 25 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class SdksCleanupStep method cleanUpProject.

@Override
public void cleanUpProject(@NotNull Project project, @NotNull IdeModifiableModelsProvider ideModifiableModelsProvider, @Nullable ProgressIndicator indicator) {
    Collection<Sdk> invalidAndroidSdks = Sets.newHashSet();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    for (Module module : moduleManager.getModules()) {
        cleanUpSdk(module, invalidAndroidSdks);
    }
    if (!invalidAndroidSdks.isEmpty()) {
        reinstallMissingPlatforms(invalidAndroidSdks, project);
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Aggregations

ModuleManager (com.intellij.openapi.module.ModuleManager)51 Module (com.intellij.openapi.module.Module)40 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)8 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)7 File (java.io.File)7 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)3 IOException (java.io.IOException)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 Variant (com.android.builder.model.Variant)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 BuildMode (com.android.tools.idea.gradle.util.BuildMode)2 AccessToken (com.intellij.openapi.application.AccessToken)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2