Commit Graph

65 Commits

Author SHA1 Message Date
David Pursehouse decb6d01cc Remove unused clirr-maven-plugin from LFS pom.xml files
Change-Id: I7252b6c89d91ac675c0e02e4d17ba0212b617098
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-05-12 08:30:45 +09:00
David Pursehouse c80d8c5901 Bazel: Restrict src globs to Java source files
Generating the src list with an unrestricted wildcard causes all
files in the source tree to be included. This results in junk files
such as .orig (generated during merge conflict resolution) to be
included, which causes in a build error:

  in srcs attribute of java_library rule //org.eclipse.jgit:jgit:
  file '//org.eclipse.jgit:src/org/eclipse/jgit/gitrepo/RepoCommand.java.orig'
  is misplaced here (expected .java, .srcjar or .properties).

Modify the globs to only include Java source files.

Change-Id: Iaef3db33ac71d71047cd28acb0378e15cb09ece9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-04-13 14:14:55 +09:00
Matthias Sohn b3cc05d886 Remove unused API filters
Change-Id: I1e00d71395228265aad4071b023024ee1bf855d5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-04-09 23:43:43 +02:00
Matthias Sohn aec22e74cf Prepare 4.8.0-SNAPSHOT builds
Change-Id: Ifea6750e79d417a8a2a891b3b5f96d68c7200011
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-04-05 14:49:49 +02:00
David Pursehouse 2d0ce094b4 Remove Buck build
Buck will be replaced with Bazel

Change-Id: I3cf07d7aaaa2a58bac34e16c50af5416693254ac
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-03-22 01:41:21 +01:00
Jonathan Nieder bc5014faec bazel: Add explicit targets for library dependencies
This provides a place to declare visibility restrictions and
transitive dependencies for each library.

Other targets should only declare dependencies on what they directly
use, making dependencies easier to maintain.

Trim the dependencies of org.eclipse.jgit:jgit to follow that rule.
It declares dependencies on Apache httpcomponents and the servlet
API but doesn't use them.

Tested:
* 'bazel build //...' succeeds
* applying the change https://gerrit-review.googlesource.com/90843
  to a copy of Gerrit, following the instructions there, and running
  'bazel test //...' in that copy of Gerrit still succeeds

Change-Id: I3ab958ce8b3227019cdbe4cc81e0f042e1541034
2017-03-19 18:51:03 -07:00
Matthias Sohn 3df65a387e Silence API error reported in LfsProtocolServlet
Breaking API for API implementors (not clients) in a minor release is ok
following OSGi semantic versioning rules.

Change-Id: I14bb4a3084b237b4cd893a130e148148cd1e5df9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-03-09 20:43:12 +01:00
David Pursehouse 5094c1a5c8 LfsProtocolServlet: Pass HTTP Authorization header to getLargeFileRepository
This allows implementations to reject operations that do not
include proper authentication.

Change-Id: If301476d8fb56a0899e424be3789c7576097d185
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-03-08 19:11:03 -04:00
David Pursehouse 3b4448637f Enable and fix warnings about redundant specification of type arguments
Since the introduction of generic type parameter inference in Java 7,
it's not necessary to explicitly specify the type of generic parameters.

Enable the warning in Eclipse, and fix all occurrences.

Change-Id: I9158caf1beca5e4980b6240ac401f3868520aad0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-02-20 22:47:23 +01:00
David Pursehouse 7ac182f4e4 Enable and fix 'Should be tagged with @Override' warning
Set missingOverrideAnnotation=warning in Eclipse compiler preferences
which enables the warning:

  The method <method> of type <type> should be tagged with @Override
  since it actually overrides a superclass method

Justification for this warning is described in:

  http://stackoverflow.com/a/94411/381622

Enabling this causes in excess of 1000 warnings across the entire
code-base. They are very easy to fix automatically with Eclipse's
"Quick Fix" tool.

Fix all of them except 2 which cause compilation failure when the
project is built with mvn; add TODO comments on those for further
investigation.

Change-Id: I5772061041fd361fe93137fd8b0ad356e748a29c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-02-19 20:05:08 -04:00
Matthias Sohn a4feeb0194 Don't rely on default locale when using toUpperCase() and toLowerCase()
Otherwise these methods may produce unexpected results if used for
strings that are intended to be interpreted locale independently.
Examples are programming language identifiers, protocol keys, and HTML
tags. For instance, "TITLE".toLowerCase() in a Turkish locale returns
"t\u0131tle", where '\u0131' is the LATIN SMALL LETTER DOTLESS I
character.

