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 2017/11/03 19:31:04 UTC
[tika] 02/02: TIKA-2490 and TIKA-2491 -- turn off initializable
problem stderr warnings in tika-app,
confirm that configuration of initializable problems works from an input
file and allow for a tika-config.xml file without specifying a classloader
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 88a5e5179f4104c8e4f8e33a58753efb06fc3139
Author: tballison <ta...@mitre.org>
AuthorDate: Fri Nov 3 15:30:40 2017 -0400
TIKA-2490 and TIKA-2491 -- turn off initializable problem stderr warnings
in tika-app, confirm that configuration of initializable problems
works from an input file and allow for a tika-config.xml file
without specifying a classloader
---
.../src/main/java/org/apache/tika/cli/TikaCLI.java | 2 --
.../test/java/org/apache/tika/cli/TikaCLITest.java | 13 +++++++++++++
.../test-data/TIKA-2389-ignore-init-problems.xml | 20 ++++++++++++++++++++
.../main/java/org/apache/tika/config/TikaConfig.java | 15 +++++++++++----
4 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java b/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
index df68210..7d87ec9 100644
--- a/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
+++ b/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
@@ -188,7 +188,6 @@ public class TikaCLI {
"Aside from the -z option, this is not the default behavior\n"+
"in Tika generally or in tika-server.";
LOG.info(warn);
- System.err.println(warn);
context.set(PDFParserConfig.class, pdfParserConfig);
}
}
@@ -1092,7 +1091,6 @@ public class TikaCLI {
name,
e.getMessage()
);
- System.err.println(msg);
LOG.warn(msg, e);
}
}
diff --git a/tika-app/src/test/java/org/apache/tika/cli/TikaCLITest.java b/tika-app/src/test/java/org/apache/tika/cli/TikaCLITest.java
index 0e084f4..85f14b3 100644
--- a/tika-app/src/test/java/org/apache/tika/cli/TikaCLITest.java
+++ b/tika-app/src/test/java/org/apache/tika/cli/TikaCLITest.java
@@ -29,6 +29,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.tika.exception.TikaException;
import org.junit.After;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -381,6 +382,18 @@ public class TikaCLITest {
}
@Test
+ public void testConfigIgnoreInit() throws Exception {
+ String[] params = new String[]{"--config="+testDataFile.toString()+"/TIKA-2389-ignore-init-problems.xml",
+ resourcePrefix+"test_recursive_embedded.docx"};
+ TikaCLI.main(params);
+ String content = outContent.toString(UTF_8.name());
+ assertTrue(content.contains("embed_1a"));
+ //TODO: add a real unit test that configures logging to a file to test that nothing is
+ //written at the various logging levels
+ }
+
+
+ @Test
public void testJsonRecursiveMetadataParserMetadataOnly() throws Exception {
String[] params = new String[]{"-m", "-J", "-r", resourcePrefix+"test_recursive_embedded.docx"};
TikaCLI.main(params);
diff --git a/tika-app/src/test/resources/test-data/TIKA-2389-ignore-init-problems.xml b/tika-app/src/test/resources/test-data/TIKA-2389-ignore-init-problems.xml
new file mode 100644
index 0000000..30af37d
--- /dev/null
+++ b/tika-app/src/test/resources/test-data/TIKA-2389-ignore-init-problems.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<properties>
+ <service-loader initializableProblemHandler="ignore"/>
+</properties>
diff --git a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
index 9518042..5b1b1ab 100644
--- a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
+++ b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
@@ -71,6 +71,8 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import static org.apache.tika.config.ServiceLoader.getContextClassLoader;
+
/**
* Parse xml config file.
*/
@@ -123,7 +125,7 @@ public class TikaConfig {
public TikaConfig(Path path)
throws TikaException, IOException, SAXException {
- this(path, new ServiceLoader());
+ this(XMLReaderUtils.getDocumentBuilder().parse(path.toFile()));
}
public TikaConfig(Path path, ServiceLoader loader)
throws TikaException, IOException, SAXException {
@@ -132,8 +134,9 @@ public class TikaConfig {
public TikaConfig(File file)
throws TikaException, IOException, SAXException {
- this(file, new ServiceLoader());
+ this(XMLReaderUtils.getDocumentBuilder().parse(file));
}
+
public TikaConfig(File file, ServiceLoader loader)
throws TikaException, IOException, SAXException {
this(XMLReaderUtils.getDocumentBuilder().parse(file), loader);
@@ -241,7 +244,7 @@ public class TikaConfig {
if (config == null) {
this.serviceLoader = new ServiceLoader();
- this.mimeTypes = getDefaultMimeTypes(ServiceLoader.getContextClassLoader());
+ this.mimeTypes = getDefaultMimeTypes(getContextClassLoader());
this.encodingDetector = getDefaultEncodingDetector(serviceLoader);
this.parser = getDefaultParser(mimeTypes, serviceLoader, encodingDetector);
this.detector = getDefaultDetector(mimeTypes, serviceLoader);
@@ -477,6 +480,7 @@ public class TikaConfig {
private static ServiceLoader serviceLoaderFromDomElement(Element element, ClassLoader loader) throws TikaConfigException {
Element serviceLoaderElement = getChild(element, "service-loader");
ServiceLoader serviceLoader;
+
if (serviceLoaderElement != null) {
boolean dynamic = Boolean.parseBoolean(serviceLoaderElement.getAttribute("dynamic"));
LoadErrorHandler loadErrorHandler = LoadErrorHandler.IGNORE;
@@ -486,8 +490,11 @@ public class TikaConfig {
} else if(LoadErrorHandler.THROW.toString().equalsIgnoreCase(loadErrorHandleConfig)) {
loadErrorHandler = LoadErrorHandler.THROW;
}
-
InitializableProblemHandler initializableProblemHandler = getInitializableProblemHandler(serviceLoaderElement.getAttribute("initializableProblemHandler"));
+
+ if (loader == null) {
+ loader = ServiceLoader.getContextClassLoader();
+ }
serviceLoader = new ServiceLoader(loader, loadErrorHandler, initializableProblemHandler, dynamic);
} else if(loader != null) {
serviceLoader = new ServiceLoader(loader);
--
To stop receiving notification emails like this one, please contact
"commits@tika.apache.org" <co...@tika.apache.org>.