Java Code Examples for com.intellij.openapi.module.ModuleManager

The following are top voted examples for showing how to use com.intellij.openapi.module.ModuleManager. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: SmartQQ4IntelliJ   File: VFSUtils.java   View source code 6 votes vote down vote up
public static VirtualFile _getVirtualFile(Project project, String file) {
    VirtualFile result = findFileByFQName(file, project);

    if (result == null) {
        final Set<VirtualFile> candidates = new HashSet<>();

        Module[] modules = ModuleManager.getInstance(project).getModules();
        for (Module module : modules) {
            findFileInModule(candidates, module, file);
        }

        int currWeight = 0;
        for (VirtualFile candidate : candidates) {
            final int newWeight = weight(candidate, file);
            if (result == null || newWeight > currWeight) {
                currWeight = newWeight;
                result = candidate;
            }
        }
    }

    return result;
}
 
Example 2
Project: green-cat   File: Utils.java   View source code 6 votes vote down vote up
public static String getAndroidSdkPath(Project project) {
    ModuleManager manager = ModuleManager.getInstance(project);
    String androidSdkPath = null;

    for (Module module : manager.getModules()) {
        if (androidSdkPath != null) {
            break;
        }
        Sdk sdk = ModuleRootManager.getInstance(module).getSdk();

        if (sdk != null && sdk.getHomePath() != null) {
            File file = new File(sdk.getHomePath());
            String[] contents = file.list();

            if (contents != null) {
                for (String path : contents) {
                    if (path.equals("build-tools")) {
                        androidSdkPath = sdk.getHomePath();
                        break;
                    }
                }
            }
        }
    }
    return androidSdkPath;
}
 
Example 3
Project: hybris-integration-intellij-idea-plugin   File: DefaultHybrisProjectDescriptor.java   View source code 6 votes vote down vote up
@NotNull
protected Set<HybrisModuleDescriptor> getAlreadyOpenedModules(@NotNull final Project project) {
    Validate.notNull(project);

    final HybrisModuleDescriptorFactory hybrisModuleDescriptorFactory = ServiceManager.getService(
        HybrisModuleDescriptorFactory.class
    );

    final Set<HybrisModuleDescriptor> existingModules = new THashSet<HybrisModuleDescriptor>();

    for (Module module : ModuleManager.getInstance(project).getModules()) {
        try {
            final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();

            if (!ArrayUtils.isEmpty(contentRoots)) {
                existingModules.add(hybrisModuleDescriptorFactory.createDescriptor(
                    VfsUtil.virtualToIoFile(contentRoots[0]), this
                ));
            }
        } catch (HybrisConfigurationException e) {
            LOG.error(e);
        }
    }

    return existingModules;
}
 
Example 4
Project: hybris-integration-intellij-idea-plugin   File: DefaultMavenConfigurator.java   View source code 6 votes vote down vote up
private void moveMavenModulesToGroup(
    final Project project,
    final List<Module> mavenModules,
    final String[] rootGroup
) {
    AccessToken token = null;
    final ModifiableModuleModel modifiableModuleModel;
    try {
        token = ApplicationManager.getApplication().acquireReadActionLock();
        modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel();

        for (Module module : mavenModules) {
            module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.MAVEN.name());
            final String[] groupPath = modifiableModuleModel.getModuleGroupPath(module);
            modifiableModuleModel.setModuleGroupPath(module, ArrayUtils.addAll(rootGroup, groupPath));
        }
    } finally {
        if (token != null) {
            token.finish();
        }
    }
    ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModuleModel::commit));
}
 
Example 5
Project: hybris-integration-intellij-idea-plugin   File: DefaultLoadedConfigurator.java   View source code 6 votes vote down vote up
@Override
public void configure(
    final Project project,
    final List<HybrisModuleDescriptor> allModules
) {
    // todo: remove "UNLOADED" mechanism completely. It is temporary disabled now, so this list should be empty
    final List<String> unloadedModuleNames = allModules
        .stream()
        .filter(e -> e.getImportStatus() == HybrisModuleDescriptor.IMPORT_STATUS.UNLOADED)
        .map(HybrisModuleDescriptor::getName)
        .collect(Collectors.toList());

    final Set<String> unusedModuleNames = allModules
        .stream()
        .filter(e -> e.getImportStatus() == HybrisModuleDescriptor.IMPORT_STATUS.UNUSED)
        .map(HybrisModuleDescriptor::getName)
        .collect(Collectors.toSet());

    ApplicationManager.getApplication().invokeAndWait(() -> {
        ModuleManager.getInstance(project).setUnloadedModules(unloadedModuleNames);
        HybrisProjectSettingsComponent.getInstance(project).getState().setUnusedExtensions(unusedModuleNames);
    });
}
 
