use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class AbstractExternalProjectImportBuilder method executeAndRestoreDefaultProjectSettings.
@SuppressWarnings("unchecked")
private void executeAndRestoreDefaultProjectSettings(@NotNull Project project, @NotNull Runnable task) {
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
Object systemStateToRestore = null;
if (systemSettings instanceof PersistentStateComponent) {
systemStateToRestore = ((PersistentStateComponent) systemSettings).getState();
}
systemSettings.copyFrom(myControl.getSystemSettings());
Collection projectSettingsToRestore = systemSettings.getLinkedProjectsSettings();
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.add(getCurrentExternalProjectSettings());
systemSettings.setLinkedProjectsSettings(projects);
try {
task.run();
} finally {
if (systemStateToRestore != null) {
((PersistentStateComponent) systemSettings).loadState(systemStateToRestore);
} else {
systemSettings.setLinkedProjectsSettings(projectSettingsToRestore);
}
}
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalSystemViewDefaultContributor method addModuleNodes.
private static void addModuleNodes(@NotNull ExternalProjectsView externalProjectsView, @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes, @NotNull List<ExternalSystemNode<?>> result) {
final Collection<DataNode<?>> moduleDataNodes = dataNodes.get(ProjectKeys.MODULE);
if (!moduleDataNodes.isEmpty()) {
final AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(externalProjectsView.getProject(), externalProjectsView.getSystemId());
for (DataNode<?> dataNode : moduleDataNodes) {
final ModuleData data = (ModuleData) dataNode.getData();
final ExternalProjectSettings projectSettings = systemSettings.getLinkedProjectSettings(data.getLinkedExternalProjectPath());
DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(dataNode, PROJECT);
final boolean isRoot = projectSettings != null && data.getLinkedExternalProjectPath().equals(projectSettings.getExternalProjectPath()) && projectDataNode != null && projectDataNode.getData().getInternalName().equals(data.getInternalName());
//noinspection unchecked
final ModuleNode moduleNode = new ModuleNode(externalProjectsView, (DataNode<ModuleData>) dataNode, isRoot);
result.add(moduleNode);
}
}
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ProjectNode method doUpdate.
@Override
protected void doUpdate() {
String autoImportHint = null;
final ProjectData projectData = getData();
if (projectData != null) {
final AbstractExternalSystemSettings externalSystemSettings = ExternalSystemApiUtil.getSettings(getExternalProjectsView().getProject(), getData().getOwner());
final ExternalProjectSettings projectSettings = externalSystemSettings.getLinkedProjectSettings(projectData.getLinkedExternalProjectPath());
if (projectSettings != null && projectSettings.isUseAutoImport())
autoImportHint = "auto-import enabled";
}
setNameAndTooltip(getName(), myTooltipCache, autoImportHint);
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings 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.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalModuleStructureExtension method disposeUIResources.
@Override
public void disposeUIResources() {
try {
if (isExternalSystemsInvolved) {
assert myOrphanProjectsCandidates != null;
assert myProject != null;
if (myExternalProjectsToRestore != null) {
for (Pair<ProjectSystemId, ExternalProjectSettings> settingsPair : myExternalProjectsToRestore.values()) {
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(myProject, settingsPair.first);
String rootProjectPath = settingsPair.second.getExternalProjectPath();
if (settings.getLinkedProjectSettings(rootProjectPath) == null) {
//noinspection unchecked
settings.linkProject(settingsPair.second);
}
myOrphanProjectsCandidates.remove(rootProjectPath);
}
}
ModulesConfigurator modulesConfigurator = getModulesConfigurator(myProject);
if (modulesConfigurator != null) {
for (Map.Entry<String, ProjectSystemId> entry : myOrphanProjectsCandidates.entrySet()) {
String rootProjectPath = entry.getKey();
if (StringUtil.isNotEmpty(rootProjectPath)) {
unlinkProject(myProject, entry.getValue(), rootProjectPath);
}
}
}
}
} catch (Throwable e) {
LOG.warn(e);
} finally {
myProject = null;
myExternalProjectsToRestore = null;
myOrphanProjectsCandidates = null;
}
}
Aggregations