diff --git a/conf/ivysettings.xml b/conf/ivysettings.xml
new file mode 100644
index 000000000000..bda842a89bb0
--- /dev/null
+++ b/conf/ivysettings.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/itests/pom.xml b/itests/pom.xml
index fd4bb41fd8f7..6f6cf742c41a 100644
--- a/itests/pom.xml
+++ b/itests/pom.xml
@@ -93,6 +93,9 @@
mkdir -p $DOWNLOAD_DIR
download "http://d3jw87u4immizc.cloudfront.net/spark-tarball/spark-${spark.version}-bin-hadoop2-without-hive.tgz" "spark"
cp -f $HIVE_ROOT/data/conf/spark/log4j.properties $BASE_DIR/spark/conf/
+ sed '/package /d' ${basedir}/${hive.path.to.root}/contrib/src/java/org/apache/hadoop/hive/contrib/udf/example/UDFExampleAdd.java > /tmp/UDFExampleAdd.java
+ javac -cp ${settings.localRepository}/org/apache/hive/hive-exec/${project.version}/hive-exec-${project.version}.jar /tmp/UDFExampleAdd.java -d /tmp
+ jar -cf /tmp/udfexampleadd-1.0.jar -C /tmp UDFExampleAdd.class
diff --git a/packaging/src/main/assembly/bin.xml b/packaging/src/main/assembly/bin.xml
index 260d8a3c50f6..2cda6233337d 100644
--- a/packaging/src/main/assembly/bin.xml
+++ b/packaging/src/main/assembly/bin.xml
@@ -146,6 +146,7 @@
${project.parent.basedir}/conf
*.template
+ ivysettings.xml
conf
diff --git a/pom.xml b/pom.xml
index 5123996ea0f7..a9a901ee3ab0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,6 +126,7 @@
4.2.5
4.2.5
+ 2.4.0
1.9.2
0.3.2
5.5.1
diff --git a/ql/pom.xml b/ql/pom.xml
index 9a4e6ca0d8d0..cfcc171b48e0 100644
--- a/ql/pom.xml
+++ b/ql/pom.xml
@@ -162,6 +162,11 @@
libfb303
${libfb303.version}
+
+ org.apache.ivy
+ ivy
+ ${ivy.version}
+
org.apache.thrift
libthrift
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/session/DependencyResolver.java b/ql/src/java/org/apache/hadoop/hive/ql/session/DependencyResolver.java
new file mode 100644
index 000000000000..27bf3e46291e
--- /dev/null
+++ b/ql/src/java/org/apache/hadoop/hive/ql/session/DependencyResolver.java
@@ -0,0 +1,179 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.session;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.io.File;
+import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
+import groovy.grape.Grape;
+import groovy.grape.GrapeIvy;
+import groovy.lang.GroovyClassLoader;
+
+
+public class DependencyResolver {
+
+ private static final String HIVE_HOME = "HIVE_HOME";
+ private static final String HIVE_CONF_DIR = "HIVE_CONF_DIR";
+ private String ivysettingsPath;
+ private static LogHelper _console = new LogHelper(LogFactory.getLog("DependencyResolver"));
+
+ public DependencyResolver() {
+
+ // Check if HIVE_CONF_DIR is defined
+ if (System.getenv().containsKey(HIVE_CONF_DIR)) {
+ ivysettingsPath = System.getenv().get(HIVE_CONF_DIR) + "/ivysettings.xml";
+ }
+
+ // If HIVE_CONF_DIR is not defined or file is not found in HIVE_CONF_DIR then check HIVE_HOME/conf
+ if (ivysettingsPath == null || !(new File(ivysettingsPath).exists())) {
+ if (System.getenv().containsKey(HIVE_HOME)) {
+ ivysettingsPath = System.getenv().get(HIVE_HOME) + "/conf/ivysettings.xml";
+ }
+ }
+
+ // If HIVE_HOME is not defined or file is not found in HIVE_HOME/conf then load default ivysettings.xml from class loader
+ if (ivysettingsPath == null || !(new File(ivysettingsPath).exists())) {
+ ivysettingsPath = ClassLoader.getSystemResource("ivysettings.xml").getFile();
+ _console.printInfo("ivysettings.xml file not found in HIVE_HOME or HIVE_CONF_DIR," + ivysettingsPath + " will be used");
+ }
+
+ }
+
+ /**
+ *
+ * @param uri
+ * @return List of URIs of downloaded jars
+ * @throws URISyntaxException
+ * @throws IOException
+ */
+ public List downloadDependencies(URI uri) throws URISyntaxException, IOException {
+ Map dependencyMap = new HashMap();
+ String authority = uri.getAuthority();
+ if (authority == null) {
+ throw new URISyntaxException(authority, "Invalid url: Expected 'org:module:version', found null");
+ }
+ String[] authorityTokens = authority.toLowerCase().split(":");
+
+ if (authorityTokens.length != 3) {
+ throw new URISyntaxException(authority, "Invalid url: Expected 'org:module:version', found " + authority);
+ }
+
+ dependencyMap.put("org", authorityTokens[0]);
+ dependencyMap.put("module", authorityTokens[1]);
+ dependencyMap.put("version", authorityTokens[2]);
+ Map queryMap = parseQueryString(uri.getQuery());
+ if (queryMap != null) {
+ dependencyMap.putAll(queryMap);
+ }
+ return grab(dependencyMap);
+ }
+
+ /**
+ * @param queryString
+ * @return queryMap Map which contains grape parameters such as transitive, exclude, ext and classifier.
+ * Example: Input: ext=jar&exclude=org.mortbay.jetty:jetty&transitive=true
+ * Output: {[ext]:[jar], [exclude]:{[group]:[org.mortbay.jetty], [module]:[jetty]}, [transitive]:[true]}
+ * @throws URISyntaxException
+ */
+ private Map parseQueryString(String queryString) throws URISyntaxException {
+ if (queryString == null || queryString.isEmpty()) {
+ return null;
+ }
+ List