Example 6
Project: hybris-integration-intellij-idea-plugin   File: DefaultGradleConfigurator.java   View source code 6 votes vote down vote up
private void moveGradleModulesToGroup(
    final Project project,
    final List<Module> gradleModules,
    final String[] gradleGroup
) {
    final ModifiableModuleModel modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel();

    for (Module module : gradleModules) {
        if (module == null) {
            // https://youtrack.jetbrains.com/issue/IDEA-177512
            continue;
        }
        module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.GRADLE.name());
        modifiableModuleModel.setModuleGroupPath(module, gradleGroup);
    }
    AccessToken token = null;
    try {
        token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
        modifiableModuleModel.commit();
    } finally {
        if (token != null) {
            token.finish();
        }
    }
}
 
Example 7
Project: hybris-integration-intellij-idea-plugin   File: DefaultEclipseConfigurator.java   View source code 6 votes vote down vote up
private void moveEclipseModulesToGroup(
    @NotNull final Project project,
    @NotNull final List<Module> eclipseModules,
    @Nullable final String[] eclipseGroup
) {
    final ModifiableModuleModel modifiableModuleModel = ModuleManager.getInstance(project).getModifiableModel();

    for (Module module : eclipseModules) {
        module.setOption(HybrisConstants.DESCRIPTOR_TYPE, HybrisModuleDescriptorType.ECLIPSE.name());
        modifiableModuleModel.setModuleGroupPath(module, eclipseGroup);
    }
    AccessToken token = null;
    try {
        token = ApplicationManager.getApplication().acquireWriteActionLock(getClass());
        modifiableModuleModel.commit();
    } finally {
        if (token != null) {
            token.finish();
        }
    }
}
 
Example 8
Project: hybris-integration-intellij-idea-plugin   File: ProjectRefreshAction.java   View source code 6 votes vote down vote up
private static void removeOldProjectData(@NotNull final Project project) {
    final ModifiableModuleModel moduleModel = ModuleManager.getInstance(project).getModifiableModel();

    for (Module module : moduleModel.getModules()) {
        moduleModel.disposeModule(module);
    }
    final LibraryTable.ModifiableModel libraryModel = ProjectLibraryTable.getInstance(project).getModifiableModel();

    for (Library library : libraryModel.getLibraries()) {
        libraryModel.removeLibrary(library);
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        moduleModel.commit();
        libraryModel.commit();
    });
    final GradleSupport gradleSupport = GradleSupport.getInstance();

    if (gradleSupport != null) {
        gradleSupport.clearLinkedProjectSettings(project);
    }
    final AntConfigurationBase antConfiguration = AntConfigurationBase.getInstance(project);

    for (AntBuildFile antBuildFile : antConfiguration.getBuildFiles()) {
        antConfiguration.removeBuildFile(antBuildFile);
    }
}
 
Example 9
Project: hybris-integration-intellij-idea-plugin   File: ModuleDepDiagramItem.java   View source code 6 votes vote down vote up
@Nullable
public static ModuleDepDiagramItem fromFQN(@NotNull final String fqn, @NotNull final Project project) {
    String moduleName = null;
    boolean customExtension = false;

    if (fqn.startsWith(MODULE_PREFIX)) {
        moduleName = fqn.substring(MODULE_PREFIX.length());
        customExtension = false;
    } else if (fqn.startsWith(CUSTOM_MODULE_PREFIX)) {
        moduleName = fqn.substring(CUSTOM_MODULE_PREFIX.length());
        customExtension = true;
    }
    if (moduleName == null) {
        return new ModuleDepDiagramItem(null, false);
    }
    final Module module = ModuleManager.getInstance(project).findModuleByName(moduleName);
    return module == null ? null : new ModuleDepDiagramItem(module, customExtension);
}
 
