diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index 0de39d9b106..d7174cb4e98 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -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, diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java index af9095b8bd4..f89e557ec04 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/XmlUtil.java @@ -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; } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/memory/GdbMemoryBlockRetrieval.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/memory/GdbMemoryBlockRetrieval.java index c0f8e14f2e7..65e543e8dbf 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/memory/GdbMemoryBlockRetrieval.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/memory/GdbMemoryBlockRetrieval.java @@ -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) diff --git a/dsf/org.eclipse.cdt.dsf/META-INF/MANIFEST.MF b/dsf/org.eclipse.cdt.dsf/META-INF/MANIFEST.MF index fc444751fd0..0e38648a9cb 100644 --- a/dsf/org.eclipse.cdt.dsf/META-INF/MANIFEST.MF +++ b/dsf/org.eclipse.cdt.dsf/META-INF/MANIFEST.MF @@ -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, diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/model/DsfMemoryBlockRetrieval.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/model/DsfMemoryBlockRetrieval.java index 89957850042..7d2488024c3 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/model/DsfMemoryBlockRetrieval.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/debug/model/DsfMemoryBlockRetrieval.java @@ -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); } ///////////////////////////////////////////////////////////////////////////