use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalSystemApiUtil method isOneToOneMapping.
/**
* Allows to answer if given ide project has 1-1 mapping with the given external project, i.e. the ide project has been
* imported from external system and no other external projects have been added.
* <p/>
* This might be necessary in a situation when project-level setting is changed (e.g. project name). We don't want to rename
* ide project if it doesn't completely corresponds to the given ide project then.
*
* @param ideProject target ide project
* @param projectData target external project
* @return <code>true</code> if given ide project has 1-1 mapping to the given external project;
* <code>false</code> otherwise
*/
public static boolean isOneToOneMapping(@NotNull Project ideProject, @NotNull ProjectData projectData) {
String linkedExternalProjectPath = null;
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : getAllManagers()) {
ProjectSystemId externalSystemId = manager.getSystemId();
AbstractExternalSystemSettings systemSettings = getSettings(ideProject, externalSystemId);
Collection projectsSettings = systemSettings.getLinkedProjectsSettings();
int linkedProjectsNumber = projectsSettings.size();
if (linkedProjectsNumber > 1) {
// More than one external project of the same external system type is linked to the given ide project.
return false;
} else if (linkedProjectsNumber == 1) {
if (linkedExternalProjectPath == null) {
// More than one external project of different external system types is linked to the current ide project.
linkedExternalProjectPath = ((ExternalProjectSettings) projectsSettings.iterator().next()).getExternalProjectPath();
} else {
return false;
}
}
}
if (linkedExternalProjectPath != null && !linkedExternalProjectPath.equals(projectData.getLinkedExternalProjectPath())) {
// New external project is being linked.
return false;
}
for (Module module : ModuleManager.getInstance(ideProject).getModules()) {
if (!isExternalSystemAwareModule(projectData.getOwner(), module)) {
return false;
}
}
return true;
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class GradleModuleBuilder method setupModule.
@Override
protected void setupModule(Module module) throws ConfigurationException {
super.setupModule(module);
assert rootProjectPath != null;
VirtualFile buildScriptFile = null;
final BuildScriptDataBuilder buildScriptDataBuilder = getBuildScriptData(module);
try {
if (buildScriptDataBuilder != null) {
buildScriptFile = buildScriptDataBuilder.getBuildScriptFile();
final String text = buildScriptDataBuilder.build();
appendToFile(buildScriptFile, "\n" + text);
}
} catch (IOException e) {
LOG.warn("Unexpected exception on applying frameworks templates", e);
}
final Project project = module.getProject();
if (myWizardContext.isCreatingNewProject()) {
getExternalProjectSettings().setExternalProjectPath(rootProjectPath);
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
//noinspection unchecked
settings.linkProject(getExternalProjectSettings());
} else {
FileDocumentManager.getInstance().saveAllDocuments();
final GradleProjectSettings gradleProjectSettings = getExternalProjectSettings();
final VirtualFile finalBuildScriptFile = buildScriptFile;
Runnable runnable = () -> {
if (myParentProject == null) {
gradleProjectSettings.setExternalProjectPath(rootProjectPath);
AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
//noinspection unchecked
settings.linkProject(gradleProjectSettings);
}
ImportSpec importSpec = new ImportSpecBuilder(project, GradleConstants.SYSTEM_ID).use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).createDirectoriesForEmptyContentRoots().useDefaultCallback().build();
ExternalSystemUtil.refreshProject(rootProjectPath, importSpec);
final PsiFile psiFile;
if (finalBuildScriptFile != null) {
psiFile = PsiManager.getInstance(project).findFile(finalBuildScriptFile);
if (psiFile != null) {
EditorHelper.openInEditor(psiFile);
}
}
};
// execute when current dialog is closed
ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, runnable);
}
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalToolWindowManager method handle.
@SuppressWarnings("unchecked")
public static void handle(@NotNull final Project project) {
for (final ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
final AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
settings.subscribe(new ExternalSystemSettingsListenerAdapter() {
@Override
public void onProjectsLinked(@NotNull Collection linked) {
if (settings.getLinkedProjectsSettings().size() != 1) {
return;
}
ToolWindow toolWindow = getToolWindow(project, manager.getSystemId());
if (toolWindow != null) {
toolWindow.setAvailable(true, null);
} else {
StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() {
@Override
public void run() {
if (project.isDisposed())
return;
ExternalSystemUtil.ensureToolWindowInitialized(project, manager.getSystemId());
ToolWindowManager.getInstance(project).invokeLater(() -> {
if (project.isDisposed())
return;
ToolWindow toolWindow1 = getToolWindow(project, manager.getSystemId());
if (toolWindow1 != null) {
toolWindow1.setAvailable(true, null);
}
});
}
});
}
}
@Override
public void onProjectsUnlinked(@NotNull Set linkedProjectPaths) {
if (!settings.getLinkedProjectsSettings().isEmpty()) {
return;
}
final ToolWindow toolWindow = getToolWindow(project, manager.getSystemId());
if (toolWindow != null) {
UIUtil.invokeLaterIfNeeded(() -> toolWindow.setAvailable(false, null));
}
}
});
}
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalSystemVcsRegistrar method handle.
@SuppressWarnings("unchecked")
public static void handle(@NotNull final Project project) {
for (final ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
final AbstractExternalSystemSettings settings = manager.getSettingsProvider().fun(project);
settings.subscribe(new ExternalSystemSettingsListenerAdapter() {
@Override
public void onProjectsLinked(@NotNull final Collection linked) {
List<VcsDirectoryMapping> newMappings = ContainerUtilRt.newArrayList();
final LocalFileSystem fileSystem = LocalFileSystem.getInstance();
ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
for (Object o : linked) {
final ExternalProjectSettings settings = (ExternalProjectSettings) o;
VirtualFile dir = fileSystem.refreshAndFindFileByPath(settings.getExternalProjectPath());
if (dir == null) {
continue;
}
if (!dir.isDirectory()) {
dir = dir.getParent();
}
newMappings.addAll(VcsUtil.findRoots(dir, project));
}
// There is a possible case that no VCS mappings are configured for the current project. There is a single
// mapping like <Project> - <No VCS> then. We want to replace it if only one mapping to the project root dir
// has been detected then.
List<VcsDirectoryMapping> oldMappings = vcsManager.getDirectoryMappings();
if (oldMappings.size() == 1 && newMappings.size() == 1 && StringUtil.isEmpty(oldMappings.get(0).getVcs())) {
VcsDirectoryMapping newMapping = newMappings.iterator().next();
String detectedDirPath = newMapping.getDirectory();
VirtualFile detectedDir = fileSystem.findFileByPath(detectedDirPath);
if (detectedDir != null && detectedDir.equals(project.getBaseDir())) {
newMappings.clear();
newMappings.add(new VcsDirectoryMapping("", newMapping.getVcs()));
vcsManager.setDirectoryMappings(newMappings);
return;
}
}
newMappings.addAll(oldMappings);
vcsManager.setDirectoryMappings(newMappings);
}
});
}
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalSystemUtil method linkExternalProject.
/**
* Tries to obtain external project info implied by the given settings and link that external project to the given ide project.
*
* @param externalSystemId target external system
* @param projectSettings settings of the external project to link
* @param project target ide project to link external project to
* @param executionResultCallback it might take a while to resolve external project info, that's why it's possible to provide
* a callback to be notified on processing result. It receives <code>true</code> if an external
* project has been successfully linked to the given ide project;
* <code>false</code> otherwise (note that corresponding notification with error details is expected
* to be shown to the end-user then)
* @param isPreviewMode flag which identifies if missing external project binaries should be downloaded
* @param progressExecutionMode identifies how progress bar will be represented for the current processing
*/
@SuppressWarnings("UnusedDeclaration")
public static void linkExternalProject(@NotNull final ProjectSystemId externalSystemId, @NotNull final ExternalProjectSettings projectSettings, @NotNull final Project project, @Nullable final Consumer<Boolean> executionResultCallback, boolean isPreviewMode, @NotNull final ProgressExecutionMode progressExecutionMode) {
ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {
@SuppressWarnings("unchecked")
@Override
public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
if (externalProject == null) {
if (executionResultCallback != null) {
executionResultCallback.consume(false);
}
return;
}
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, externalSystemId);
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.add(projectSettings);
systemSettings.setLinkedProjectsSettings(projects);
ensureToolWindowInitialized(project, externalSystemId);
ServiceManager.getService(ProjectDataManager.class).importData(externalProject, project, true);
if (executionResultCallback != null) {
executionResultCallback.consume(true);
}
}
@Override
public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
if (executionResultCallback != null) {
executionResultCallback.consume(false);
}
}
};
refreshProject(project, externalSystemId, projectSettings.getExternalProjectPath(), callback, isPreviewMode, progressExecutionMode);
}
Aggregations