Example 10
Project: hybris-integration-intellij-idea-plugin   File: DefaultCommonIdeaService.java   View source code 6 votes vote down vote up
@Override
public boolean isPotentiallyHybrisProject(@NotNull final Project project) {
    final Module[] modules = ModuleManager.getInstance(project).getModules();
    if (modules.length == 0) {
        return false;
    }
    final ArrayList<String> moduleNames = Arrays.stream(modules)
                                                .map(Module::getName)
                                                .collect(Collectors.toCollection(ArrayList::new));

    final Collection<String> acceleratorNames = Arrays.asList("*cockpits", "*core", "*facades", "*storefront");
    if (matchAllModuleNames(acceleratorNames, moduleNames)) {
        return true;
    }
    final Collection<String> webservicesNames = Arrays.asList("*hmc", "hmc", "platform");
    return matchAllModuleNames(webservicesNames, moduleNames);
}
 
Example 11
Project: educational-plugin   File: EduPluginConfiguratorBase.java   View source code 6 votes vote down vote up
@Override
public PsiDirectory createLessonContent(@NotNull Project project, @NotNull Lesson lesson, @Nullable IdeView view, @NotNull PsiDirectory parentDirectory) {
  NewModuleAction newModuleAction = new NewModuleAction();
  String courseDirPath = parentDirectory.getVirtualFile().getPath();
  Module utilModule = ModuleManager.getInstance(project).findModuleByName(EduIntelliJNames.UTIL);
  if (utilModule == null) {
    return null;
  }
  newModuleAction.createModuleFromWizard(project, null, new AbstractProjectWizard("", project, "") {
    @Override
    public StepSequence getSequence() {
      return null;
    }

    @Override
    public ProjectBuilder getProjectBuilder() {
      return new EduLessonModuleBuilder(courseDirPath, lesson, utilModule);
    }
  });
  return parentDirectory.findSubdirectory(EduNames.LESSON + lesson.getIndex());
}
 
Example 12
Project: processing-idea   File: ProcessingImportBuilder.java   View source code 6 votes vote down vote up
@NotNull
public Parameters getParameters() {
    if (parameters == null) {
        parameters = new Parameters();
        parameters.existingModuleNames = new HashSet<>();
        if (isUpdate()) {
            Project project = getCurrentProject();
            if (project != null) {
                for (Module module : ModuleManager.getInstance(project).getModules()) {
                    parameters.existingModuleNames.add(module.getName());
                }
            }
        }
    }

    return parameters;
}
 
Example 13
Project: manifold-ij   File: ModuleClasspathListener.java   View source code 6 votes vote down vote up
@Override
public void rootsChanged( ModuleRootEvent event )
{
  Project project = (Project)event.getSource();
  if( !shouldProcessRootChanges( project ) )
  {
    return;
  }
  boolean processDependencies = true;

  if( processDependencies )
  {
    processModuleDependenciesChange( project );
  }

  final Module[] modules = ModuleManager.getInstance( project ).getModules();
  for( Module ijModule : modules )
  {
    ManModule manModule = ManProject.getModule( ijModule );
    processClasspathChange( manModule, ijModule );
    changeSourceRoots( manModule );
  }
}
 
Example 14
Project: intellij-ce-playground   File: MvcModuleStructureSynchronizer.java   View source code 6 votes vote down vote up
@NotNull
private List<Module> determineModuleBySyncActionObject(Object o) {
  if (o instanceof Module) {
    return Collections.singletonList((Module)o);
  }
  if (o instanceof Project) {
    return Arrays.asList(ModuleManager.getInstance((Project)o).getModules());
  }
  if (o instanceof VirtualFile) {
    final VirtualFile file = (VirtualFile)o;
    if (file.isValid()) {
      final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
      if (module == null) {
        return Collections.emptyList();
      }

      return Collections.singletonList(module);
    }
  }
  return Collections.emptyList();
}
 
Example 15
Project: intellij-ce-playground   File: FileTreeModelBuilder.java   View source code 6 votes vote down vote up
public FileTreeModelBuilder(Project project, Marker marker, DependenciesPanel.DependencyPanelSettings settings) {
  myProject = project;
  myBaseDir = myProject.getBaseDir();
  myContentRoots = ProjectRootManager.getInstance(myProject).getContentRoots();
  final boolean multiModuleProject = ModuleManager.getInstance(myProject).getModules().length > 1;
  myShowModules = settings.UI_SHOW_MODULES && multiModuleProject;
  final ProjectViewDirectoryHelper directoryHelper = ProjectViewDirectoryHelper.getInstance(myProject);
  myFlattenPackages = directoryHelper.supportsFlattenPackages() && settings.UI_FLATTEN_PACKAGES;
  myCompactEmptyMiddlePackages = directoryHelper.supportsHideEmptyMiddlePackages() && settings.UI_COMPACT_EMPTY_MIDDLE_PACKAGES;
  myShowFiles = settings.UI_SHOW_FILES;
  myShowModuleGroups = settings.UI_SHOW_MODULE_GROUPS && multiModuleProject;
  myMarker = marker;
  myAddUnmarkedFiles = !settings.UI_FILTER_LEGALS;
  myRoot = new RootNode(myProject);
  myFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
}
 
