@Override
  public void setupRootModel(final ModifiableRootModel modifiableRootModel)
      throws ConfigurationException {
    String contentEntryPath = getContentEntryPath();
    if (StringUtil.isEmpty(contentEntryPath)) {
      return;
    }
    File contentRootDir = new File(contentEntryPath);
    FileUtilRt.createDirectory(contentRootDir);
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile modelContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
    if (modelContentRootDir == null) {
      return;
    }

    modifiableRootModel.addContentEntry(modelContentRootDir);
    modifiableRootModel.inheritSdk();

    final Project project = modifiableRootModel.getProject();

    setupGradleBuildFile(modelContentRootDir);
    setupGradleSettingsFile(modelContentRootDir, modifiableRootModel);

    if (myWizardContext.isCreatingNewProject()) {
      String externalProjectPath = FileUtil.toCanonicalPath(project.getBasePath());
      getExternalProjectSettings().setExternalProjectPath(externalProjectPath);
      AbstractExternalSystemSettings settings =
          ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
      //noinspection unchecked
      settings.linkProject(getExternalProjectSettings());
    } else {
      FileDocumentManager.getInstance().saveAllDocuments();
      ExternalSystemUtil.refreshProjects(project, GradleConstants.SYSTEM_ID, false);
    }
  }
  protected void setupRootModel(
      final String testDir, final VirtualFile[] sourceDir, final String sdkName) {
    VirtualFile projectDir =
        LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir));
    assertNotNull("could not find project dir " + testDir, projectDir);
    sourceDir[0] = projectDir.findChild("src");
    if (sourceDir[0] == null) {
      sourceDir[0] = projectDir;
    }
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
    final ModifiableRootModel rootModel = rootManager.getModifiableModel();
    rootModel.clear();
    // configure source and output path
    final ContentEntry contentEntry = rootModel.addContentEntry(projectDir);
    contentEntry.addSourceFolder(sourceDir[0], false);
    ext_src =
        LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(testDir + "/ext_src"));
    if (ext_src != null) {
      contentEntry.addSourceFolder(ext_src, false);
    }

    // IMPORTANT! The jdk must be obtained in a way it is obtained in the normal program!
    // ProjectJdkEx jdk = ProjectJdkTable.getInstance().getInternalJdk();

    rootModel.setSdk(getTestProjectSdk());

    rootModel.commit();
  }
예제 #3
0
 private void setupContentRoot() {
   ModifiableRootModel modifiableModel =
       ModuleRootManager.getInstance(myModule).getModifiableModel();
   ContentEntry contentEntry = modifiableModel.addContentEntry(getContentRoot());
   VirtualFile src = getContentRoot().findChild("src");
   if (src != null) {
     contentEntry.addSourceFolder(src, false);
   }
   modifiableModel.commit();
 }
 public static void addSourceRoot(
     final ModuleRootManager manager, @NotNull final VirtualFile root) {
   final ModifiableRootModel model = manager.getModifiableModel();
   ContentEntry contentEntry = findContentEntryForRoot(model, root);
   if (contentEntry == null) {
     contentEntry = model.addContentEntry(root);
   }
   contentEntry.addSourceFolder(root, false);
   model.commit();
 }
  @Override
  public void setupRootModel(ModifiableRootModel model) throws ConfigurationException {
    String contentPath = getContentEntryPath();
    if (StringUtil.isEmpty(contentPath)) {
      return;
    }
    File contentRootDir = new File(contentPath);
    FileUtilRt.createDirectory(contentRootDir);
    LocalFileSystem fileSystem = LocalFileSystem.getInstance();
    VirtualFile vContentRootDir = fileSystem.refreshAndFindFileByIoFile(contentRootDir);
    if (vContentRootDir == null) {
      return;
    }

    model.addContentEntry(vContentRootDir);

    VirtualFile configFile = getExternalProjectConfigFile(vContentRootDir);
    if (configFile != null && myTemplateConfigName != null) {
      FileTemplateManager manager = FileTemplateManager.getInstance();
      FileTemplate template = manager.getInternalTemplate(myTemplateConfigName);
      try {
        VfsUtil.saveText(configFile, template.getText());
      } catch (IOException e) {
        LOG.warn(
            String.format(
                "Unexpected exception on applying template %s config",
                myExternalSystemId.getReadableName()),
            e);
        throw new ConfigurationException(
            e.getMessage(),
            String.format(
                "Can't apply %s template config text", myExternalSystemId.getReadableName()));
      }
    }

    AbstractExternalSystemSettings settings =
        ExternalSystemApiUtil.getSettings(model.getProject(), myExternalSystemId);
    S externalProjectSettings = createSettings();
    if (myExternalProjectSettingsControl != null) {
      String errorMessage = myExternalProjectSettingsControl.apply(externalProjectSettings);
      myExternalProjectSettingsControl.disposeUIResources();
      if (errorMessage != null) {
        throw new ConfigurationException(errorMessage);
      }
    }
    //noinspection unchecked
    settings.linkProject(externalProjectSettings);
  }
