use of com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo 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.model.internal.InternalExternalProjectInfo in project intellij-community by JetBrains.
the class ExternalProjectsDataStorage method mergeLocalSettings.
private void mergeLocalSettings() {
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
final ProjectSystemId systemId = manager.getSystemId();
AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(myProject);
final Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> availableProjects = settings.getAvailableProjects();
final Map<String, Collection<ExternalTaskPojo>> availableTasks = settings.getAvailableTasks();
for (Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>> entry : availableProjects.entrySet()) {
final ExternalProjectPojo projectPojo = entry.getKey();
final String externalProjectPath = projectPojo.getPath();
final Pair<ProjectSystemId, File> key = Pair.create(systemId, new File(externalProjectPath));
InternalExternalProjectInfo externalProjectInfo = myExternalRootProjects.get(key);
if (externalProjectInfo == null) {
final DataNode<ProjectData> dataNode = convert(systemId, projectPojo, entry.getValue(), availableTasks);
externalProjectInfo = new InternalExternalProjectInfo(systemId, externalProjectPath, dataNode);
myExternalRootProjects.put(key, externalProjectInfo);
changed.set(true);
}
// restore linked project sub-modules
ExternalProjectSettings linkedProjectSettings = manager.getSettingsProvider().fun(myProject).getLinkedProjectSettings(externalProjectPath);
if (linkedProjectSettings != null && ContainerUtil.isEmpty(linkedProjectSettings.getModules())) {
final Set<String> modulePaths = ContainerUtil.map2Set(ExternalSystemApiUtil.findAllRecursively(externalProjectInfo.getExternalProjectStructure(), ProjectKeys.MODULE), node -> node.getData().getLinkedExternalProjectPath());
linkedProjectSettings.setModules(modulePaths);
}
}
}
}
use of com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo in project intellij-community by JetBrains.
the class ExternalProjectsDataStorage method update.
synchronized void update(@NotNull ExternalProjectInfo externalProjectInfo) {
restoreInclusionSettings(externalProjectInfo.getExternalProjectStructure());
final ProjectSystemId projectSystemId = externalProjectInfo.getProjectSystemId();
final String projectPath = externalProjectInfo.getExternalProjectPath();
DataNode<ProjectData> externalProjectStructure = externalProjectInfo.getExternalProjectStructure();
long lastSuccessfulImportTimestamp = externalProjectInfo.getLastSuccessfulImportTimestamp();
long lastImportTimestamp = externalProjectInfo.getLastImportTimestamp();
final Pair<ProjectSystemId, File> key = Pair.create(projectSystemId, new File(projectPath));
final InternalExternalProjectInfo old = myExternalRootProjects.get(key);
if (old != null) {
lastImportTimestamp = externalProjectInfo.getLastImportTimestamp();
if (lastSuccessfulImportTimestamp == -1) {
lastSuccessfulImportTimestamp = old.getLastSuccessfulImportTimestamp();
}
if (externalProjectInfo.getExternalProjectStructure() == null) {
externalProjectStructure = old.getExternalProjectStructure();
} else {
externalProjectStructure = externalProjectInfo.getExternalProjectStructure().graphCopy();
}
} else {
externalProjectStructure = externalProjectStructure != null ? externalProjectStructure.graphCopy() : null;
}
InternalExternalProjectInfo merged = new InternalExternalProjectInfo(projectSystemId, projectPath, externalProjectStructure);
merged.setLastImportTimestamp(lastImportTimestamp);
merged.setLastSuccessfulImportTimestamp(lastSuccessfulImportTimestamp);
myExternalRootProjects.put(key, merged);
changed.set(true);
}
use of com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo in project intellij-community by JetBrains.
the class ExternalProjectsDataStorage method doSave.
private static void doSave(@NotNull final Project project, @NotNull Collection<InternalExternalProjectInfo> externalProjects) throws IOException {
final File projectConfigurationFile = getProjectConfigurationFile(project);
if (!FileUtil.createParentDirs(projectConfigurationFile)) {
throw new IOException("Unable to save " + projectConfigurationFile);
}
for (Iterator<InternalExternalProjectInfo> iterator = externalProjects.iterator(); iterator.hasNext(); ) {
InternalExternalProjectInfo externalProject = iterator.next();
if (!validate(externalProject)) {
iterator.remove();
continue;
}
ExternalSystemApiUtil.visit(externalProject.getExternalProjectStructure(), dataNode -> {
try {
dataNode.getDataBytes();
} catch (IOException e) {
dataNode.clear(true);
}
});
}
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(projectConfigurationFile)));
try {
out.writeUTF(STORAGE_VERSION);
out.writeInt(externalProjects.size());
ObjectOutputStream os = new ObjectOutputStream(out);
try {
for (InternalExternalProjectInfo externalProject : externalProjects) {
os.writeObject(externalProject);
}
} finally {
os.close();
}
} finally {
out.close();
}
}
use of com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo in project intellij-community by JetBrains.
the class ExternalSystemResolveProjectTask method setState.
@Override
protected void setState(@NotNull ExternalSystemTaskState state) {
super.setState(state);
if (state.isStopped()) {
InternalExternalProjectInfo projectInfo = new InternalExternalProjectInfo(getExternalSystemId(), getExternalProjectPath(), getExternalProject());
final long currentTimeMillis = System.currentTimeMillis();
projectInfo.setLastImportTimestamp(currentTimeMillis);
projectInfo.setLastSuccessfulImportTimestamp(state == ExternalSystemTaskState.FAILED ? -1 : currentTimeMillis);
ProjectDataManager.getInstance().updateExternalProjectData(getIdeProject(), projectInfo);
}
}
Aggregations