Skip to content

Commit

Permalink
TIKA-4215 -- avoid loading all the tika resources just to get the ver…
Browse files Browse the repository at this point in the history
…sion (#1672)

(cherry picked from commit 85d713a)
  • Loading branch information
tballison committed Mar 21, 2024
1 parent 49fedc6 commit bf00061
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ private void usage() {
}

private void version() {
System.out.println(new Tika().toString());
System.out.println(Tika.getString());
}

private boolean testForHelp(String[] args) {
Expand Down
4 changes: 4 additions & 0 deletions tika-core/src/main/java/org/apache/tika/Tika.java
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,10 @@ public Translator getTranslator() {
//--------------------------------------------------------------< Object >

public String toString() {
return getString();
}

public static String getString() {
String version = null;

try (InputStream stream = Tika.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static Options getOptions() {
}

public static void main(String[] args) throws Exception {
LOG.info("Starting {} server", new Tika());
LOG.info("Starting {} server", Tika.getString());
try {
Options options = getOptions();
CommandLineParser cliParser = new DefaultParser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
public class TikaResource {

public static final String GREETING =
"This is Tika Server (" + new Tika().toString() + "). Please PUT\n";
"This is Tika Server (" + Tika.getString() + "). Please PUT\n";
private static final String META_PREFIX = "meta_";
private static final Logger LOG = LoggerFactory.getLogger(TikaResource.class);
private static Pattern ALLOWABLE_HEADER_CHARS = Pattern.compile("(?i)^[-/_+\\.A-Z0-9 ]+$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testGetVersion() throws Exception {
WebClient.create(endPoint + VERSION_PATH).type("text/plain").accept("text/plain")
.get();

assertEquals(new Tika().toString(),
assertEquals(Tika.getString(),
getStringFromInputStream((InputStream) response.getEntity()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testGetHTMLWelcome() throws Exception {
.get(String.class);


assertContains(new Tika().toString(), html);
assertContains(Tika.getString(), html);
assertContains("href=\"http", html);

// Check our details were found
Expand All @@ -81,7 +81,7 @@ public void testGetTextWelcome() throws Exception {
.get();

String text = getStringFromInputStream((InputStream) response.getEntity());
assertContains(new Tika().toString(), text);
assertContains(Tika.getString(), text);

// Check our details were found
assertContains("GET " + WELCOME_PATH, text);
Expand Down

0 comments on commit bf00061

Please sign in to comment.