@Override
 @Nullable
 public Module getModule(String name) {
   final Module moduleByName = myModuleModel.findModuleByName(name);
   if (moduleByName != null) {
     return moduleByName;
   }
   return myModuleModel.getModuleToBeRenamed(name); // if module was renamed
 }
Example #2
0
 private void refreshSolutionDescriptorName() {
   ModifiableModuleModel moduleModel =
       ProjectStructureConfigurable.getInstance(myContext.getProject())
           .getContext()
           .getModulesConfigurator()
           .getModuleModel();
   String moduleName = moduleModel.getNewName(myContext.getModule());
   if (moduleName == null) {
     moduleName = myContext.getModule().getName();
   }
   mySolutionNamespace.setText(moduleName);
 }
 @Override
 public void setDisplayName(String name) {
   name = name.trim();
   final ModifiableModuleModel modifiableModuleModel = myConfigurator.getModuleModel();
   if (StringUtil.isEmpty(name)) return; // empty string comes on double click on module node
   if (Comparing.strEqual(name, myModuleName)) return; // nothing changed
   try {
     modifiableModuleModel.renameModule(myModule, name);
   } catch (ModuleWithNameAlreadyExistsException ignored) {
   }
   myConfigurator.moduleRenamed(myModule, myModuleName, name);
   myModuleName = name;
   myConfigurator.setModified(!Comparing.strEqual(myModuleName, myModule.getName()));
   myContext.getDaemonAnalyzer().queueUpdateForAllElementsWithErrors();
 }
 public boolean isModified() {
   if (myModuleModel.isChanged()) {
     return true;
   }
   for (ModuleEditor moduleEditor : myModuleEditors.values()) {
     if (moduleEditor.isModified()) {
       return true;
     }
   }
   return myModified || myFacetsConfigurator.isModified();
 }
 @NotNull
 @Override
 public Module createModule(@NotNull ModifiableModuleModel moduleModel)
     throws InvalidDataException, IOException, ModuleWithNameAlreadyExists, JDOMException,
         ConfigurationException {
   final String path = getContentEntryPath();
   unzip(path, true);
   Module module = ImportImlMode.setUpLoader(getModuleFilePath()).createModule(moduleModel);
   if (myProjectMode) {
     moduleModel.renameModule(module, module.getProject().getName());
   }
   return module;
 }
 @Nullable
 public Module findModuleByName(String moduleName) {
   return myModuleModel.findModuleByName(moduleName);
 }
  private static DFSTBuilder<RootModelImpl> createDFSTBuilder(
      List<RootModelImpl> rootModels, final ModifiableModuleModel moduleModel) {
    final Map<String, RootModelImpl> nameToModel = ContainerUtil.newHashMap();
    for (RootModelImpl rootModel : rootModels) {
      String name = rootModel.getModule().getName();
      LOG.assertTrue(!nameToModel.containsKey(name), name);
      nameToModel.put(name, rootModel);
    }

    Module[] modules = moduleModel.getModules();
    for (Module module : modules) {
      String name = module.getName();
      if (!nameToModel.containsKey(name)) {
        RootModelImpl rootModel =
            ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).getRootModel();
        nameToModel.put(name, rootModel);
      }
    }

    final Collection<RootModelImpl> allRootModels = nameToModel.values();
    GraphGenerator.SemiGraph<RootModelImpl> graph =
        new GraphGenerator.SemiGraph<RootModelImpl>() {
          @Override
          public Collection<RootModelImpl> getNodes() {
            return allRootModels;
          }

          @Override
          public Iterator<RootModelImpl> getIn(RootModelImpl rootModel) {
            OrderEnumerator entries =
                rootModel
                    .orderEntries()
                    .withoutSdk()
                    .withoutLibraries()
                    .withoutModuleSourceEntries();
            List<String> namesList =
                entries.process(
                    new RootPolicy<List<String>>() {
                      @Override
                      public List<String> visitModuleOrderEntry(
                          ModuleOrderEntry moduleOrderEntry, List<String> strings) {
                        Module module = moduleOrderEntry.getModule();
                        if (module != null && !module.isDisposed()) {
                          strings.add(module.getName());
                        } else {
                          final Module moduleToBeRenamed =
                              moduleModel.getModuleToBeRenamed(moduleOrderEntry.getModuleName());
                          if (moduleToBeRenamed != null && !moduleToBeRenamed.isDisposed()) {
                            strings.add(moduleToBeRenamed.getName());
                          }
                        }
                        return strings;
                      }
                    },
                    new ArrayList<String>());

            String[] names = ArrayUtil.toStringArray(namesList);
            List<RootModelImpl> result = new ArrayList<RootModelImpl>();
            for (String name : names) {
              RootModelImpl depRootModel = nameToModel.get(name);
              if (depRootModel != null) { // it is ok not to find one
                result.add(depRootModel);
              }
            }
            return result.iterator();
          }
        };
    return new DFSTBuilder<RootModelImpl>(
        new GraphGenerator<RootModelImpl>(new CachingSemiGraph<RootModelImpl>(graph)));
  }
 @Override
 @NotNull
 public Module[] getModules() {
   return myModuleModel.getModules();
 }
  @Override
  public List<Module> commit(
      @NotNull Project project,
      @Nullable ModifiableModuleModel moduleModel,
      @NotNull ModulesProvider modulesProvider,
      @Nullable ModifiableArtifactModel modifiableArtifactModel) {
    Set<String> selectedAppNames = ContainerUtil.newHashSet();
    for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) {
      selectedAppNames.add(importedOtpApp.getName());
    }
    Sdk projectSdk = fixProjectSdk(project);
    List<Module> createdModules = new ArrayList<Module>();
    final List<ModifiableRootModel> createdRootModels = new ArrayList<ModifiableRootModel>();
    final ModifiableModuleModel obtainedModuleModel =
        moduleModel != null ? moduleModel : ModuleManager.getInstance(project).getModifiableModel();
    for (ImportedOtpApp importedOtpApp : mySelectedOtpApps) {
      VirtualFile ideaModuleDir = importedOtpApp.getRoot();
      String ideaModuleFile =
          ideaModuleDir.getCanonicalPath() + File.separator + importedOtpApp.getName() + ".iml";
      Module module =
          obtainedModuleModel.newModule(ideaModuleFile, ErlangModuleType.getInstance().getId());
      createdModules.add(module);
      importedOtpApp.setModule(module);
      if (importedOtpApp.getIdeaModuleFile() == null) {
        ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
        // Make it inherit SDK from the project.
        rootModel.inheritSdk();
        // Initialize source and test paths.
        ContentEntry content = rootModel.addContentEntry(importedOtpApp.getRoot());
        addSourceDirToContent(content, ideaModuleDir, "src", false);
        addSourceDirToContent(content, ideaModuleDir, "test", true);
        addIncludeDirectories(content, importedOtpApp);
        // Exclude standard folders
        excludeDirFromContent(content, ideaModuleDir, "doc");
        // Initialize output paths according to Rebar conventions.
        CompilerModuleExtension compilerModuleExt =
            rootModel.getModuleExtension(CompilerModuleExtension.class);
        compilerModuleExt.inheritCompilerOutputPath(false);
        compilerModuleExt.setCompilerOutputPath(ideaModuleDir + File.separator + "ebin");
        compilerModuleExt.setCompilerOutputPathForTests(ideaModuleDir + File.separator + ".eunit");
        createdRootModels.add(rootModel);
        // Set inter-module dependencies
        resolveModuleDeps(rootModel, importedOtpApp, projectSdk, selectedAppNames);
      }
    }
    // Commit project structure.
    LOG.info("Commit project structure");
    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                for (ModifiableRootModel rootModel : createdRootModels) {
                  rootModel.commit();
                }
                obtainedModuleModel.commit();
              }
            });

    addErlangFacets(mySelectedOtpApps);
    RebarSettings.getInstance(project).setRebarPath(myRebarPath);
    if (myIsImportingProject) {
      ErlangCompilerSettings.getInstance(project).setUseRebarCompilerEnabled(true);
    }
    CompilerWorkspaceConfiguration.getInstance(project).CLEAR_OUTPUT_DIRECTORY = false;

    return createdModules;
  }