1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 565628: Unify line endings for memory block configuration

As the memory browser configuration is preserved in the launch
configuration file as an indented serialized XML string, the string will
contain the result of System.lineSeparator(). As the launch
configuration file can be shared among developers with different
platforms, there is a risk that the launch configuration file is always
modified although there is no real modification, just line endings.
To avoid this scenario, always save the XML string without any
indentation or line endings.

Change-Id: I94497a924f7aa5a881ac6a32f146d2cbceb6324f
Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
This commit is contained in:
Torbjörn Svensson 2020-08-20 22:08:39 +02:00 committed by Jonah Graham
parent 416a7f4f30
commit e4e1f6780d
5 changed files with 33 additions and 16 deletions

View file

@ -49,6 +49,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.internal.core;
x-friends:="org.eclipse.cdt.codan.core.cxx,
org.eclipse.cdt.debug.core,
org.eclipse.cdt.dsf,
org.eclipse.cdt.dsf.gdb,
org.eclipse.cdt.make.core,
org.eclipse.cdt.make.ui,

View file

@ -292,16 +292,12 @@ public class XmlUtil {
*/
public static void serializeXml(Document doc, URI uriLocation, String lineSeparator)
throws IOException, TransformerException, CoreException {
XmlUtil.prettyFormat(doc);
java.io.File storeFile = new java.io.File(uriLocation);
if (!storeFile.exists()) {
storeFile.createNewFile();
}
String utfString = new String(toByteArray(doc), ENCODING_UTF_8);
utfString = XmlUtil.replaceLineSeparatorInternal(utfString, lineSeparator);
utfString = XmlUtil.insertNewlineAfterXMLVersionTag(utfString, lineSeparator);
String utfString = toString(doc, lineSeparator);
FileOutputStream output = getFileOutputStreamWorkaround(storeFile);
output.write(utfString.getBytes(ENCODING_UTF_8));
@ -351,8 +347,6 @@ public class XmlUtil {
* @throws CoreException if something goes wrong.
*/
private static byte[] toByteArray(Document doc) throws CoreException {
XmlUtil.prettyFormat(doc);
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@ -420,13 +414,9 @@ public class XmlUtil {
* @throws CoreException if something goes wrong.
*/
public static void serializeXml(Document doc, IFile file) throws CoreException {
XmlUtil.prettyFormat(doc);
try {
String utfString = new String(toByteArray(doc), ENCODING_UTF_8);
String lineSeparator = Util.getLineSeparator(file);
utfString = XmlUtil.replaceLineSeparatorInternal(utfString, lineSeparator);
utfString = XmlUtil.insertNewlineAfterXMLVersionTag(utfString, lineSeparator);
String utfString = toString(doc, lineSeparator);
byte[] newContents = utfString.getBytes(ENCODING_UTF_8);
InputStream input = new ByteArrayInputStream(newContents);
@ -466,12 +456,36 @@ public class XmlUtil {
/**
* Serialize XML Document into a string.
* Note: This will return a non-pretty formatted string
*
* @param doc - DOM Document to serialize.
* @return XML as a String.
* @throws CoreException if something goes wrong.
*/
public static String toString(Document doc) throws CoreException {
return new String(toByteArray(doc));
try {
return new String(toByteArray(doc), ENCODING_UTF_8);
} catch (UnsupportedEncodingException e) {
throw new CoreException(CCorePlugin.createStatus(Messages.XmlUtil_InternalErrorSerializing, e));
}
}
/**
* Serialize XML Document into a pretty formatted string.
* Note: This will return a pretty formatted string
*
* @param doc - DOM Document to serialize.
* @param lineSeparator - line separator
* @return XML as a pretty formatted String.
* @throws CoreException if something goes wrong.
*/
public static String toString(Document doc, String lineSeparator) throws CoreException {
XmlUtil.prettyFormat(doc);
String utfString = toString(doc);
utfString = XmlUtil.replaceLineSeparatorInternal(utfString, lineSeparator);
utfString = XmlUtil.insertNewlineAfterXMLVersionTag(utfString, lineSeparator);
return utfString;
}
}

View file

@ -42,6 +42,7 @@ import org.eclipse.cdt.dsf.gdb.service.IGDBMemory;
import org.eclipse.cdt.dsf.gdb.service.IGDBMemory2;
import org.eclipse.cdt.dsf.service.DsfServices;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.internal.core.XmlUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
@ -445,7 +446,7 @@ public class GdbMemoryBlockRetrieval extends DsfMemoryBlockRetrieval implements
}
}
document.appendChild(expressionList);
return DebugPlugin.serializeDocument(document);
return XmlUtil.toString(document);
}
/* (non-Javadoc)

View file

@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.cdt.dsf;singleton:=true
Bundle-Version: 2.8.200.qualifier
Bundle-Version: 2.8.300.qualifier
Bundle-Activator: org.eclipse.cdt.dsf.internal.DsfPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,

View file

@ -40,6 +40,7 @@ import org.eclipse.cdt.dsf.internal.DsfPlugin;
import org.eclipse.cdt.dsf.service.DsfServices;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.dsf.service.IDsfService;
import org.eclipse.cdt.internal.core.XmlUtil;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
@ -321,7 +322,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl
}
}
document.appendChild(expressionList);
return DebugPlugin.serializeDocument(document);
return XmlUtil.toString(document);
}
///////////////////////////////////////////////////////////////////////////