com.intellij.openapi.roots.ModifiableRootModel Java Examples

The following examples show how to use com.intellij.openapi.roots.ModifiableRootModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnzipNewModuleBuilderProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected void unzip(@Nonnull ModifiableRootModel model) {
  InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(myPath);
  if (resourceAsStream == null) {
    LOG.error("Resource by path '" + myPath + "' not found");
    return;
  }
  try {
    File tempFile = FileUtil.createTempFile("template", "zip");
    FileUtil.writeToFile(tempFile, FileUtil.loadBytes(resourceAsStream));
    final VirtualFile moduleDir = model.getModule().getModuleDir();

    File outputDir = VfsUtil.virtualToIoFile(moduleDir);

    ZipUtil.extract(tempFile, outputDir, null);
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
Example #2
Source File: DubboPluginModuleBuilder.java    From intellij-idea-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {

    String s = new Gson().toJson(userChooseDependency);
    System.out.println("set up root model json is:" + s);
    Project project = rootModel.getProject();
    VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);
    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }
    System.out.println("start to create folder in path");


}
 
Example #3
Source File: MuleMavenModuleBuilder.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    super.setupRootModel(rootModel);

    addListener(new ModuleBuilderListener() {
        @Override
        public void moduleCreated(@NotNull Module module) {
            setMuleFramework(module);
        }
    });

    setMuleFacet(rootModel.getModule());

    final Project project = rootModel.getProject();
    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);

    //Check if this is a module and has parent
    final MavenId parentId = (this.getParentProject() != null ? this.getParentProject().getMavenId() : null);

    MavenUtil.runWhenInitialized(project, (DumbAwareRunnable) () -> {
        new MuleMavenProjectBuilderHelper().configure(project, getProjectId(), muleVersion, root, parentId);
    });
}
 
Example #4
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void addFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        return; // dependency already exists
      }
    }

    modifiableModel.addLibraryEntry(library);

    ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #5
Source File: CS0227.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredWriteAction
public void invoke(@Nonnull Project project, Editor editor, PsiFile file) throws IncorrectOperationException
{
	Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(file);
	if(moduleForPsiElement == null)
	{
		return;
	}

	ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(moduleForPsiElement);

	final ModifiableRootModel modifiableModel = moduleRootManager.getModifiableModel();
	CSharpSimpleMutableModuleExtension cSharpModuleExtension = modifiableModel.getExtension(CSharpSimpleMutableModuleExtension.class);
	if(cSharpModuleExtension != null)
	{
		cSharpModuleExtension.setAllowUnsafeCode(true);
	}

	modifiableModel.commit();
}
 
Example #6
Source File: OCamlModuleBuilder.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(@NotNull ModifiableRootModel rootModel) {
    rootModel.inheritSdk();

    ContentEntry contentEntry = doAddContentEntry(rootModel);
    if (contentEntry != null) {
        List<Pair<String, String>> sourcePaths = getSourcePaths();

        if (sourcePaths != null) {
            for (final Pair<String, String> sourcePath : sourcePaths) {
                String first = sourcePath.first;
                boolean created = new File(first).mkdirs();
                if (created) {
                    VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
                    if (sourceRoot != null) {
                        contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
                    }
                }
            }
        }
    }
}
 
Example #7
Source File: ModuleDependencyTabContext.java    From consulo with Apache License 2.0 6 votes vote down vote up
private List<Module> getNotAddedModules() {
  final ModifiableRootModel rootModel = myClasspathPanel.getRootModel();
  Set<Module> addedModules = new HashSet<Module>(Arrays.asList(rootModel.getModuleDependencies(true)));
  addedModules.add(rootModel.getModule());

  final Module[] modules = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getModules();
  final List<Module> elements = new ArrayList<Module>();
  for (final Module module : modules) {
    if (!addedModules.contains(module)) {
      elements.add(module);
    }
  }
  ContainerUtil.sort(elements, new Comparator<Module>() {
    @Override
    public int compare(Module o1, Module o2) {
      return StringUtil.compare(o1.getName(), o2.getName(), false);
    }
  });
  return elements;
}
 