Example 16
Project: intellij-ce-playground   File: SourceScope.java   View source code 6 votes vote down vote up
public static SourceScope wholeProject(final Project project) {
  return new SourceScope() {
    public GlobalSearchScope getGlobalSearchScope() {
      return GlobalSearchScope.allScope(project);
    }

    public Project getProject() {
      return project;
    }

    public Module[] getModulesToCompile() {
      return ModuleManager.getInstance(project).getModules();
    }

    public GlobalSearchScope getLibrariesScope() {
      return getGlobalSearchScope();
    }
  };
}
 
Example 17
Project: intellij-ce-playground   File: ReadableExternalAnnotationsManager.java   View source code 6 votes vote down vote up
@NotNull
private synchronized Set<VirtualFile> initRoots() {
  if (myAnnotationsRoots == null) {
    myAnnotationsRoots = new HashSet<VirtualFile>();
    final Module[] modules = ModuleManager.getInstance(myPsiManager.getProject()).getModules();
    for (Module module : modules) {
      for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
        final VirtualFile[] files = AnnotationOrderRootType.getFiles(entry);
        if (files.length > 0) {
          Collections.addAll(myAnnotationsRoots, files);
        }
      }
    }
  }
  return myAnnotationsRoots;
}
 
Example 18
Project: intellij-ce-playground   File: ProjectFacetManagerImpl.java   View source code 6 votes vote down vote up
public ProjectFacetManagerImpl(Project project) {
  myProject = project;
  myCachedValueProvider = new ParameterizedCachedValueProvider<Boolean, FacetTypeId<?>>() {
    @Override
    public CachedValueProvider.Result<Boolean> compute(FacetTypeId<?> param) {
      boolean result = false;
      for (Module module : ModuleManager.getInstance(myProject).getModules()) {
        if (!FacetManager.getInstance(module).getFacetsByType(param).isEmpty()) {
          result = true;
          break;
        }
      }
      return CachedValueProvider.Result.create(result, FacetFinder.getInstance(myProject).getAllFacetsOfTypeModificationTracker(param));
    }
  };
}
 
Example 19
Project: intellij-ce-playground   File: ConfigureAndroidModuleStepDynamicTest.java   View source code 6 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();

  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      final ModuleManager manager = ModuleManager.getInstance(getProject());
      File moduleRoot = new File(getProject().getBasePath(), "app");
      manager.newModule(moduleRoot.getPath(), ModuleTypeId.JAVA_MODULE);

      moduleRoot = new File(getProject().getBasePath(), "Lib");
      manager.newModule(moduleRoot.getPath(), ModuleTypeId.JAVA_MODULE);

      moduleRoot = new File(getProject().getBasePath(), "lib2");
      manager.newModule(moduleRoot.getPath(), ModuleTypeId.JAVA_MODULE);
    }
  });

  ScopedStateStore wizardState = new ScopedStateStore(ScopedStateStore.Scope.WIZARD, null, null);
  ScopedStateStore pathState = new ScopedStateStore(ScopedStateStore.Scope.PATH, wizardState, null);

  myStep = new ConfigureAndroidModuleStepDynamic(getTestRootDisposable());
  myStep.myState = new ScopedStateStore(ScopedStateStore.Scope.STEP, pathState, myStep);
}
 
Example 20
Project: intellij-ce-playground   File: ModuleTestCase.java   View source code 6 votes vote down vote up
protected Module loadModule(@NotNull String modulePath) {
  String normalizedPath = FileUtil.toSystemIndependentName(modulePath);
  LocalFileSystem.getInstance().refreshAndFindFileByPath(normalizedPath);

  ModuleManager moduleManager = ModuleManager.getInstance(myProject);
  Module module;
  AccessToken token = WriteAction.start();
  try {
    module = moduleManager.loadModule(normalizedPath);
  }
  catch (Exception e) {
    LOG.error(e);
    return null;
  }
  finally {
    token.finish();
  }

  myModulesToDispose.add(module);
  return module;
}
 
