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 ExternalSystemImportingTestCase method doImportProject.
private void doImportProject() {
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
projectSettings.setExternalProjectPath(getProjectPath());
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
projects.remove(projectSettings);
projects.add(projectSettings);
systemSettings.setLinkedProjectsSettings(projects);
final Ref<Couple<String>> error = Ref.create();
ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(myProject, getExternalSystemId()).use(ProgressExecutionMode.MODAL_SYNC).callback(new ExternalProjectRefreshCallback() {
@Override
public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
if (externalProject == null) {
System.err.println("Got null External project after import");
return;
}
ServiceManager.getService(ProjectDataManager.class).importData(externalProject, myProject, true);
System.out.println("External project was successfully imported");
}
@Override
public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
error.set(Couple.of(errorMessage, errorDetails));
}
}).forceWhenUptodate());
if (!error.isNull()) {
String failureMsg = "Import failed: " + error.get().first;
if (StringUtil.isNotEmpty(error.get().second)) {
failureMsg += "\nError details: \n" + error.get().second;
}
fail(failureMsg);
}
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class AbstractExternalProjectImportBuilder method commit.
@Override
public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
if (externalProjectNode != null) {
beforeCommit(externalProjectNode, project);
}
final boolean isFromUI = model != null;
final List<Module> modules = ContainerUtil.newSmartList();
final IdeModifiableModelsProvider modelsProvider = isFromUI ? new IdeUIModifiableModelsProvider(project, model, (ModulesConfigurator) modulesProvider, artifactModel) {
@NotNull
@Override
public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
final Module module = super.newModule(filePath, moduleTypeId);
modules.add(module);
return module;
}
} : new IdeModifiableModelsProviderImpl(project) {
@NotNull
@Override
public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
final Module module = super.newModule(filePath, moduleTypeId);
modules.add(module);
return module;
}
};
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
//noinspection unchecked
Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
// add current importing project settings to linked projects settings or replace if similar already exist
projects.remove(projectSettings);
projects.add(projectSettings);
//noinspection unchecked
systemSettings.copyFrom(myControl.getSystemSettings());
//noinspection unchecked
systemSettings.setLinkedProjectsSettings(projects);
if (externalProjectNode != null) {
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(myExternalSystemId, projectSettings.getExternalProjectPath(), externalProjectNode));
if (dialog.hasMultipleDataToSelect()) {
dialog.showAndGet();
} else {
Disposer.dispose(dialog.getDisposable());
}
}
if (!project.isInitialized()) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings));
} else
finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings);
}
return modules;
}
use of com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings in project intellij-community by JetBrains.
the class ExternalModuleStructureExtension method getLinkedProjects.
private static Map<String, Pair<ProjectSystemId, ExternalProjectSettings>> getLinkedProjects(Project project) {
Map<String, Pair<ProjectSystemId, ExternalProjectSettings>> result = new HashMap<>();
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
ProjectSystemId systemId = manager.getSystemId();
AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, systemId);
Collection projectsSettings = systemSettings.getLinkedProjectsSettings();
for (Object settings : projectsSettings) {
if (settings instanceof ExternalProjectSettings) {
ExternalProjectSettings projectSettings = (ExternalProjectSettings) settings;
result.put((projectSettings).getExternalProjectPath(), Pair.create(systemId, projectSettings));
}
}
}
return result;
}
Aggregations