From 9cc34a027684a327cd9b2fe9bad85093eec8aac1 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich Date: Tue, 28 May 2019 09:17:24 -0400 Subject: [PATCH] all: add support for 1.20 and 1.21 --- cmd/tika/main.go | 20 ++++++++++++-------- tika/server.go | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cmd/tika/main.go b/cmd/tika/main.go index c59aebd..d1ec8d6 100644 --- a/cmd/tika/main.go +++ b/cmd/tika/main.go @@ -54,7 +54,7 @@ const ( // Command line flags. var ( - downloadVersion = flag.String("download_version", "", "Tika Server JAR version to download. If -serverJAR is specified, it will be downloaded to that location, otherwise it will be downloaded to your working directory. If the JAR has already been downloaded and has the correct MD5, this will do nothing. Valid versions: 1.19.") + downloadVersion = flag.String("download_version", "", fmt.Sprintf("Tika Server JAR version to download. If -serverJAR is specified, it will be downloaded to that location, otherwise it will be downloaded to your working directory. If the JAR has already been downloaded and has the correct MD5, this will do nothing. Valid versions: %v.", tika.Versions)) filename = flag.String("filename", "", "Path to file to parse.") metaField = flag.String("field", "", `Specific field to get when using the "meta" action. Undefined when using the -recursive flag.`) recursive = flag.Bool("recursive", false, `Whether to run "parse" or "meta" recursively, returning a list with one element per embedded document. Undefined when using the -field flag.`) @@ -72,18 +72,22 @@ func main() { action := flag.Arg(0) if *downloadVersion != "" { - v := tika.Version119 - switch *downloadVersion { - case "1.19": - v = tika.Version119 - default: + v := tika.Versions[len(tika.Versions) - 1] + supported := false + for _, sv := range tika.Versions { + if tika.Version(*downloadVersion) == sv { + v = tika.Version(*downloadVersion) + supported = true + break + } + } + if !supported { log.Fatalf("unsupported server version: %q", *downloadVersion) } if *serverJAR == "" { *serverJAR = "tika-server-" + string(v) + ".jar" } - err := tika.DownloadServer(context.Background(), v, *serverJAR) - if err != nil { + if err := tika.DownloadServer(context.Background(), v, *serverJAR); err != nil { log.Fatal(err) } } diff --git a/tika/server.go b/tika/server.go index e33fa6c..2475b76 100644 --- a/tika/server.go +++ b/tika/server.go @@ -137,25 +137,32 @@ func sha512Hash(path string) (string, error) { return fmt.Sprintf("%x", h.Sum(nil)), nil } -// A version represents a Tika Server version. -type version string +// A Version represents a Tika Server version. +type Version string // Supported versions of Tika Server. const ( - Version119 version = "1.19" + Version119 Version = "1.19" + Version120 Version = "1.20" + Version121 Version = "1.21" ) -var sha512s = map[version]string{ +// Versions is a list of supported versions of Apache Tika. +var Versions = []Version{Version119, Version120, Version121} + +var sha512s = map[Version]string{ Version119: "a9e2b6186cdb9872466d3eda791d0e1cd059da923035940d4b51bb1adc4a356670fde46995725844a2dd500a09f3a5631d0ca5fbc2d61a59e8e0bd95c9dfa6c2", + Version120: "a7ef35317aba76be8606f9250893efece8b93384e835a18399da18a095b19a15af591e3997828d4ebd3023f21d5efad62a91918610c44e692cfd9bed01d68382", + Version121: "e705c836b2110530c8d363d05da27f65c4f6c9051b660cefdae0e5113c365dbabed2aa1e4171c8e52dbe4cbaa085e3d8a01a5a731e344942c519b85836da646c", } // DownloadServer downloads and validates the given server version, // saving it at path. DownloadServer returns an error if it could -// not be downloaded/validated. Valid values for the version are 1.19. +// not be downloaded/validated. // It is the caller's responsibility to remove the file when no longer needed. // If the file already exists and has the correct sha512, DownloadServer will // do nothing. -func DownloadServer(ctx context.Context, v version, path string) error { +func DownloadServer(ctx context.Context, v Version, path string) error { hash := sha512s[v] if hash == "" { return fmt.Errorf("unsupported Tika version: %s", v)