See
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toLowerCase--
http://blog.thetaphi.de/2012/07/default-locales-default-charsets-and.html

Bug: 511238
Change-Id: Id8d8f37d84d62239c918b81f8d883ed798d87656
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-28 15:06:15 +01:00
David Pursehouse 9d1474431f Implement Bazel build for http-apache, lfs, lfs-server
Test plan:

  $ bazel build all

  $ unzip -t bazel-genfiles/all.zip
    Archive:  bazel-genfiles/all.zip
      testing: libhttp-apache.jar       OK
      testing: libjgit-archive.jar      OK
      testing: libjgit-lfs-server.jar   OK
      testing: libjgit-lfs.jar          OK
      testing: libjgit-servlet.jar      OK
      testing: libjgit.jar              OK
      testing: libjunit.jar             OK
    No errors detected in compressed data of bazel-genfiles/all.zip.

Change-Id: I9e6c60898ccc6d2a4557ec7544c297442a9702b4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-22 22:34:12 +01:00
David Pursehouse d3148f300a Make ObjectDownloadListener public
The same was already done for ObjectUploadListener in I5b0fb1220.

Change-Id: Ie8a79f715fe69bed9331962fb478f7e35acf8680
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-19 13:42:59 +09:00
Zhen Chen d3148f9410 Add missing slf4j dependency in BUCK file for jgit-lfs-server
Change-Id: I0c7fcae123f94ebd8e5eb2700e3d601a1b199be9
Signed-off-by: Zhen Chen <czhen@google.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-14 15:49:14 +09:00
David Pursehouse 55c629a9f3 LfsProtocolServlet#LfsRequest: Add operation type helper methods
Server implementations may need to check what type of operation is
being performed. Add helper methods to make it a bit simpler.

Change-Id: Ia33ed6699ebcb9000ef514ce79bcddbebf94e1c5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-14 01:07:52 +01:00
David Pursehouse 56fe217784 Expose LFS operation strings as public constants
So that they can be used either by third party LFS server implementations
or from within other parts of JGit's internal LFS implementation.

Change-Id: I58da6230247204588e017c010ce5b14e4615448d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-13 19:23:33 -04:00
David Pursehouse 590141163f LfsProtocolServlet: Improve error on getLargeFileRepository failure
Externalize the error message and make it more specific. Also emit
an error log.

Change-Id: Ie7b1c90c54673bfb8e133fb0aa19a117d4ca6587
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-14 00:05:56 +01:00
David Pursehouse 7245aa0316 Add support for refusing LFS request due to invalid authorization
Add a new exception type that server implementations can throw when a
client attempts to make an unauthorized LFS operation, which will result
in HTTP 401 Unauthorized being returned to the client.

An example of this is a Gerrit server that rejects a request to perform
an LFS operation on a ref that is not visible to the caller.

As defined in the LFS spec [1] the request may include authentication,
and per RFC 2616 [2], "401 response indicates that authorization has been
refused for those credentials".

[1] https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
[2] https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Change-Id: I2aa22e2144df5fb7972df0e3285b77b08ecc63f2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-13 10:46:15 +09:00
Matthias Sohn 44936a1216 Remove unused API warning filters
Change-Id: If6d343a55245219a652e35c9cfde69349dc09889
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-12-29 00:59:02 +01:00
Matthias Sohn 5fee071f6a Prepare 4.7.0-SNAPSHOT builds
Change-Id: I20754d13007e6591d36aae5766f3a9a82b24e120
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-12-27 01:45:50 +01:00
Matthias Sohn 3857c3168f Prepare 4.6.1-SNAPSHOT builds
Change-Id: I6b05a6f6c3f92365c272e1bdaf76093ca01f2d58
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-12-24 15:51:54 +01:00
Matthias Sohn 73a4325149 JGit v4.6.0.201612231935-r
Change-Id: Iaa88fe1b195dfe6be99a7b4cb064684e75563715
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-12-24 01:42:38 +01:00
Jacek Centkowski c7d8fbfaad Expose getObjectToTransfer method of FileLfsServlet
Providing own implementation to doGet/doPut methods is troublesome when
this method is private.

Change-Id: I098cdc5cb90410eaaebc56c88c2d9e168584dd6d
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-12-06 16:57:16 +09:00
David Pursehouse c62933bf59 Merge branch 'stable-4.5'
* stable-4.5:
  Use the same variable to check and extract LFS object id

