* changes: LfsProtocolServlet: Allow access to objects in request LfsProtocolServlet: Allow getLargeFileRepository to raise exceptions Remove references to org.eclipse.jgit.java7tags/v4.5.0.201609210915-r
@@ -18,10 +18,6 @@ there, but the automated builds use Maven. | |||
All portions of JGit are covered by the EDL. Absolutely no GPL, | |||
LGPL or EPL contributions are accepted within this package. | |||
- org.eclipse.jgit.java7 | |||
Extensions for users of Java 7. | |||
- org.eclipse.jgit.ant | |||
Ant tasks based on JGit. | |||
@@ -59,10 +55,6 @@ Tests | |||
Unit tests for org.eclipse.jgit | |||
- org.eclipse.jgit.java7.test | |||
Unit tests for Java 7 specific features | |||
- org.eclipse.jgit.ant.test | |||
- org.eclipse.jgit.pgm.test | |||
- org.eclipse.jgit.http.test | |||
@@ -73,11 +65,9 @@ Tests | |||
Warnings/Caveats | |||
---------------- | |||
- Native smbolic links are supported, but only if you are using Java 7 | |||
or newer and include the org.eclipse.jgit.java7 jar/bundle in the | |||
classpath, provided the file system supports them. For Windows you | |||
must have Windows Vista/Windows 2008 or newer, use a | |||
non-administrator account and have the SeCreateSymbolicLinkPrivilege. | |||
- Native smbolic links are supported, provided the file system supports | |||
them. For Windows you must have Windows Vista/Windows 2008 or newer, | |||
use a non-administrator account and have the SeCreateSymbolicLinkPrivilege. | |||
- Only the timestamp of the index is used by jgit if the index is | |||
dirty. | |||
@@ -153,12 +143,6 @@ Package Features | |||
* Assorted set of command line utilities. Mostly for ad-hoc testing of jgit | |||
log, glog, fetch etc. | |||
- org.eclipse.jgit.java7/ | |||
* Support for symbolic links. | |||
* Optimizations for reading file system attributes | |||
- org.eclipse.jgit.ant/ | |||
* Ant tasks |
@@ -42,7 +42,25 @@ | |||
*/ | |||
package org.eclipse.jgit.lfs.server; | |||
class LfsObject { | |||
/** | |||
* LFS object. | |||
* | |||
*/ | |||
public class LfsObject { | |||
String oid; | |||
long size; | |||
/** | |||
* @return the object ID. | |||
*/ | |||
public String getOid() { | |||
return oid; | |||
} | |||
/** | |||
* @return the object size. | |||
*/ | |||
public long getSize() { | |||
return size; | |||
} | |||
} |
@@ -43,14 +43,18 @@ | |||
package org.eclipse.jgit.lfs.server; | |||
import static java.nio.charset.StandardCharsets.UTF_8; | |||
import static javax.servlet.http.HttpServletResponse.SC_OK; | |||
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; | |||
import static org.apache.http.HttpStatus.SC_FORBIDDEN; | |||
import static org.apache.http.HttpStatus.SC_NOT_FOUND; | |||
import static org.apache.http.HttpStatus.SC_OK; | |||
import static org.apache.http.HttpStatus.SC_SERVICE_UNAVAILABLE; | |||
import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY; | |||
import java.io.BufferedReader; | |||
import java.io.BufferedWriter; | |||
import java.io.IOException; | |||
import java.io.InputStreamReader; | |||
import java.io.OutputStreamWriter; | |||
import java.io.PrintWriter; | |||
import java.io.Reader; | |||
import java.io.Writer; | |||
import java.util.List; | |||
@@ -60,6 +64,11 @@ import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import org.eclipse.jgit.lfs.errors.LfsException; | |||
import org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound; | |||
import org.eclipse.jgit.lfs.errors.LfsRepositoryReadOnly; | |||
import org.eclipse.jgit.lfs.errors.LfsValidationError; | |||
import com.google.gson.FieldNamingPolicy; | |||
import com.google.gson.Gson; | |||
import com.google.gson.GsonBuilder; | |||
@@ -80,7 +89,7 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
private Gson gson = createGson(); | |||
/** | |||
* Get the large file repository | |||
* Get the large file repository for the given request and path. | |||
* | |||
* @param request | |||
* the request | |||
@@ -89,9 +98,10 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
* | |||
* @return the large file repository storing large files or null if the | |||
* request is not supported. | |||
* @throws LfsException | |||
*/ | |||
protected abstract LargeFileRepository getLargeFileRepository( | |||
LfsRequest request, String path); | |||
LfsRequest request, String path) throws LfsException; | |||
/** LFS request. */ | |||
protected static class LfsRequest { | |||
@@ -107,6 +117,15 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
public String getOperation() { | |||
return operation; | |||
} | |||
/** | |||
* Get the LFS objects. | |||
* | |||
* @return the objects | |||
*/ | |||
public List<LfsObject> getObjects() { | |||
return objects; | |||
} | |||
} | |||
@Override | |||
@@ -119,7 +138,22 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
LfsRequest request = gson.fromJson(r, LfsRequest.class); | |||
String path = req.getPathInfo(); | |||
LargeFileRepository repo = getLargeFileRepository(request, path); | |||
LargeFileRepository repo = null; | |||
try { | |||
repo = getLargeFileRepository(request, path); | |||
} catch (LfsValidationError e) { | |||
sendError(res, SC_UNPROCESSABLE_ENTITY, e.getMessage()); | |||
return; | |||
} catch (LfsRepositoryNotFound e) { | |||
sendError(res, SC_NOT_FOUND, e.getMessage()); | |||
return; | |||
} catch (LfsRepositoryReadOnly e) { | |||
sendError(res, SC_FORBIDDEN, e.getMessage()); | |||
return; | |||
} catch (LfsException e) { | |||
sendError(res, SC_SERVICE_UNAVAILABLE, e.getMessage()); | |||
return; | |||
} | |||
if (repo == null) { | |||
res.setStatus(SC_SERVICE_UNAVAILABLE); | |||
return; | |||
@@ -133,7 +167,25 @@ public abstract class LfsProtocolServlet extends HttpServlet { | |||
w.flush(); | |||
} | |||
private static Gson createGson() { | |||
static class Error { | |||
String message; | |||
Error(String m) { | |||
this.message = m; | |||
} | |||
} | |||
private void sendError(HttpServletResponse rsp, int status, String message) | |||
throws IOException { | |||
rsp.setStatus(status); | |||
PrintWriter writer = rsp.getWriter(); | |||
gson.toJson(new Error(message), writer); | |||
writer.flush(); | |||
writer.close(); | |||
rsp.flushBuffer(); | |||
} | |||
private Gson createGson() { | |||
GsonBuilder gb = new GsonBuilder() | |||
.setFieldNamingPolicy( | |||
FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) |
@@ -0,0 +1,60 @@ | |||
/* | |||
* Copyright (C) 2016, David Pursehouse <david.pursehouse@gmail.com> | |||
* and other copyright owners as documented in the project's IP log. | |||
* | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Distribution License v1.0 which | |||
* accompanies this distribution, is reproduced below, and is | |||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||
* | |||
* All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or | |||
* without modification, are permitted provided that the following | |||
* conditions are met: | |||
* | |||
* - Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* - Redistributions in binary form must reproduce the above | |||
* copyright notice, this list of conditions and the following | |||
* disclaimer in the documentation and/or other materials provided | |||
* with the distribution. | |||
* | |||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||
* names of its contributors may be used to endorse or promote | |||
* products derived from this software without specific prior | |||
* written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
*/ | |||
package org.eclipse.jgit.lfs.errors; | |||
/** | |||
* Thrown when an error occurs during LFS operation. | |||
* | |||
* @since 4.5 | |||
*/ | |||
public class LfsException extends Exception { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* @param message | |||
*/ | |||
public LfsException(String message) { | |||
super(message); | |||
} | |||
} |
@@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright (C) 2016, David Pursehouse <david.pursehouse@gmail.com> | |||
* and other copyright owners as documented in the project's IP log. | |||
* | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Distribution License v1.0 which | |||
* accompanies this distribution, is reproduced below, and is | |||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||
* | |||
* All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or | |||
* without modification, are permitted provided that the following | |||
* conditions are met: | |||
* | |||
* - Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* - Redistributions in binary form must reproduce the above | |||
* copyright notice, this list of conditions and the following | |||
* disclaimer in the documentation and/or other materials provided | |||
* with the distribution. | |||
* | |||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||
* names of its contributors may be used to endorse or promote | |||
* products derived from this software without specific prior | |||
* written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
*/ | |||
package org.eclipse.jgit.lfs.errors; | |||
/** | |||
* Thrown when the repository does not exist for the user. | |||
* | |||
* @since 4.5 | |||
*/ | |||
public class LfsRepositoryNotFound extends LfsException { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* @param name | |||
* | |||
*/ | |||
public LfsRepositoryNotFound(String name) { | |||
super("repository " + name + " not found"); //$NON-NLS-1$ //$NON-NLS-2$ | |||
} | |||
} |
@@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright (C) 2016, David Pursehouse <david.pursehouse@gmail.com> | |||
* and other copyright owners as documented in the project's IP log. | |||
* | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Distribution License v1.0 which | |||
* accompanies this distribution, is reproduced below, and is | |||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||
* | |||
* All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or | |||
* without modification, are permitted provided that the following | |||
* conditions are met: | |||
* | |||
* - Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* - Redistributions in binary form must reproduce the above | |||
* copyright notice, this list of conditions and the following | |||
* disclaimer in the documentation and/or other materials provided | |||
* with the distribution. | |||
* | |||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||
* names of its contributors may be used to endorse or promote | |||
* products derived from this software without specific prior | |||
* written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
*/ | |||
package org.eclipse.jgit.lfs.errors; | |||
/** | |||
* Thrown when the user has read, but not write access. Only applicable when the | |||
* operation in the request is "upload". | |||
* | |||
* @since 4.5 | |||
*/ | |||
public class LfsRepositoryReadOnly extends LfsException { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* @param name | |||
*/ | |||
public LfsRepositoryReadOnly(String name) { | |||
super("repository " + name + "is read-only"); //$NON-NLS-1$ //$NON-NLS-2$ | |||
} | |||
} |
@@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright (C) 2016, David Pursehouse <david.pursehouse@gmail.com> | |||
* and other copyright owners as documented in the project's IP log. | |||
* | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Distribution License v1.0 which | |||
* accompanies this distribution, is reproduced below, and is | |||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||
* | |||
* All rights reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or | |||
* without modification, are permitted provided that the following | |||
* conditions are met: | |||
* | |||
* - Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* - Redistributions in binary form must reproduce the above | |||
* copyright notice, this list of conditions and the following | |||
* disclaimer in the documentation and/or other materials provided | |||
* with the distribution. | |||
* | |||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||
* names of its contributors may be used to endorse or promote | |||
* products derived from this software without specific prior | |||
* written permission. | |||
* | |||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
*/ | |||
package org.eclipse.jgit.lfs.errors; | |||
/** | |||
* Thrown when there is a validation error with one or more of the objects in | |||
* the request. | |||
* | |||
* @since 4.5 | |||
*/ | |||
public class LfsValidationError extends LfsException { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* @param message | |||
*/ | |||
public LfsValidationError(String message) { | |||
super(message); | |||
} | |||
} |
@@ -2,9 +2,6 @@ | |||
<projectDescription> | |||
<name>org.eclipse.jgit.test</name> | |||
<comment></comment> | |||
<projects> | |||
<project>org.eclipse.jgit.java7</project> | |||
</projects> | |||
<buildSpec> | |||
<buildCommand> | |||
<name>org.eclipse.jdt.core.javabuilder</name> |