mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +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:
parent
416a7f4f30
commit
e4e1f6780d
5 changed files with 33 additions and 16 deletions
|
@ -49,6 +49,7 @@ Export-Package: org.eclipse.cdt.core,
|
||||||
org.eclipse.cdt.internal.core;
|
org.eclipse.cdt.internal.core;
|
||||||
x-friends:="org.eclipse.cdt.codan.core.cxx,
|
x-friends:="org.eclipse.cdt.codan.core.cxx,
|
||||||
org.eclipse.cdt.debug.core,
|
org.eclipse.cdt.debug.core,
|
||||||
|
org.eclipse.cdt.dsf,
|
||||||
org.eclipse.cdt.dsf.gdb,
|
org.eclipse.cdt.dsf.gdb,
|
||||||
org.eclipse.cdt.make.core,
|
org.eclipse.cdt.make.core,
|
||||||
org.eclipse.cdt.make.ui,
|
org.eclipse.cdt.make.ui,
|
||||||
|
|
|
@ -292,16 +292,12 @@ public class XmlUtil {
|
||||||
*/
|
*/
|
||||||
public static void serializeXml(Document doc, URI uriLocation, String lineSeparator)
|
public static void serializeXml(Document doc, URI uriLocation, String lineSeparator)
|
||||||
throws IOException, TransformerException, CoreException {
|
throws IOException, TransformerException, CoreException {
|
||||||
XmlUtil.prettyFormat(doc);
|
|
||||||
|
|
||||||
java.io.File storeFile = new java.io.File(uriLocation);
|
java.io.File storeFile = new java.io.File(uriLocation);
|
||||||
if (!storeFile.exists()) {
|
if (!storeFile.exists()) {
|
||||||
storeFile.createNewFile();
|
storeFile.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
String utfString = new String(toByteArray(doc), ENCODING_UTF_8);
|
String utfString = toString(doc, lineSeparator);
|
||||||
utfString = XmlUtil.replaceLineSeparatorInternal(utfString, lineSeparator);
|
|
||||||
utfString = XmlUtil.insertNewlineAfterXMLVersionTag(utfString, lineSeparator);
|
|
||||||
|
|
||||||
FileOutputStream output = getFileOutputStreamWorkaround(storeFile);
|
FileOutputStream output = getFileOutputStreamWorkaround(storeFile);
|
||||||
output.write(utfString.getBytes(ENCODING_UTF_8));
|
output.write(utfString.getBytes(ENCODING_UTF_8));
|
||||||
|
@ -351,8 +347,6 @@ public class XmlUtil {
|
||||||
* @throws CoreException if something goes wrong.
|
* @throws CoreException if something goes wrong.
|
||||||
*/
|
*/
|
||||||
private static byte[] toByteArray(Document doc) throws CoreException {
|
private static byte[] toByteArray(Document doc) throws CoreException {
|
||||||
XmlUtil.prettyFormat(doc);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
|
@ -420,13 +414,9 @@ public class XmlUtil {
|
||||||
* @throws CoreException if something goes wrong.
|
* @throws CoreException if something goes wrong.
|
||||||
*/
|
*/
|
||||||
public static void serializeXml(Document doc, IFile file) throws CoreException {
|
public static void serializeXml(Document doc, IFile file) throws CoreException {
|
||||||
XmlUtil.prettyFormat(doc);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String utfString = new String(toByteArray(doc), ENCODING_UTF_8);
|
|
||||||
String lineSeparator = Util.getLineSeparator(file);
|
String lineSeparator = Util.getLineSeparator(file);
|
||||||
utfString = XmlUtil.replaceLineSeparatorInternal(utfString, lineSeparator);
|
String utfString = toString(doc, lineSeparator);
|
||||||
utfString = XmlUtil.insertNewlineAfterXMLVersionTag(utfString, lineSeparator);
|
|
||||||
byte[] newContents = utfString.getBytes(ENCODING_UTF_8);
|
byte[] newContents = utfString.getBytes(ENCODING_UTF_8);
|
||||||
InputStream input = new ByteArrayInputStream(newContents);
|
InputStream input = new ByteArrayInputStream(newContents);
|
||||||
|
|
||||||
|
@ -466,12 +456,36 @@ public class XmlUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize XML Document into a string.
|
* Serialize XML Document into a string.
|
||||||
|
* Note: This will return a non-pretty formatted string
|
||||||
*
|
*
|
||||||
* @param doc - DOM Document to serialize.
|
* @param doc - DOM Document to serialize.
|
||||||
* @return XML as a String.
|
* @return XML as a String.
|
||||||
* @throws CoreException if something goes wrong.
|
* @throws CoreException if something goes wrong.
|
||||||
*/
|
*/
|
||||||
public static String toString(Document doc) throws CoreException {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.gdb.service.IGDBMemory2;
|
||||||
import org.eclipse.cdt.dsf.service.DsfServices;
|
import org.eclipse.cdt.dsf.service.DsfServices;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
@ -445,7 +446,7 @@ public class GdbMemoryBlockRetrieval extends DsfMemoryBlockRetrieval implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.appendChild(expressionList);
|
document.appendChild(expressionList);
|
||||||
return DebugPlugin.serializeDocument(document);
|
return XmlUtil.toString(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-Vendor: %providerName
|
Bundle-Vendor: %providerName
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.dsf;singleton:=true
|
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-Activator: org.eclipse.cdt.dsf.internal.DsfPlugin
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Require-Bundle: org.eclipse.core.runtime,
|
Require-Bundle: org.eclipse.core.runtime,
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.eclipse.cdt.dsf.internal.DsfPlugin;
|
||||||
import org.eclipse.cdt.dsf.service.DsfServices;
|
import org.eclipse.cdt.dsf.service.DsfServices;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||||
import org.eclipse.cdt.dsf.service.IDsfService;
|
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.CoreException;
|
||||||
import org.eclipse.core.runtime.IAdaptable;
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
@ -321,7 +322,7 @@ public class DsfMemoryBlockRetrieval extends PlatformObject implements IMemoryBl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.appendChild(expressionList);
|
document.appendChild(expressionList);
|
||||||
return DebugPlugin.serializeDocument(document);
|
return XmlUtil.toString(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Reference in a new issue