Repository: tika Updated Branches: refs/heads/2.x 1d53ff4cf -> c342d3407
Copy Proxy download fix to 2.x Project: http://git-wip-us.apache.org/repos/asf/tika/repo Commit: http://git-wip-us.apache.org/repos/asf/tika/commit/c4feaff1 Tree: http://git-wip-us.apache.org/repos/asf/tika/tree/c4feaff1 Diff: http://git-wip-us.apache.org/repos/asf/tika/diff/c4feaff1 Branch: refs/heads/2.x Commit: c4feaff19187f548730f48a77fc437ca12bb40b4 Parents: f1e4ebd Author: Thamme Gowda <[email protected]> Authored: Wed Mar 2 01:12:26 2016 -0800 Committer: Thamme Gowda <[email protected]> Committed: Wed Mar 2 01:12:26 2016 -0800 ---------------------------------------------------------------------- tika-test-resources/pom.xml | 22 ++++++------ .../tika/parser/ner/opennlp/ModelGetter.groovy | 35 ++++++++++++++++---- 2 files changed, 38 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tika/blob/c4feaff1/tika-test-resources/pom.xml ---------------------------------------------------------------------- diff --git a/tika-test-resources/pom.xml b/tika-test-resources/pom.xml index 5df07f4..a39fc62 100644 --- a/tika-test-resources/pom.xml +++ b/tika-test-resources/pom.xml @@ -34,23 +34,21 @@ <missing>${basedir}/src/test/resources/org/apache/tika/parser/ner/opennlp/ner-person.bin</missing> </file> </activation> - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-model</artifactId> - <version>3.3.3</version> - </dependency> - </dependencies> <build> <plugins> <plugin> - <groupId>org.codehaus.groovy.maven</groupId> - <artifactId>gmaven-plugin</artifactId> + <groupId>org.codehaus.gmaven</groupId> + <artifactId>groovy-maven-plugin</artifactId> <dependencies> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.4</version> + <groupId>org.apache.maven</groupId> + <artifactId>maven-model</artifactId> + <version>3.3.3</version> + </dependency> + <dependency> + <groupId>org.codehaus.groovy</groupId> + <artifactId>groovy-all</artifactId> + <version>2.4.4</version> </dependency> </dependencies> <executions> http://git-wip-us.apache.org/repos/asf/tika/blob/c4feaff1/tika-test-resources/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy ---------------------------------------------------------------------- diff --git a/tika-test-resources/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy b/tika-test-resources/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy index 3b61f20..3b9fd0d 100644 --- a/tika-test-resources/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy +++ b/tika-test-resources/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy @@ -20,7 +20,26 @@ * This file downloads Apache OpenNLP NER models for testing the NamedEntityParser */ -import org.apache.commons.io.IOUtils +import org.apache.maven.settings.Proxy as MvnProxy +import java.net.Proxy as JDKProxy +import groovy.transform.Field + +//BEGIN: Global context ; ${settings} is injected by the plugin +List<MvnProxy> mvnProxies = settings.getProxies()?.findAll{it.isActive()} +@Field JDKProxy proxy = null +if (mvnProxies && mvnProxies.size() > 0) { + mvnProxy = mvnProxies.get(0) + println "Using the first Proxy setting : ${mvnProxy.username}@ ${mvnProxy.host} : ${mvnProxy.port} " + proxy = new JDKProxy(JDKProxy.Type.HTTP, new InetSocketAddress(mvnProxy.host, mvnProxy.port)) + Authenticator.setDefault(new Authenticator(){ + @Override + protected PasswordAuthentication getPasswordAuthentication(){ + return new PasswordAuthentication(mvnProxy.username, mvnProxy.password?.toCharArray()) + } + }) + println "Proxy is configured" +} +//END : Global Context /** * Copies input stream to output stream, additionally printing the progress. @@ -45,8 +64,8 @@ def copyWithProgress(InputStream inStr, OutputStream outStr, long totalLength){ } } println "Copy complete. " - IOUtils.closeQuietly(inStr) - IOUtils.closeQuietly(outStr) + inStr.close() + outStr.close() } /** @@ -56,16 +75,18 @@ def copyWithProgress(InputStream inStr, OutputStream outStr, long totalLength){ * @return */ def downloadFile(String urlStr, File file) { - println "GET : $urlStr -> $file" - urlConn = new URL(urlStr).openConnection() + println "GET : $urlStr -> $file (Using proxy? ${proxy != null})" + url = new URL(urlStr) + + urlConn = proxy ? url.openConnection(proxy) : url.openConnection() contentLength = urlConn.getContentLengthLong() file.getParentFile().mkdirs() inStream = urlConn.getInputStream() outStream = new FileOutputStream(file) copyWithProgress(inStream, outStream, contentLength) - IOUtils.closeQuietly(outStream) - IOUtils.closeQuietly(inStream) + outStream.close() + inStream.close() println "Download Complete.." }
