summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-26 16:54:58 (EDT)
committerSteffen Pingel2013-04-30 13:08:53 (EDT)
commitaf505574701f1e70b64d892666dac6f4cffe9945 (patch)
tree8858a2f7915f54acfc3b15b786127f664982fe70
parentefd5db80f0b94f2b9d94df6a153a4e98cfbd9e8b (diff)
downloadorg.eclipse.mylyn.tasks-af505574701f1e70b64d892666dac6f4cffe9945.zip
org.eclipse.mylyn.tasks-af505574701f1e70b64d892666dac6f4cffe9945.tar.gz
org.eclipse.mylyn.tasks-af505574701f1e70b64d892666dac6f4cffe9945.tar.bz2
406647: task data gets corrupted when falling back to XML 1.1refs/changes/34/12234/12
Change-Id: I28a69c4aec071ae5ac72aa007285f9ca2acbedb1 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=406647
-rw-r--r--org.eclipse.mylyn.sdk-feature/feature.xml32
-rw-r--r--org.eclipse.mylyn.tasks-target/.project22
-rw-r--r--org.eclipse.mylyn.tasks-target/mylyn-tasks-e3.5.target4
-rw-r--r--org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.core/build.properties1
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java4
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java50
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java4
-rw-r--r--org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java75
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zipbin0 -> 2430 bytes
11 files changed, 179 insertions, 19 deletions
diff --git a/org.eclipse.mylyn.sdk-feature/feature.xml b/org.eclipse.mylyn.sdk-feature/feature.xml
index 90a52b4..b6547ff 100644
--- a/org.eclipse.mylyn.sdk-feature/feature.xml
+++ b/org.eclipse.mylyn.sdk-feature/feature.xml
@@ -40,11 +40,33 @@
id="org.eclipse.mylyn.bugzilla_feature"
version="0.0.0"/>
- <!--
- <includes
- id="org.eclipse.mylyn.commons.sdk"
- version="0.0.0"/>
- -->
+ <plugin
+ id="javax.xml"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.apache.xerces"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.apache.xml.resolver"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.apache.xml.serializer"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
<plugin
id="org.apache.lucene.core"
diff --git a/org.eclipse.mylyn.tasks-target/.project b/org.eclipse.mylyn.tasks-target/.project
new file mode 100644
index 0000000..198cb1d
--- /dev/null
+++ b/org.eclipse.mylyn.tasks-target/.project
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.mylyn.tasks-target</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ </natures>
+ <filteredResources>
+ <filter>
+ <id>1367109048408</id>
+ <name></name>
+ <type>10</type>
+ <matcher>
+ <id>org.eclipse.ui.ide.multiFilter</id>
+ <arguments>1.0-projectRelativePath-matches-false-false-target</arguments>
+ </matcher>
+ </filter>
+ </filteredResources>
+</projectDescription>
diff --git a/org.eclipse.mylyn.tasks-target/mylyn-tasks-e3.5.target b/org.eclipse.mylyn.tasks-target/mylyn-tasks-e3.5.target
index 6855d77..995378a 100644
--- a/org.eclipse.mylyn.tasks-target/mylyn-tasks-e3.5.target
+++ b/org.eclipse.mylyn.tasks-target/mylyn-tasks-e3.5.target
@@ -15,6 +15,10 @@
<unit id="org.junit" version="4.8.2.v4_8_2_v20110321-1705"/>
<unit id="org.mockito" version="1.8.4.v201303031500"/>
<unit id="org.objenesis" version="1.0.0.v201105211943"/>
+<unit id="javax.xml" version="1.3.4.v201005080400"/>
+<unit id="org.apache.xml.resolver" version="1.2.0.v201005080400"/>
+<unit id="org.apache.xml.serializer" version="2.7.1.v201005080400"/>
+<unit id="org.apache.xerces" version="2.9.0.v201101211617"/>
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/S20130308121626/repository/"/>
</location>
<location includeAllPlatforms="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
index ab138b5..fa7eb7a 100644
--- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.mylyn.commons.core;bundle-version="3.8.0",
org.eclipse.mylyn.commons.net;bundle-version="3.8.0",
org.eclipse.mylyn.commons.repositories.core;bundle-version="1.0.0",
- org.eclipse.core.runtime.compatibility.auth;resolution:=optional;x-installation:=greedy
+ org.eclipse.core.runtime.compatibility.auth;resolution:=optional;x-installation:=greedy,
+ org.apache.xerces;bundle-version="2.9.0";resolution:=optional
Export-Package: org.eclipse.mylyn.internal.provisional.tasks.core;x-internal:=true,
org.eclipse.mylyn.internal.tasks.core;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
org.eclipse.mylyn.internal.tasks.core.activity;x-friends:="org.eclipse.mylyn.tasks.ui,org.eclipse.mylyn.tasks.bugs",
diff --git a/org.eclipse.mylyn.tasks.core/build.properties b/org.eclipse.mylyn.tasks.core/build.properties
index d8c42eb..608daa4 100644
--- a/org.eclipse.mylyn.tasks.core/build.properties
+++ b/org.eclipse.mylyn.tasks.core/build.properties
@@ -15,3 +15,4 @@ bin.includes = META-INF/,\
src.includes = about.html,\
schema/
source.. = src/
+
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
index 6eb633b..9f0a331 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
@@ -29,7 +29,6 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author Rob Elves
@@ -112,7 +111,7 @@ public class TaskRepositoriesExternalizer {
}
SaxRepositoriesContentHandler contentHandler = new SaxRepositoriesContentHandler();
- XMLReader reader = XMLReaderFactory.createXMLReader();
+ XMLReader reader = XmlReaderUtil.createXmlReader();
reader.setContentHandler(contentHandler);
reader.parse(new InputSource(inputStream));
return contentHandler.getRepositories();
@@ -132,4 +131,5 @@ public class TaskRepositoriesExternalizer {
}
}
}
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java
new file mode 100644
index 0000000..482d017
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.core;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * Utility to create {@link XMLReader} instances. Uses Xerces if available to ensure XML 1.1 parsing works correctly.
+ *
+ * @author Steffen Pingel
+ */
+public class XmlReaderUtil {
+
+ public static XMLReader createXmlReader() throws SAXException {
+ try {
+ // use Xerces to ensure XML 1.1 is handled correctly
+ Class<?> clazz = Class.forName("org.apache.xerces.parsers.SAXParser"); //$NON-NLS-1$
+ return (XMLReader) clazz.newInstance();
+ } catch (Throwable e) {
+ SAXParser saxParser;
+ try {
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setNamespaceAware(true);
+ saxParser = saxParserFactory.newSAXParser();
+ } catch (ParserConfigurationException e2) {
+ throw new SAXException(e2);
+ }
+ return saxParser.getXMLReader();
+ }
+ }
+
+ private XmlReaderUtil() {
+ // clients must not instantiate class
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
index 02c1d35..477b467 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
@@ -27,6 +27,7 @@ import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.mylyn.internal.tasks.core.XmlReaderUtil;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryManager;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -36,7 +37,6 @@ import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author Steffen Pingel
@@ -177,7 +177,7 @@ public class TaskDataExternalizer {
}
public TaskDataState readState(InputStream in) throws IOException, SAXException {
- XMLReader parser = XMLReaderFactory.createXMLReader();
+ XMLReader parser = XmlReaderUtil.createXmlReader();
TaskDataStateReader handler = new TaskDataStateReader(taskRepositoryManager);
parser.setContentHandler(handler);
parser.parse(new InputSource(in));
diff --git a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
index e94d6cc..35965e2 100644
--- a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
@@ -5,7 +5,8 @@ Bundle-SymbolicName: org.eclipse.mylyn.tasks.tests;singleton:=true
Bundle-Version: 3.9.0.qualifier
Bundle-Activator: org.eclipse.mylyn.tasks.tests.TasksTestsPlugin
Bundle-Vendor: Eclipse Mylyn
-Require-Bundle: org.junit;bundle-version="4.8.2",
+Require-Bundle: org.junit;bundle-version="4.8.2",
+ org.apache.xerces;bundle-version="2.9.0",
org.eclipse.core.expressions,
org.eclipse.core.resources,
org.eclipse.core.runtime,
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
index a506fd4..bce08e9 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataStoreTest.java
@@ -16,7 +16,9 @@ import java.util.Date;
import junit.framework.TestCase;
+import org.apache.commons.lang.RandomStringUtils;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataState;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataStore;
@@ -198,8 +200,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u0000");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
try {
@@ -213,8 +213,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u0001\u001F");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
TaskDataState state2 = storage.getTaskDataState(file);
@@ -225,8 +223,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u007F\u0080");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
TaskDataState state2 = storage.getTaskDataState(file);
@@ -237,8 +233,6 @@ public class TaskDataStoreTest extends TestCase {
setupData();
data.getRoot().createAttribute("attribute").setValue("\u0001\u001F\u007F\u0080");
- File file = File.createTempFile("mylyn", null);
- file.deleteOnExit();
storage.putTaskData(file, state);
if (System.getProperty("java.version").compareTo("1.6") < 0) {
@@ -288,4 +282,69 @@ public class TaskDataStoreTest extends TestCase {
TaskDataState state2 = storage.getTaskDataState(file);
assertFalse(state2.getRepositoryData().getRoot().getAttribute("attribute").hasValue());
}
+
+ public void testCorruptedData() throws Exception {
+ if (!hasXerces()) {
+ System.err.println("Skipping testCorruptedData() due to Xerces missing");
+ return;
+ }
+ state = storage.getTaskDataState(CommonTestUtil.getFile(this, "testdata/taskdata-bug406647.zip"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("<ke"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("<va"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("ey>"));
+ assertFalse(state.getRepositoryData().getRoot().toString().contains("al>"));
+ }
+
+ private boolean hasXerces() {
+ try {
+ Class.forName("org.apache.xerces.parsers.SAXParser");
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
+ public void testRandomDataXml_1_0() throws Exception {
+ randomData(32, Integer.MAX_VALUE);
+ }
+
+ public void testRandomDataXml_1_1() throws Exception {
+ if (!hasXerces()) {
+ System.err.println("Skipping testRandomDataXml_1_1 due to Xerces missing");
+ return;
+ }
+ randomData(0, Integer.MAX_VALUE);
+ }
+
+ private void randomData(int start, int end) throws Exception {
+ setupData();
+
+ for (int i = 0; i < 1000; i++) {
+ TaskAttribute attribute = data.getRoot().createAttribute("testId");
+ attribute.getMetaData().setLabel(generateString(start, end));
+ attribute.putOption(generateString(start, end), generateString(start, end));
+ attribute.putOption(generateString(start, end), generateString(start, end));
+ attribute.addValue(generateString(start, end));
+ attribute.addValue(generateString(start, end));
+ if (start == 0) {
+ // ensure that XML is read as version 1.1
+ attribute.addValue(generateString(start, end) + "\u0001");
+ }
+ }
+
+ String expectedValue = data.getRoot().toString();
+ storage.putTaskData(file, state);
+
+ state = storage.getTaskDataState(file);
+ String actualValue = state.getRepositoryData().getRoot().toString();
+ assertEquals(expectedValue, actualValue);
+ }
+
+ /**
+ * Returns a random string that doesn't contain "key" or "val".
+ */
+ private String generateString(int start, int end) {
+ return RandomStringUtils.random(1000, start, end, true, true);
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zip b/org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zip
new file mode 100644
index 0000000..c4ddcb8
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/taskdata-bug406647.zip
Binary files differ