This commit is contained in:
Roman Shevchenko
2012-05-23 21:04:26 +04:00
parent 9eb02e318a
commit 8439c9dc97
2 changed files with 47 additions and 30 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -31,6 +31,7 @@ import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedWriter;
import java.io.File;
@@ -51,7 +52,7 @@ public class Convertor34 {
private static final String JAVA_DOC_ROOTS_CANNOT_BE_CONVERTED = ProjectBundle.message("project.convert.javadoc.paths.error");
private static final String MULTIPLE_OUTPUT_PATHS = ProjectBundle.message("project.convert.multiple.output.paths.error");
public static void execute(Element root, String filePath, ArrayList<String> conversionProblems) {
public static void execute(Element root, String filePath, @Nullable ArrayList<String> conversionProblems) {
if (filePath == null) return;
if (conversionProblems == null) {
@@ -1,27 +1,46 @@
/*
* Copyright 2000-2012 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.project.convertors;
import com.intellij.application.options.PathMacrosImpl;
import com.intellij.ide.highlighter.ModuleFileType;
import com.intellij.ide.highlighter.ProjectFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ExpandMacroToPathMap;
import com.intellij.openapi.project.impl.convertors.Convertor34;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.refactoring.MultiFileTestCase;
import com.intellij.ide.highlighter.ProjectFileType;
import com.intellij.ide.highlighter.ModuleFileType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import java.io.IOException;
import java.util.List;
/**
* @author dsl
*/
public class Convertor34Test extends MultiFileTestCase {
public Convertor34Test() {
@Override
public void setUp() throws Exception {
myDoCompare = false;
super.setUp();
}
@Override
@@ -44,17 +63,18 @@ public class Convertor34Test extends MultiFileTestCase {
public void testScr25298() throws Exception { doTest(createPerformActionForLibraryTable());}
private PerformAction createPerformAction(final String projectName) {
private static PerformAction createPerformAction(final String projectName) {
return new PerformAction() {
@Override
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
final VirtualFile projectFile = rootDir.findChild(projectName + ProjectFileType.DOT_DEFAULT_EXTENSION);
assertNotNull(rootDir.getPath(), projectFile);
final ExpandMacroToPathMap macros = new ExpandMacroToPathMap();
macros.addMacroExpand(PathMacrosImpl.PROJECT_DIR_MACRO_NAME, rootDir.getPath());
macros.addMacroExpand(PathMacrosImpl.MODULE_DIR_MACRO_NAME, rootDir.getPath());
final Document projectDocument = JDOMUtil.loadDocument(
VfsUtil.loadText(projectFile));
final Document projectDocument = JDOMUtil.loadDocument(VfsUtilCore.loadText(projectFile));
macros.substitute(projectDocument.getRootElement(), true);
Convertor34.execute(projectDocument.getRootElement(), projectFile.getPath(), null);
@@ -65,18 +85,11 @@ public class Convertor34Test extends MultiFileTestCase {
LocalFileSystem.getInstance().refresh(false);
}
});
final VirtualFile moduleFile = rootDir.findChild(projectName + ModuleFileType.DOT_DEFAULT_EXTENSION);
assertNotNull(moduleFile);
final Document moduleDocument = JDOMUtil.loadDocument(
VfsUtil.loadText(moduleFile));
final Document moduleDocument = loadDocument(rootDir, projectName + ModuleFileType.DOT_DEFAULT_EXTENSION);
macros.substitute(moduleDocument.getRootElement(), true);
final Document goldenProjectDocument = JDOMUtil.loadDocument(
VfsUtil.loadText(rootAfter.findChild(projectName + ProjectFileType.DOT_DEFAULT_EXTENSION))
);
final Document goldenProjectDocument = loadDocument(rootAfter, projectName + ProjectFileType.DOT_DEFAULT_EXTENSION);
macros.substitute(goldenProjectDocument.getRootElement(), true);
final Document goldenModuleDocument = JDOMUtil.loadDocument(
VfsUtil.loadText(rootAfter.findChild(projectName + ModuleFileType.DOT_DEFAULT_EXTENSION))
);
final Document goldenModuleDocument = loadDocument(rootAfter, projectName + ModuleFileType.DOT_DEFAULT_EXTENSION);
macros.substitute(goldenModuleDocument.getRootElement(), true);
assertConfigsEqual("ProjectModuleManager", goldenProjectDocument, projectDocument);
@@ -85,16 +98,17 @@ public class Convertor34Test extends MultiFileTestCase {
};
}
private PerformAction createPerformActionForLibraryTable() {
private static PerformAction createPerformActionForLibraryTable() {
return new PerformAction() {
@Override
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
final VirtualFile libFile = rootDir.findChild("library.table.xml");
assertNotNull(rootDir.getPath(), libFile);
final ExpandMacroToPathMap macros = new ExpandMacroToPathMap();
macros.addMacroExpand("DIR", rootDir.getPath());
final Document oldTable = JDOMUtil.loadDocument(
VfsUtil.loadText(libFile));
final Document oldTable = JDOMUtil.loadDocument(VfsUtilCore.loadText(libFile));
macros.substitute(oldTable.getRootElement(), true);
Convertor34.convertLibraryTable34(oldTable.getRootElement(), libFile.getPath());
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@@ -103,25 +117,27 @@ public class Convertor34Test extends MultiFileTestCase {
LocalFileSystem.getInstance().refresh(false);
}
});
final VirtualFile applicationLibraries = rootDir.findChild("applicationLibraries.xml");
assertNotNull(applicationLibraries);
final Document newTable = JDOMUtil.loadDocument(
VfsUtil.loadText(applicationLibraries));
final Document goldenNewTable = JDOMUtil.loadDocument(
VfsUtil.loadText(rootAfter.findChild("applicationLibraries.xml")));
final Document newTable = loadDocument(rootDir, "applicationLibraries.xml");
final Document goldenNewTable = loadDocument(rootAfter, "applicationLibraries.xml");
macros.substitute(goldenNewTable.getRootElement(), true);
assertElementsEqual(goldenNewTable.getRootElement(), newTable.getRootElement());
}
};
}
private void assertConfigsEqual(String componentName, Document goldenDocument, Document document) {
private static Document loadDocument(VirtualFile parent, String name) throws IOException, JDOMException {
final VirtualFile child = parent.findChild(name);
assertNotNull(parent + "/" + name, child);
return JDOMUtil.loadDocument(VfsUtilCore.loadText(child));
}
private static void assertConfigsEqual(String componentName, Document goldenDocument, Document document) {
final Element goldenElement = getComponentElement(goldenDocument, componentName);
final Element element = getComponentElement(document, componentName);
assertElementsEqual(goldenElement, element);
}
private void assertElementsEqual(final Element goldenElement, final Element element) {
private static void assertElementsEqual(final Element goldenElement, final Element element) {
assertEquals(JDOMUtil.createOutputter("\n").outputString(goldenElement),
JDOMUtil.createOutputter("\n").outputString(element));
}