From 1dfcc9f43392ee64b0dc401134e80ca4df974e48 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 29 May 2019 18:37:50 +0300 Subject: [PATCH] shelf: cleanup - move unused method to test, move test to another package GitOrigin-RevId: ef711f238243e8a1552cdbb1f17dca3c68807b43 --- .../changes/shelf/ShelveChangesManager.java | 20 +--------- .../ShelveChangesManagerMigrationTest.java | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 37 deletions(-) rename platform/vcs-tests/testSrc/com/intellij/openapi/{ => vcs/changes}/shelf/ShelveChangesManagerMigrationTest.java (66%) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java index a0858933e278..96813c0ddf34 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java @@ -331,26 +331,8 @@ public class ShelveChangesManager implements PersistentStateComponent, } } - /** - * Should be called only once: when Settings Repository plugin runs first time - * - * @return collection of non-migrated or not deleted files to show a error somewhere outside - */ @NotNull - public Collection checkAndMigrateOldPatchResourcesToNewSchemeStorage() { - Collection nonMigratedPaths = new ArrayList<>(); - for (ShelvedChangeList list : mySchemeManager.getAllSchemes()) { - File newPatchDir = new File(getShelfResourcesDirectory(), list.getName()); - // it should be enough for migration to check if resource directory exists. If any bugs appeared add isAncestor checks for each path - if (!newPatchDir.exists() && newPatchDir.mkdirs()) { - nonMigratedPaths.addAll(migrateResourcesTo(list, newPatchDir, true)); - } - } - return nonMigratedPaths; - } - - @NotNull - private static Collection migrateResourcesTo(@NotNull ShelvedChangeList list, + static Collection migrateResourcesTo(@NotNull ShelvedChangeList list, @NotNull File targetDirectory, boolean deleteOld) { Collection nonMigratedPaths = new ArrayList<>(); diff --git a/platform/vcs-tests/testSrc/com/intellij/openapi/shelf/ShelveChangesManagerMigrationTest.java b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManagerMigrationTest.java similarity index 66% rename from platform/vcs-tests/testSrc/com/intellij/openapi/shelf/ShelveChangesManagerMigrationTest.java rename to platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManagerMigrationTest.java index 7765b82baddf..b1270c402a54 100644 --- a/platform/vcs-tests/testSrc/com/intellij/openapi/shelf/ShelveChangesManagerMigrationTest.java +++ b/platform/vcs-tests/testSrc/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManagerMigrationTest.java @@ -1,32 +1,20 @@ -/* - * Copyright 2000-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.shelf; +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.vcs.changes.shelf; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vcs.VcsTestUtil; -import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.PlatformTestUtil; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import java.io.File; +import static com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager.migrateResourcesTo; + public class ShelveChangesManagerMigrationTest extends PlatformTestCase { public void testMigrateInfo() throws Exception { @@ -70,10 +58,23 @@ public class ShelveChangesManagerMigrationTest extends PlatformTestCase { ShelveChangesManager shelveChangesManager = ShelveChangesManager.getInstance(myProject); shelveChangesManager.loadState(element); if (migrateResources) { - shelveChangesManager.checkAndMigrateOldPatchResourcesToNewSchemeStorage(); + checkAndMigrateOldPatchResourcesToNewSchemeStorage(shelveChangesManager); } shelfDir.refresh(false, true); PlatformTestUtil.saveProject(myProject); PlatformTestUtil.assertDirectoriesEqual(afterDir, shelfDir); } + + /** + * Should be called only once: when Settings Repository plugin runs first time + */ + private static void checkAndMigrateOldPatchResourcesToNewSchemeStorage(@NotNull ShelveChangesManager shelveChangesManager) { + for (ShelvedChangeList list : shelveChangesManager.getAllLists()) { + File newPatchDir = new File(shelveChangesManager.getShelfResourcesDirectory(), list.getName()); + // it should be enough for migration to check if resource directory exists. If any bugs appeared add isAncestor checks for each path + if (!newPatchDir.exists() && newPatchDir.mkdirs()) { + migrateResourcesTo(list, newPatchDir, true); + } + } + } }