Change-Id: I314bd4373f40843c68853b3999f60d85e08628d9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-12-06 16:55:28 +09:00
Jacek Centkowski 8f60297861 Use the same variable to check and extract LFS object id
It is easier to maintain when the same variable is used for both check
and extraction of LFS object id.

Change-Id: I5406f9bc4a085aa164c4565a9667ad2925105190
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
2016-11-24 11:32:48 +01:00
Matthias Sohn 52fa09c8d4 Add missing @since tags for new API
Change-Id: Iaf83f66637d6a13e4a6d096ba8529553af7e30ed
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-11-14 16:10:40 -08:00
David Pursehouse a45cfee7a3 Organize imports
Change-Id: I7c545d06b1bced678c020fab9af1382bc4416b6e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-11-14 13:25:20 -08:00
David Pursehouse f5a40c26ac FileLfsServlet: Make sendError protected
Change-Id: Id89b3cd0da86a535946feb15254737bbf8d855d4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-11-13 14:31:17 -08:00
David Pursehouse dfa6895687 Make ObjectUploadListener public
Change-Id: I5b0fb1220bc0e5c660f1b5373abc5868d985c60b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-11-13 14:31:17 -08:00
Matthias Sohn cb617e7ffc Prepare 4.5.1-SNAPSHOT builds
Change-Id: I3305e8a09a3fb06f25a316cff2bdbb551d3ade68
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-09-21 17:05:27 +02:00
Matthias Sohn e7142a3937 JGit v4.5.0.201609210915-r
Change-Id: Idc02a1a1d74f84605d764c239803f0cfbad94eb7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-09-21 15:06:18 +02:00
Matthias Sohn ab79ce91c1 Change JGit minimum execution environment to JavaSE-1.8
Bug: 500059
Change-Id: I47f3f6749a67da52029f84e002d9b155ed56d2b7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-09-20 11:32:36 +02:00
Christian Halstrick e4e39a6d05 Move AtomicObjectOutputStream to lfs/internal
The class AtomicObjectOutputStream should be available to all lfs
related classes, not only to the server side. Move the class from
org.eclipse.jgit.lfs.server.fs to org.eclipse.jgit.lfs.internal to
achieve that.

Change-Id: I028e1c9ec7c21f316340b21d558b9a6b77e2060d
2016-09-20 10:58:20 +02:00
Matthias Sohn 9d4ffcc1ab Prepare 4.6.0-SNAPSHOT builds
Change-Id: Id2eafc331ee32c332c2a9b867b05c260beb0d10f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-09-19 17:06:42 +02:00
Matthias Sohn 5a4dcceb7b Improve JavaDoc for LfsProtocolServlet.getLargeFileRepository
Guide implementors which exception to throw in case of errors.

Change-Id: I74fb76cdf6b7cdef513f3fe8c144572e869cc533
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-09-01 16:57:45 -04:00
David Pursehouse d52bf2eee0 Add specific exception for LFS unavailable
Instead of returning null, LfsProtocolServlet#getLargeFileRepository
should throw LfsUnavailable.

If null is returned, throw a generic LfsException.

Handle LfsException as an internal server error and return HTTP 500.

Change-Id: I33e2a19fcc0fde8aaf0f703860c8fa8ce2de2db5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-30 20:51:02 +02:00
David Pursehouse ffbe03aa9b LfsProtocolServlet: Add support for insufficient storage error
Since [1], the git-lfs specification allows the server to return
HTTP 507 if there is insufficient storage for the uploaded object(s).

Add a new exception class, which implementations may throw from the
getRepository() method, causing HTTP 507 to be returned to the client.

[1] https://github.com/github/git-lfs/pull/1473

Change-Id: If5bc0a35fcf870d4216af6ca2f7c8924689ef9c5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-24 21:29:32 -04:00
David Pursehouse 1096652e71 LfsProtocolServlet: Add support for rate limit and bandwidth limit errors
The git-lfs specification [1] describes the following optional status codes
that may be returned:

429 - The user has hit a rate limit with the server. Though the API does
      not specify any rate limits, implementors are encouraged to set some
      for availability reasons.

509 - Returned if the bandwidth limit for the user or repository has been
      exceeded. The API does not specify any bandwidth limit, but implementors
      may track usage.

Add two new exception classes to represent these cases. Implementations may
throw these from #getLargeFileRepository(), causing the corresponding HTTP
status codes to be returned to the client.

[1] https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md

