mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
+2
-2
@@ -24,8 +24,8 @@ import org.jetbrains.jps.model.JpsElement;
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsElementExtensionSerializerBase<E extends JpsElement> {
|
||||
protected final String myConfigFileName;
|
||||
protected final String myComponentName;
|
||||
private final String myConfigFileName;
|
||||
private final String myComponentName;
|
||||
|
||||
protected JpsElementExtensionSerializerBase(@Nullable String configFileName, @NotNull String componentName) {
|
||||
myComponentName = componentName;
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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 org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.jps.model.JpsGlobal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsGlobalElementSaver {
|
||||
private static final JpsGlobalExtensionSerializer[] SERIALIZERS = {
|
||||
new JpsGlobalLoader.GlobalLibrariesSerializer(), new JpsGlobalLoader.SdkTableSerializer()
|
||||
};
|
||||
private final JpsGlobal myGlobal;
|
||||
|
||||
public JpsGlobalElementSaver(JpsGlobal global) {
|
||||
myGlobal = global;
|
||||
}
|
||||
|
||||
public static void saveGlobalElement(JpsGlobal global, String optionsPath) throws IOException {
|
||||
File optionsDir = new File(FileUtil.toCanonicalPath(optionsPath));
|
||||
new JpsGlobalElementSaver(global).save(optionsDir);
|
||||
}
|
||||
|
||||
private void save(File optionsDir) throws IOException {
|
||||
for (JpsGlobalExtensionSerializer serializer : SERIALIZERS) {
|
||||
saveGlobalComponents(serializer, optionsDir);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveGlobalComponents(JpsGlobalExtensionSerializer serializer, File optionsDir) throws IOException {
|
||||
String fileName = serializer.getConfigFileName();
|
||||
File configFile = new File(optionsDir, fileName != null ? fileName : "other.xml");
|
||||
Element rootElement = loadOrCreateRootElement(configFile);
|
||||
serializer.saveExtension(myGlobal, JDomSerializationUtil.findOrCreateComponentElement(rootElement, serializer.getComponentName()));
|
||||
JDOMUtil.writeDocument(new Document(rootElement), configFile, SystemProperties.getLineSeparator());
|
||||
}
|
||||
|
||||
private static Element loadOrCreateRootElement(File configFile) {
|
||||
if (!configFile.exists()) {
|
||||
return new Element("application");
|
||||
}
|
||||
try {
|
||||
return JDOMUtil.loadDocument(configFile).getRootElement();
|
||||
}
|
||||
catch (JDOMException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -45,7 +45,7 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
public static final String FILE_TYPES_COMPONENT_NAME_KEY = "jps.file.types.component.name";
|
||||
private final JpsGlobal myGlobal;
|
||||
|
||||
public JpsGlobalLoader(JpsGlobal global, Map<String, String> pathVariables) {
|
||||
private JpsGlobalLoader(JpsGlobal global, Map<String, String> pathVariables) {
|
||||
super(new JpsMacroExpander(pathVariables));
|
||||
myGlobal = global;
|
||||
global.getContainer().setChild(PATH_VARIABLES_ROLE, JpsElementFactory.getInstance().createSimpleElement(pathVariables));
|
||||
@@ -78,8 +78,8 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
loadComponents(optionsDir, "other.xml", serializer, myGlobal);
|
||||
}
|
||||
|
||||
private static class GlobalLibrariesSerializer extends JpsGlobalExtensionSerializer {
|
||||
private GlobalLibrariesSerializer() {
|
||||
public static class GlobalLibrariesSerializer extends JpsGlobalExtensionSerializer {
|
||||
public GlobalLibrariesSerializer() {
|
||||
super("applicationLibraries.xml", "libraryTable");
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ public class JpsGlobalLoader extends JpsLoaderBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SdkTableSerializer extends JpsGlobalExtensionSerializer {
|
||||
private SdkTableSerializer() {
|
||||
public static class SdkTableSerializer extends JpsGlobalExtensionSerializer {
|
||||
public SdkTableSerializer() {
|
||||
super("jdk.table.xml", SDK_TABLE_COMPONENT_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -31,7 +29,6 @@ import java.io.IOException;
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class JpsLoaderBase {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.model.serialization.JpsLoaderBase");
|
||||
private final JpsMacroExpander myMacroExpander;
|
||||
|
||||
protected JpsLoaderBase(JpsMacroExpander macroExpander) {
|
||||
|
||||
+3
@@ -17,6 +17,7 @@ package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsGlobal;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
@@ -34,4 +35,6 @@ public abstract class JpsSerializationManager {
|
||||
@NotNull
|
||||
public abstract JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath, @NotNull Map<String, String> pathVariables)
|
||||
throws IOException;
|
||||
|
||||
public abstract void saveGlobalSettings(@NotNull JpsGlobal global, @NotNull String optionsPath) throws IOException;
|
||||
}
|
||||
|
||||
+7
@@ -18,7 +18,9 @@ package org.jetbrains.jps.model.serialization.impl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.JpsElementFactory;
|
||||
import org.jetbrains.jps.model.JpsGlobal;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalElementSaver;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsProjectLoader;
|
||||
import org.jetbrains.jps.model.serialization.JpsSerializationManager;
|
||||
@@ -41,4 +43,9 @@ public class JpsSerializationManagerImpl extends JpsSerializationManager {
|
||||
JpsProjectLoader.loadProject(model.getProject(), pathVariables, projectPath);
|
||||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveGlobalSettings(@NotNull JpsGlobal global, @NotNull String optionsPath) throws IOException {
|
||||
JpsGlobalElementSaver.saveGlobalElement(global, optionsPath);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.jetbrains.jps.model.serialization;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
import org.jetbrains.jps.model.JpsEncodingConfigurationService;
|
||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||
import org.jetbrains.jps.model.serialization.library.JpsSdkTableSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -32,7 +32,7 @@ import java.util.List;
|
||||
public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
private static final String OPTIONS_DIR = "jps/model-serialization/testData/config/options";
|
||||
|
||||
public void testLoadSdks() {
|
||||
public void testLoadSdksAndGlobalLibraries() {
|
||||
loadGlobalSettings(OPTIONS_DIR);
|
||||
final List<JpsLibrary> libraries = myModel.getGlobal().getLibraryCollection().getLibraries();
|
||||
assertEquals(3, libraries.size());
|
||||
@@ -43,13 +43,20 @@ public class JpsGlobalSerializationTest extends JpsSerializationTestCase {
|
||||
assertEquals("1.6", sdk2.getName());
|
||||
}
|
||||
|
||||
public void testSaveSdks() throws JDOMException, IOException {
|
||||
public void testSaveSdksAndGlobalLibraries() throws JDOMException, IOException {
|
||||
loadGlobalSettings(OPTIONS_DIR);
|
||||
Element actual = new Element("component").setAttribute("name", "ProjectJdkTable");
|
||||
JpsSdkTableSerializer.saveSdks(myModel.getGlobal().getLibraryCollection(), actual);
|
||||
File jdkTableFile = new File(getTestDataFileAbsolutePath(OPTIONS_DIR), "jdk.table.xml");
|
||||
File targetOptionsDir = FileUtil.createTempDirectory("options" ,null);
|
||||
JpsSerializationManager.getInstance().saveGlobalSettings(myModel.getGlobal(), targetOptionsDir.getAbsolutePath());
|
||||
|
||||
File originalOptionsDir = new File(getTestDataFileAbsolutePath(OPTIONS_DIR));
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "jdk.table.xml");
|
||||
assertOptionsFilesEqual(originalOptionsDir, targetOptionsDir, "applicationLibraries.xml");
|
||||
}
|
||||
|
||||
private void assertOptionsFilesEqual(File originalOptionsDir, File targetOptionsDir, final String fileName) throws IOException {
|
||||
JpsMacroExpander expander = new JpsMacroExpander(getPathVariables());
|
||||
Element expected = JDomSerializationUtil.findComponent(JpsLoaderBase.loadRootElement(jdkTableFile, expander), "ProjectJdkTable");
|
||||
Element expected = JpsLoaderBase.loadRootElement(new File(originalOptionsDir, fileName), expander);
|
||||
Element actual = JpsLoaderBase.loadRootElement(new File(targetOptionsDir, fileName), expander);
|
||||
PlatformTestUtil.assertElementsEqual(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user