summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid E. Narváez2013-08-16 15:21:26 (EDT)
committerTomasz Zarna2013-09-11 05:05:54 (EDT)
commit82dd7193d0a9c05c0fd73377cd240bbeae829fa7 (patch)
treebcc3f083d0be68d8e2b42570981a9078cf4bcbb4
parent0d545d83a640ac5ec9353e3133e7583a945a0e69 (diff)
downloadorg.eclipse.mylyn.reviews-82dd7193d0a9c05c0fd73377cd240bbeae829fa7.zip
org.eclipse.mylyn.reviews-82dd7193d0a9c05c0fd73377cd240bbeae829fa7.tar.gz
org.eclipse.mylyn.reviews-82dd7193d0a9c05c0fd73377cd240bbeae829fa7.tar.bz2
Parse optional version param before config paramrefs/changes/57/15557/5
Required since 8f1c7[0]. Tested this change with Gerrit installations of Eclipse (currently, 2.6.1) and Wikimedia (currently, 2.7-rc2-505-g7502a46) [0] https://gerrit.googlesource.com/gerrit/+/8f1c7 Change-Id: Icc82033f898471586d10363b7c1b8ece27e100b1 Signed-off-by: David E. Narváez <david.narvaez@computer.org> Also-by: Tomasz Zarna <tomasz.zarna@tasktop.com>
-rw-r--r--org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessorTest.java50
-rw-r--r--org.eclipse.mylyn.gerrit.core.tests/testdata/eclipse-gerrit-2.6.html2
-rw-r--r--org.eclipse.mylyn.gerrit.core.tests/testdata/wikimedia-gerrit-2.7.html2
-rw-r--r--org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java10
5 files changed, 62 insertions, 4 deletions
diff --git a/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF
index 68bd67f..2302cce 100644
--- a/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.gerrit.core.tests/META-INF/MANIFEST.MF
@@ -19,3 +19,5 @@ Require-Bundle: org.junit;bundle-version="4.5.0",
Export-Package: org.eclipse.mylyn.internal.gerrit.core;x-internal:=true,
org.eclipse.mylyn.internal.gerrit.core.client;x-internal:=true,
org.eclipse.mylyn.internal.gerrit.core.egit;x-internal:=true
+Import-Package: org.apache.commons.io;version="2.0.1",
+ org.eclipse.mylyn.commons.sdk.util
diff --git a/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessorTest.java b/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessorTest.java
new file mode 100644
index 0000000..cd3d263
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core.tests/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessorTest.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2013 David E. Narvaez 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:
+ * David E. Narvaez - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.gerrit.core.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+public class GerritHtmlProcessorTest extends TestCase {
+ @Test
+ public void testHTMLProcessorGerrit2_6() throws Exception {
+ GerritHtmlProcessor processor = new GerritHtmlProcessor();
+ ByteArrayInputStream input = new ByteArrayInputStream(read("testdata/wikimedia-gerrit-2.7.html").getBytes()); //$NON-NLS-1$
+
+ processor.parse(input, "utf-8"); //$NON-NLS-1$
+
+ assertNotNull(processor.getConfig());
+ }
+
+ @Test
+ public void testHTMLProcessorGerrit2_7() throws Exception {
+ GerritHtmlProcessor processor = new GerritHtmlProcessor();
+ ByteArrayInputStream input = new ByteArrayInputStream(read("testdata/eclipse-gerrit-2.6.html").getBytes()); //$NON-NLS-1$
+
+ processor.parse(input, "utf-8"); //$NON-NLS-1$
+
+ assertNotNull(processor.getConfig());
+ }
+
+ private static String read(String path) throws IOException {
+ URL url = new URL("platform:/plugin/org.eclipse.mylyn.gerrit.core.tests/" + path); //$NON-NLS-1$
+ InputStream input = url.openConnection().getInputStream();
+ return IOUtils.toString(input, "utf-8"); //$NON-NLS-1$
+ }
+}
diff --git a/org.eclipse.mylyn.gerrit.core.tests/testdata/eclipse-gerrit-2.6.html b/org.eclipse.mylyn.gerrit.core.tests/testdata/eclipse-gerrit-2.6.html
new file mode 100644
index 0000000..9a6d539
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core.tests/testdata/eclipse-gerrit-2.6.html
@@ -0,0 +1,2 @@
+<!-- Excerpt from Wikimedia's Gerrit installation (2.7-rc2-505-g7502a46 as of Aug 23rd, 2013) -->
+<script id="gerrit_hostpagedata" language="javascript" type="text/javascript">var gerrit_hostpagedata={"config":{"registerUrl":"https://dev.eclipse.org/site_login/createaccount.php","reportBugUrl":"http://code.google.com/p/gerrit/issues/list","useContributorAgreements":false,"useContactInfo":false,"allowRegisterNewEmail":false,"authType":"LDAP","downloadSchemes":["HTTP","ANON_GIT","SSH","ANON_HTTP"],"downloadCommands":["DEFAULT_DOWNLOADS"],"gitDaemonUrl":"git://git.eclipse.org/gitroot/","sshdAddress":"git.eclipse.org:29418","wildProject":{"name":"All-Projects"},"editableAccountFields":["REGISTER_NEW_EMAIL"],"commentLinks":[{"find":"(I[0-9a-f]{8,40})","replace":"\u003ca href\u003d\"#/q/$1,n,z\"\u003e$\u0026\u003c/a\u003e"},{"find":"([Bb]ug:?\\s*#?)(\\d+)","replace":"$1\u003ca href\u003d\"https://bugs.eclipse.org/bugs/show_bug.cgi?id\u003d$2\"\u003e$2\u003c/a\u003e"},{"find":"(CQ:?\\s*#?)(\\d+)","replace":"$1\u003ca href\u003d\"https://dev.eclipse.org/ipzilla/show_bug.cgi?id\u003d$2\"\u003e$2\u003c/a\u003e"}],"documentationAvailable":true,"testChangeMerge":false,"anonymousCowardName":"Anonymous Coward","suggestFrom":0}};gerrit_hostpagedata.theme={"backgroundColor":"#FFFFFF","topMenuColor":"#FFFFFF","textColor":"#353535","trimColor":"#d3d3d3","selectionColor":"#D8EDF9","changeTableOutdatedColor":"#F08080","tableOddRowColor":"transparent","tableEvenRowColor":"transparent"};</script>
diff --git a/org.eclipse.mylyn.gerrit.core.tests/testdata/wikimedia-gerrit-2.7.html b/org.eclipse.mylyn.gerrit.core.tests/testdata/wikimedia-gerrit-2.7.html
new file mode 100644
index 0000000..9ac992b
--- /dev/null
+++ b/org.eclipse.mylyn.gerrit.core.tests/testdata/wikimedia-gerrit-2.7.html
@@ -0,0 +1,2 @@
+<!-- Excerpt from Wikimedia's Gerrit installation (2.7-rc2-505-g7502a46 as of Aug 23rd, 2013) -->
+<script id="gerrit_hostpagedata" language="javascript" type="text/javascript">var gerrit_hostpagedata={"version":"2.7-rc2-505-g7502a46","config":{"registerUrl":"https://wikitech.wikimedia.org/w/index.php?title\u003dSpecial:UserLogin\u0026returnto\u003dHelp%3AGetting+Started\u0026type\u003dsignup","reportBugUrl":"https://bugzilla.wikimedia.org/enter_bug.cgi?product\u003dWikimedia\u0026component\u003dGit/Gerrit","gitweb":{"baseUrl":"https://git.wikimedia.org","type":{"name":"gitblit","revision":"/commit/${project}/${commit}","project":"/summary/${project}","branch":"/log/${project}/${branch}","fileHistory":"/blob/${project}/${branch}/${file}","pathSeparator":"/","linkDrafts":false}},"useContributorAgreements":false,"useContactInfo":false,"allowRegisterNewEmail":false,"authType":"LDAP","downloadSchemes":["DEFAULT_DOWNLOADS"],"downloadCommands":["DEFAULT_DOWNLOADS"],"sshdAddress":"*:29418","wildProject":{"name":"All-Projects"},"editableAccountFields":["REGISTER_NEW_EMAIL"],"documentationAvailable":true,"testChangeMerge":true,"anonymousCowardName":"Anonymous Coward","suggestFrom":0}};gerrit_hostpagedata.theme={"backgroundColor":"#fff","topMenuColor":"#fff","textColor":"#353535","trimColor":"#eee","selectionColor":"#d8edf9","changeTableOutdatedColor":"#F08080","tableOddRowColor":"transparent","tableEvenRowColor":"transparent"};</script>
diff --git a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java
index bd0bf02..efcc193 100644
--- a/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java
+++ b/org.eclipse.mylyn.gerrit.core/src/org/eclipse/mylyn/internal/gerrit/core/client/GerritHtmlProcessor.java
@@ -16,6 +16,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.swing.text.html.HTML.Tag;
@@ -101,13 +103,14 @@ public class GerritHtmlProcessor {
* Parses the configuration from <code>text</code>.
*/
private void parse(String text) {
- String configPrefix = "var gerrit_hostpagedata={\"config\":"; //$NON-NLS-1$
+ Pattern p = Pattern.compile("var gerrit_hostpagedata=\\{(\"version\":\"([^\"]+)\",)?\"config\":"); //$NON-NLS-1$
String configXsrfToken = "hostpagedata.xsrfToken=\""; //$NON-NLS-1$
String configXGerritAuth = "hostpagedata.xGerritAuth=\""; //$NON-NLS-1$
String[] tokens = text.split(";gerrit_"); //$NON-NLS-1$
for (String token : tokens) {
- if (token.startsWith(configPrefix)) {
- token = token.substring(configPrefix.length());
+ Matcher m = p.matcher(token);
+ if (m.find()) {
+ token = token.substring(m.toMatchResult().group(0).length());
// remove closing }
token = token.substring(0, token.length() - 1);
this.config = gerritConfigFromString(token);
@@ -124,5 +127,4 @@ public class GerritHtmlProcessor {
}
}
}
-
}