You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2016/01/11 15:23:20 UTC

svn commit: r1724034 - in /tika/trunk/tika-parsers: pom.xml src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy

Author: tallison
Date: Mon Jan 11 14:23:20 2016
New Revision: 1724034

URL: http://svn.apache.org/viewvc?rev=1724034&view=rev
Log:
Fix for TIKA-1816: Lenient testing for NamedEntityParser contributed by Thamme Gowda <tg...@gmail.com>

Modified:
    tika/trunk/tika-parsers/pom.xml
    tika/trunk/tika-parsers/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy

Modified: tika/trunk/tika-parsers/pom.xml
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/pom.xml?rev=1724034&r1=1724033&r2=1724034&view=diff
==============================================================================
--- tika/trunk/tika-parsers/pom.xml (original)
+++ tika/trunk/tika-parsers/pom.xml Mon Jan 11 14:23:20 2016
@@ -464,18 +464,23 @@
           <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>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>
               <execution>
                 <id>testSetup</id>

Modified: tika/trunk/tika-parsers/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy?rev=1724034&r1=1724033&r2=1724034&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy (original)
+++ tika/trunk/tika-parsers/src/test/resources/org/apache/tika/parser/ner/opennlp/ModelGetter.groovy Mon Jan 11 14:23:20 2016
@@ -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.
@@ -35,6 +54,7 @@ def copyWithProgress(InputStream inStr,
     byte[] buffer = new byte[1024 * 4]
     long count = 0
     int len
+
     long tt = System.currentTimeMillis()
     while ((len = inStr.read(buffer)) > 0) {
         outStr.write(buffer, 0, len)
@@ -45,8 +65,8 @@ def copyWithProgress(InputStream inStr,
         }
     }
     println "Copy complete. "
-    IOUtils.closeQuietly(inStr)
-    IOUtils.closeQuietly(outStr)
+    inStr.close()
+    outStr.close()
 }
 
 /**
@@ -56,20 +76,21 @@ def copyWithProgress(InputStream inStr,
  * @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.."
 }
 
-
 def urlPrefix = "http://opennlp.sourceforge.net/models-1.5"
 def prefixPath = "src/test/resources/org/apache/tika/parser/ner/opennlp/"
 
@@ -90,4 +111,4 @@ for (def entry : modelFiles) {
     if (!file.exists()) {
         downloadFile(entry.value, file)
     }
-}
\ No newline at end of file
+}