fix SaveProjectAsTemplateTest - avoid reusing the same path for different macros (for simplicity)

GitOrigin-RevId: a665b4620be233a2a5bd35599de22f1415f12881
This commit is contained in:
Vladimir Krivosheev
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent 579d45efc8
commit 87bf970bad
5 changed files with 18 additions and 27 deletions
+1
View File
@@ -11,5 +11,6 @@
<orderEntry type="module" module-name="intellij.java.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.aetherDependencyResolver" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.execution.impl" scope="TEST" />
<orderEntry type="library" scope="TEST" name="assertJ" level="project" />
</component>
</module>
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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.
// 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.ide.projectWizard;
import com.intellij.application.UtilKt;
@@ -37,9 +37,12 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dmitry Avdeev
*/
@@ -67,7 +70,7 @@ public class SaveProjectAsTemplateTest extends NewProjectWizardTestCase {
"public class Bar {\n" +
"}");
}
public void testSaveProjectUnescaped() throws Exception {
doTest(false, false, "/** No comments */\n" +
"\n" +
@@ -88,7 +91,7 @@ public class SaveProjectAsTemplateTest extends NewProjectWizardTestCase {
}
private void doTest(boolean shouldEscape, boolean replaceParameters, String initialText, String expected) throws IOException {
assertEquals(StorageScheme.DIRECTORY_BASED, ProjectKt.getStateStore(getProject()).getStorageScheme());
assertThat(ProjectKt.getStateStore(getProject()).getStorageScheme()).isEqualTo(StorageScheme.DIRECTORY_BASED);
VirtualFile root = ProjectRootManager.getInstance(getProject()).getContentRoots()[0];
File rootFile = new File(VfsUtilCore.virtualToIoFile(root), FOO_BAR_JAVA);
rootFile.getParentFile().mkdirs();
@@ -105,8 +108,8 @@ public class SaveProjectAsTemplateTest extends NewProjectWizardTestCase {
SaveProjectAsTemplateAction.saveProject(getProject(), zipFile, null, "bar", replaceParameters, new MockProgressIndicator(), shouldEscape);
return Unit.INSTANCE;
});
assertEquals("foo.zip", zipFile.getFileName().toString());
assertTrue(Files.size(zipFile) > 0);
assertThat(zipFile.getFileName().toString()).isEqualTo("foo.zip");
assertThat(Files.size(zipFile)).isGreaterThan(0);
Project fromTemplate = createProjectFromTemplate(ProjectTemplatesFactory.CUSTOM_GROUP, "foo", null);
VirtualFile descriptionFile = SaveProjectAsTemplateAction.getDescriptionFile(fromTemplate, LocalArchivedTemplate.DESCRIPTION_PATH);
@@ -116,10 +119,9 @@ public class SaveProjectAsTemplateTest extends NewProjectWizardTestCase {
VirtualFile[] roots = ProjectRootManager.getInstance(fromTemplate).getContentRoots();
VirtualFile child = roots[0].findFileByRelativePath(FOO_BAR_JAVA);
assertNotNull(Arrays.asList(roots[0].getChildren()).toString(), child);
String s = VfsUtilCore.loadText(child);
assertEquals(expected, StringUtil.convertLineSeparators(s));
assertEquals(expected, StringUtil.convertLineSeparators(VfsUtilCore.loadText(child)));
assertNotNull(fromTemplate.getBaseDir().findFileByRelativePath(".idea/workspace.xml"));
assertThat(Paths.get(fromTemplate.getBasePath(), ".idea/workspace.xml")).isRegularFile();
}
@Override
@@ -122,6 +122,8 @@ abstract class ProjectStoreBase(final override val project: Project) : Component
if (isUnitTestMode) {
// load state only if there are existing files
isOptimiseTestLoadSpeed = !Paths.get(filePath).toFile().exists()
storageManager.addMacro(StoragePathMacros.PRODUCT_WORKSPACE_FILE, workspacePath)
}
}
else {
@@ -135,6 +137,8 @@ abstract class ProjectStoreBase(final override val project: Project) : Component
if (isUnitTestMode) {
// load state only if there are existing files
isOptimiseTestLoadSpeed = !Paths.get(filePath).exists()
storageManager.addMacro(StoragePathMacros.PRODUCT_WORKSPACE_FILE, "$configDir/product-workspace.xml")
}
if (isRefreshVfsNeeded) {
@@ -150,7 +154,6 @@ abstract class ProjectStoreBase(final override val project: Project) : Component
storageManager.addMacro(StoragePathMacros.CACHE_FILE, appSystemDir.resolve("workspace").resolve(cacheFileName).systemIndependentPath)
if (isUnitTestMode) {
storageManager.addMacro(StoragePathMacros.PRODUCT_WORKSPACE_FILE, storageManager.expandMacro(StoragePathMacros.WORKSPACE_FILE))
return
}
@@ -178,16 +178,10 @@ open class StateStorageManagerImpl(private val rootTagName: String,
if (storageClass != StateStorage::class.java) {
return storageClass.name!!
}
if (normalizedCollapsedPath.isEmpty()) {
throw Exception("Normalized path is empty, raw path '$collapsedPath'")
}
val key = storageCreator?.key ?: normalizedCollapsedPath
if (key == StoragePathMacros.PRODUCT_WORKSPACE_FILE && ApplicationManager.getApplication().isUnitTestMode) {
return StoragePathMacros.WORKSPACE_FILE
}
return key
return storageCreator?.key ?: normalizedCollapsedPath
}
fun getCachedFileStorages(): Set<StateStorage> = storageLock.read { storages.values.toSet() }
@@ -31,7 +31,6 @@ import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.io.StreamUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -145,10 +144,7 @@ public class SaveProjectAsTemplateAction extends AnAction implements DumbAware {
indicator.setText("Saving project...");
StoreUtil.saveSettings(project, true);
indicator.setText("Processing project files...");
ZipOutputStream stream = null;
try {
stream = new ZipOutputStream(PathKt.outputStream(zipFile));
try (ZipOutputStream stream = new ZipOutputStream(PathKt.outputStream(zipFile))) {
final VirtualFile dir = getDirectoryToSave(project, moduleToSave);
List<LocalArchivedTemplate.RootDescription> roots = collectStructure(project, moduleToSave);
@@ -166,9 +162,7 @@ public class SaveProjectAsTemplateAction extends AnAction implements DumbAware {
FileIndex index = moduleToSave == null
? ProjectRootManager.getInstance(project).getFileIndex()
: ModuleRootManager.getInstance(moduleToSave).getFileIndex();
final ZipOutputStream finalStream = stream;
MyContentIterator iterator = new MyContentIterator(indicator, finalStream, project, parameters, shouldEscape);
MyContentIterator iterator = new MyContentIterator(indicator, stream, project, parameters, shouldEscape);
for (LocalArchivedTemplate.RootDescription root : roots) {
String prefix = LocalArchivedTemplate.ROOT_FILE_NAME + root.myIndex;
VirtualFile rootFile = root.myFile;
@@ -183,9 +177,6 @@ public class SaveProjectAsTemplateAction extends AnAction implements DumbAware {
LOG.error(ex);
UIUtil.invokeLaterIfNeeded(() -> Messages.showErrorDialog(project, "Can't save project as template", "Internal Error"));
}
finally {
StreamUtil.closeStream(stream);
}
}
private static LocalArchivedTemplate.RootDescription findOrAddBaseRoot(List<LocalArchivedTemplate.RootDescription> roots, VirtualFile dirToSave) {