use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class IntegrationTestCase method addExcludedDir.
protected void addExcludedDir(final String path) {
ApplicationManager.getApplication().runWriteAction(() -> {
ModuleRootManager rm = ModuleRootManager.getInstance(myModule);
ModifiableRootModel m = rm.getModifiableModel();
for (ContentEntry e : m.getContentEntries()) {
if (!Comparing.equal(e.getFile(), myRoot))
continue;
e.addExcludeFolder(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(path)));
}
m.commit();
});
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class EclipseEmlTest method doLoadModule.
private static Module doLoadModule(@NotNull String path, @NotNull Project project) throws IOException, JDOMException, InvalidDataException {
Module module = WriteAction.compute(() -> ModuleManager.getInstance(project).newModule(path + '/' + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION, StdModuleTypes.JAVA.getId()));
replaceRoot(path, EclipseXml.DOT_CLASSPATH_EXT, project);
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
new EclipseClasspathConverter(module).readClasspath(rootModel);
WriteAction.run(() -> rootModel.commit());
return module;
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class EclipseImlTest method doTest.
protected static void doTest(final String relativePath, final Project project) throws Exception {
final String path = project.getBaseDir().getPath() + relativePath;
final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
String fileText = FileUtil.loadFile(classpathFile).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath());
if (!SystemInfo.isWindows) {
fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL);
}
String communityLib = FileUtil.toSystemIndependentName(PathManagerEx.findFileUnderCommunityHome("lib").getAbsolutePath());
fileText = fileText.replaceAll("\\$" + JUNIT + "\\$", communityLib);
final Element classpathElement = JdomKt.loadElement(fileText);
final Module module = WriteCommandAction.runWriteCommandAction(null, (Computable<Module>) () -> ModuleManager.getInstance(project).newModule(new File(path) + File.separator + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION, StdModuleTypes.JAVA.getId()));
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, null);
classpathReader.init(rootModel);
classpathReader.readClasspath(rootModel, classpathElement);
ApplicationManager.getApplication().runWriteAction(rootModel::commit);
final Element actualImlElement = new Element("root");
((ModuleRootManagerImpl) ModuleRootManager.getInstance(module)).getState().writeExternal(actualImlElement);
PathMacros.getInstance().setMacro(JUNIT, communityLib);
PathMacroManager.getInstance(module).collapsePaths(actualImlElement);
PathMacroManager.getInstance(project).collapsePaths(actualImlElement);
PathMacros.getInstance().removeMacro(JUNIT);
assertThat(actualImlElement).isEqualTo(Paths.get(project.getBaseDir().getPath(), "expected", "expected.iml"));
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class CloudGitChooseAccountStepImpl method updateDataModel.
@Override
public void updateDataModel() {
super.updateDataModel();
final MultiMap<CloudGitProjectRoot, DetectedSourceRoot> project2sourceRoots = new MultiMap<>();
new RootIterator() {
CloudGitProjectRoot lastProjectRoot = null;
@Override
protected void processProjectRoot(CloudGitProjectRoot root) {
lastProjectRoot = root;
project2sourceRoots.put(lastProjectRoot, new ArrayList<>());
}
@Override
protected void processJavaSourceRoot(DetectedSourceRoot root) {
project2sourceRoots.putValue(lastProjectRoot, root);
}
}.iterate();
List<ModuleDescriptor> modules = new ArrayList<>(myProjectDescriptor.getModules());
for (Map.Entry<CloudGitProjectRoot, Collection<DetectedSourceRoot>> project2sourceRootsEntry : project2sourceRoots.entrySet()) {
final CloudGitProjectRoot projectRoot = project2sourceRootsEntry.getKey();
final File directory = projectRoot.getDirectory();
ModuleDescriptor moduleDescriptor = new ModuleDescriptor(directory, StdModuleTypes.JAVA, project2sourceRootsEntry.getValue());
final String applicationName = projectRoot.getApplicationName();
moduleDescriptor.addConfigurationUpdater(new ModuleBuilder.ModuleConfigurationUpdater() {
@Override
public void update(@NotNull final Module module, @NotNull ModifiableRootModel rootModel) {
final MessageBusConnection connection = module.getProject().getMessageBus().connect();
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
@Override
public void moduleAdded(@NotNull Project project, @NotNull Module addedModule) {
if (addedModule == module) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> onModuleAdded(module));
connection.disconnect();
}
}
});
}
private void onModuleAdded(Module module) {
createRunConfiguration(module, applicationName);
GitInit.refreshAndConfigureVcsMappings(module.getProject(), projectRoot.getRepositoryRoot(), directory.getAbsolutePath());
}
});
modules.add(moduleDescriptor);
}
myProjectDescriptor.setModules(modules);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class ContentRootsModuleSetupStep method doSetUpModule.
@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
ModifiableRootModel moduleModel = ideModelsProvider.getModifiableRootModel(module);
boolean hasNativeModel = hasNativeModel(module, ideModelsProvider, gradleModels);
AndroidContentEntriesSetup setup = myContentEntriesSetupFactory.create(androidModel, moduleModel, hasNativeModel);
List<ContentEntry> contentEntries = findContentEntries(moduleModel, androidModel, hasNativeModel);
setup.execute(contentEntries);
}
Aggregations