Skip to content

Commit

Permalink
all: add support for 1.20 and 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
tbpg committed May 28, 2019
1 parent 1893828 commit 9cc34a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
20 changes: 12 additions & 8 deletions cmd/tika/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand All @@ -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)
}
}
Expand Down
19 changes: 13 additions & 6 deletions tika/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9cc34a0

Please sign in to comment.