예제 #6
0
  public static VirtualFile[] configureByFiles(
      @Nullable VirtualFile rawProjectRoot,
      VirtualFile[] files,
      @Nullable VirtualFile[] auxiliaryFiles,
      Module module,
      @Nullable
          TripleFunction<ModifiableRootModel, VirtualFile, List<String>, Void> moduleInitializer)
      throws Exception {
    return WriteAction.compute(
        () -> {
          VirtualFile dummyRoot = VirtualFileManager.getInstance().findFileByUrl("temp:///");
          //noinspection ConstantConditions
          dummyRoot.refresh(false, false);
          final VirtualFile sourceDir = dummyRoot.createChildDirectory(DesignerTests.class, "s");
          assert sourceDir != null;

          final IndexableFileSet indexableFileSet =
              new IndexableFileSet() {
                @Override
                public boolean isInSet(@NotNull final VirtualFile file) {
                  return file.getFileSystem() == sourceDir.getFileSystem();
                }

                @Override
                public void iterateIndexableFilesIn(
                    @NotNull final VirtualFile file, @NotNull final ContentIterator iterator) {
                  if (file.isDirectory()) {
                    for (VirtualFile child : file.getChildren()) {
                      iterateIndexableFilesIn(child, iterator);
                    }
                  } else {
                    iterator.processFile(file);
                  }
                }
              };
          FileBasedIndex.getInstance().registerIndexableSet(indexableFileSet, module.getProject());

          Disposer.register(
              module,
              new Disposable() {
                @Override
                public void dispose() {
                  FileBasedIndex.getInstance().removeIndexableSet(indexableFileSet);
                  ApplicationManager.getApplication()
                      .runWriteAction(
                          () -> {
                            try {
                              sourceDir.delete(null);
                            } catch (IOException e) {
                              throw new RuntimeException(e);
                            }
                          });
                }
              });

          final ModifiableRootModel rootModel =
              ModuleRootManager.getInstance(module).getModifiableModel();

          VirtualFile[] toFiles = copyFiles(files, sourceDir, rawProjectRoot);
          if (auxiliaryFiles != null) {
            copyFiles(auxiliaryFiles, sourceDir, rawProjectRoot);
          }

          rootModel.addContentEntry(sourceDir).addSourceFolder(sourceDir, false);
          final List<String> libs = new ArrayList<>();
          if (moduleInitializer != null) {
            moduleInitializer.fun(rootModel, sourceDir, libs);
          }
          rootModel.commit();

          for (String path : libs) {
            VirtualFile virtualFile = path.charAt(0) != '/' ? getFile("lib", path) : getFile(path);
            FlexTestUtils.addLibrary(
                module, path, virtualFile.getParent().getPath(), virtualFile.getName(), null, null);
          }
          return toFiles;
        });
  }
 private void initContentRoots() {
   Url url = toUrl(myMavenProject.getDirectory());
   if (getContentRootFor(url) != null) return;
   myRootModel.addContentEntry(url.getUrl());
 }
 public void init(ModifiableRootModel model) {
   myContentEntry = model.addContentEntry(pathToUrl(myRootPath));
 }
 @Override
 protected void addSourceFolder(ModifiableRootModel rootModel, String srcUrl, boolean testFolder) {
   rootModel.addContentEntry(srcUrl).addSourceFolder(srcUrl, testFolder);
 }
  @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;
  }