Do not create misc.xml because of ProjectLevelVcsManagerImpl

This commit is contained in:
Vladimir Krivosheev
2016-08-04 16:33:31 +02:00
parent 9118c554f4
commit d257bd15b8
7 changed files with 72 additions and 26 deletions
@@ -167,7 +167,6 @@ fun getExportableComponentsMap(onlyExisting: Boolean,
}
}
@Suppress("DEPRECATION")
(ApplicationManager.getApplication() as ComponentManagerEx).getComponentInstancesOfType(ExportableApplicationComponent::class.java).forEach(processor)
ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent::class.java).forEach(processor)
@@ -24,8 +24,11 @@ import com.intellij.openapi.application.invokeAndWaitIfNeed
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.components.*
import com.intellij.openapi.components.StateStorage.SaveSession
import com.intellij.openapi.components.ex.ComponentManagerEx
import com.intellij.openapi.components.impl.stores.IComponentStore
import com.intellij.openapi.components.impl.stores.IProjectStore
import com.intellij.openapi.components.impl.stores.StoreUtil
import com.intellij.openapi.diagnostic.catchAndLog
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
@@ -40,8 +43,10 @@ import com.intellij.openapi.vfs.ReadonlyStatusHandler
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.*
import com.intellij.util.containers.forEachGuaranteed
import com.intellij.util.containers.isNullOrEmpty
import com.intellij.util.lang.CompoundRuntimeException
import org.jdom.Element
import java.io.File
import java.io.IOException
import java.nio.file.Path
@@ -90,10 +95,11 @@ abstract class ProjectStoreBase(override final val project: ProjectImpl) : Compo
override final fun loadProjectFromTemplate(defaultProject: Project) {
defaultProject.save()
val element = (defaultProject.stateStore as DefaultProjectStoreImpl).getStateCopy()
if (element != null) {
(storageManager.getOrCreateStorage(PROJECT_FILE) as XmlElementStorage).setDefaultState(element)
val element = (defaultProject.stateStore as DefaultProjectStoreImpl).getStateCopy() ?: return
LOG.catchAndLog {
removeWorkspaceComponentConfiguration(defaultProject, element)
}
(storageManager.getOrCreateStorage(PROJECT_FILE) as XmlElementStorage).setDefaultState(element)
}
override final fun getProjectBasePath(): String {
@@ -373,4 +379,34 @@ private fun useOldWorkspaceContent(filePath: String, ws: File) {
catch (e: IOException) {
LOG.error(e)
}
}
// public only to test
fun removeWorkspaceComponentConfiguration(defaultProject: Project, element: Element) {
val componentElements = element.getChildren("component")
if (componentElements.isEmpty()) {
return
}
val projectComponents = (defaultProject as ComponentManagerEx).getComponentInstancesOfType(PersistentStateComponent::class.java)
projectComponents.forEachGuaranteed {
val stateAnnotation = StoreUtil.getStateSpec(it.javaClass)
if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty()) {
return@forEachGuaranteed
}
val storage = stateAnnotation.storages.sortByDeprecated().firstOrNull() ?: return@forEachGuaranteed
if (storage.path != StoragePathMacros.WORKSPACE_FILE) {
return@forEachGuaranteed
}
val iterator = componentElements.iterator()
for (componentElement in iterator) {
if (componentElement.getAttributeValue("name") == stateAnnotation.name) {
iterator.remove()
break
}
}
}
return
}
@@ -10,10 +10,7 @@ import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.util.JDOMUtil
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.*
import com.intellij.util.delete
import com.intellij.util.loadElement
import com.intellij.util.refreshVfs
import com.intellij.util.systemIndependentPath
import com.intellij.util.*
import org.assertj.core.api.Assertions.assertThat
import org.jdom.Element
import org.junit.ClassRule
@@ -24,7 +21,8 @@ import java.nio.file.Paths
internal class DefaultProjectStoreTest {
companion object {
@JvmField
@ClassRule val projectRule = ProjectRule()
@ClassRule
val projectRule = ProjectRule()
internal const val TEST_COMPONENT_NAME = "Foo"
@@ -100,4 +98,13 @@ internal class DefaultProjectStoreTest {
stateStore.removeComponent(TEST_COMPONENT_NAME)
}
}
@Test fun `new project from default - remove workspace component configuration`() {
val element = loadElement("""
<state>
<component name="ProjectLevelVcsManager" settingsEditedManually="false" />
</state>""")
removeWorkspaceComponentConfiguration(ProjectManager.getInstance().defaultProject, element)
assertThat(element.isEmpty()).isTrue()
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,8 +29,7 @@ public interface ComponentManagerEx extends ComponentManager {
/**
* Gets all components whose implementation class is derived from <code>baseClass</code>.
*
* @return array of components
* @deprecated use extension points instead
* Consider using extension points instead.
*/
@NotNull
<T> List<T> getComponentInstancesOfType(@NotNull Class<T> baseClass);
@@ -17,7 +17,6 @@
<component>
<interface-class>com.intellij.openapi.vcs.ProjectLevelVcsManager</interface-class>
<implementation-class>com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl</implementation-class>
<option name="workspace" value="true"/>
<loadForDefaultProject/>
</component>
<!-- <component>
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package com.intellij.openapi.util;
public class InvalidDataException extends Exception {
public class InvalidDataException extends RuntimeException {
public InvalidDataException() {
super();
}
@@ -27,7 +27,7 @@ import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.extensions.Extensions;
@@ -81,7 +81,8 @@ import java.awt.*;
import java.util.*;
import java.util.List;
public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx implements ProjectComponent, JDOMExternalizable {
@State(name = "ProjectLevelVcsManager", storages = @Storage(StoragePathMacros.WORKSPACE_FILE))
public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx implements ProjectComponent, PersistentStateComponent<Element> {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl");
@NonNls public static final String SETTINGS_EDITED_MANUALLY = "settingsEditedManually";
@@ -596,10 +597,21 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
VcsRootIterator.iterateVcsRoot(myProject, root, iterator, directoryFilter);
}
@Nullable
@Override
public void readExternal(Element element) throws InvalidDataException {
mySerialization.readExternalUtil(element, myOptionsAndConfirmations);
final Attribute attribute = element.getAttribute(SETTINGS_EDITED_MANUALLY);
public Element getState() {
Element element = new Element("state");
mySerialization.writeExternalUtil(element, myOptionsAndConfirmations);
if (myHaveLegacyVcsConfiguration) {
element.setAttribute(SETTINGS_EDITED_MANUALLY, "true");
}
return element;
}
@Override
public void loadState(Element state) {
mySerialization.readExternalUtil(state, myOptionsAndConfirmations);
final Attribute attribute = state.getAttribute(SETTINGS_EDITED_MANUALLY);
if (attribute != null) {
try {
myHaveLegacyVcsConfiguration = attribute.getBooleanValue();
@@ -609,12 +621,6 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
}
}
@Override
public void writeExternal(Element element) throws WriteExternalException {
mySerialization.writeExternalUtil(element, myOptionsAndConfirmations);
element.setAttribute(SETTINGS_EDITED_MANUALLY, String.valueOf(myHaveLegacyVcsConfiguration));
}
@Override
@NotNull
public VcsShowConfirmationOption getStandardConfirmation(@NotNull VcsConfiguration.StandardConfirmation option,