Example 21
Project: intellij-ce-playground   File: RefManagerImpl.java   View source code 6 votes vote down vote up
public RefManagerImpl(@NotNull Project project, @Nullable AnalysisScope scope, @NotNull GlobalInspectionContext context) {
  myProject = project;
  myScope = scope;
  myContext = context;
  myPsiManager = PsiManager.getInstance(project);
  myRefProject = new RefProjectImpl(this);
  for (InspectionExtensionsFactory factory : Extensions.getExtensions(InspectionExtensionsFactory.EP_NAME)) {
    final RefManagerExtension extension = factory.createRefManagerExtension(this);
    if (extension != null) {
      myExtensions.put(extension.getID(), extension);
      myLanguageExtensions.put(extension.getLanguage(), extension);
    }
  }
  if (scope != null) {
    for (Module module : ModuleManager.getInstance(getProject()).getModules()) {
      getRefModule(module);
    }
  }
}
 
Example 22
Project: intellij-ce-playground   File: PluginRunConfiguration.java   View source code 6 votes vote down vote up
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
  if (getModule() == null) {
    throw new RuntimeConfigurationException(DevKitBundle.message("run.configuration.no.module.specified"));
  }
  String moduleName = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    public String compute() {
      return getModule().getName();
    }
  });
  if (ModuleManager.getInstance(getProject()).findModuleByName(moduleName) == null){
    throw new RuntimeConfigurationException(DevKitBundle.message("run.configuration.no.module.specified"));
  }
  final ModuleRootManager rootManager = ModuleRootManager.getInstance(getModule());
  final Sdk sdk = rootManager.getSdk();
  if (sdk == null) {
    throw new RuntimeConfigurationException(DevKitBundle.message("sdk.no.specified", moduleName));
  }
  if (IdeaJdk.findIdeaJdk(sdk) == null) {
    throw new RuntimeConfigurationException(DevKitBundle.message("sdk.type.incorrect", moduleName));
  }
}
 
Example 23
Project: intellij-ce-playground   File: PrepareAllToDeployAction.java   View source code 6 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return;

  List<Module> pluginModules = new ArrayList<Module>();
  for (Module aModule : ModuleManager.getInstance(project).getModules()) {
    if (PluginModuleType.isOfType(aModule)) {
      pluginModules.add(aModule);
    }
  }

  ChooseModulesDialog dialog = new ChooseModulesDialog(project,
                                                       pluginModules,
                                                       DevKitBundle.message("select.plugin.modules.title"),
                                                       DevKitBundle.message("select.plugin.modules.description"));
  if (dialog.showAndGet()) {
    doPrepare(dialog.getChosenElements(), project);
  }
}
 
Example 24
Project: intellij-ce-playground   File: FailedToParseSdkErrorHandler.java   View source code 6 votes vote down vote up
@Nullable
private static File findPathOfSdkMissingOrEmptyAddonsFolder(@NotNull Project project) {
  ModuleManager moduleManager = ModuleManager.getInstance(project);
  for (Module module : moduleManager.getModules()) {
    Sdk moduleSdk = ModuleRootManager.getInstance(module).getSdk();
    if (moduleSdk != null && isAndroidSdk(moduleSdk)) {
      String homePath = moduleSdk.getHomePath();
      if (homePath != null) {
        File sdkHomeDirPath = new File(FileUtil.toSystemDependentName(homePath));
        File addonsDir = new File(sdkHomeDirPath, SdkConstants.FD_ADDONS);
        if (!addonsDir.isDirectory() || FileUtil.notNullize(addonsDir.listFiles()).length == 0) {
          return sdkHomeDirPath;
        }
      }
    }
  }
  return null;
}
 
Example 25
Project: intellij-ce-playground   File: GroovyScriptRunConfiguration.java   View source code 6 votes vote down vote up
@Override
public Collection<Module> getValidModules() {
  Module[] modules = ModuleManager.getInstance(getProject()).getModules();
  final GroovyScriptRunner scriptRunner = findConfiguration();
  if (scriptRunner == null) {
    return Arrays.asList(modules);
  }


  ArrayList<Module> res = new ArrayList<Module>();
  for (Module module : modules) {
    if (scriptRunner.isValidModule(module)) {
      res.add(module);
    }
  }
  return res;
}
 