Example #8
Source File: AbstractLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static void removeFlutterLibraryDependency(@NotNull Module module, @NotNull Library library) {
  final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();

  try {
    boolean wasFound = false;

    for (final OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry &&
          LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry)orderEntry).getLibraryLevel()) &&
          StringUtil.equals(library.getName(), ((LibraryOrderEntry)orderEntry).getLibraryName())) {
        wasFound = true;
        modifiableModel.removeOrderEntry(orderEntry);
      }
    }

    if (wasFound) {
      ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(modifiableModel::commit));
    }
  }
  finally {
    if (!modifiableModel.isDisposed()) {
      modifiableModel.dispose();
    }
  }
}
 
Example #9
Source File: AddModuleDependencyDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
public AddModuleDependencyDialog(@Nonnull ClasspathPanel panel, StructureConfigurableContext context) {
  super(panel.getComponent(), true);

  ModifiableRootModel rootModel = panel.getRootModel();

  myTabs = new StripeTabPanel();

  for (AddModuleDependencyTabFactory factory : AddModuleDependencyTabFactory.EP_NAME.getExtensions()) {
    if(!factory.isAvailable(rootModel)) {
      continue;
    }
    AddModuleDependencyTabContext tabContext = factory.createTabContext(myDisposable, panel, context);

    JComponent component = tabContext.getComponent();
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(component, true);

    StripeTabPanel.TabInfo tabInfo = myTabs.addTab(tabContext.getTabName(), scrollPane, component);
    tabInfo.setEnabled(!tabContext.isEmpty());
    tabInfo.putUserData(CONTEXT_KEY, tabContext);
  }

  setTitle("Add Dependencies");
  init();
}
 
Example #10
Source File: ProjectFromSourcesBuilderImplModified.java    From tmc-intellij with MIT License 6 votes vote down vote up
private static Module createModule(
        ProjectDescriptor projectDescriptor,
        final ModuleDescriptor descriptor,
        final Map<LibraryDescriptor, Library> projectLibs,
        final ModifiableModuleModel moduleModel) {

    logger.info("Starting createModule in ProjectFromSourcesBuilderImplModified");
    final String moduleFilePath = descriptor.computeModuleFilePath();
    ModuleBuilder.deleteModuleFile(moduleFilePath);

    final Module module =
            moduleModel.newModule(moduleFilePath, descriptor.getModuleType().getId());
    final ModifiableRootModel modifiableModel =
            ModuleRootManager.getInstance(module).getModifiableModel();
    setupRootModel(projectDescriptor, descriptor, modifiableModel, projectLibs);
    descriptor.updateModuleConfiguration(module, modifiableModel);
    modifiableModel.commit();
    logger.info("ending createModule in ProjectFromSourcesBuilderImplModified");
    return module;
}
 
Example #11
Source File: ArmaModuleBuilder.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
	ContentEntry contentEntry = doAddContentEntry(rootModel);
	if (contentEntry != null) {
		final List<Pair<String, String>> sourcePaths = getSourcePaths();

		if (sourcePaths != null) {
			for (final Pair<String, String> sourcePath : sourcePaths) {
				String first = sourcePath.first;
				new File(first).mkdirs();
				final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
				if (sourceRoot != null) {
					contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
				}
			}
		}
	}
}
 
Example #12
Source File: CamelLightCodeInsightFixtureTestCaseIT.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    LanguageLevel languageLevel = LanguageLevel.JDK_1_8;
    return new DefaultLightProjectDescriptor() {
        @Override
        public Sdk getSdk() {
            String compilerOption = JpsJavaSdkType.complianceOption(languageLevel.toJavaVersion());
            return JavaSdk.getInstance().createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false );
        }

        @Override
        public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
            model.getModuleExtension( LanguageLevelModuleExtension.class ).setLanguageLevel( languageLevel );
        }
    };
}
 
