/** * 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 externalProject 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 DataNode<ProjectData> externalProject) { String linkedExternalProjectPath = null; for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) { ProjectSystemId externalSystemId = manager.getSystemId(); AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.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; } } } ProjectData projectData = externalProject.getData(); if (linkedExternalProjectPath != null && !linkedExternalProjectPath.equals(projectData.getLinkedExternalProjectPath())) { // New external project is being linked. return false; } Set<String> externalModulePaths = ContainerUtilRt.newHashSet(); for (DataNode<ModuleData> moduleNode : ExternalSystemApiUtil.findAll(externalProject, ProjectKeys.MODULE)) { externalModulePaths.add(moduleNode.getData().getLinkedExternalProjectPath()); } externalModulePaths.remove(linkedExternalProjectPath); PlatformFacade platformFacade = ServiceManager.getService(PlatformFacade.class); for (Module module : platformFacade.getModules(ideProject)) { String path = module.getOptionValue(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY); if (!StringUtil.isEmpty(path) && !externalModulePaths.remove(path)) { return false; } } return externalModulePaths.isEmpty(); }
@Override public void writeExternal(Element element) throws WriteExternalException { super.writeExternal(element); JavaRunConfigurationExtensionManager.getInstance().writeExternal(this, element); writeModule(element); DefaultJDOMExternalizer.writeExternal(this, element); DefaultJDOMExternalizer.writeExternal(getPersistantData(), element); EnvironmentVariablesComponent.writeExternal(element, getPersistantData().getEnvs()); Element propertiesElement = element.getChild("properties"); if (propertiesElement == null) { propertiesElement = new Element("properties"); element.addContent(propertiesElement); } Map<String, String> properties = getPersistantData().TEST_PROPERTIES; for (Map.Entry<String, String> entry : properties.entrySet()) { Element property = new Element("property"); property.setAttribute("name", entry.getKey()); property.setAttribute("value", entry.getValue()); propertiesElement.addContent(property); } Element listenersElement = element.getChild("listeners"); if (listenersElement == null) { listenersElement = new Element("listeners"); element.addContent(listenersElement); } List<String> listeners = getPersistantData().TEST_LISTENERS; for (String listener : listeners) { Element listenerElement = new Element("listener"); listenerElement.setAttribute("class", listener); listenersElement.addContent(listenerElement); } final Set<String> patterns = getPersistantData().getPatterns(); if (!patterns.isEmpty()) { final Element patternsElement = new Element(PATTERNS_EL_NAME); for (String o : patterns) { final Element patternElement = new Element(PATTERN_EL_NAME); patternElement.setAttribute(TEST_CLASS_ATT_NAME, o); patternsElement.addContent(patternElement); } element.addContent(patternsElement); } }
/** * Asks to refresh all external projects of the target external system linked to the given ide * project based on provided spec * * @param specBuilder import specification builder */ public static void refreshProjects(@NotNull final ImportSpecBuilder specBuilder) { ImportSpec spec = specBuilder.build(); ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(spec.getExternalSystemId()); if (manager == null) { return; } AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(spec.getProject()); final Collection<? extends ExternalProjectSettings> projectsSettings = settings.getLinkedProjectsSettings(); if (projectsSettings.isEmpty()) { return; } final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class); final int[] counter = new int[1]; ExternalProjectRefreshCallback callback = new MyMultiExternalProjectRefreshCallback( spec.getProject(), projectDataManager, counter, spec.getExternalSystemId()); Map<String, Long> modificationStamps = manager .getLocalSettingsProvider() .fun(spec.getProject()) .getExternalConfigModificationStamps(); Set<String> toRefresh = ContainerUtilRt.newHashSet(); for (ExternalProjectSettings setting : projectsSettings) { // don't refresh project when auto-import is disabled if such behavior needed (e.g. on project // opening when auto-import is disabled) if (!setting.isUseAutoImport() && spec.isWhenAutoImportEnabled()) continue; if (spec.isForceWhenUptodate()) { toRefresh.add(setting.getExternalProjectPath()); } else { Long oldModificationStamp = modificationStamps.get(setting.getExternalProjectPath()); long currentModificationStamp = getTimeStamp(setting, spec.getExternalSystemId()); if (oldModificationStamp == null || oldModificationStamp < currentModificationStamp) { toRefresh.add(setting.getExternalProjectPath()); } } } if (!toRefresh.isEmpty()) { ExternalSystemNotificationManager.getInstance(spec.getProject()) .clearNotifications(null, NotificationSource.PROJECT_SYNC, spec.getExternalSystemId()); counter[0] = toRefresh.size(); for (String path : toRefresh) { refreshProject( spec.getProject(), spec.getExternalSystemId(), path, callback, false, spec.getProgressExecutionMode()); } } }