Example 26
Project: intellij-ce-playground   File: AndroidPrecompileTask.java   View source code 6 votes vote down vote up
private static void createGenModulesAndSourceRoots(final Project project) {
  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  final List<AndroidFacet> facets = new ArrayList<AndroidFacet>();

  for (Module module : ModuleManager.getInstance(project).getModules()) {
    final AndroidFacet facet = AndroidFacet.getInstance(module);

    if (facet != null) {
      facets.add(facet);
    }
  }

  if (facets.size() > 0) {
    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
      @Override
      public void run() {
        AndroidCompileUtil.createGenModulesAndSourceRoots(project, facets);
      }
    }, indicator != null ? indicator.getModalityState() : ModalityState.NON_MODAL);
  }
}
 
Example 27
Project: intellij-ce-playground   File: PyConsoleOptions.java   View source code 6 votes vote down vote up
public void reset(Project project, AbstractPythonRunConfigurationParams form) {
  form.setEnvs(myEnvs);
  form.setInterpreterOptions(myInterpreterOptions);
  form.setSdkHome(mySdkHome);
  form.setUseModuleSdk(myUseModuleSdk);
  form.setAddContentRoots(myAddContentRoots);
  form.setAddSourceRoots(myAddSourceRoots);

  boolean moduleWasAutoselected = false;
  if (form.isUseModuleSdk() != myUseModuleSdk) {
    myUseModuleSdk = form.isUseModuleSdk();
    moduleWasAutoselected = true;
  }

  if (myModuleName != null) {
    form.setModule(ModuleManager.getInstance(project).findModuleByName(myModuleName));
  }

  if (moduleWasAutoselected && form.getModule() != null) {
    myModuleName = form.getModule().getName();
  }

  form.setWorkingDirectory(myWorkingDirectory);

  form.setMappingSettings(myMappings);
}
 
Example 28
Project: intellij-ce-playground   File: DirectoryIndexTest.java   View source code 6 votes vote down vote up
public void testModuleInIgnoredDir() throws IOException {
  final VirtualFile ignored = createChildDirectory(myRootVFile, "RCS");
  assertTrue(FileTypeManager.getInstance().isFileIgnored(ignored));
  
  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      ModuleManager moduleManager = ModuleManager.getInstance(myProject);
      ModifiableModuleModel model = moduleManager.getModifiableModel();
      model.disposeModule(myModule);
      model.disposeModule(myModule2);
      model.disposeModule(myModule3);
      model.commit();
      Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId());
      PsiTestUtil.addContentRoot(module, ignored);
      checkInfo(ignored, module, false, false, null, null);
    }
  }.execute().throwException();
}
 
Example 29
Project: intellij-ce-playground   File: PyEduDebugRunner.java   View source code 6 votes vote down vote up
private static void initEduConsole(@NotNull final XDebugSession session,
                                   @NotNull final RunnerLayoutUi ui) {
  Project project = session.getProject();
  final Sdk sdk = PythonSdkType.findPythonSdk(ModuleManager.getInstance(project).getModules()[0]);
  final PythonDebugLanguageConsoleView view = new PythonDebugLanguageConsoleView(project, sdk);
  final ProcessHandler processHandler = session.getDebugProcess().getProcessHandler();

  view.attachToProcess(processHandler);
  view.addMessageFilter(new PythonTracebackFilter(project));
  view.addMessageFilter(new UrlFilter());

  view.enableConsole(false);

  Content eduConsole =
    ui.createContent("EduConsole", view.getComponent(),
                     XDebuggerBundle.message("debugger.session.tab.console.content.name"),
                     AllIcons.Debugger.ToolConsole, view.getPreferredFocusableComponent());
  eduConsole.setCloseable(false);
  ui.addContent(eduConsole, 0, PlaceInGrid.right, false);

  PyDebugProcess process = (PyDebugProcess)session.getDebugProcess();
  PyDebugRunner.initDebugConsoleView(project, process, view, processHandler, session);

  patchLeftToolbar(session, ui);
}
 
Example 30
Project: intellij-ce-playground   File: BuildVariantView.java   View source code 6 votes vote down vote up
@NotNull
private List<Module> getModulesIfProjectSupportsUnitTests() {
  FullRevision minimumSupportedVersion = new PreciseRevision(1, 1, 0);

  List<Module> modules = Lists.newArrayList();
  for (Module module : ModuleManager.getInstance(myProject).getModules()) {
    AndroidFacet androidFacet = AndroidFacet.getInstance(module);
    if (androidFacet != null && androidFacet.isGradleProject()) {
      IdeaAndroidProject ideaAndroidProject = androidFacet.getIdeaAndroidProject();
      if (ideaAndroidProject != null) {
        if (!supportsUnitTests(ideaAndroidProject.getDelegate(), minimumSupportedVersion)) {
          return Collections.emptyList();
        }
        modules.add(module);
      }
    }
  }
  return modules;
}
 