Example #13
Source File: ModuleStructureConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void addLibraryOrderEntry(final Module module, final Library library) {
  Component parent = TargetAWT.to(WindowManager.getInstance().suggestParentWindow(module.getProject()));

  final ModuleEditor moduleEditor = myContext.myModulesConfigurator.getModuleEditor(module);
  LOG.assertTrue(moduleEditor != null, "Current module editor was not initialized");
  final ModifiableRootModel modelProxy = moduleEditor.getModifiableRootModelProxy();
  final OrderEntry[] entries = modelProxy.getOrderEntries();
  for (OrderEntry entry : entries) {
    if (entry instanceof LibraryOrderEntry && Comparing.strEqual(entry.getPresentableName(), library.getName())) {
      if (Messages.showYesNoDialog(parent,
                                   ProjectBundle.message("project.roots.replace.library.entry.message", entry.getPresentableName()),
                                   ProjectBundle.message("project.roots.replace.library.entry.title"),
                                   Messages.getInformationIcon()) == Messages.YES) {
        modelProxy.removeOrderEntry(entry);
        break;
      }
    }
  }
  modelProxy.addLibraryEntry(library);
  myContext.getDaemonAnalyzer().queueUpdate(new ModuleProjectStructureElement(myContext, module));
  myTree.repaint();
}
 
Example #14
Source File: ArmaModuleBuilder.java    From arma-intellij-plugin with MIT License 6 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
	ContentEntry contentEntry = doAddContentEntry(rootModel);
	if (contentEntry != null) {
		final List<Pair<String, String>> sourcePaths = getSourcePaths();

		if (sourcePaths != null) {
			for (final Pair<String, String> sourcePath : sourcePaths) {
				String first = sourcePath.first;
				new File(first).mkdirs();
				final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
				if (sourceRoot != null) {
					contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
				}
			}
		}
	}
}
 
Example #15
Source File: ContentEntriesEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void moduleStateChanged() {
  myEntryToEditorMap.clear();
  myEditorsPanel.removeAll();

  final ModifiableRootModel model = getModel();
  if (model != null) {
    final ContentEntry[] contentEntries = model.getContentEntries();
    if (contentEntries.length > 0) {
      for (final ContentEntry contentEntry : contentEntries) {
        addContentEntryPanel(contentEntry);
      }
      selectContentEntry(contentEntries[0]);
    }
    else {
      selectContentEntry(null);
      myRootTreeEditor.setContentEntryEditor(null);
    }
  }

  if(myRootTreeEditor != null) {
    myRootTreeEditor.update();
  }
}
 
Example #16
Source File: RPiJavaModuleBuilder.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Used to define the hierachy of the project definition
 *
 * @param rootModel
 * @throws ConfigurationException
 */
@Override
public void setupRootModel(final ModifiableRootModel rootModel) throws ConfigurationException {
    super.setupRootModel(rootModel);

    final Project project = rootModel.getProject();

    final VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);

    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }

    createProjectFiles(rootModel, project);

}
 
Example #17
Source File: BlazeGoSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProjectStructure(
    Project project,
    BlazeContext context,
    WorkspaceRoot workspaceRoot,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData,
    @Nullable BlazeProjectData oldBlazeProjectData,
    ModuleEditor moduleEditor,
    Module workspaceModule,
    ModifiableRootModel workspaceModifiableModel) {
  if (!blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.GO)) {
    return;
  }
  for (Library lib : getGoLibraries(project)) {
    if (workspaceModifiableModel.findLibraryOrderEntry(lib) == null) {
      workspaceModifiableModel.addLibraryEntry(lib);
    }
  }
  PropertiesComponent.getInstance().setValue(DO_NOT_SHOW_NOTIFICATION_ABOUT_EMPTY_GOPATH, true);
}
 
Example #18
Source File: BlazeScalaSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProjectStructure(
    Project project,
    BlazeContext context,
    WorkspaceRoot workspaceRoot,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData,
    @Nullable BlazeProjectData oldBlazeProjectData,
    ModuleEditor moduleEditor,
    Module workspaceModule,
    ModifiableRootModel workspaceModifiableModel) {
  if (!blazeProjectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.SCALA)) {
    return;
  }
  for (Library library : ProjectLibraryTable.getInstance(project).getLibraries()) {
    // Convert the type of the SDK library to prevent the scala plugin from
    // showing the missing SDK notification.
    // TODO: use a canonical class in the SDK (e.g., scala.App) instead of the name?
    if (library.getName() != null && library.getName().startsWith("scala-library")) {
      ExistingLibraryEditor editor = new ExistingLibraryEditor(library, null);
      editor.setType(ScalaLibraryType.apply());
      editor.commit();
      return;
    }
  }
}
 
