use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class CreateNewModuleTask method perform.
@Override
public Exception perform() {
final Module depModule = ApplicationManager.getApplication().runWriteAction(new Computable<Module>() {
@Override
public Module compute() {
final Module depModule = ModuleManager.getInstance(myProject).newModule(myContentRoot.getPath() + '/' + myContentRoot.getName() + ".iml", StdModuleTypes.JAVA.getId());
final ModifiableRootModel model = ModuleRootManager.getInstance(depModule).getModifiableModel();
model.addContentEntry(myContentRoot);
model.commit();
return depModule;
}
});
if (AndroidFacet.getInstance(depModule) == null) {
AndroidUtils.addAndroidFacetInWriteAction(depModule, myContentRoot, true);
}
AndroidSdkUtils.setupAndroidPlatformIfNecessary(depModule, false);
setDepModule(depModule);
return null;
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class JavaModuleSetupTest method testSetUpAndroidModuleWithoutVariants.
public void testSetUpAndroidModuleWithoutVariants() {
IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
when(myJavaModuleModel.isAndroidModuleWithoutVariants()).thenReturn(true);
Module module = getModule();
// Add AndroidFacet to verify that is removed.
createAndAddAndroidFacet(module);
ApplicationManager.getApplication().runWriteAction(() -> {
// Add source folders and excluded folders to verify that they are removed.
ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
ContentEntry contentEntry = modifiableModel.addContentEntry("file://fakePath");
contentEntry.addSourceFolder("file://fakePath/sourceFolder", false);
contentEntry.addExcludeFolder("file://fakePath/excludedFolder");
modifiableModel.commit();
});
myModuleSetup.setUpModule(module, modelsProvider, myJavaModuleModel, myModuleModels, null);
ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
// Verify AndroidFacet was removed.
assertNull(AndroidFacet.getInstance(module));
// Verify source folders and excluded folders were removed.
ContentEntry[] contentEntries = ModuleRootManager.getInstance(module).getContentEntries();
assertThat(contentEntries).hasLength(1);
ContentEntry contentEntry = contentEntries[0];
assertThat(contentEntry.getSourceFolders()).isEmpty();
assertThat(contentEntry.getExcludeFolderUrls()).isEmpty();
}
use of com.intellij.openapi.roots.ModifiableRootModel in project android by JetBrains.
the class ContentRootsModuleSetupStepTest method addContentRoots.
private void addContentRoots(@NotNull String... names) throws IOException {
assertThat(names).isNotEmpty();
VirtualFile projectFolder = getProject().getBaseDir();
Module module = getModule();
ModuleRootManager manager = ModuleRootManager.getInstance(module);
ModifiableRootModel modifiableModel = manager.getModifiableModel();
for (String name : names) {
VirtualFile folder = findOrCreateChildFolder(projectFolder, name);
modifiableModel.addContentEntry(folder);
}
ApplicationManager.getApplication().runWriteAction(modifiableModel::commit);
ContentEntry[] entries = manager.getContentEntries();
assertThat(entries).hasLength(names.length);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.
the class DartResolveTest method configureLibrary.
private void configureLibrary(final VirtualFile root) {
ApplicationManager.getApplication().runWriteAction(() -> {
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
final Library library = model.getModuleLibraryTable().createLibrary();
final Library.ModifiableModel libModel = library.getModifiableModel();
libModel.addRoot(root, OrderRootType.CLASSES);
libModel.commit();
model.getContentEntries()[0].addExcludeFolder(root);
model.commit();
});
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-plugins by JetBrains.
the class DartHighlightingTest method unexcludeFolder.
private void unexcludeFolder(final String relPath) {
ApplicationManager.getApplication().runWriteAction(() -> {
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
try {
final ContentEntry[] contentEntries = model.getContentEntries();
contentEntries[0].removeExcludeFolder(contentEntries[0].getUrl() + "/" + relPath);
model.commit();
} finally {
if (!model.isDisposed()) {
model.dispose();
}
}
});
}
Aggregations