Example 31
Project: intellij-ce-playground   File: PlatformProjectConfigurator.java   View source code 6 votes vote down vote up
@Override
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, final Ref<Module> moduleRef) {
  final ModuleManager moduleManager = ModuleManager.getInstance(project);
  final Module[] modules = moduleManager.getModules();
  if (modules.length == 0) {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        String moduleName = baseDir.getName().replace(":", "");     // correct module name when opening root of drive as project (RUBY-5181)
        String imlName = baseDir.getPath() + "/.idea/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
        ModuleTypeManager instance = ModuleTypeManager.getInstance();
        String id = instance == null ? "unknown" : instance.getDefaultModuleType().getId();
        final Module module = moduleManager.newModule(imlName, id);
        ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
        ModifiableRootModel rootModel = rootManager.getModifiableModel();
        if (rootModel.getContentRoots().length == 0) {
          rootModel.addContentEntry(baseDir);
        }
        rootModel.inheritSdk();
        rootModel.commit();
        moduleRef.set(module);
      }
    });
  }
}
 
Example 32
Project: intellij-ce-playground   File: ProjectResourceIdResolver.java   View source code 6 votes vote down vote up
private TIntObjectHashMap<String> getIdMap() {
  AndroidFacet facet = null;
  for (Module m : ModuleManager.getInstance(myProject).getModules()) {
    facet = AndroidFacet.getInstance(m);
    if (facet != null) {
      break;
    }
  }

  AndroidSdkData sdkData = facet == null ? null : facet.getSdkData();
  if (sdkData == null) {
    return null;
  }

  IAndroidTarget[] targets = sdkData.getTargets();
  if (targets.length == 0) {
    return null;
  }

  return sdkData.getTargetData(targets[targets.length - 1]).getPublicIdMap();
}
 
Example 33
Project: intellij-ce-playground   File: RenameProjectAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final DataContext dataContext = e.getDataContext();
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  LOG.assertTrue(project instanceof ProjectEx);
  Module module;
  Module[] modules = ModuleManager.getInstance(project).getModules();
  if (modules.length == 1 && project.getName().equals(modules[0].getName())) {
    module = modules[0];
  }
  else {
    module = null;
  }
  Messages.showInputDialog(project, RefactoringBundle.message("enter.new.project.name"), RefactoringBundle.message("rename.project"),
                           Messages.getQuestionIcon(),
                           project.getName(),
                           new RenameProjectHandler.MyInputValidator((ProjectEx)project, module));
}
 
Example 34
Project: intellij-ce-playground   File: VcsStructureChooser.java   View source code 6 votes vote down vote up
private void calculateRoots() {
  final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
  // assertion for read access inside
  final Module[] modules = ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
    public Module[] compute() {
      return moduleManager.getModules();
    }
  });

  final TreeSet<VirtualFile> checkSet = new TreeSet<VirtualFile>(FilePathComparator.getInstance());
  myRoots = new HashSet<VirtualFile>();
  myRoots.addAll(myInitialRoots);
  checkSet.addAll(myInitialRoots);
  for (Module module : modules) {
    final VirtualFile[] files = ModuleRootManager.getInstance(module).getContentRoots();
    for (VirtualFile file : files) {
      final VirtualFile floor = checkSet.floor(file);
      if (floor != null) {
        myModulesSet.put(file, module.getName());
        myRoots.add(file);
      }
    }
  }
}
 
Example 35
Project: intellij-ce-playground   File: ImportModuleAction.java   View source code 6 votes vote down vote up
public static List<Module> createFromWizard(@Nullable Project project, AbstractProjectWizard wizard) {
  if (project == null) {
    Project newProject = NewProjectUtil.createFromWizard(wizard, null);
    return newProject == null ? Collections.<Module>emptyList() : Arrays.asList(ModuleManager.getInstance(newProject).getModules());
  }

  final ProjectBuilder projectBuilder = wizard.getProjectBuilder();
  try {
    if (wizard.getStepCount() > 0) {
      Module module = new NewModuleAction().createModuleFromWizard(project, null, wizard);
      return Collections.singletonList(module);
    }
    else {
      return projectBuilder.commit(project);
    }
  }
  finally {
    if (projectBuilder != null) {
      projectBuilder.cleanup();
    }
  }
}
 