Example #19
Source File: ModuleEditorImpl.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public Module createModule(String moduleName, ModuleType moduleType) {
  Module module = moduleModel.findModuleByName(moduleName);
  if (module == null) {
    File imlFile = new File(imlDirectory, moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
    removeImlFile(imlFile);
    module = moduleModel.newModule(imlFile.getPath(), moduleType.getId());
    module.setOption(EXTERNAL_SYSTEM_ID_KEY, EXTERNAL_SYSTEM_ID_VALUE);
  }
  module.setOption(Module.ELEMENT_TYPE, moduleType.getId());

  ModifiableRootModel modifiableModel =
      ModuleRootManager.getInstance(module).getModifiableModel();
  modules.put(module.getName(), modifiableModel);
  modifiableModel.clear();
  modifiableModel.inheritSdk();
  CompilerModuleExtension compilerSettings =
      modifiableModel.getModuleExtension(CompilerModuleExtension.class);
  if (compilerSettings != null) {
    compilerSettings.inheritCompilerOutputPath(false);
  }

  return module;
}
 
Example #20
Source File: BlazeAndroidSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Override
public void updateProjectStructure(
    Project project,
    BlazeContext context,
    WorkspaceRoot workspaceRoot,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData,
    @Nullable BlazeProjectData oldBlazeProjectData,
    ModuleEditor moduleEditor,
    Module workspaceModule,
    ModifiableRootModel workspaceModifiableModel) {
  BlazeAndroidProjectStructureSyncer.updateProjectStructure(
      project,
      context,
      projectViewSet,
      blazeProjectData,
      moduleEditor,
      workspaceModule,
      workspaceModifiableModel,
      isAndroidWorkspace(blazeProjectData.getWorkspaceLanguageSettings()));
}
 
Example #21
Source File: CamelInspectionTestHelper.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    LanguageLevel languageLevel = LanguageLevel.JDK_1_8;
    return new DefaultLightProjectDescriptor() {
        @Override
        public Sdk getSdk() {
            String compilerOption = JpsJavaSdkType.complianceOption(languageLevel.toJavaVersion());
            return JavaSdk.getInstance().createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false );
        }

        @Override
        public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
            model.getModuleExtension( LanguageLevelModuleExtension.class ).setLanguageLevel( languageLevel );
        }
    };
}
 
Example #22
Source File: ModifiableModelCommitter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredWriteAction
public static void multiCommit(ModifiableRootModel[] rootModels, ModifiableModuleModel moduleModel) {
  ApplicationManager.getApplication().assertWriteAccessAllowed();

  final List<RootModelImpl> modelsToCommit = getSortedChangedModels(rootModels, moduleModel);

  final List<ModifiableRootModel> modelsToDispose = new ArrayList<ModifiableRootModel>(Arrays.asList(rootModels));
  modelsToDispose.removeAll(modelsToCommit);

  ModuleManagerImpl.commitModelWithRunnable(moduleModel, new Runnable() {
    @Override
    public void run() {
      for (RootModelImpl rootModel : modelsToCommit) {
        rootModel.doCommitAndDispose(true);
      }

      for (ModifiableRootModel model : modelsToDispose) {
        model.dispose();
      }
    }
  });
}
 
Example #23
Source File: NutzBootModuleBuilder.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
    VirtualFile root = createAndGetContentEntry();
    rootModel.addContentEntry(root);
    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }
    System.out.println("start to create folder in path");
}
 
Example #24
Source File: GaugeModuleBuilder.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void setupRootModel(ModifiableRootModel modifiableRootModel) throws ConfigurationException {
    checkGaugeIsInstalled();
    super.setupRootModel(modifiableRootModel);
    gaugeInit(modifiableRootModel);
    new GaugeLibHelper(modifiableRootModel.getModule()).checkDeps();
}
 
