aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Foster2012-10-01 19:36:21 (EDT)
committerBob Foster2012-10-01 19:36:21 (EDT)
commit8f9ce8f8fcf6d21e28c09ee3a38d21b41a429903 (patch)
tree2e135a143c478a12f6112c1e5bdf14db7df29695
parent2c275345fc8f9d9f06adcd7601633965495b133b (diff)
downloadorg.eclipse.hudson.core-8f9ce8f8fcf6d21e28c09ee3a38d21b41a429903.zip
org.eclipse.hudson.core-8f9ce8f8fcf6d21e28c09ee3a38d21b41a429903.tar.gz
org.eclipse.hudson.core-8f9ce8f8fcf6d21e28c09ee3a38d21b41a429903.tar.bz2
Fix bugzilla 390760refs/changes/14/8014/1
-rw-r--r--hudson-core/pom.xml9
-rw-r--r--hudson-core/src/main/java/hudson/model/Api.java8
-rw-r--r--hudson-core/src/main/java/hudson/tools/JDKInstaller.java10
-rw-r--r--hudson-test-framework/src/main/java/org/jvnet/hudson/test/JellyTestSuiteBuilder.java10
4 files changed, 32 insertions, 5 deletions
diff --git a/hudson-core/pom.xml b/hudson-core/pom.xml
index 86059be..f485779 100644
--- a/hudson-core/pom.xml
+++ b/hudson-core/pom.xml
@@ -440,9 +440,18 @@
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.hudsonci.xpath</groupId>
+ <artifactId>xpath-service</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
+ <groupId>org.hudsonci.xpath</groupId>
+ <artifactId>xpath-service</artifactId>
+ <version>1.0.1</version>
+ </dependency>
+ <dependency>
<groupId>commons-jelly</groupId>
<artifactId>commons-jelly-tags-fmt</artifactId>
<version>${commons-jelly-tags-fmt.version}</version>
diff --git a/hudson-core/src/main/java/hudson/model/Api.java b/hudson-core/src/main/java/hudson/model/Api.java
index c10ae1b..ec44ec1 100644
--- a/hudson-core/src/main/java/hudson/model/Api.java
+++ b/hudson-core/src/main/java/hudson/model/Api.java
@@ -24,6 +24,7 @@ import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
+import org.hudsonci.xpath.XPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -37,6 +38,7 @@ import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.List;
+import org.hudsonci.xpath.XPathException;
/**
* Used to expose remote access API for ".../api/"
@@ -100,7 +102,7 @@ public class Api extends AbstractModelObject {
// apply exclusions
if (excludes != null) {
for (String exclude : excludes) {
- List<org.dom4j.Node> list = (List<org.dom4j.Node>) dom.selectNodes(exclude);
+ List<org.dom4j.Node> list = (List<org.dom4j.Node>) new XPath(exclude).selectNodes(dom);
for (org.dom4j.Node n : list) {
Element parent = n.getParent();
if (parent != null) {
@@ -113,7 +115,7 @@ public class Api extends AbstractModelObject {
if (xpath == null) {
result = dom;
} else {
- List list = dom.selectNodes(xpath);
+ List list = new XPath(xpath).selectNodes(dom);
if (wrapper != null) {
Element root = DocumentFactory.getInstance().createElement(wrapper);
for (Object o : list) {
@@ -137,6 +139,8 @@ public class Api extends AbstractModelObject {
}
}
+ } catch (XPathException e) {
+ throw new IOException2(e);
} catch (DocumentException e) {
throw new IOException2(e);
}
diff --git a/hudson-core/src/main/java/hudson/tools/JDKInstaller.java b/hudson-core/src/main/java/hudson/tools/JDKInstaller.java
index 8cf6edc..73a3096 100644
--- a/hudson-core/src/main/java/hudson/tools/JDKInstaller.java
+++ b/hudson-core/src/main/java/hudson/tools/JDKInstaller.java
@@ -63,6 +63,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.json.JSONObject;
+import org.hudsonci.xpath.XPath;
+import org.hudsonci.xpath.XPathException;
/**
* Install JDKs from java.sun.com.
@@ -347,7 +349,7 @@ public class JDKInstaller extends ToolInstaller {
Document dom = domReader.read(tidy.parseDOM(con.getInputStream(), null));
form = null;
- for (Element e : (List<Element>) dom.selectNodes("//form")) {
+ for (Element e : (List<Element>) new XPath("//form").selectNodes(dom)) {
String action = e.attributeValue("action");
LOGGER.fine("Found form:" + action);
if (action.contains("ViewFilteredProducts")) {
@@ -355,6 +357,8 @@ public class JDKInstaller extends ToolInstaller {
break;
}
}
+ } catch (XPathException e) {
+ throw new IOException2("Failed to access (xpath) " + url, e);
} catch (IOException e) {
throw new IOException2("Failed to access " + url, e);
}
@@ -405,7 +409,7 @@ public class JDKInstaller extends ToolInstaller {
}
// the rest
- for (Element e : (List<Element>) form.selectNodes(".//input")) {
+ for (Element e : (List<Element>) new XPath(".//input").selectNodes(form)) {
os.print('&');
os.print(e.attributeValue("name"));
os.print('=');
@@ -417,6 +421,8 @@ public class JDKInstaller extends ToolInstaller {
}
}
return con;
+ } catch (XPathException e) {
+ throw new IOException2("Failed to access (xpath) " + url, e);
} catch (IOException e) {
throw new IOException2("Failed to access " + url, e);
} finally {
diff --git a/hudson-test-framework/src/main/java/org/jvnet/hudson/test/JellyTestSuiteBuilder.java b/hudson-test-framework/src/main/java/org/jvnet/hudson/test/JellyTestSuiteBuilder.java
index 438fc77..e28d32b 100644
--- a/hudson-test-framework/src/main/java/org/jvnet/hudson/test/JellyTestSuiteBuilder.java
+++ b/hudson-test-framework/src/main/java/org/jvnet/hudson/test/JellyTestSuiteBuilder.java
@@ -33,6 +33,10 @@ import java.util.Enumeration;
import java.util.concurrent.Callable;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.hudsonci.xpath.XPath;
+import org.hudsonci.xpath.XPathException;
/**
* Builds up a {@link TestSuite} for performing static syntax checks on Jelly
@@ -97,11 +101,15 @@ public class JellyTestSuiteBuilder {
*/
private void checkLabelFor(Document dom) {
if (isConfigJelly() || isGlobalJelly()) {
- if (!dom.selectNodes("//label[@for]").isEmpty()) {
+ try {
+ if (!new XPath("//label[@for]").selectNodes(dom).isEmpty()) {
throw new AssertionError("<label for=...> shouldn't be used because it doesn't work "
+ "when the configuration item is repeated. Use <label class=\"attach-previous\"> "
+ "to have your label attach to the previous DOM node instead.");
}
+ } catch (XPathException ex) {
+ throw new AssertionError("XPathException evaluating \"//label[@for]\"");
+ }
}
}