use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class LibraryTest method testResolveDependencyToRenamedLibrary.
public void testResolveDependencyToRenamedLibrary() {
Library library = createLibrary("jdom2", getJDomJar(), null);
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
model.addInvalidLibrary("jdom", LibraryTablesRegistrar.PROJECT_LEVEL);
commit(model);
assertEmpty(getLibraries());
Library.ModifiableModel libModel = library.getModifiableModel();
libModel.setName("jdom");
commit(libModel);
assertSameElements(getLibraries(), library);
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class ContentRootDataService method importData.
private static void importData(@NotNull IdeModifiableModelsProvider modelsProvider, @NotNull final Collection<DataNode<ContentRootData>> data, @NotNull final Module module, boolean forceDirectoriesCreation) {
final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
final ContentEntry[] contentEntries = modifiableRootModel.getContentEntries();
final Map<String, ContentEntry> contentEntriesMap = ContainerUtilRt.newHashMap();
for (ContentEntry contentEntry : contentEntries) {
contentEntriesMap.put(contentEntry.getUrl(), contentEntry);
}
boolean createEmptyContentRootDirectories = forceDirectoriesCreation;
if (!forceDirectoriesCreation && !data.isEmpty()) {
ProjectSystemId projectSystemId = data.iterator().next().getData().getOwner();
AbstractExternalSystemSettings externalSystemSettings = ExternalSystemApiUtil.getSettings(module.getProject(), projectSystemId);
String path = module.getOptionValue(ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
if (path != null) {
ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(path);
createEmptyContentRootDirectories = projectSettings != null && projectSettings.isCreateEmptyContentRootDirectories();
}
}
final Set<ContentEntry> importedContentEntries = ContainerUtil.newIdentityTroveSet();
for (final DataNode<ContentRootData> node : data) {
final ContentRootData contentRoot = node.getData();
final ContentEntry contentEntry = findOrCreateContentRoot(modifiableRootModel, contentRoot.getRootPath());
if (!importedContentEntries.contains(contentEntry)) {
// clear source folders but do not remove existing excluded folders
contentEntry.clearSourceFolders();
importedContentEntries.add(contentEntry);
}
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Importing content root '%s' for module '%s'", contentRoot.getRootPath(), module.getName()));
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE)) {
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, false, createEmptyContentRootDirectories);
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST)) {
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, false, createEmptyContentRootDirectories);
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.SOURCE_GENERATED)) {
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.SOURCE, true, createEmptyContentRootDirectories);
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_GENERATED)) {
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaSourceRootType.TEST_SOURCE, true, createEmptyContentRootDirectories);
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.RESOURCE)) {
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.RESOURCE, false, createEmptyContentRootDirectories);
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.TEST_RESOURCE)) {
createSourceRootIfAbsent(contentEntry, path, module.getName(), JavaResourceRootType.TEST_RESOURCE, false, createEmptyContentRootDirectories);
}
for (SourceRoot path : contentRoot.getPaths(ExternalSystemSourceType.EXCLUDED)) {
createExcludedRootIfAbsent(contentEntry, path, module.getName(), module.getProject());
}
contentEntriesMap.remove(contentEntry.getUrl());
}
for (ContentEntry contentEntry : contentEntriesMap.values()) {
modifiableRootModel.removeContentEntry(contentEntry);
}
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class IdeFrameFixture method getSourceFolderRelativePaths.
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull final JpsModuleSourceRootType<?> sourceType) {
final Set<String> paths = new HashSet<>();
Module module = getModule(moduleName);
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
try {
for (ContentEntry contentEntry : rootModel.getContentEntries()) {
for (SourceFolder folder : contentEntry.getSourceFolders()) {
JpsModuleSourceRootType<?> rootType = folder.getRootType();
if (rootType.equals(sourceType)) {
String path = urlToPath(folder.getUrl());
String relativePath = getRelativePath(myProjectPath, new File(toSystemDependentName(path)));
paths.add(relativePath);
}
}
}
} finally {
rootModel.dispose();
}
}
});
return paths;
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class TemplateModuleBuilder method fixModuleName.
private void fixModuleName(Module module) {
List<RunConfiguration> configurations = RunManager.getInstance(module.getProject()).getAllConfigurationsList();
for (RunConfiguration configuration : configurations) {
if (configuration instanceof ModuleBasedConfiguration) {
((ModuleBasedConfiguration) configuration).getConfigurationModule().setModule(module);
}
}
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
for (WizardInputField field : myAdditionalFields) {
ProjectTemplateParameterFactory factory = WizardInputField.getFactoryById(field.getId());
factory.applyResult(field.getValue(), model);
}
model.commit();
}
use of com.intellij.openapi.roots.ModifiableRootModel in project intellij-community by JetBrains.
the class PlatformProjectConfigurator method configureProject.
@Override
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, final Ref<Module> moduleRef) {
final ModuleManager moduleManager = ModuleManager.getInstance(project);
final Module[] modules = moduleManager.getModules();
if (modules.length == 0) {
ApplicationManager.getApplication().runWriteAction(() -> {
// correct module name when opening root of drive as project (RUBY-5181)
String moduleName = baseDir.getName().replace(":", "");
String imlName = baseDir.getPath() + "/.idea/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
ModuleTypeManager instance = ModuleTypeManager.getInstance();
String id = instance == null ? "unknown" : instance.getDefaultModuleType().getId();
final Module module = moduleManager.newModule(imlName, id);
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = rootManager.getModifiableModel();
if (rootModel.getContentRoots().length == 0) {
rootModel.addContentEntry(baseDir);
}
rootModel.inheritSdk();
rootModel.commit();
moduleRef.set(module);
});
}
}
Aggregations