Change-Id: I7b93f3cf90f7344c90b1587e07927fdeb167097e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-20 11:26:06 +09:00
David Pursehouse de89b7d040 LfsProtocolServlet: Always include message in error response
If the message is not sent, the client shows:

  Unable to parse HTTP response for POST http://admin@localhost:8080/test-project/info/lfs/objects/batch

Change-Id: I8b72d1aded2bcd41b7389676e2373034625a1379
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-20 11:26:06 +09:00
David Pursehouse 0b4751e805 LfsProtocolServlet: Always set the Content-Type header on response
If the Content-Type is not set on error responses, the git-lfs client
does not read the body which contains the error message, and instead
just displays a generic error message.

Also set the charset on the Content-Type header.

Change-Id: I88e6f07f20b622a670e7c5063145dffb8b630aee
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-16 11:01:20 +09:00
David Pursehouse 59b96549a6 LfsProtocolServlet: Don't set pretty printing on Gson
Pretty printing is only used for outputting json content, which is
interpreted by the client and does not need to be pretty printed.

Change-Id: I48e0280241b6b0f5706300ae0f4c9bc461a89110
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-16 11:00:54 +09:00
David Pursehouse 4651d6e723 LfsProtocolServlet: Reuse existing Writer when sending error response
Trying to open a new writer on the response causes an illegal state
exception and the response is not sent.

Change-Id: Ic718d23cfb3e74f5691cc2aea7283003af7df207
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-09 11:10:39 +09:00
Matthias Sohn 6ccc7992d4 Silence API errors in LfsProtocolServlet
bb9988c2 changed the signature of getLargeFileRepository() which is only
breaking implementors which is ok according to OSGi semantic versioning
rules.

Change-Id: I68bda7900b72e217571f74aee53705167f8100a2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-08-09 00:45:30 +02:00
Matthias Sohn ae779f60b7 Add missing @since tags for new API
Change-Id: I8db29a0313fbc476152cef47f2eaa76954f1e280
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-08-09 00:45:30 +02:00
David Pursehouse 584035a5fb LfsProtocolServlet: Allow access to objects in request
Classes implementing the LFS servlet should be able to inspect the
objects given in the request.

Add a getObjects method. Make the LfsObject class public, and add
accessor methods.

Change-Id: I27961679f620eb3a89dc8521aadd4ea2f936c60e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-05 11:22:27 +09:00
David Pursehouse 571c9f5fd6 LfsProtocolServlet: Allow getLargeFileRepository to raise exceptions
According to the specification [1] the server may return the following
HTTP error responses:

- 403: The user has read, but not write access.
- 404: The repository does not exist for the user.
- 422: Validation error with one or more of the objects in the request.

In the current implementation, however, getLargeFileRepository can only
return null to indicate an error. This results in the error code:

- 503: Service Unavailable

being returned to the client regardless of what the actual reason was.

Add exception classes to cover these cases, derived from a common base
exception, and change the specification of getLargeFileRepository to throw
the base exception.

In LfsProtocolServlet#post, handle the new exceptions and send back the
appropriate HTTP responses as mentioned above.

The specification also mentions several other optional response codes (406,
429, 501, and 509) but these are not implemented in this commit. It should
be trivial to implement them in follow-up commits.

[1] https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md#response-errors

Change-Id: I91be6165bcaf856d0cefc533882330962e2fc9b2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-08-05 11:22:27 +09:00
David Pursehouse f703a5eb2c Fix typo in email address in copyright headers
Change-Id: Ib7b73d7d37574682bb58f969822c842e4e579233
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-07-28 16:05:22 +09:00
David Pursehouse bb9988c236 LfsProtocolServlet: Pass request and path to getLargeFileRepository
Passing the request and path to the method will allow implementations
to have more control over determination of the backend, for example:

- return different backends for different requests
- accept or refuse requests based on request characteristics
- etc

Change-Id: I1ec6ec54c91a5f0601b620ed18846eb4a3f46783
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-07-27 15:54:03 +09:00
David Pursehouse e27eab26e2 FileLfsServlet: Include error message in response body
According to the specification [1], the error response body must
include the error message in json format.

[1] https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md#response-errors

Change-Id: I79e7a841d230fdedefa53b9c6d2d477e81e1f9e6
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-07-27 11:07:05 +09:00
David Pursehouse 2e652aebab FileLfsServlet: Return HTTP 422 instead of 400
According to the specification [1], the error response status code
should be 422 when there is a validation error with one or more of
the objects in the request

[1] https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md#response-errors

Change-Id: Id03fe00a2109b896d9a154228a14a33bce5accc3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2016-07-27 11:01:14 +09:00