fix(setup): read a file:/// repository from the local file system - #3510
Merged
Merged
Conversation
A server with no route to the Internet cannot reach the Maven repository, so the natural way to install plugins there is to copy the repository onto it and point --repository at the copy. `fess-setup install plugin ... --repository file:///path` instead died with a stack trace from IllegalArgumentException: invalid URI scheme file, because every read went through java.net.http.HttpClient, which only takes http and https and throws an unchecked exception for anything else, which the command line does not catch. Downloader now reads a file: URI from the local file system and treats it the way it treats HTTP: a missing file is what a 404 is, so the optional .sha1 lookup and the "try the next source" logic behave the same, and a directory reads as the index a web server would list for it, so list plugins works against the copy too. The metadata, the jar or theme archive and its checksum all go through Downloader, so resolving a version, installing and verifying the SHA-1 work unchanged. The body copy is shared with the HTTP path, including the .part file and the existing-size check. Any other scheme, or a --repository with no scheme at all, is now refused with a SetupException, which reaches the user as the usual one-line "error: ..." instead of a stack trace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On a server with no route to the Internet, plugins and themes can be installed by copying the Maven repository onto the server and pointing
--repositoryat the copy.fess-setup install plugin ... --repository file:///path/to/repository/org/codelibs/fess/instead fails with a stack trace (IllegalArgumentException: invalid URI scheme file) and exit code 1. Other failures print oneerror: ...line.Cause
Every read in
fess-setupgoes throughDownloader, andDownloaderalways usesjava.net.http.HttpClient. That client only acceptshttpandhttpsand throws an uncheckedIllegalArgumentExceptionfor any other scheme.FessSetup.runcatches onlySetupExceptionandIOException, so the exception reaches the user as a stack trace. A--repositorywith no scheme at all, such as a plain path, fails the same way.Fix
Downloaderreads afile:URI from the local file system and treats it like HTTP:.sha1lookup (readStringIfPresent) and the "try the next source" logic (downloadIfPresent) therefore behave as they do over HTTP.list plugins --repository file:///...works too..partfile and the existing-size check. The HTTP body-writing code was moved into a shared helper for this.maven-metadata.xml, the snapshot build metadata, the plugin jar, the theme archive and itstheme-index.txt, and the published SHA-1 are all read throughDownloader. Version resolution, installation and checksum verification therefore work against afile:repository without other changes.--repositoryalready disables the GitHub download source, so nothing else goes to the network.Downloadernow refuses any scheme other thanhttp,httpsandfile, and any--repositorywith no scheme, with aSetupException. The user gets the usual singleerror: ...line instead of a stack trace. Afile:URI that does not name an absolute local path is reported the same way.The
install pluginhelp mentions that afile:///URL can name a local copy of the repository.Tests
DownloaderTest: reading afile:URL; a missing file failsreadString/downloadand returnsnullfromreadStringIfPresent/downloadIfPresent; a directory is listed as an index; copying reports progress and leaves no.partfile; an unsupported scheme and a URI with no scheme are refused withSetupException.FileRepositoryTest(new) builds a repository layout in a temporary directory (org/codelibs/fess/<artifact>/maven-metadata.xml,<version>/<artifact>-<version>.jarand.jar.sha1) and runsfess-setupagainst it:install plugin fess-ds-git:15.9.0 --repository file:///...installs the jar and verifies its checksum without a warning..sha1fails the install witherror: Checksum mismatch ...and leaves no jar.error:line.--repository ftp://...fails with oneerror:line.maven-metadata.xmlfrom thefile:repository.list pluginslists the plugins in the repository directory and leaves out non-plugin artifacts.Downloaderchange, 14 of these tests fail.mvn test -Dtest='org.codelibs.fess.setup.*Test': 226 tests, all pass.