Example #25
Source File: HaxeProjectConfigurationUpdater.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private void setupCompilationSettings(Module module, ModifiableRootModel model) {
  Project project = module.getProject();
  for(VirtualFile root:model.getContentRoots()) {
    if(hasCompilationTarget(project, root.getPath(), myHxml)) {
      HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module);
      settings.setBuildConfig(HaxeConfiguration.HXML.asBuildConfigValue());
      settings.setHxmlPath(getPath(root.getPath(), myHxml));
      //TODO: Proper implementation of running the output of every Haxe target.
      settings.setHaxeTarget(HaxeTarget.INTERP);
      break;
    }
  }
}
 
Example #26
Source File: Utils.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Searches for excluded roots in given {@link Project}.
 *
 * @param project current project
 * @return list of excluded roots
 */
public static List<VirtualFile> getExcludedRoots(@NotNull Project project) {
    List<VirtualFile> roots = new ArrayList<>();
    ModuleManager manager = ModuleManager.getInstance(project);
    for (Module module : manager.getModules()) {
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        if (model.isDisposed()) {
            continue;
        }
        Collections.addAll(roots, model.getExcludeRoots());
        model.dispose();
    }
    return roots;
}
 
Example #27
Source File: MultipleJavaClassesTestContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@After
public final void removeSourceFolder() {
  ApplicationManager.getApplication()
      .runWriteAction(
          () -> {
            final ModifiableRootModel model =
                ModuleRootManager.getInstance(testFixture.getModule()).getModifiableModel();
            ContentEntry contentEntry = model.getContentEntries()[0];
            contentEntry.removeSourceFolder(javaSourceRoot);
            model.commit();
          });
}
 
Example #28
Source File: GaugeLibHelper.java    From Intellij-Plugin with Apache License 2.0 5 votes vote down vote up
private void addLib(ProjectLib lib, ModifiableRootModel modifiableRootModel) {
    final Library library = modifiableRootModel.getModuleLibraryTable().createLibrary(lib.getLibName());
    final VirtualFile libDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(lib.getDir());
    if (libDir != null) {
        final Library.ModifiableModel libModel = library.getModifiableModel();
        libModel.addJarDirectory(libDir, true);
        libModel.commit();
    }
}
 
Example #29
Source File: MultipleJavaClassesTestContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Before
public final void addSourceFolder() {
  // create a source root so that the package prefixes are correct.
  VirtualFile pkgRoot = workspace.createDirectory(new WorkspacePath("java"));
  ApplicationManager.getApplication()
      .runWriteAction(
          () -> {
            final ModifiableRootModel model =
                ModuleRootManager.getInstance(testFixture.getModule()).getModifiableModel();
            ContentEntry contentEntry = model.getContentEntries()[0];
            javaSourceRoot = contentEntry.addSourceFolder(pkgRoot, true, "");
            model.commit();
          });

  BlazeProjectDataManager mockProjectDataManager =
      new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).build());
  registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
  registerProjectService(
      WorkspaceFileFinder.Provider.class, () -> file -> file.getPath().contains("test"));

  // required for IntelliJ to recognize annotations, JUnit version, etc.
  workspace.createPsiFile(
      new WorkspacePath("org/junit/runner/RunWith.java"),
      "package org.junit.runner;"
          + "public @interface RunWith {"
          + "    Class<? extends Runner> value();"
          + "}");
  workspace.createPsiFile(
      new WorkspacePath("org/junit/Test.java"),
      "package org.junit;",
      "public @interface Test {}");
  workspace.createPsiFile(
      new WorkspacePath("org/junit/runners/JUnit4.java"),
      "package org.junit.runners;",
      "public class JUnit4 {}");
}
 
Example #30
Source File: ContentEntriesEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected ContentEntryEditor createContentEntryEditor(ContentEntry contentEntry) {
  return new ContentEntryEditor(contentEntry) {
    @Override
    protected ModifiableRootModel getModel() {
      return ContentEntriesEditor.this.getModel();
    }
  };
}