Example 36
Project: intellij-ce-playground   File: PostProjectBuildTasksExecutor.java   View source code 6 votes vote down vote up
/**
 * Even though {@link com.android.tools.idea.gradle.customizer.android.ContentRootModuleCustomizer} already excluded the folders
 * "$buildDir/intermediates" and "$buildDir/outputs" we go through the children of "$buildDir" and exclude any non-generated folders
 * that may have been created by other plug-ins. We need to be aggressive when excluding folder to prevent over-indexing files, which
 * will degrade the IDE's performance.
 */
private void excludeOutputFolders() {
  if (myProject.isDisposed()) {
    return;
  }
  ModuleManager moduleManager = ModuleManager.getInstance(myProject);
  if (myProject.isDisposed()) {
    return;
  }

  for (Module module : moduleManager.getModules()) {
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet != null && facet.isGradleProject()) {
      excludeOutputFolders(facet);
    }
  }
}
 
Example 37
Project: intellij-ce-playground   File: PythonSourceRootConfigurator.java   View source code 6 votes vote down vote up
private static void addSourceRoot(Project project, final VirtualFile baseDir, final VirtualFile root, final boolean unique) {
  final Module[] modules = ModuleManager.getInstance(project).getModules();
  if (modules.length > 0 && root != null) {
    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      public void run() {
        final ModifiableRootModel model = ModuleRootManager.getInstance(modules[0]).getModifiableModel();
        final ContentEntry[] contentEntries = model.getContentEntries();
        for (ContentEntry contentEntry : contentEntries) {
          if (Comparing.equal(contentEntry.getFile(), baseDir)) {
            final SourceFolder[] sourceFolders = contentEntry.getSourceFolders();
            if (!unique || sourceFolders.length == 0) {
              contentEntry.addSourceFolder(root, false);
            }
          }
        }
        model.commit();
      }
    });
  }
}
 
Example 38
Project: intellij-ce-playground   File: ValidationConfigurable.java   View source code 6 votes vote down vote up
private static ExcludedEntriesConfigurable createExcludedConfigurable(final Project project) {
  final ExcludesConfiguration configuration = ValidationConfiguration.getExcludedEntriesConfiguration(project);
  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true) {
    public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
      return super.isFileVisible(file, showHiddenFiles) && (project.isDefault() || !index.isExcluded(file));
    }
  };

  List<VirtualFile> allContentRoots = new ArrayList<VirtualFile>();
  for (final Module module: ModuleManager.getInstance(project).getModules()) {
    final VirtualFile[] moduleContentRoots = ModuleRootManager.getInstance(module).getContentRoots();
    Collections.addAll(allContentRoots, moduleContentRoots);
  }
  descriptor.setRoots(allContentRoots);
  return new ExcludedEntriesConfigurable(project, descriptor, configuration);
}
 
Example 39
Project: intellij-ce-playground   File: ModuleGroup.java   View source code 6 votes vote down vote up
public Collection<ModuleGroup> childGroups(ModifiableModuleModel model, Project project) {
  final Module[] allModules;
  if ( model != null ) {
    allModules = model.getModules();
  } else {
    allModules = ModuleManager.getInstance(project).getModules();
  }

  Set<ModuleGroup> result = new THashSet<ModuleGroup>();
  for (Module module : allModules) {
    String[] group;
    if ( model != null ) {
      group = model.getModuleGroupPath(module);
    } else {
      group = ModuleManager.getInstance(project).getModuleGroupPath(module);
    }
    if (group == null) continue;
    final String[] directChild = directChild(myGroupPath, group);
    if (directChild != null) {
      result.add(new ModuleGroup(directChild));
    }
  }

  return result;
}
 
Example 40
Project: intellij-ce-playground   File: GradleProjectImporter.java   View source code 6 votes vote down vote up
private static void resetProject(@NotNull final Project project) {
  executeProjectChanges(project, new Runnable() {
    @Override
    public void run() {
      removeLibrariesAndStoreAttachments(project);

      // Remove all AndroidProjects from module. Otherwise, if re-import/sync fails, editors will not show the proper notification of the
      // failure.
      ModuleManager moduleManager = ModuleManager.getInstance(project);
      for (Module module : moduleManager.getModules()) {
        AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null) {
          facet.setIdeaAndroidProject(null);
        }
      }
    }
  });
}