This is an automated email from the ASF dual-hosted git repository.
tballison pushed a commit to branch branch_3x
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/branch_3x by this push:
new e6ec38434c TIKA-4986: keep ISArchiveParser directory and study name
per parse; deprecate ISArchiveParser(String location) (backport of #3374)
(#3397)
e6ec38434c is described below
commit e6ec38434cb5f3ed615758103e4c648434f4b5fe
Author: Tim Allison <[email protected]>
AuthorDate: Thu Oct 22 16:11:27 2026 -0400
TIKA-4986: keep ISArchiveParser directory and study name per parse;
deprecate ISArchiveParser(String location) (backport of #3374) (#3397)
---
CHANGES.txt | 8 ++++++
.../apache/tika/parser/isatab/ISArchiveParser.java | 32 +++++++++++++---------
.../tika/parser/isatab/ISArchiveParserTest.java | 29 ++++++++++++++++++++
3 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 13d44cd96c..4a2e918629 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,13 @@
Release 3.4.0 - ???
+ * ISArchiveParser resolves the ISA-Tab directory on each parse instead of
reading every
+ later document's investigation and assay files from the first document's
directory,
+ and concurrent parses no longer share the study file name (TIKA-4986).
+
+ * ISArchiveParser(String location) is deprecated and removed in 4.x: the
ISA-Tab
+ directory is always the parent directory of the study file, so pass a
file-backed
+ TikaInputStream (TikaInputStream.get(Path)) (TIKA-4986).
+
* The file-system emitter can gzip its output (param "compression": "gzip"),
and tika-eval
finds gzipped extracts (.json.gz) when comparing against a plain extract
set, measuring
their extract lengths and min/max length limits on uncompressed size
(TIKA-4989).
diff --git
a/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/main/java/org/apache/tika/parser/isatab/ISArchiveParser.java
b/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/main/java/org/apache/tika/parser/isatab/ISArchiveParser.java
index 197c6c27fa..810ac89767 100644
---
a/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/main/java/org/apache/tika/parser/isatab/ISArchiveParser.java
+++
b/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/main/java/org/apache/tika/parser/isatab/ISArchiveParser.java
@@ -45,9 +45,7 @@ public class ISArchiveParser implements Parser {
private static String studyAssayFileNameField = "Study Assay File Name";
private final Set<MediaType> SUPPORTED_TYPES =
Collections.singleton(MediaType.application("x-isatab"));
- private String location = null;
-
- private String studyFileName = null;
+ private final String location;
/**
* Default constructor.
@@ -60,7 +58,11 @@ public class ISArchiveParser implements Parser {
* Constructor that accepts the pathname of ISArchive folder.
*
* @param location pathname of ISArchive folder including ISA-Tab files
+ * @deprecated the ISA-Tab directory is the study file's parent directory;
use the
+ * default constructor and pass a file-backed TikaInputStream
(TikaInputStream.get(Path)).
+ * This constructor is removed in 4.x.
*/
+ @Deprecated
public ISArchiveParser(String location) {
if (location != null && !location.endsWith(File.separator)) {
location += File.separator;
@@ -82,10 +84,12 @@ public class ISArchiveParser implements Parser {
TikaInputStream tis = TikaInputStream.get(stream, tmp, metadata);
try {
- if (this.location == null) {
- this.location = tis.getFile().getParent() + File.separator;
+ // the parser is shared across parses: resolve the directory per
document
+ String location = this.location;
+ if (location == null) {
+ location = tis.getFile().getParent() + File.separator;
}
- this.studyFileName = tis.getFile().getName();
+ String studyFileName = tis.getFile().getName();
File locationFile = new File(location);
String[] investigationList = locationFile.list((dir, name) ->
name.matches("i_.+\\.txt"));
@@ -93,9 +97,9 @@ public class ISArchiveParser implements Parser {
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler,
metadata);
xhtml.startDocument();
- parseInvestigation(investigationList, xhtml, metadata, context);
+ parseInvestigation(location, studyFileName, investigationList,
xhtml, metadata, context);
parseStudy(stream, xhtml, metadata, context);
- parseAssay(xhtml, metadata, context);
+ parseAssay(location, xhtml, metadata, context);
xhtml.endDocument();
} finally {
@@ -105,7 +109,8 @@ public class ISArchiveParser implements Parser {
}
}
- private void parseInvestigation(String[] investigationList,
XHTMLContentHandler xhtml,
+ private void parseInvestigation(String location, String studyFileName,
+ String[] investigationList,
XHTMLContentHandler xhtml,
Metadata metadata, ParseContext context)
throws IOException, SAXException, TikaException {
if ((investigationList == null) || (investigationList.length == 0)) {
@@ -118,8 +123,8 @@ public class ISArchiveParser implements Parser {
}
String investigation = investigationList[0]; // TODO add to metadata?
- try (InputStream stream = TikaInputStream.get(new File(this.location +
investigation).toPath())) {
- ISATabUtils.parseInvestigation(stream, xhtml, metadata, context,
this.studyFileName);
+ try (InputStream stream = TikaInputStream.get(new File(location +
investigation).toPath())) {
+ ISATabUtils.parseInvestigation(stream, xhtml, metadata, context,
studyFileName);
}
xhtml.element("h1", "INVESTIGATION " + metadata.get("Investigation
Identifier"));
}
@@ -131,12 +136,13 @@ public class ISArchiveParser implements Parser {
ISATabUtils.parseStudy(stream, xhtml, metadata, context);
}
- private void parseAssay(XHTMLContentHandler xhtml, Metadata metadata,
ParseContext context)
+ private void parseAssay(String location, XHTMLContentHandler xhtml,
Metadata metadata,
+ ParseContext context)
throws IOException, SAXException, TikaException {
// location starts with "/C:" on windows, so build the directory Path
from a File
// rather than Paths.get(). The assay file names come from the
investigation file and
// are resolved within this directory.
- Path locationDir = new File(this.location).toPath();
+ Path locationDir = new File(location).toPath();
for (String assayFileName :
metadata.getValues(studyAssayFileNameField)) {
xhtml.startElement("div");
xhtml.element("h3", "ASSAY " + assayFileName);
diff --git
a/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/test/java/org/apache/tika/parser/isatab/ISArchiveParserTest.java
b/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/test/java/org/apache/tika/parser/isatab/ISArchiveParserTest.java
index 884754a5bf..d890c13c3b 100644
---
a/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/test/java/org/apache/tika/parser/isatab/ISArchiveParserTest.java
+++
b/tika-parsers/tika-parsers-extended/tika-parser-scientific-module/src/test/java/org/apache/tika/parser/isatab/ISArchiveParserTest.java
@@ -106,4 +106,33 @@ public class ISArchiveParserTest {
assertFalse(handler.toString().contains("OUTSIDE_DIRECTORY_CONTENT"),
"assay reader read a file outside the ISA-Tab directory");
}
+
+ @Test
+ public void testDirectoryNotCachedAcrossParses(@TempDir Path root) throws
Exception {
+ Parser parser = new ISArchiveParser();
+ assertEquals("FIRST", parseInvestigationId(parser, writeArchive(root,
"first", "FIRST")));
+ assertEquals("SECOND", parseInvestigationId(parser, writeArchive(root,
"second", "SECOND")));
+ }
+
+ private static Path writeArchive(Path root, String dirName, String
investigationId)
+ throws IOException {
+ Path isaDir = Files.createDirectory(root.resolve(dirName));
+ Files.write(isaDir.resolve("i_test.txt"),
+ ("INVESTIGATION\n"
+ + "Investigation Identifier\t\"" + investigationId +
"\"\n"
+ + "STUDY\n"
+ + "Study File Name\t\"s_test.txt\"\n")
+ .getBytes(StandardCharsets.UTF_8));
+ Path study = isaDir.resolve("s_test.txt");
+ Files.write(study, "\"Source
Name\"\n\"culture1\"\n".getBytes(StandardCharsets.UTF_8));
+ return study;
+ }
+
+ private static String parseInvestigationId(Parser parser, Path study)
throws Exception {
+ Metadata metadata = new Metadata();
+ try (TikaInputStream tis = TikaInputStream.get(study)) {
+ parser.parse(tis, new BodyContentHandler(), metadata, new
ParseContext());
+ }
+ return metadata.get("Investigation Identifier");
+ }
}