Search in sources :

Example 1 with InternalExternalProjectInfo

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;
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) NotNull(org.jetbrains.annotations.NotNull) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 2 with InternalExternalProjectInfo

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);
            }
        }
    }
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) AbstractCollection(com.intellij.util.xmlb.annotations.AbstractCollection) Collection(java.util.Collection) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) Map(java.util.Map) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 3 with InternalExternalProjectInfo

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);
}
Also used : InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 4 with InternalExternalProjectInfo

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();
    }
}
Also used : InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)

Example 5 with InternalExternalProjectInfo

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);
    }
}
Also used : InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)

Aggregations

InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)9 NotNull (org.jetbrains.annotations.NotNull)4 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)3 ExternalProjectDataSelectorDialog (com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog)3 DataNode (com.intellij.openapi.externalSystem.model.DataNode)2 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)2 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)2 Nullable (org.jetbrains.annotations.Nullable)2 Application (com.intellij.openapi.application.Application)1 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)1 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)1 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)1 IdeUIModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider)1 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.ProjectDataManager)1 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)1 AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 Module (com.intellij.openapi.module.Module)1 ModulesConfigurator (com.intellij.openapi.roots.ui.configuration.ModulesConfigurator)1 MultiMap (com.intellij.util.containers.MultiMap)1