diff --git a/WORKSPACE b/WORKSPACE index 547c439bd..5fa28f9e2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -77,20 +77,20 @@ maven_jar( maven_jar( name = "javaewah", - artifact = "com.googlecode.javaewah:JavaEWAH:1.1.6", - sha1 = "94ad16d728b374d65bd897625f3fbb3da223a2b6", + artifact = "com.googlecode.javaewah:JavaEWAH:1.1.7", + sha1 = "570dde3cd706ae10c62fe19b150928cfdb415e87", ) maven_jar( name = "httpclient", - artifact = "org.apache.httpcomponents:httpclient:4.5.6", - sha1 = "1afe5621985efe90a92d0fbc9be86271efbe796f", + artifact = "org.apache.httpcomponents:httpclient:4.5.10", + sha1 = "7ca2e4276f4ef95e4db725a8cd4a1d1e7585b9e5", ) maven_jar( name = "httpcore", - artifact = "org.apache.httpcomponents:httpcore:4.4.10", - sha1 = "acc54d9b28bdffe4bbde89ed2e4a1e86b5285e2b", + artifact = "org.apache.httpcomponents:httpcore:4.4.12", + sha1 = "21ebaf6d532bc350ba95bd81938fa5f0e511c132", ) maven_jar( @@ -107,8 +107,8 @@ maven_jar( maven_jar( name = "commons-codec", - artifact = "commons-codec:commons-codec:1.10", - sha1 = "4b95f4897fa13f2cd904aee711aeafc0c5295cd8", + artifact = "commons-codec:commons-codec:1.13", + sha1 = "3f18e1aa31031d89db6f01ba05d501258ce69d2c", ) maven_jar( @@ -137,8 +137,8 @@ maven_jar( maven_jar( name = "commons-compress", - artifact = "org.apache.commons:commons-compress:1.18", - sha1 = "1191f9f2bc0c47a8cce69193feb1ff0a8bcb37d5", + artifact = "org.apache.commons:commons-compress:1.19", + sha1 = "7e65777fb451ddab6a9c054beb879e521b7eab78", ) maven_jar( @@ -155,8 +155,8 @@ maven_jar( maven_jar( name = "junit", - artifact = "junit:junit:4.12", - sha1 = "2973d150c0dc1fefe998f834810d68f278ea58ec", + artifact = "junit:junit:4.13", + sha1 = "e49ccba652b735c93bd6e6f59760d8254cf597dd", ) maven_jar( @@ -177,6 +177,12 @@ maven_jar( sha1 = "497ddb32fd5d01f9dbe99a2ec790aeb931dff1b1", ) +maven_jar( + name = "assertj-core", + artifact = "org.assertj:assertj-core:3.14.0", + sha1 = "3b7b0fcac821f3d167764e9926573cd64f78f9e9", +) + BYTE_BUDDY_VERSION = "1.9.0" maven_jar( @@ -203,48 +209,48 @@ maven_jar( sha1 = "3edcfe49d2c6053a70a2a47e4e1c2f94998a49cf", ) -JETTY_VER = "9.4.24.v20191120" +JETTY_VER = "9.4.25.v20191220" maven_jar( name = "jetty-servlet", artifact = "org.eclipse.jetty:jetty-servlet:" + JETTY_VER, - sha1 = "ca1803fde51b795c0a8346ca8bc6277d9d04d01d", - src_sha1 = "8781c162df92d27456d4370df943f6a5234f32c4", + sha1 = "bee77d6a4f87dc90d5bc142cbd6cef470ec46aae", + src_sha1 = "e8b09b6431fc9cfbff588698ac0262a745fe00e4", ) maven_jar( name = "jetty-security", artifact = "org.eclipse.jetty:jetty-security:" + JETTY_VER, - sha1 = "9fa640d36c088cf55843900043d28aef830ade4d", - src_sha1 = "40128e3547b43f09e176fb0738672f483c477119", + sha1 = "593ff5b5dfd5bf973184329f5d1209b9a411ec12", + src_sha1 = "369f869a13a33d25535db3176a84945e94a3718a", ) maven_jar( name = "jetty-server", artifact = "org.eclipse.jetty:jetty-server:" + JETTY_VER, - sha1 = "7885cc3d5d7701a444acada7ab97f89846514875", - src_sha1 = "709650068c26029303ab3776d1e5ed6a66e0b065", + sha1 = "5b352c9f9135a1c20e4808e5cb1d84fbddfdc460", + src_sha1 = "0f3acc2abcdb86491a2c37074592860cb1100269", ) maven_jar( name = "jetty-http", artifact = "org.eclipse.jetty:jetty-http:" + JETTY_VER, - sha1 = "d3f0b0fb016ef8d35ffb199d928ffbcbfa121c86", - src_sha1 = "b29d870576e3edff354af0dae86c60d5956cd643", + sha1 = "c3aa7da362f1a492667ce754ba16b2535b793668", + src_sha1 = "70ef1436dc895eafe2cc24cf59af6e2d2874d963", ) maven_jar( name = "jetty-io", artifact = "org.eclipse.jetty:jetty-io:" + JETTY_VER, - sha1 = "dcb6d4d505ef74898e3a64a38c40195c01e97119", - src_sha1 = "863a6c575eadb626b50cda13a6484609a9449934", + sha1 = "3eb34b5481012701de0ea9dfaf2bdf1dbb947b16", + src_sha1 = "ad129617793088aaf69eab18a13c9bce02cb1195", ) maven_jar( name = "jetty-util", artifact = "org.eclipse.jetty:jetty-util:" + JETTY_VER, - sha1 = "3095acb088f4ff9e3fd9aedf98db73e3c18ea849", - src_sha1 = "f503199317d9df74062d722db4a7af8cf5e59322", + sha1 = "fd8b642cc16728f1c36ca6a64653cb1b26ec0232", + src_sha1 = "c84dc3026cc4aea013dc97b18228756816167745", ) BOUNCYCASTLE_VER = "1.64" diff --git a/lib/BUILD b/lib/BUILD index 058899fce..6c974865e 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -213,6 +213,15 @@ java_library( ], ) +java_library( + name = "assertj-core", + testonly = 1, + visibility = ["//visibility:public"], + exports = [ + "@assertj-core//jar", + ], +) + java_library( name = "servlet-api", visibility = [ diff --git a/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF index a8e76b254..95a6da374 100644 --- a/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF @@ -14,4 +14,4 @@ Import-Package: org.apache.tools.ant, org.eclipse.jgit.lib;version="[5.7.0,5.8.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.hamcrest.core;version="[1.1.0,2.0.0)", - org.junit;version="[4.12,5.0.0)" + org.junit;version="[4.13,5.0.0)" diff --git a/org.eclipse.jgit.benchmarks/pom.xml b/org.eclipse.jgit.benchmarks/pom.xml index 426fb7ffe..5e707719e 100644 --- a/org.eclipse.jgit.benchmarks/pom.xml +++ b/org.eclipse.jgit.benchmarks/pom.xml @@ -69,9 +69,6 @@ javac-with-errorprone true - - -Xep:ExpectedExceptionChecker:ERROR - diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java index 9b17132d0..1769832fb 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/GitFilter.java @@ -298,7 +298,8 @@ public class GitFilter extends MetaFilter { try { return StringUtils.toBoolean(n); } catch (IllegalArgumentException err) { - throw new ServletException(MessageFormat.format(HttpServerText.get().invalidBoolean, param, n)); + throw new ServletException(MessageFormat.format( + HttpServerText.get().invalidBoolean, param, n), err); } } diff --git a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF index d4ea15886..ad9413f50 100644 --- a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF @@ -49,8 +49,8 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.hamcrest;version="[1.1.0,2.0.0)", org.hamcrest.core;version="[1.1.0,2.0.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.rules;version="[4.12,5.0.0)", - org.junit.runner;version="[4.12,5.0.0)", - org.junit.runners;version="[4.12,5.0.0)" + org.junit;version="[4.13,5.0.0)", + org.junit.rules;version="[4.13,5.0.0)", + org.junit.runner;version="[4.13,5.0.0)", + org.junit.runners;version="[4.13,5.0.0)" Require-Bundle: org.hamcrest.library;bundle-version="[1.1.0,2.0.0)" diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java index 7b1428849..96657761c 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java @@ -10,12 +10,12 @@ package org.eclipse.jgit.http.test; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java index 9a7c0776a..51a7a8ddc 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -88,18 +89,12 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.transport.http.HttpConnectionFactory; import org.eclipse.jgit.util.HttpSupport; import org.eclipse.jgit.util.SystemReader; -import org.hamcrest.Matchers; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase { private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding"; - @Rule - public ExpectedException thrown = ExpectedException.none(); - private AdvertiseRefsHook advertiseRefsHook; private Repository remoteRepository; @@ -462,11 +457,12 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase { try (Repository dst = createBareRepository(); Transport t = Transport.open(dst, remoteURI)) { assertFalse(dst.getObjectDatabase().has(A_txt)); - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( + Exception e = assertThrows(TransportException.class, + () -> t.fetch(NullProgressMonitor.INSTANCE, + Collections.singletonList( + new RefSpec(unreachableCommit.name())))); + assertTrue(e.getMessage().contains( "want " + unreachableCommit.name() + " not valid")); - t.fetch(NullProgressMonitor.INSTANCE, Collections - .singletonList(new RefSpec(unreachableCommit.name()))); } } @@ -484,11 +480,11 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase { try (Repository dst = createBareRepository(); Transport t = Transport.open(dst, remoteURI)) { assertFalse(dst.getObjectDatabase().has(A_txt)); - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + A.name() + " not valid")); - t.fetch(NullProgressMonitor.INSTANCE, Collections - .singletonList(new RefSpec(A.name()))); + Exception e = assertThrows(TransportException.class, + () -> t.fetch(NullProgressMonitor.INSTANCE, + Collections.singletonList(new RefSpec(A.name())))); + assertTrue( + e.getMessage().contains("want " + A.name() + " not valid")); } } diff --git a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF index 5c889f6df..a622488cd 100644 --- a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF @@ -30,7 +30,7 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)", org.eclipse.jgit.revwalk;version="[5.7.0,5.8.0)", org.eclipse.jgit.transport;version="[5.7.0,5.8.0)", org.eclipse.jgit.transport.resolver;version="[5.7.0,5.8.0)", - org.junit;version="[4.12,5.0.0)" + org.junit;version="[4.13,5.0.0)" Export-Package: org.eclipse.jgit.junit.http;version="5.7.0"; uses:="org.eclipse.jgit.transport, org.eclipse.jgit.junit, diff --git a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF index 871e32915..531f3be23 100644 --- a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF @@ -25,11 +25,11 @@ Import-Package: org.eclipse.jgit.annotations;version="[5.7.0,5.8.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.eclipse.jgit.util.io;version="[5.7.0,5.8.0)", org.eclipse.jgit.util.time;version="[5.7.0,5.8.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.rules;version="[4.12,5.0.0)", - org.junit.runner;version="[4.12,5.0.0)", - org.junit.runners;version="[4.12,5.0.0)", - org.junit.runners.model;version="[4.12,5.0.0)", + org.junit;version="[4.13,5.0.0)", + org.junit.rules;version="[4.13,5.0.0)", + org.junit.runner;version="[4.13,5.0.0)", + org.junit.runners;version="[4.13,5.0.0)", + org.junit.runners.model;version="[4.13,5.0.0)", org.slf4j;version="[1.7.0,2.0.0)" Export-Package: org.eclipse.jgit.junit;version="5.7.0"; uses:="org.eclipse.jgit.dircache, diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index d68c5c891..a5b3b1f3a 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -973,7 +973,7 @@ public class TestRepository implements AutoCloseable { try { lck.write(bin); } catch (IOException ioe) { - throw new ObjectWritingException("Can't write " + p); + throw new ObjectWritingException("Can't write " + p, ioe); } if (!lck.commit()) throw new ObjectWritingException("Can't write " + p); diff --git a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF index c4d3c90f0..ac7ee5f5c 100644 --- a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF @@ -47,7 +47,7 @@ Import-Package: javax.servlet;version="[3.1.0,4.0.0)", org.eclipse.jgit.treewalk.filter;version="[5.7.0,5.8.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.hamcrest.core;version="[1.1.0,2.0.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.rules;version="[4.12,5.0.0)", - org.junit.runner;version="[4.12,5.0.0)", - org.junit.runners;version="[4.12,5.0.0)" + org.junit;version="[4.13,5.0.0)", + org.junit.rules;version="[4.13,5.0.0)", + org.junit.runner;version="[4.13,5.0.0)", + org.junit.runners;version="[4.13,5.0.0)" diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java index d29541449..8d32f9e75 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java @@ -12,6 +12,7 @@ package org.eclipse.jgit.lfs.server.fs; import static org.apache.http.HttpStatus.SC_NOT_FOUND; import static org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import java.io.IOException; import java.nio.file.Path; @@ -22,15 +23,10 @@ import org.apache.http.client.ClientProtocolException; import org.eclipse.jgit.lfs.lib.AnyLongObjectId; import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils; import org.eclipse.jgit.util.FileUtils; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class DownloadTest extends LfsServerTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testDownload() throws Exception { String TEXT = "test"; @@ -49,10 +45,8 @@ public class DownloadTest extends LfsServerTest { Path f = Paths.get(getTempDirectory().toString(), "download"); String error = String.format( "Invalid pathInfo: '/%s' does not match '/{SHA-256}'", id); - exception.expect(RuntimeException.class); - exception.expectMessage( - formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error)); - getContent(id, f); + assertThrows(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error), + RuntimeException.class, () -> getContent(id, f)); } @Test @@ -62,22 +56,18 @@ public class DownloadTest extends LfsServerTest { String id = putContent(TEXT).name().replace('f', 'z'); Path f = Paths.get(getTempDirectory().toString(), "download"); String error = String.format("Invalid id: %s", id); - exception.expect(RuntimeException.class); - exception.expectMessage( - formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error)); - getContent(id, f); + assertThrows(formatErrorMessage(SC_UNPROCESSABLE_ENTITY, error), + RuntimeException.class, () -> getContent(id, f)); } @Test - public void testDownloadNotFound() - throws ClientProtocolException, IOException { + public void testDownloadNotFound() { String TEXT = "test"; AnyLongObjectId id = LongObjectIdTestUtils.hash(TEXT); Path f = Paths.get(getTempDirectory().toString(), "download"); String error = String.format("Object '%s' not found", id.getName()); - exception.expect(RuntimeException.class); - exception.expectMessage(formatErrorMessage(SC_NOT_FOUND, error)); - getContent(id, f); + assertThrows(formatErrorMessage(SC_NOT_FOUND, error), + RuntimeException.class, () -> getContent(id, f)); } @SuppressWarnings("boxing") diff --git a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF index e3fcf70ce..2682ba6b8 100644 --- a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF @@ -18,7 +18,7 @@ Import-Package: org.eclipse.jgit.internal.storage.dfs;version="[5.7.0,5.8.0)", org.eclipse.jgit.treewalk.filter;version="[5.7.0,5.8.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.hamcrest.core;version="[1.1.0,2.0.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.runner;version="[4.12,5.0.0)", - org.junit.runners;version="[4.12,5.0.0)" + org.junit;version="[4.13,5.0.0)", + org.junit.runner;version="[4.13,5.0.0)", + org.junit.runners;version="[4.13,5.0.0)" Export-Package: org.eclipse.jgit.lfs.test;version="5.7.0";x-friends:="org.eclipse.jgit.lfs.server.test" diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java index c4a51c7b9..55d2cfa6e 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java @@ -18,7 +18,6 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; -import java.nio.charset.UnsupportedCharsetException; import java.util.Locale; import org.eclipse.jgit.annotations.Nullable; @@ -110,7 +109,6 @@ public class LfsPointer implements Comparable { ps.print(size + "\n"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { // should not happen, we are using a standard charset - throw new UnsupportedCharsetException(UTF_8.name()); } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectId.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectId.java index a2bcc35ee..9016e5394 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectId.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/AbbreviatedLongObjectId.java @@ -121,8 +121,11 @@ public final class AbbreviatedLongObjectId implements Serializable { final long c = hexUInt64(bs, ptr + 32, end); final long d = hexUInt64(bs, ptr + 48, end); return new AbbreviatedLongObjectId(end - ptr, a, b, c, d); - } catch (ArrayIndexOutOfBoundsException e1) { - throw new InvalidLongObjectIdException(bs, ptr, end - ptr); + } catch (ArrayIndexOutOfBoundsException e) { + InvalidLongObjectIdException e1 = new InvalidLongObjectIdException( + bs, ptr, end - ptr); + e1.initCause(e); + throw e1; } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LongObjectId.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LongObjectId.java index 000e9b206..15b3ca4c6 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LongObjectId.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/LongObjectId.java @@ -223,9 +223,11 @@ public class LongObjectId extends AnyLongObjectId implements Serializable { final long c = RawParseUtils.parseHexInt64(bs, p + 32); final long d = RawParseUtils.parseHexInt64(bs, p + 48); return new LongObjectId(a, b, c, d); - } catch (ArrayIndexOutOfBoundsException e1) { - throw new InvalidLongObjectIdException(bs, p, - Constants.LONG_OBJECT_ID_STRING_LENGTH); + } catch (ArrayIndexOutOfBoundsException e) { + InvalidLongObjectIdException e1 = new InvalidLongObjectIdException( + bs, p, Constants.LONG_OBJECT_ID_STRING_LENGTH); + e1.initCause(e); + throw e1; } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/MutableLongObjectId.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/MutableLongObjectId.java index 368f6af7e..012e4ae91 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/MutableLongObjectId.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/lib/MutableLongObjectId.java @@ -213,9 +213,11 @@ public class MutableLongObjectId extends AnyLongObjectId { w2 = RawParseUtils.parseHexInt64(bs, p + 16); w3 = RawParseUtils.parseHexInt64(bs, p + 32); w4 = RawParseUtils.parseHexInt64(bs, p + 48); - } catch (ArrayIndexOutOfBoundsException e1) { - throw new InvalidLongObjectIdException(bs, p, - Constants.LONG_OBJECT_ID_STRING_LENGTH); + } catch (ArrayIndexOutOfBoundsException e) { + InvalidLongObjectIdException e1 = new InvalidLongObjectIdException( + bs, p, Constants.LONG_OBJECT_ID_STRING_LENGTH); + e1.initCause(e); + throw e1; } } diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml index 17a732b4a..8da600137 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml @@ -47,4 +47,11 @@ version="0.0.0" unpack="false"/> + + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target index 3cfe1b395..f49adf9a6 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd index 19ebf13e3..fc18203cb 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.10.tpd @@ -1,7 +1,7 @@ target "jgit-4.10" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/2018-12/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target index b42ae5758..e68ab631f 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd index b54e1771b..dd1f6245b 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.11.tpd @@ -1,7 +1,7 @@ target "jgit-4.11" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/2019-03/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target index 3b27528c3..e83924c3f 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd index fe5a8d63b..bf32ed904 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.12.tpd @@ -1,7 +1,7 @@ target "jgit-4.12" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/2019-06/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target index c87f25d3f..c79f20669 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd index caeae9c60..e46a5dfe4 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.13.tpd @@ -1,7 +1,7 @@ target "jgit-4.13" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/2019-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.target index 92e67946a..39f52ace3 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.tpd index 0b61b90d0..d1f0d49cc 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.14-staging.tpd @@ -1,7 +1,7 @@ target "jgit-4.14-staging" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/staging/2019-12/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target index c77b6fca6..4d862e2c1 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd index 895f37c6c..eb3f96d3b 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd @@ -1,7 +1,7 @@ target "jgit-4.6" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/neon/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target index 5fbe5e980..780b668ad 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd index 19a733b3f..cb98e4c87 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd @@ -1,7 +1,7 @@ target "jgit-4.7" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/oxygen/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target index c4c5799f5..596cd6915 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd index 1aad52ad4..e0d886adf 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd @@ -1,7 +1,7 @@ target "jgit-4.8" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/photon/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target index de451fd6a..7da901f04 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.target @@ -1,7 +1,7 @@ - + @@ -29,8 +29,8 @@ - - + + @@ -41,22 +41,24 @@ - - - - + + + + - - - - + + + + + + @@ -68,8 +70,8 @@ - - + + @@ -82,7 +84,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd index 9ab5a5921..32321d874 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9.tpd @@ -1,7 +1,7 @@ target "jgit-4.9" with source configurePhase include "projects/jetty-9.4.x.tpd" -include "orbit/R20191126223242-2019-12.tpd" +include "orbit/staging-2020-03.tpd" location "http://download.eclipse.org/releases/2018-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/staging-2020-03.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/staging-2020-03.tpd new file mode 100644 index 000000000..9269a642c --- /dev/null +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/staging-2020-03.tpd @@ -0,0 +1,67 @@ +target "staging-2020-03" with source configurePhase +// see http://download.eclipse.org/tools/orbit/downloads/ + +location "https://download.eclipse.org/tools/orbit/downloads/drops/S20200128200239/repository" { + com.google.gson [2.8.2.v20180104-1110,2.8.2.v20180104-1110] + com.google.gson.source [2.8.2.v20180104-1110,2.8.2.v20180104-1110] + com.jcraft.jsch [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jsch.source [0.1.55.v20190404-1902,0.1.55.v20190404-1902] + com.jcraft.jzlib [1.1.1.v201205102305,1.1.1.v201205102305] + com.jcraft.jzlib.source [1.1.1.v201205102305,1.1.1.v201205102305] + javaewah [1.1.7.v20200107-0831,1.1.7.v20200107-0831] + javaewah.source [1.1.7.v20200107-0831,1.1.7.v20200107-0831] + javax.servlet [3.1.0.v201410161800,3.1.0.v201410161800] + javax.servlet.source [3.1.0.v201410161800,3.1.0.v201410161800] + net.bytebuddy.byte-buddy [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.bytebuddy.byte-buddy-agent [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy-agent.source [1.9.0.v20181106-1534,1.9.0.v20181106-1534] + net.bytebuddy.byte-buddy.source [1.9.0.v20181107-1410,1.9.0.v20181107-1410] + net.i2p.crypto.eddsa [0.3.0.v20181102-1323,0.3.0.v20181102-1323] + net.i2p.crypto.eddsa.source [0.3.0.v20181102-1323,0.3.0.v20181102-1323] + org.apache.ant [1.10.7.v20190926-0324,1.10.7.v20190926-0324] + org.apache.ant.source [1.10.7.v20190926-0324,1.10.7.v20190926-0324] + org.apache.commons.codec [1.13.0.v20200108-0001,1.13.0.v20200108-0001] + org.apache.commons.codec.source [1.13.0.v20200108-0001,1.13.0.v20200108-0001] + org.apache.commons.compress [1.19.0.v20200106-2343,1.19.0.v20200106-2343] + org.apache.commons.compress.source [1.19.0.v20200106-2343,1.19.0.v20200106-2343] + org.apache.commons.logging [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.commons.logging.source [1.2.0.v20180409-1502,1.2.0.v20180409-1502] + org.apache.httpcomponents.httpclient [4.5.10.v20200114-1512,4.5.10.v20200114-1512] + org.apache.httpcomponents.httpclient.source [4.5.10.v20200114-1512,4.5.10.v20200114-1512] + org.apache.httpcomponents.httpcore [4.4.12.v20200108-1212,4.4.12.v20200108-1212] + org.apache.httpcomponents.httpcore.source [4.4.12.v20200108-1212,4.4.12.v20200108-1212] + org.apache.log4j [1.2.15.v201012070815,1.2.15.v201012070815] + org.apache.log4j.source [1.2.15.v201012070815,1.2.15.v201012070815] + org.apache.sshd.osgi [2.2.0.v20190425-2127,2.2.0.v20190425-2127] + org.apache.sshd.osgi.source [2.2.0.v20190425-2127,2.2.0.v20190425-2127] + org.apache.sshd.sftp [2.2.0.v20190425-2127,2.2.0.v20190425-2127] + org.apache.sshd.sftp.source [2.2.0.v20190425-2127,2.2.0.v20190425-2127] + org.assertj [3.14.0.v20200120-1926,3.14.0.v20200120-1926] + org.assertj.source [3.14.0.v20200120-1926,3.14.0.v20200120-1926] + org.bouncycastle.bcpg [1.64.0.v20191109-0815,1.64.0.v20191109-0815] + org.bouncycastle.bcpg.source [1.64.0.v20191109-0815,1.64.0.v20191109-0815] + org.bouncycastle.bcpkix [1.64.0.v20191109-0815,1.64.0.v20191109-0815] + org.bouncycastle.bcpkix.source [1.64.0.v20191109-0815,1.64.0.v20191109-0815] + org.bouncycastle.bcprov [1.64.0.v20191109-0815,1.64.0.v20191109-0815] + org.bouncycastle.bcprov.source [1.64.0.v20191109-0815,1.64.0.v20191109-0815] + org.hamcrest [1.1.0.v20090501071000,1.1.0.v20090501071000] + org.hamcrest.core [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.core.source [1.3.0.v20180420-1519,1.3.0.v20180420-1519] + org.hamcrest.library [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.hamcrest.library.source [1.3.0.v20180524-2246,1.3.0.v20180524-2246] + org.junit [4.13.0.v20200128-1312,4.13.0.v20200128-1312] + org.junit.source [4.13.0.v20200128-1312,4.13.0.v20200128-1312] + org.kohsuke.args4j [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.kohsuke.args4j.source [2.33.0.v20160323-2218,2.33.0.v20160323-2218] + org.mockito [2.23.0.v20190527-1420,2.23.0.v20190527-1420] + org.mockito.source [2.23.0.v20190527-1420,2.23.0.v20190527-1420] + org.objenesis [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.objenesis.source [2.6.0.v20180420-1519,2.6.0.v20180420-1519] + org.slf4j.api [1.7.2.v20121108-1250,1.7.2.v20121108-1250] + org.slf4j.api.source [1.7.2.v20121108-1250,1.7.2.v20121108-1250] + org.slf4j.impl.log4j12 [1.7.2.v20131105-2200,1.7.2.v20131105-2200] + org.slf4j.impl.log4j12.source [1.7.2.v20131105-2200,1.7.2.v20131105-2200] + org.tukaani.xz [1.8.0.v20180207-1613,1.8.0.v20180207-1613] + org.tukaani.xz.source [1.8.0.v20180207-1613,1.8.0.v20180207-1613] +} + diff --git a/org.eclipse.jgit.packaging/pom.xml b/org.eclipse.jgit.packaging/pom.xml index ae777789d..35caa3e24 100644 --- a/org.eclipse.jgit.packaging/pom.xml +++ b/org.eclipse.jgit.packaging/pom.xml @@ -22,7 +22,7 @@ JGit Tycho Parent - 1.5.1 + 1.6.0 ${tycho-version} jgit-4.6 diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF index b48c1e5ff..a7a11b404 100644 --- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF @@ -26,7 +26,7 @@ Import-Package: org.eclipse.jgit.api;version="[5.7.0,5.8.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.eclipse.jgit.util.io;version="[5.7.0,5.8.0)", org.hamcrest.core;bundle-version="[1.1.0,2.0.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.rules;version="[4.12,5.0.0)", + org.junit;version="[4.13,5.0.0)", + org.junit.rules;version="[4.13,5.0.0)", org.kohsuke.args4j;version="[2.33.0,3.0.0)" Require-Bundle: org.tukaani.xz;bundle-version="[1.3.0,2.0.0)" diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java index 006039bdc..ea3043358 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/BlameTest.java @@ -9,6 +9,7 @@ */ package org.eclipse.jgit.pgm; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import org.eclipse.jgit.api.Git; @@ -17,24 +18,18 @@ import org.eclipse.jgit.lib.CLIRepositoryTestCase; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.revwalk.RevCommit; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class BlameTest extends CLIRepositoryTestCase { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testBlameNoHead() throws Exception { try (Git git = new Git(db)) { writeTrashFile("inIndex.txt", "index"); git.add().addFilepattern("inIndex.txt").call(); } - thrown.expect(Die.class); - thrown.expectMessage("no such ref: HEAD"); - execute("git blame inIndex.txt"); + assertThrows("no such ref: HEAD", Die.class, + () -> execute("git blame inIndex.txt")); } @Test @@ -68,9 +63,8 @@ public class BlameTest extends CLIRepositoryTestCase { git.commit().setMessage("initial commit").call(); } writeTrashFile("onlyInWorkingTree.txt", "not in repo"); - thrown.expect(Die.class); - thrown.expectMessage("no such path 'onlyInWorkingTree.txt' in HEAD"); - execute("git blame onlyInWorkingTree.txt"); + assertThrows("no such path 'onlyInWorkingTree.txt' in HEAD", Die.class, + () -> execute("git blame onlyInWorkingTree.txt")); } @Test @@ -78,9 +72,8 @@ public class BlameTest extends CLIRepositoryTestCase { try (Git git = new Git(db)) { git.commit().setMessage("initial commit").call(); } - thrown.expect(Die.class); - thrown.expectMessage("no such path 'does_not_exist.txt' in HEAD"); - execute("git blame does_not_exist.txt"); + assertThrows("no such path 'does_not_exist.txt' in HEAD", Die.class, + () -> execute("git blame does_not_exist.txt")); } @Test @@ -88,9 +81,8 @@ public class BlameTest extends CLIRepositoryTestCase { try (Git git = new Git(db)) { git.commit().setMessage("initial commit").call(); } - thrown.expect(Die.class); - thrown.expectMessage("no such path 'sub/does_not_exist.txt' in HEAD"); - execute("git blame sub/does_not_exist.txt"); + assertThrows("no such path 'sub/does_not_exist.txt' in HEAD", Die.class, + () -> execute("git blame sub/does_not_exist.txt")); } @Test diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java index 455abcd37..98724bfce 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java @@ -100,7 +100,7 @@ class Checkout extends TextBuiltin { .format(CLIText.get().pathspecDidNotMatch, name), e); } catch (RefAlreadyExistsException e) { throw die(MessageFormat - .format(CLIText.get().branchAlreadyExists, name)); + .format(CLIText.get().branchAlreadyExists, name), e); } catch (CheckoutConflictException e) { StringBuilder builder = new StringBuilder(); builder.append(CLIText.get().checkoutConflict); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 243e99fdf..8f80d6d70 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -110,7 +110,7 @@ class Clone extends AbstractFetchCommand implements CloneCommand.Callback { outw.println(CLIText.get().clonedEmptyRepository); } catch (InvalidRemoteException e) { throw die(MessageFormat.format(CLIText.get().doesNotExist, - sourceUri)); + sourceUri), e); } finally { if (db != null) db.close(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java index cbb5d846b..f570f7f99 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ReceivePack.java @@ -42,7 +42,7 @@ class ReceivePack extends TextBuiltin { db = key.open(true /* must exist */); } catch (RepositoryNotFoundException notFound) { throw die(MessageFormat.format(CLIText.get().notAGitRepository, - dstGitdir.getPath())); + dstGitdir.getPath()), notFound); } catch (IOException e) { throw die(e.getMessage(), e); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java index 8c3988603..b408b78f3 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java @@ -74,7 +74,7 @@ class Tag extends TextBuiltin { command.call(); } catch (RefAlreadyExistsException e) { throw die(MessageFormat.format( - CLIText.get().tagAlreadyExists, tagName)); + CLIText.get().tagAlreadyExists, tagName), e); } } } else { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java index 69c8eb570..36103f2e6 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/UploadPack.java @@ -50,7 +50,7 @@ class UploadPack extends TextBuiltin { up.upload(ins, outs, errs); } catch (RepositoryNotFoundException notFound) { throw die(MessageFormat.format(CLIText.get().notAGitRepository, - srcGitdir.getPath())); + srcGitdir.getPath()), notFound); } catch (IOException e) { throw die(e.getMessage(), e); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index ddd48da46..8d884c12d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -235,7 +235,9 @@ class RebuildCommitGraph extends TextBuiltin { try { lck.write(content); } catch (IOException ioe) { - throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file)); + throw new ObjectWritingException( + MessageFormat.format(CLIText.get().cantWrite, file), + ioe); } if (!lck.commit()) throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file)); @@ -266,7 +268,9 @@ class RebuildCommitGraph extends TextBuiltin { errw.println(MessageFormat.format(CLIText.get().skippingObject, type, name)); continue; } - throw new MissingObjectException(id, type); + MissingObjectException mue1 = new MissingObjectException(id, type); + mue1.initCause(mue); + throw mue1; } refs.put(name, new ObjectIdRef.Unpeeled(Ref.Storage.PACKED, name, id)); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java index 6f0aba377..49f7ada45 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java @@ -57,7 +57,7 @@ class ShowPackDelta extends TextBuiltin { if (BinaryDelta.getResultSize(delta) != size) throw die("Object " + obj.name() + " is not a delta"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (ArrayIndexOutOfBoundsException bad) { - throw die("Object " + obj.name() + " is not a delta"); //$NON-NLS-1$ //$NON-NLS-2$ + throw die("Object " + obj.name() + " is not a delta", bad); //$NON-NLS-1$ //$NON-NLS-2$ } outw.println(BinaryDelta.format(delta)); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java index 07a1bb801..d8604726a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/AbstractTreeIteratorHandler.java @@ -101,8 +101,10 @@ public class AbstractTreeIteratorHandler extends try (ObjectReader curs = clp.getRepository().newObjectReader()) { p.reset(curs, clp.getRevWalk().parseTree(id)); } catch (MissingObjectException | IncorrectObjectTypeException e) { - throw new CmdLineException(clp, + CmdLineException cle = new CmdLineException(clp, CLIText.format(CLIText.get().notATree), name); + cle.initCause(e); + throw cle; } catch (IOException e) { throw new CmdLineException(clp, CLIText.format(CLIText.get().cannotReadBecause), name, diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java index f521775c7..8b2bed36a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevCommitHandler.java @@ -98,8 +98,10 @@ public class RevCommitHandler extends OptionHandler { try { c = clp.getRevWalk().parseCommit(id); } catch (MissingObjectException | IncorrectObjectTypeException e) { - throw new CmdLineException(clp, + CmdLineException cle = new CmdLineException(clp, CLIText.format(CLIText.get().notACommit), name); + cle.initCause(e); + throw cle; } catch (IOException e) { throw new CmdLineException(clp, CLIText.format(CLIText.get().cannotReadBecause), name, diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java index fa9636168..357886d0f 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/RevTreeHandler.java @@ -70,8 +70,10 @@ public class RevTreeHandler extends OptionHandler { try { c = clp.getRevWalk().parseTree(id); } catch (MissingObjectException | IncorrectObjectTypeException e) { - throw new CmdLineException(clp, + CmdLineException cle = new CmdLineException(clp, CLIText.format(CLIText.get().notATree), name); + cle.initCause(e); + throw cle; } catch (IOException e) { throw new CmdLineException(clp, CLIText.format(CLIText.get().cannotReadBecause), name, diff --git a/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF index 8fd175644..5bf2563aa 100644 --- a/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF @@ -24,6 +24,6 @@ Import-Package: org.apache.sshd.client.config.hosts;version="[2.2.0,2.3.0)", org.eclipse.jgit.transport.ssh;version="[5.7.0,5.8.0)", org.eclipse.jgit.transport.sshd;version="[5.7.0,5.8.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.experimental.theories;version="[4.12,5.0.0)", - org.junit.runner;version="[4.12,5.0.0)" + org.junit;version="[4.13,5.0.0)", + org.junit.experimental.theories;version="[4.13,5.0.0)", + org.junit.runner;version="[4.13,5.0.0)" diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD index 3d487960c..b34ef2a79 100644 --- a/org.eclipse.jgit.test/BUILD +++ b/org.eclipse.jgit.test/BUILD @@ -55,6 +55,7 @@ java_library( srcs = HELPERS, resources = DATA, deps = [ + "//lib:assertj-core", "//lib:jsch", "//lib:junit", "//lib:mockito", diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index d8f6bcfe2..18f16d91f 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", org.apache.commons.compress.compressors.bzip2;version="[1.15.0,2.0)", org.apache.commons.compress.compressors.gzip;version="[1.15.0,2.0)", org.apache.commons.compress.compressors.xz;version="[1.15.0,2.0)", + org.assertj.core.api;version="[3.14.0,4.0.0)", org.bouncycastle.util.encoders;version="[1.61.0,2.0.0)", org.eclipse.jgit.annotations;version="[5.7.0,5.8.0)", org.eclipse.jgit.api;version="[5.7.0,5.8.0)", @@ -70,11 +71,12 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", org.eclipse.jgit.util;version="[5.7.0,5.8.0)", org.eclipse.jgit.util.io;version="[5.7.0,5.8.0)", org.eclipse.jgit.util.sha1;version="[5.7.0,5.8.0)", - org.junit;version="[4.12,5.0.0)", - org.junit.experimental.theories;version="[4.12,5.0.0)", - org.junit.rules;version="[4.12,5.0.0)", - org.junit.runner;version="[4.12,5.0.0)", - org.junit.runners;version="[4.12,5.0.0)", + org.junit;version="[4.13,5.0.0)", + org.junit.experimental.theories;version="[4.13,5.0.0)", + org.junit.function;version="[4.13.0,5.0.0)", + org.junit.rules;version="[4.13,5.0.0)", + org.junit.runner;version="[4.13,5.0.0)", + org.junit.runners;version="[4.13,5.0.0)", org.mockito;version="[2.23.0,3.0.0)", org.mockito.invocation;version="[2.23.0,3.0.0)", org.mockito.junit;version="[2.23.0,3.0.0)", diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml index 60e6818dc..7ba19d4ef 100644 --- a/org.eclipse.jgit.test/pom.xml +++ b/org.eclipse.jgit.test/pom.xml @@ -65,6 +65,11 @@ [1.1.0,2.0.0) + + org.assertj + assertj-core + + org.mockito mockito-core diff --git a/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java b/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java deleted file mode 100644 index cd0a6f106..000000000 --- a/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/MoreAsserts.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2019, Google LLC and others - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0 which is available at - * https://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -package org.eclipse.jgit.lib; - -/** Assertion methods. */ -public class MoreAsserts { - /** - * Simple version of assertThrows that will be introduced in JUnit 4.13. - * - * @param expected - * Expected throwable class - * @param r - * Runnable that is expected to throw an exception. - * @return The thrown exception. - */ - public static T assertThrows(Class expected, - ThrowingRunnable r) { - try { - r.run(); - } catch (Throwable actual) { - if (expected.isAssignableFrom(actual.getClass())) { - @SuppressWarnings("unchecked") - T toReturn = (T) actual; - return toReturn; - } - throw new AssertionError("Expected " + expected.getSimpleName() - + ", but got " + actual.getClass().getSimpleName(), actual); - } - throw new AssertionError( - "Expected " + expected.getSimpleName() + " to be thrown"); - } - - public interface ThrowingRunnable { - void run() throws Throwable; - } - - private MoreAsserts() { - } -} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java index 6f7ec9a44..534ebd9c6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RenameBranchCommandTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import org.eclipse.jgit.api.errors.RefAlreadyExistsException; @@ -25,9 +26,7 @@ import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Unit tests of {@link RenameBranchCommand} @@ -40,9 +39,6 @@ public class RenameBranchCommandTest extends RepositoryTestCase { private Git git; - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Override @Before public void setUp() throws Exception { @@ -57,8 +53,8 @@ public class RenameBranchCommandTest extends RepositoryTestCase { @Test public void renameToExisting() throws Exception { assertNotNull(git.branchCreate().setName("foo").call()); - thrown.expect(RefAlreadyExistsException.class); - git.branchRename().setOldName("master").setNewName("foo").call(); + assertThrows(RefAlreadyExistsException.class, () -> git.branchRename() + .setOldName("master").setNewName("foo").call()); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java new file mode 100644 index 000000000..a07f37009 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2019 Alex Jitianu and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.api; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.Policy; +import java.util.Collections; + +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.WriterAppender; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests that using a SecurityManager does not result in errors logged. + */ +public class SecurityManagerMissingPermissionsTest extends RepositoryTestCase { + + /** + * Collects all logging sent to the logging system. + */ + private final StringWriter errorOutputWriter = new StringWriter(); + + /** + * Appender to intercept all logging sent to the logging system. + */ + private WriterAppender appender; + + private SecurityManager originalSecurityManager; + + @Override + @Before + public void setUp() throws Exception { + originalSecurityManager = System.getSecurityManager(); + + appender = new WriterAppender( + new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), + errorOutputWriter); + + Logger.getRootLogger().addAppender(appender); + + refreshPolicyAllPermission(Policy.getPolicy()); + System.setSecurityManager(new SecurityManager()); + super.setUp(); + } + + /** + * If a SecurityManager is active a lot of {@link java.io.FilePermission} + * errors are thrown and logged while initializing a repository. + * + * @throws Exception + */ + @Test + public void testCreateNewRepos_MissingPermissions() throws Exception { + File wcTree = new File(getTemporaryDirectory(), + "CreateNewRepositoryTest_testCreateNewRepos"); + + File marker = new File(getTemporaryDirectory(), "marker"); + Files.write(marker.toPath(), Collections.singletonList("Can write")); + assertTrue("Can write in test directory", marker.isFile()); + FileUtils.delete(marker); + assertFalse("Can delete in test direcory", marker.exists()); + + Git git = Git.init().setBare(false) + .setDirectory(new File(wcTree.getAbsolutePath())).call(); + + addRepoToClose(git.getRepository()); + + assertEquals("", errorOutputWriter.toString()); + } + + @Override + @After + public void tearDown() throws Exception { + System.setSecurityManager(originalSecurityManager); + Logger.getRootLogger().removeAppender(appender); + super.tearDown(); + } + + /** + * Refresh the Java Security Policy. + * + * @param policy + * the policy object + * + * @throws IOException + * if the temporary file that contains the policy could not be + * created + */ + private static void refreshPolicyAllPermission(Policy policy) + throws IOException { + // Starting with an all permissions policy. + String policyString = "grant { permission java.security.AllPermission; };"; + + // Do not use TemporaryFilesFactory, it will create a dependency cycle + Path policyFile = Files.createTempFile("testpolicy", ".txt"); + + try { + Files.write(policyFile, Collections.singletonList(policyString)); + System.setProperty("java.security.policy", + policyFile.toUri().toURL().toString()); + policy.refresh(); + } finally { + try { + Files.delete(policyFile); + } catch (IOException e) { + // Do not log; the test tests for no logging having occurred + e.printStackTrace(); + } + } + } + +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java index 3886c1595..f8c7dae7d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java @@ -13,9 +13,9 @@ import static org.eclipse.jgit.diff.DiffEntry.DEV_NULL; import static org.eclipse.jgit.util.FileUtils.delete; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.File; @@ -26,8 +26,8 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; -import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.dircache.DirCacheEntry; +import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.FileMode; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java index e612061ab..2df0ba1b0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfigTest.java @@ -40,23 +40,18 @@ package org.eclipse.jgit.internal.storage.dfs; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThrows; import org.eclipse.jgit.internal.JGitText; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class DfsBlockCacheConfigTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void blockSizeNotPowerOfTwoExpectsException() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage(is(JGitText.get().blockSizeNotPowerOf2)); - - new DfsBlockCacheConfig().setBlockSize(1000); + assertThrows(JGitText.get().blockSizeNotPowerOf2, + IllegalArgumentException.class, + () -> new DfsBlockCacheConfig().setBlockSize(1000)); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java index 770991e51..72bff1683 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileReftableStackTest.java @@ -12,6 +12,7 @@ package org.eclipse.jgit.internal.storage.file; import static org.eclipse.jgit.lib.Ref.Storage.PACKED; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.io.File; @@ -21,6 +22,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; + import org.eclipse.jgit.internal.storage.file.FileReftableStack.Segment; import org.eclipse.jgit.internal.storage.reftable.MergedReftable; import org.eclipse.jgit.internal.storage.reftable.RefCursor; @@ -31,9 +33,7 @@ import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.util.FileUtils; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class FileReftableStackTest { @@ -113,9 +113,6 @@ public class FileReftableStackTest { testCompaction(1024); } - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @SuppressWarnings({ "resource", "unused" }) @Test public void missingReftable() throws Exception { @@ -143,9 +140,9 @@ public class FileReftableStackTest { } } } - thrown.expect(FileNotFoundException.class); - new FileReftableStack(new File(reftableDir, "refs"), reftableDir, null, - () -> new Config()); + assertThrows(FileNotFoundException.class, + () -> new FileReftableStack(new File(reftableDir, "refs"), + reftableDir, null, () -> new Config())); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java index 74f1aea6f..8baa3cc34 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java @@ -10,13 +10,13 @@ package org.eclipse.jgit.internal.storage.file; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; import java.io.File; import java.io.IOException; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java index 97c56385b..d269457eb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.internal.storage.file; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.io.File; @@ -67,15 +68,10 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.util.FS; import org.junit.Assume; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class ObjectDirectoryTest extends RepositoryTestCase { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Test public void testConcurrentInsertionOfBlobsToTheSameNewFanOutDirectory() throws Exception { @@ -199,8 +195,7 @@ public class ObjectDirectoryTest extends RepositoryTestCase { } @Test - public void testShallowFileCorrupt() - throws Exception { + public void testShallowFileCorrupt() throws Exception { FileRepository repository = createBareRepository(); ObjectDirectory dir = repository.getObjectDatabase(); @@ -210,11 +205,9 @@ public class ObjectDirectoryTest extends RepositoryTestCase { UTF_8.name())) { writer.println(commit); } - - expectedEx.expect(IOException.class); - expectedEx.expectMessage(MessageFormat - .format(JGitText.get().badShallowLine, commit)); - dir.getShallowCommits(); + assertThrows( + MessageFormat.format(JGitText.get().badShallowLine, commit), + IOException.class, () -> dir.getShallowCommits()); } private Collection> blobInsertersForTheSameFanOutDir( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java index 8e438bc0e..8c56480fe 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java @@ -45,15 +45,14 @@ package org.eclipse.jgit.internal.storage.file; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.toList; - import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java index a6a8a17b2..49e8a7be6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -53,13 +54,9 @@ import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.IO; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class T0003_BasicTest extends SampleDataRepositoryTestCase { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Test public void test001_Initalize() { @@ -311,10 +308,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase { // We won't create a tree entry with an empty filename // final TreeFormatter formatter = new TreeFormatter(); - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage(JGitText.get().invalidTreeZeroLengthName); - formatter.append("", FileMode.TREE, - ObjectId.fromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904")); + assertThrows(JGitText.get().invalidTreeZeroLengthName, + IllegalArgumentException.class, + () -> formatter.append("", FileMode.TREE, ObjectId.fromString( + "4b825dc642cb6eb9a060e54bf8d69288fbee4904"))); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java index f73dfedae..009914b35 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java @@ -13,16 +13,16 @@ package org.eclipse.jgit.internal.storage.reftable; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH; import static org.eclipse.jgit.lib.Constants.R_HEADS; -import static org.eclipse.jgit.lib.MoreAsserts.assertThrows; import static org.eclipse.jgit.lib.Ref.Storage.NEW; import static org.eclipse.jgit.lib.Ref.Storage.PACKED; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java index 5a7a034ad..6c8c3ba61 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java @@ -9,6 +9,10 @@ */ package org.eclipse.jgit.internal.transport.http; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.io.InputStream; import java.io.Writer; @@ -27,10 +31,8 @@ import java.util.Set; import java.util.regex.Pattern; import org.eclipse.jgit.internal.storage.file.LockFile; -import org.eclipse.jgit.internal.transport.http.NetscapeCookieFile; import org.eclipse.jgit.util.http.HttpCookiesMatcher; import org.hamcrest.CoreMatchers; -import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -81,11 +83,10 @@ public class NetscapeCookieFileTest { cookie = new HttpCookie("key3", "valueFromSet2"); cookiesExpectedMergedSet.add(cookie); - Assert.assertThat( - NetscapeCookieFile.mergeCookies(cookieSet1, cookieSet2), + assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, cookieSet2), HttpCookiesMatcher.containsInOrder(cookiesExpectedMergedSet)); - Assert.assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, null), + assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, null), HttpCookiesMatcher.containsInOrder(cookieSet1)); } @@ -110,8 +111,7 @@ public class NetscapeCookieFileTest { String expectedExpiration = String .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000)); - Assert.assertThat( - Files.readAllLines(tmpFile, StandardCharsets.US_ASCII), + assertThat(Files.readAllLines(tmpFile, StandardCharsets.US_ASCII), CoreMatchers .equalTo(Arrays.asList("mydomain.com\tTRUE\t/\tTRUE\t" + expectedExpiration + "\tkey2\tvalue"))); @@ -136,8 +136,7 @@ public class NetscapeCookieFileTest { String expectedExpiration = String .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000)); - Assert.assertThat( - Files.readAllLines(tmpFile, StandardCharsets.US_ASCII), + assertThat(Files.readAllLines(tmpFile, StandardCharsets.US_ASCII), CoreMatchers.equalTo( Arrays.asList("domain.com\tTRUE\t/my/path\tFALSE\t" + expectedExpiration + "\tkey2\tvalue2"))); @@ -154,7 +153,7 @@ public class NetscapeCookieFileTest { // now imitate another process/thread holding the lock file LockFile lockFile = new LockFile(tmpFile.toFile()); try { - Assert.assertTrue("Could not acquire lock", lockFile.lock()); + assertTrue("Could not acquire lock", lockFile.lock()); cookieFile.write(baseUrl); } finally { lockFile.unlock(); @@ -184,7 +183,7 @@ public class NetscapeCookieFileTest { List lines = Files.readAllLines(tmpFile, StandardCharsets.US_ASCII); - Assert.assertEquals("Expected 3 lines", 3, lines.size()); + assertEquals("Expected 3 lines", 3, lines.size()); assertStringMatchesPatternWithInexactNumber(lines.get(0), "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey1\tvalueFromSimple2", JAN_01_2030_NOON, 1000); @@ -202,12 +201,12 @@ public class NetscapeCookieFileTest { long delta) { java.util.regex.Matcher matcher = Pattern.compile(pattern) .matcher(string); - Assert.assertTrue("Given string '" + string + "' does not match '" - + pattern + "'", matcher.matches()); + assertTrue("Given string '" + string + "' does not match '" + pattern + + "'", matcher.matches()); // extract numeric value Long actualNumericValue = Long.decode(matcher.group(1)); - Assert.assertTrue( + assertTrue( "Value is supposed to be close to " + expectedNumericValue + " but is " + actualNumericValue + ".", Math.abs(expectedNumericValue - actualNumericValue) <= delta); @@ -238,8 +237,7 @@ public class NetscapeCookieFileTest { } Set actualCookies = new NetscapeCookieFile(tmpFile, creationDate).getCookies(true); - Assert.assertThat(actualCookies, - HttpCookiesMatcher.containsInOrder(cookies)); + assertThat(actualCookies, HttpCookiesMatcher.containsInOrder(cookies)); } @Test @@ -259,8 +257,7 @@ public class NetscapeCookieFileTest { NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate); } // compare original file with newly written one, they should not differ - Assert.assertEquals(Files.readAllLines(tmpFile), - Files.readAllLines(tmpFile2)); + assertEquals(Files.readAllLines(tmpFile), Files.readAllLines(tmpFile2)); } @Test @@ -289,8 +286,7 @@ public class NetscapeCookieFileTest { Set actualCookies = new NetscapeCookieFile(tmpFile, creationDate) .getCookies(true); - Assert.assertThat(actualCookies, - HttpCookiesMatcher.containsInOrder(cookies)); + assertThat(actualCookies, HttpCookiesMatcher.containsInOrder(cookies)); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index a80d8b377..9b5691775 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -29,6 +29,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -58,7 +59,6 @@ import org.eclipse.jgit.util.SystemReader; import org.junit.After; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; /** @@ -75,9 +75,6 @@ public class ConfigTest { private static final String REFS_BACKUP = "+refs/heads/*:refs/remotes/backup/*"; - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - @Rule public TemporaryFolder tmp = new TemporaryFolder(); @@ -721,24 +718,22 @@ public class ConfigTest { } @Test - public void testIncludeInvalidName() throws ConfigInvalidException { - expectedEx.expect(ConfigInvalidException.class); - expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile); - parse("[include]\nbar\n"); + public void testIncludeInvalidName() { + assertThrows(JGitText.get().invalidLineInConfigFile, + ConfigInvalidException.class, () -> parse("[include]\nbar\n")); } @Test - public void testIncludeNoValue() throws ConfigInvalidException { - expectedEx.expect(ConfigInvalidException.class); - expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile); - parse("[include]\npath\n"); + public void testIncludeNoValue() { + assertThrows(JGitText.get().invalidLineInConfigFile, + ConfigInvalidException.class, () -> parse("[include]\npath\n")); } @Test - public void testIncludeEmptyValue() throws ConfigInvalidException { - expectedEx.expect(ConfigInvalidException.class); - expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile); - parse("[include]\npath=\n"); + public void testIncludeEmptyValue() { + assertThrows(JGitText.get().invalidLineInConfigFile, + ConfigInvalidException.class, + () -> parse("[include]\npath=\n")); } @Test @@ -1269,25 +1264,24 @@ public class ConfigTest { } @Test - public void testTimeUnitInvalid() throws ConfigInvalidException { - expectedEx.expect(IllegalArgumentException.class); - expectedEx - .expectMessage("Invalid time unit value: a.a=1 monttthhh"); - parseTime("1 monttthhh", DAYS); + public void testTimeUnitInvalid() { + assertThrows("Invalid time unit value: a.a=1 monttthhh", + IllegalArgumentException.class, + () -> parseTime("1 monttthhh", DAYS)); } @Test public void testTimeUnitInvalidWithSection() throws ConfigInvalidException { Config c = parse("[a \"b\"]\na=1 monttthhh\n"); - expectedEx.expect(IllegalArgumentException.class); - expectedEx.expectMessage("Invalid time unit value: a.b.a=1 monttthhh"); - c.getTimeUnit("a", "b", "a", 0, DAYS); + assertThrows("Invalid time unit value: a.b.a=1 monttthhh", + IllegalArgumentException.class, + () -> c.getTimeUnit("a", "b", "a", 0, DAYS)); } @Test - public void testTimeUnitNegative() throws ConfigInvalidException { - expectedEx.expect(IllegalArgumentException.class); - parseTime("-1", MILLISECONDS); + public void testTimeUnitNegative() { + assertThrows(IllegalArgumentException.class, + () -> parseTime("-1", MILLISECONDS)); } @Test @@ -1430,10 +1424,10 @@ public class ConfigTest { } @Test - public void testInvalidGroupHeader() throws ConfigInvalidException { - expectedEx.expect(ConfigInvalidException.class); - expectedEx.expectMessage(JGitText.get().badGroupHeader); - parse("[foo \"bar\" ]\nfoo=bar\n"); + public void testInvalidGroupHeader() { + assertThrows(JGitText.get().badGroupHeader, + ConfigInvalidException.class, + () -> parse("[foo \"bar\" ]\nfoo=bar\n")); } @Test @@ -1447,17 +1441,15 @@ public class ConfigTest { } @Test - public void testCrCharContinuation() throws ConfigInvalidException { - expectedEx.expect(ConfigInvalidException.class); - expectedEx.expectMessage("Bad escape: \\u000d"); - parseEscapedValue("tr\\\rue"); + public void testCrCharContinuation() { + assertThrows("Bad escape: \\u000d", ConfigInvalidException.class, + () -> parseEscapedValue("tr\\\rue")); } @Test - public void testCrEOFContinuation() throws ConfigInvalidException { - expectedEx.expect(ConfigInvalidException.class); - expectedEx.expectMessage("Bad escape: \\u000d"); - parseEscapedValue("tr\\\r"); + public void testCrEOFContinuation() { + assertThrows("Bad escape: \\u000d", ConfigInvalidException.class, + () -> parseEscapedValue("tr\\\r")); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java index 11ed8fdf0..5c44c9c44 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java @@ -34,6 +34,7 @@ import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE; import static org.eclipse.jgit.util.RawParseUtils.decode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import java.text.MessageFormat; @@ -41,9 +42,7 @@ import java.text.MessageFormat; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.internal.JGitText; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class ObjectCheckerTest { private static final ObjectChecker SECRET_KEY_CHECKER = new ObjectChecker() { @@ -84,9 +83,6 @@ public class ObjectCheckerTest { private ObjectChecker checker; - @Rule - public final ExpectedException thrown = ExpectedException.none(); - @Before public void setUp() throws Exception { checker = new ObjectChecker(); @@ -116,9 +112,9 @@ public class ObjectCheckerTest { } @Test - public void testCheckBlobCorrupt() throws CorruptObjectException { - thrown.expect(CorruptObjectException.class); - SECRET_KEY_CHECKER.check(OBJ_BLOB, encodeASCII("key = \"secret_key\"")); + public void testCheckBlobCorrupt() { + assertThrows(CorruptObjectException.class, () -> SECRET_KEY_CHECKER + .check(OBJ_BLOB, encodeASCII("key = \"secret_key\""))); } @Test @@ -129,11 +125,9 @@ public class ObjectCheckerTest { } @Test - public void testCheckBlobWithBlobObjectCheckerCorrupt() - throws CorruptObjectException { - thrown.expect(CorruptObjectException.class); - SECRET_KEY_BLOB_CHECKER.check(OBJ_BLOB, - encodeASCII("key = \"secret_key\"")); + public void testCheckBlobWithBlobObjectCheckerCorrupt() { + assertThrows(CorruptObjectException.class, () -> SECRET_KEY_BLOB_CHECKER + .check(OBJ_BLOB, encodeASCII("key = \"secret_key\""))); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java index 32dc7eb12..cec69c499 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java @@ -11,12 +11,12 @@ package org.eclipse.jgit.lib; import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index b5ab9d2ac..054eb9c5a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -17,6 +17,7 @@ import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -44,36 +45,30 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class BundleWriterTest extends SampleDataRepositoryTestCase { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testEmptyBundleFails() throws Exception { Repository newRepo = createBareRepository(); - thrown.expect(TransportException.class); - fetchFromBundle(newRepo, new byte[0]); + assertThrows(TransportException.class, + () -> fetchFromBundle(newRepo, new byte[0])); } @Test public void testNonBundleFails() throws Exception { Repository newRepo = createBareRepository(); - thrown.expect(TransportException.class); - fetchFromBundle(newRepo, "Not a bundle file".getBytes(UTF_8)); + assertThrows(TransportException.class, () -> fetchFromBundle(newRepo, + "Not a bundle file".getBytes(UTF_8))); } @Test public void testGarbageBundleFails() throws Exception { Repository newRepo = createBareRepository(); - thrown.expect(TransportException.class); - fetchFromBundle(newRepo, + assertThrows(TransportException.class, () -> fetchFromBundle(newRepo, (TransportBundle.V2_BUNDLE_SIGNATURE + '\n' + "Garbage") - .getBytes(UTF_8)); + .getBytes(UTF_8))); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java index b55c91f34..965a2faf8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java @@ -10,8 +10,8 @@ package org.eclipse.jgit.transport; import static org.eclipse.jgit.transport.ObjectIdMatcher.hasOnlyObjectIds; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java index e16b84fec..038ce717b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java @@ -9,12 +9,13 @@ */ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.transport.ObjectIdMatcher.hasOnlyObjectIds; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItems; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.eclipse.jgit.transport.ObjectIdMatcher.hasOnlyObjectIds; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -27,15 +28,10 @@ import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class ProtocolV2ParserTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private TestRepository testRepo; @Before @@ -236,8 +232,8 @@ public class ProtocolV2ParserTest { ProtocolV2Parser parser = new ProtocolV2Parser( ConfigBuilder.start().allowFilter().done()); - thrown.expect(PackProtocolException.class); - parser.parseFetchRequest(pckIn); + assertThrows(PackProtocolException.class, + () -> parser.parseFetchRequest(pckIn)); } @Test @@ -247,8 +243,8 @@ public class ProtocolV2ParserTest { ProtocolV2Parser parser = new ProtocolV2Parser( ConfigBuilder.getDefault()); - thrown.expect(PackProtocolException.class); - parser.parseFetchRequest(pckIn); + assertThrows(PackProtocolException.class, + () -> parser.parseFetchRequest(pckIn)); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java index f15fa4864..cc910b3b9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RequestValidatorTestCase.java @@ -9,12 +9,15 @@ */ package org.eclipse.jgit.transport; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowableOfType; + import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.eclipse.jgit.errors.PackProtocolException; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; @@ -25,17 +28,11 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.transport.UploadPack.RequestValidator; -import org.hamcrest.Matchers; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public abstract class RequestValidatorTestCase { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private RevCommit reachableCommit; private RevCommit tipAdvertisedCommit; @@ -111,156 +108,165 @@ public abstract class RequestValidatorTestCase { protected abstract boolean isUnreachableBlobValid(); @Test - public void validateReachableCommitWithBitmaps() - throws PackProtocolException, IOException { + public void validateReachableCommitWithBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithBitmaps()), + Arrays.asList(reachableCommit)); if (!isReachableCommitValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers - .containsString( - "want " + reachableCommit.name() + " not valid")); - + assertTransportException(c, + "want " + reachableCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), - Arrays.asList(reachableCommit)); + c.call(); } @Test - public void validateReachableCommitWithoutBitmaps() - throws PackProtocolException, IOException { + public void validateReachableCommitWithoutBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithoutBitmaps()), + Arrays.asList(reachableCommit)); if (!isReachableCommitValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + reachableCommit.name() + " not valid")); - + assertTransportException(c, + "want " + reachableCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), - Arrays.asList(reachableCommit)); + c.call(); } @Test - public void validateAdvertisedTipWithBitmaps() - throws PackProtocolException, IOException { + public void validateAdvertisedTipWithBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithBitmaps()), + Arrays.asList(tipAdvertisedCommit)); if (!isAdvertisedTipValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + tipAdvertisedCommit.name() + " not valid")); - + assertTransportException(c, + "want " + tipAdvertisedCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), - Arrays.asList(tipAdvertisedCommit)); + c.call(); } @Test - public void validateAdvertisedTipWithoutBitmaps() - throws PackProtocolException, IOException { + public void validateAdvertisedTipWithoutBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithoutBitmaps()), + Arrays.asList(tipAdvertisedCommit)); if (!isAdvertisedTipValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + tipAdvertisedCommit.name() + " not valid")); - + assertTransportException(c, + "want " + tipAdvertisedCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), - Arrays.asList(tipAdvertisedCommit)); + c.call(); } @Test - public void validateUnadvertisedTipWithBitmaps() - throws PackProtocolException, IOException { + public void validateUnadvertisedTipWithBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithBitmaps()), + Arrays.asList(tipUnadvertisedCommit)); if (!isUnadvertisedTipCommitValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + tipUnadvertisedCommit.name() + " not valid")); - + assertTransportException(c, + "want " + tipUnadvertisedCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), - Arrays.asList(tipUnadvertisedCommit)); + c.call(); } @Test - public void validateUnadvertisedTipWithoutBitmaps() - throws PackProtocolException, IOException { + public void validateUnadvertisedTipWithoutBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithoutBitmaps()), + Arrays.asList(tipUnadvertisedCommit)); if (!isUnadvertisedTipCommitValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + tipUnadvertisedCommit.name() + " not valid")); - + assertTransportException(c, + "want " + tipUnadvertisedCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), - Arrays.asList(tipUnadvertisedCommit)); + c.call(); } @Test - public void validateUnreachableCommitWithBitmaps() - throws PackProtocolException, IOException { + public void validateUnreachableCommitWithBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithBitmaps()), + Arrays.asList(unreachableCommit)); if (!isUnreachableCommitValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + unreachableCommit.name() + " not valid")); - + assertTransportException(c, + "want " + unreachableCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), - Arrays.asList(unreachableCommit)); + c.call(); } @Test - public void validateUnreachableCommitWithoutBitmaps() - throws PackProtocolException, IOException { + public void validateUnreachableCommitWithoutBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithoutBitmaps()), + Arrays.asList(unreachableCommit)); if (!isUnreachableCommitValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + unreachableCommit.name() + " not valid")); - + assertTransportException(c, + "want " + unreachableCommit.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), - Arrays.asList(unreachableCommit)); + c.call(); } @Test - public void validateReachableBlobWithBitmaps() - throws PackProtocolException, IOException { + public void validateReachableBlobWithBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithBitmaps()), + Arrays.asList(reachableBlob)); if (!isReachableBlobValid_withBitmaps()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + reachableBlob.name() + " not valid")); + assertTransportException(c, + "want " + reachableBlob.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), - Arrays.asList(reachableBlob)); + c.call(); } @Test - public void validateReachableBlobWithoutBitmaps() - throws PackProtocolException, IOException { + public void validateReachableBlobWithoutBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithoutBitmaps()), + Arrays.asList(reachableBlob)); if (!isReachableBlobValid_withoutBitmaps()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + reachableBlob.name() + " not valid")); + assertTransportException(c, + "want " + reachableBlob.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), - Arrays.asList(reachableBlob)); + c.call(); } @Test - public void validateUnreachableBlobWithBitmaps() - throws PackProtocolException, IOException { + public void validateUnreachableBlobWithBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithBitmaps()), + Arrays.asList(unreachableBlob)); if (!isUnreachableBlobValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + unreachableBlob.name() + " not valid")); + assertTransportException(c, + "want " + unreachableBlob.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithBitmaps()), - Arrays.asList(unreachableBlob)); + c.call(); } @Test - public void validateUnreachableBlobWithoutBitmaps() - throws PackProtocolException, IOException { + public void validateUnreachableBlobWithoutBitmaps() throws Throwable { + ThrowingCallable c = () -> createValidator().checkWants( + getUploadPack(getRepoWithoutBitmaps()), + Arrays.asList(unreachableBlob)); if (!isUnreachableBlobValid()) { - thrown.expect(TransportException.class); - thrown.expectMessage(Matchers.containsString( - "want " + unreachableBlob.name() + " not valid")); + assertTransportException(c, + "want " + unreachableBlob.name() + " not valid"); + return; } - createValidator().checkWants(getUploadPack(getRepoWithoutBitmaps()), - Arrays.asList(unreachableBlob)); + c.call(); + } + + private void assertTransportException(ThrowingCallable c, + String messageContent) throws AssertionError { + assertThat(catchThrowableOfType(c, TransportException.class)) + .hasMessageContaining(messageContent); } private UploadPack getUploadPack(Repository repository) throws IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java index 7fe5b5981..b84b6b2e0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java @@ -9,6 +9,8 @@ */ package org.eclipse.jgit.transport; +import static org.hamcrest.MatcherAssert.assertThat; + import java.io.File; import java.io.IOException; import java.net.HttpCookie; @@ -120,7 +122,7 @@ public class TransportHttpTest extends SampleDataRepositoryTestCase { cookie.setMaxAge(1234); expectedCookies.add(cookie); - Assert.assertThat( + assertThat( new NetscapeCookieFile(cookieFile.toPath()) .getCookies(true), HttpCookiesMatcher.containsInOrder(expectedCookies, 5)); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java index 2c9712c99..271176264 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackReachabilityTest.java @@ -9,10 +9,10 @@ */ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.MoreAsserts.assertThrows; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.util.Collections; @@ -32,9 +32,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import org.eclipse.jgit.transport.resolver.UploadPackFactory; import org.junit.After; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; /** * Test combinations of: @@ -46,9 +44,6 @@ import org.junit.rules.ExpectedException; */ public class UploadPackReachabilityTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private URIish uri; private TestProtocol testProtocol; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java index 99fe214cd..37c87057d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackRefSortingForReachabilityTest.java @@ -10,8 +10,8 @@ package org.eclipse.jgit.transport; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; import java.util.List; import java.util.stream.Collectors; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 108e5edb7..ea86563da 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -1,6 +1,6 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.MoreAsserts.assertThrows; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItems; @@ -9,7 +9,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java index f6dd9adc0..c9fd0c9b1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java @@ -9,11 +9,12 @@ */ package org.eclipse.jgit.util; +import static org.hamcrest.MatcherAssert.assertThat; + import java.util.LinkedHashMap; import java.util.Map; import org.hamcrest.collection.IsIterableContainingInOrder; -import org.junit.Assert; import org.junit.Test; public class LRUMapTest { @@ -38,8 +39,7 @@ public class LRUMapTest { expectedMap.put(0, 0); expectedMap.put(3, 3); - Assert.assertThat(map.entrySet(), - IsIterableContainingInOrder - .contains(expectedMap.entrySet().toArray())); + assertThat(map.entrySet(), IsIterableContainingInOrder + .contains(expectedMap.entrySet().toArray())); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java index 7ea96dd9d..1c2d8d7f6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java @@ -13,16 +13,12 @@ package org.eclipse.jgit.util; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import org.eclipse.jgit.errors.BinaryBlobException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; public class RawParseUtils_LineMapTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testEmpty() throws Exception { @@ -62,8 +58,8 @@ public class RawParseUtils_LineMapTest { @Test public void testLineMapOrBinary() throws Exception { final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1); - exception.expect(BinaryBlobException.class); - RawParseUtils.lineMapOrBinary(buf, 3, buf.length); + assertThrows(BinaryBlobException.class, + () -> RawParseUtils.lineMapOrBinary(buf, 3, buf.length)); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java index 024f0f3b0..567880f47 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TimeoutOutputStreamTest.java @@ -149,7 +149,9 @@ public class TimeoutOutputStreamTest { try { Thread.sleep(1000); } catch (InterruptedException e) { - throw new InterruptedIOException(); + InterruptedIOException e1 = new InterruptedIOException(); + e1.initCause(e); + throw e1; } } } @@ -202,7 +204,9 @@ public class TimeoutOutputStreamTest { try { Thread.sleep(1000); } catch (InterruptedException e) { - throw new InterruptedIOException(); + InterruptedIOException e1 = new InterruptedIOException(); + e1.initCause(e); + throw e1; } } } diff --git a/org.eclipse.jgit/resources/META-INF/services/org.eclipse.jgit.transport.SshSessionFactory b/org.eclipse.jgit/resources/META-INF/services/org.eclipse.jgit.transport.SshSessionFactory new file mode 100644 index 000000000..1f8828457 --- /dev/null +++ b/org.eclipse.jgit/resources/META-INF/services/org.eclipse.jgit.transport.SshSessionFactory @@ -0,0 +1 @@ +org.eclipse.jgit.transport.DefaultSshSessionFactory diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 2525cbb58..78afe18f3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -164,7 +164,7 @@ public class CloneCommand extends TransportCommand { verifyDirectories(u); } catch (URISyntaxException e) { throw new InvalidRemoteException( - MessageFormat.format(JGitText.get().invalidURL, uri)); + MessageFormat.format(JGitText.get().invalidURL, uri), e); } setFetchType(); @SuppressWarnings("resource") // Closed by caller @@ -185,8 +185,9 @@ public class CloneCommand extends TransportCommand { repository.close(); } cleanup(); - throw new InvalidRemoteException(MessageFormat.format( - JGitText.get().invalidRemote, remote)); + throw new InvalidRemoteException( + MessageFormat.format(JGitText.get().invalidRemote, remote), + e); } catch (GitAPIException | RuntimeException e) { if (repository != null) { repository.close(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java index a4b9bcf00..033dd60c3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java @@ -223,7 +223,7 @@ public class FetchCommand extends TransportCommand { e.getMessage(), e); } catch (URISyntaxException e) { throw new InvalidRemoteException(MessageFormat.format( - JGitText.get().invalidRemote, remote)); + JGitText.get().invalidRemote, remote), e); } catch (NotSupportedException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfFetchCommand, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java index 12517df51..a4ca30909 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LsRemoteCommand.java @@ -180,7 +180,7 @@ public class LsRemoteCommand extends } } catch (URISyntaxException e) { throw new InvalidRemoteException(MessageFormat.format( - JGitText.get().invalidRemote, remote)); + JGitText.get().invalidRemote, remote), e); } catch (NotSupportedException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java index b9b15ebdc..aa5a63499 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java @@ -152,8 +152,9 @@ public class PushCommand extends } } catch (URISyntaxException e) { - throw new InvalidRemoteException(MessageFormat.format( - JGitText.get().invalidRemote, remote)); + throw new InvalidRemoteException( + MessageFormat.format(JGitText.get().invalidRemote, remote), + e); } catch (TransportException e) { throw new org.eclipse.jgit.api.errors.TransportException( e.getMessage(), e); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java index fcfae65bc..fb6e5df58 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java @@ -350,6 +350,7 @@ public class SimilarityIndex { return (1 << idHashBits) * (idHashBits - 3) / idHashBits; } + @SuppressWarnings("UnusedException") private void grow() throws TableFullException { if (idHashBits == 30) throw new TableFullException(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index bbaed3766..fdc89cd54 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -3,41 +3,14 @@ * Copyright (C) 2008, Robin Rosenberg * Copyright (C) 2008, Roger C. Soares * Copyright (C) 2006, Shawn O. Pearce - * Copyright (C) 2010, Chrisian Halstrick and - * other copyright owners as documented in the project's IP log. + * Copyright (C) 2010, Chrisian Halstrick + * Copyright (C) 2019-2020, Andre Bossert * * 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 + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://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. + * SPDX-License-Identifier: BSD-3-Clause */ package org.eclipse.jgit.dircache; @@ -1504,29 +1477,9 @@ public class DirCacheCheckout { File tmpFile = File.createTempFile( "._" + name, null, parentDir); //$NON-NLS-1$ - EolStreamType nonNullEolStreamType; - if (checkoutMetadata.eolStreamType != null) { - nonNullEolStreamType = checkoutMetadata.eolStreamType; - } else if (opt.getAutoCRLF() == AutoCRLF.TRUE) { - nonNullEolStreamType = EolStreamType.AUTO_CRLF; - } else { - nonNullEolStreamType = EolStreamType.DIRECT; - } - try (OutputStream channel = EolStreamTypeUtil.wrapOutputStream( - new FileOutputStream(tmpFile), nonNullEolStreamType)) { - if (checkoutMetadata.smudgeFilterCommand != null) { - if (FilterCommandRegistry - .isRegistered(checkoutMetadata.smudgeFilterCommand)) { - runBuiltinFilterCommand(repo, checkoutMetadata, ol, - channel); - } else { - runExternalFilterCommand(repo, entry, checkoutMetadata, ol, - fs, channel); - } - } else { - ol.copyTo(channel); - } - } + getContent(repo, entry.getPathString(), checkoutMetadata, ol, opt, + new FileOutputStream(tmpFile)); + // The entry needs to correspond to the on-disk filesize. If the content // was filtered (either by autocrlf handling or smudge filters) ask the // filesystem again for the length. Otherwise the objectloader knows the @@ -1565,11 +1518,69 @@ public class DirCacheCheckout { entry.setLastModified(fs.lastModifiedInstant(f)); } + /** + * Return filtered content for a specific object (blob). EOL handling and + * smudge-filter handling are applied in the same way as it would be done + * during a checkout. + * + * @param repo + * the repository + * @param path + * the path used to determine the correct filters for the object + * @param checkoutMetadata + * containing + *
    + *
  • smudgeFilterCommand to be run for smudging the object
  • + *
  • eolStreamType used for stream conversion (can be + * null)
  • + *
+ * @param ol + * the object loader to read raw content of the object + * @param opt + * the working tree options where only 'core.autocrlf' is used + * for EOL handling if 'checkoutMetadata.eolStreamType' is not + * valid + * @param os + * the output stream the filtered content is written to. The + * caller is responsible to close the stream. + * @throws IOException + * + * @since 5.7 + */ + public static void getContent(Repository repo, String path, + CheckoutMetadata checkoutMetadata, ObjectLoader ol, + WorkingTreeOptions opt, OutputStream os) + throws IOException { + EolStreamType nonNullEolStreamType; + if (checkoutMetadata.eolStreamType != null) { + nonNullEolStreamType = checkoutMetadata.eolStreamType; + } else if (opt.getAutoCRLF() == AutoCRLF.TRUE) { + nonNullEolStreamType = EolStreamType.AUTO_CRLF; + } else { + nonNullEolStreamType = EolStreamType.DIRECT; + } + try (OutputStream channel = EolStreamTypeUtil.wrapOutputStream( + os, nonNullEolStreamType)) { + if (checkoutMetadata.smudgeFilterCommand != null) { + if (FilterCommandRegistry + .isRegistered(checkoutMetadata.smudgeFilterCommand)) { + runBuiltinFilterCommand(repo, checkoutMetadata, ol, + channel); + } else { + runExternalFilterCommand(repo, path, checkoutMetadata, ol, + channel); + } + } else { + ol.copyTo(channel); + } + } + } + // Run an external filter command - private static void runExternalFilterCommand(Repository repo, - DirCacheEntry entry, - CheckoutMetadata checkoutMetadata, ObjectLoader ol, FS fs, + private static void runExternalFilterCommand(Repository repo, String path, + CheckoutMetadata checkoutMetadata, ObjectLoader ol, OutputStream channel) throws IOException { + FS fs = repo.getFS(); ProcessBuilder filterProcessBuilder = fs.runInShell( checkoutMetadata.smudgeFilterCommand, new String[0]); filterProcessBuilder.directory(repo.getWorkTree()); @@ -1588,12 +1599,12 @@ public class DirCacheCheckout { } catch (IOException | InterruptedException e) { throw new IOException(new FilterFailedException(e, checkoutMetadata.smudgeFilterCommand, - entry.getPathString())); + path)); } if (rc != 0) { throw new IOException(new FilterFailedException(rc, checkoutMetadata.smudgeFilterCommand, - entry.getPathString(), + path, result.getStdout().toByteArray(MAX_EXCEPTION_TEXT_SIZE), RawParseUtils.decode(result.getStderr() .toByteArray(MAX_EXCEPTION_TEXT_SIZE)))); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java index 023efd8e1..6a2c3898a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java @@ -139,7 +139,7 @@ public class ManifestParser extends DefaultHandler { try { xr = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { - throw new IOException(JGitText.get().noXMLParserAvailable); + throw new IOException(JGitText.get().noXMLParserAvailable, e); } xr.setContentHandler(this); try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index 98f61d159..c039aaffa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -541,7 +541,7 @@ public class RepoCommand extends GitCommand { inputStream = new FileInputStream(manifestPath); } catch (IOException e) { throw new IllegalArgumentException( - JGitText.get().pathNotConfigured); + JGitText.get().pathNotConfigured, e); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckPackParser.java index ad7aebc27..3b9498456 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/fsck/FsckPackParser.java @@ -290,9 +290,12 @@ public class FsckPackParser extends PackParser { ErrorType.MISMATCH_CRC); } } catch (MissingObjectException e) { - throw new CorruptPackIndexException(MessageFormat - .format(JGitText.get().missingCRC, entry.getName()), + CorruptPackIndexException cpe = new CorruptPackIndexException( + MessageFormat.format(JGitText.get().missingCRC, + entry.getName()), ErrorType.MISSING_CRC); + cpe.initCause(e); + throw cpe; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java index bee2e01a8..6e7ad3e61 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java @@ -236,7 +236,7 @@ public class DfsBlockCacheConfig { JGitText.get().enumValueNotSupported3, CONFIG_CORE_SECTION, CONFIG_DFS_SECTION, - CONFIG_KEY_STREAM_RATIO, v)); + CONFIG_KEY_STREAM_RATIO, v), e); } } return this; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index 857c1730f..169587081 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -769,7 +769,8 @@ public class ObjectDirectory extends FileObjectDatabase { shallowCommitsIds.add(ObjectId.fromString(line)); } catch (IllegalArgumentException ex) { throw new IOException(MessageFormat - .format(JGitText.get().badShallowLine, line)); + .format(JGitText.get().badShallowLine, line), + ex); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java index 0de818a1d..b99733875 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java @@ -71,13 +71,12 @@ import org.slf4j.LoggerFactory; */ public class PackFile implements Iterable { private final static Logger LOG = LoggerFactory.getLogger(PackFile.class); - /** Sorts PackFiles to be most recently created to least recently created. */ - public static final Comparator SORT = new Comparator() { - @Override - public int compare(PackFile a, PackFile b) { - return b.packLastModified.compareTo(a.packLastModified); - } - }; + + /** + * Sorts PackFiles to be most recently created to least recently created. + */ + public static final Comparator SORT = (a, b) -> b.packLastModified + .compareTo(a.packLastModified); private final File packFile; @@ -1071,7 +1070,7 @@ public class PackFile implements Iterable { } catch (DataFormatException e) { throw new CorruptObjectException(MessageFormat.format( JGitText.get().objectAtHasBadZlibStream, Long.valueOf(pos), - getPackFile())); + getPackFile()), e); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index b636db6f2..fddd430bf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -1035,7 +1035,10 @@ public class RefDirectory extends RefDatabase { lck.waitForStatChange(); } catch (InterruptedException e) { lck.unlock(); - throw new ObjectWritingException(MessageFormat.format(JGitText.get().interruptedWriting, name)); + throw new ObjectWritingException( + MessageFormat.format( + JGitText.get().interruptedWriting, name), + e); } if (!lck.commit()) throw new ObjectWritingException(MessageFormat.format(JGitText.get().unableToWrite, name)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java index 743badbcc..bf47d2c3c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java @@ -149,8 +149,10 @@ public class UnpackedObject { } return new LargeObject(type, size, path, id, wc.db); } catch (ZipException badStream) { - throw new CorruptObjectException(id, + CorruptObjectException coe = new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); + coe.initCause(badStream); + throw coe; } } @@ -192,8 +194,10 @@ public class UnpackedObject { } return size; } catch (ZipException badStream) { - throw new CorruptObjectException(id, + CorruptObjectException coe = new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); + coe.initCause(badStream); + throw coe; } } @@ -205,8 +209,10 @@ public class UnpackedObject { try { r = inf.inflate(buf); } catch (DataFormatException e) { - throw new CorruptObjectException(id, + CorruptObjectException coe = new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); + coe.initCause(e); + throw coe; } if (r != 0) throw new CorruptObjectException(id, @@ -277,8 +283,10 @@ public class UnpackedObject { remaining -= r; return r; } catch (ZipException badStream) { - throw new CorruptObjectException(id, + CorruptObjectException coe = new CorruptObjectException(id, JGitText.get().corruptObjectBadStream); + coe.initCause(badStream); + throw coe; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 33ffe0717..e8f0e1fd9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -142,43 +142,42 @@ public class PackWriter implements AutoCloseable { private static final Map, Boolean> instances = new ConcurrentHashMap<>(); - private static final Iterable instancesIterable = new Iterable() { + private static final Iterable instancesIterable = () -> new Iterator() { + + private final Iterator> it = instances + .keySet().iterator(); + + private PackWriter next; + @Override - public Iterator iterator() { - return new Iterator() { - private final Iterator> it = - instances.keySet().iterator(); - private PackWriter next; - - @Override - public boolean hasNext() { - if (next != null) - return true; - while (it.hasNext()) { - WeakReference ref = it.next(); - next = ref.get(); - if (next != null) - return true; - it.remove(); - } - return false; + public boolean hasNext() { + if (next != null) { + return true; + } + while (it.hasNext()) { + WeakReference ref = it.next(); + next = ref.get(); + if (next != null) { + return true; } + it.remove(); + } + return false; + } - @Override - public PackWriter next() { - if (hasNext()) { - PackWriter result = next; - next = null; - return result; - } - throw new NoSuchElementException(); - } + @Override + public PackWriter next() { + if (hasNext()) { + PackWriter result = next; + next = null; + return result; + } + throw new NoSuchElementException(); + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - }; + @Override + public void remove() { + throw new UnsupportedOperationException(); } }; @@ -1579,8 +1578,8 @@ public class PackWriter implements AutoCloseable { if (pool.awaitTermination(60, TimeUnit.SECONDS)) break; } catch (InterruptedException e) { - throw new IOException( - JGitText.get().packingCancelledDuringObjectsWriting); + throw new IOException(JGitText + .get().packingCancelledDuringObjectsWriting, e); } } } @@ -1604,7 +1603,8 @@ public class PackWriter implements AutoCloseable { // Cross our fingers and just break out anyway. // throw new IOException( - JGitText.get().packingCancelledDuringObjectsWriting); + JGitText.get().packingCancelledDuringObjectsWriting, + ie); } } @@ -1645,7 +1645,7 @@ public class PackWriter implements AutoCloseable { for (Future f : futures) f.cancel(true); throw new IOException( - JGitText.get().packingCancelledDuringObjectsWriting); + JGitText.get().packingCancelledDuringObjectsWriting, ie); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java index 20066bec7..d0e24413b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/submodule/SubmoduleValidator.java @@ -165,9 +165,10 @@ public class SubmoduleValidator { } } } catch (ConfigInvalidException e) { - throw new SubmoduleValidationException( - JGitText.get().invalidGitModules, - GITMODULES_PARSE); + SubmoduleValidationException sve = new SubmoduleValidationException( + JGitText.get().invalidGitModules, GITMODULES_PARSE); + sve.initCause(e); + throw sve; } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java index a5e4d787f..dc5e5cc20 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java @@ -114,8 +114,11 @@ public final class AbbreviatedObjectId implements Serializable { final int d = hexUInt32(bs, ptr + 24, end); final int e = hexUInt32(bs, ptr + 32, end); return new AbbreviatedObjectId(end - ptr, a, b, c, d, e); - } catch (ArrayIndexOutOfBoundsException e1) { - throw new InvalidObjectIdException(bs, ptr, end - ptr); + } catch (ArrayIndexOutOfBoundsException e) { + InvalidObjectIdException e1 = new InvalidObjectIdException(bs, ptr, + end - ptr); + e1.initCause(e); + throw e1; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index d502274c4..ffc742d47 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -601,7 +601,10 @@ public final class Constants { throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType); } } catch (ArrayIndexOutOfBoundsException bad) { - throw new CorruptObjectException(id, JGitText.get().corruptObjectInvalidType); + CorruptObjectException coe = new CorruptObjectException(id, + JGitText.get().corruptObjectInvalidType); + coe.initCause(bad); + throw coe; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java index abc9b2119..cc0b995f1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java @@ -46,7 +46,7 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter { return StringUtils.toBoolean(n); } catch (IllegalArgumentException err) { throw new IllegalArgumentException(MessageFormat.format( - JGitText.get().invalidBooleanValue, section, name, n)); + JGitText.get().invalidBooleanValue, section, name, n), err); } } @@ -152,7 +152,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter { return mul * Long.parseLong(n); } catch (NumberFormatException nfe) { throw new IllegalArgumentException(MessageFormat.format( - JGitText.get().invalidIntegerValue, section, name, str)); + JGitText.get().invalidIntegerValue, section, name, str), + nfe); } } @@ -239,7 +240,10 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter { return wantUnit.convert(Long.parseLong(digits) * inputMul, inputUnit); } catch (NumberFormatException nfe) { - throw notTimeUnit(section, subsection, unitName, valueString); + IllegalArgumentException iae = notTimeUnit(section, subsection, + unitName, valueString); + iae.initCause(nfe); + throw iae; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java index 86b306d5b..4a712ba36 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java @@ -234,9 +234,11 @@ public class MutableObjectId extends AnyObjectId { w3 = RawParseUtils.parseHexInt32(bs, p + 16); w4 = RawParseUtils.parseHexInt32(bs, p + 24); w5 = RawParseUtils.parseHexInt32(bs, p + 32); - } catch (ArrayIndexOutOfBoundsException e1) { - throw new InvalidObjectIdException(bs, p, + } catch (ArrayIndexOutOfBoundsException e) { + InvalidObjectIdException e1 = new InvalidObjectIdException(bs, p, Constants.OBJECT_ID_STRING_LENGTH); + e1.initCause(e); + throw e1; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java index 11c0aefe3..269049f4a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java @@ -213,9 +213,11 @@ public class ObjectId extends AnyObjectId implements Serializable { final int d = RawParseUtils.parseHexInt32(bs, p + 24); final int e = RawParseUtils.parseHexInt32(bs, p + 32); return new ObjectId(a, b, c, d, e); - } catch (ArrayIndexOutOfBoundsException e1) { - throw new InvalidObjectIdException(bs, p, + } catch (ArrayIndexOutOfBoundsException e) { + InvalidObjectIdException e1 = new InvalidObjectIdException(bs, p, Constants.OBJECT_ID_STRING_LENGTH); + e1.initCause(e); + throw e1; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 503e218b5..a7a832c1a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -550,9 +550,11 @@ public abstract class Repository implements AutoCloseable { try { pnum = Integer.parseInt(parentnum); } catch (NumberFormatException e) { - throw new RevisionSyntaxException( + RevisionSyntaxException rse = new RevisionSyntaxException( JGitText.get().invalidCommitParentNumber, revstr); + rse.initCause(e); + throw rse; } if (pnum != 0) { RevCommit commit = (RevCommit) rev; @@ -647,8 +649,10 @@ public abstract class Repository implements AutoCloseable { try { dist = Integer.parseInt(distnum); } catch (NumberFormatException e) { - throw new RevisionSyntaxException( + RevisionSyntaxException rse = new RevisionSyntaxException( JGitText.get().invalidAncestryLength, revstr); + rse.initCause(e); + throw rse; } } else dist = 1; @@ -707,7 +711,10 @@ public abstract class Repository implements AutoCloseable { remoteConfig = new RemoteConfig(getConfig(), "origin"); //$NON-NLS-1$ } catch (URISyntaxException e) { - throw new RevisionSyntaxException(revstr); + RevisionSyntaxException rse = new RevisionSyntaxException( + revstr); + rse.initCause(e); + throw rse; } String remoteBranchName = getConfig() .getString( @@ -874,8 +881,11 @@ public abstract class Repository implements AutoCloseable { try { number = Integer.parseInt(time); } catch (NumberFormatException nfe) { - throw new RevisionSyntaxException(MessageFormat.format( - JGitText.get().invalidReflogRevision, time)); + RevisionSyntaxException rse = new RevisionSyntaxException( + MessageFormat.format(JGitText.get().invalidReflogRevision, + time)); + rse.initCause(nfe); + throw rse; } assert number >= 0; ReflogReader reader = getReflogReader(ref.getName()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index a177c290e..9210ec172 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -33,6 +33,7 @@ import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -44,6 +45,8 @@ import java.util.Set; import java.util.SortedMap; import java.util.TimeZone; import java.util.TreeMap; +import java.util.stream.Collectors; +import java.time.Instant; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; @@ -288,6 +291,8 @@ public class AmazonS3 { *

* This method is primarily meant for obtaining a "recursive directory * listing" rooted under the specified bucket and prefix location. + * It returns the keys sorted in reverse order of LastModified time + * (freshest keys first). * * @param bucket * name of the bucket whose objects should be listed. @@ -311,7 +316,10 @@ public class AmazonS3 { do { lp.list(); } while (lp.truncated); - return lp.entries; + + Comparator comparator = Comparator.comparingLong(KeyInfo::getLastModifiedSecs); + return lp.entries.stream().sorted(comparator.reversed()) + .map(KeyInfo::getName).collect(Collectors.toList()); } /** @@ -620,8 +628,26 @@ public class AmazonS3 { return p; } + /** + * KeyInfo enables sorting of keys by lastModified time + */ + private static final class KeyInfo { + private final String name; + private final long lastModifiedSecs; + public KeyInfo(String aname, long lsecs) { + name = aname; + lastModifiedSecs = lsecs; + } + public String getName() { + return name; + } + public long getLastModifiedSecs() { + return lastModifiedSecs; + } + } + private final class ListParser extends DefaultHandler { - final List entries = new ArrayList<>(); + final List entries = new ArrayList<>(); private final String bucket; @@ -630,6 +656,8 @@ public class AmazonS3 { boolean truncated; private StringBuilder data; + private String keyName; + private Instant keyLastModified; ListParser(String bn, String p) { bucket = bn; @@ -641,7 +669,7 @@ public class AmazonS3 { if (prefix.length() > 0) args.put("prefix", prefix); //$NON-NLS-1$ if (!entries.isEmpty()) - args.put("marker", prefix + entries.get(entries.size() - 1)); //$NON-NLS-1$ + args.put("marker", prefix + entries.get(entries.size() - 1).getName()); //$NON-NLS-1$ for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) { final HttpURLConnection c = open("GET", bucket, "", args); //$NON-NLS-1$ //$NON-NLS-2$ @@ -650,12 +678,15 @@ public class AmazonS3 { case HttpURLConnection.HTTP_OK: truncated = false; data = null; + keyName = null; + keyLastModified = null; final XMLReader xr; try { xr = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { - throw new IOException(JGitText.get().noXMLParserAvailable); + throw new IOException( + JGitText.get().noXMLParserAvailable, e); } xr.setContentHandler(this); try (InputStream in = c.getInputStream()) { @@ -682,8 +713,13 @@ public class AmazonS3 { public void startElement(final String uri, final String name, final String qName, final Attributes attributes) throws SAXException { - if ("Key".equals(name) || "IsTruncated".equals(name)) //$NON-NLS-1$ //$NON-NLS-2$ + if ("Key".equals(name) || "IsTruncated".equals(name) || "LastModified".equals(name)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ data = new StringBuilder(); + } + if ("Contents".equals(name)) { //$NON-NLS-1$ + keyName = null; + keyLastModified = null; + } } @Override @@ -703,10 +739,16 @@ public class AmazonS3 { @Override public void endElement(final String uri, final String name, final String qName) throws SAXException { - if ("Key".equals(name)) //$NON-NLS-1$ - entries.add(data.toString().substring(prefix.length())); - else if ("IsTruncated".equals(name)) //$NON-NLS-1$ + if ("Key".equals(name)) { //$NON-NLS-1$ + keyName = data.toString().substring(prefix.length()); + } else if ("IsTruncated".equals(name)) { //$NON-NLS-1$ truncated = StringUtils.equalsIgnoreCase("true", data.toString()); //$NON-NLS-1$ + } else if ("LastModified".equals(name)) { //$NON-NLS-1$ + keyLastModified = Instant.parse(data.toString()); + } else if ("Contents".equals(name)) { //$NON-NLS-1$ + entries.add(new KeyInfo(keyName, keyLastModified.getEpochSecond())); + } + data = null; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java index 8604244db..1417faee8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java @@ -203,7 +203,9 @@ abstract class BasePackConnection extends BaseConnection { try { id = ObjectId.fromString(line.substring(0, 40)); } catch (InvalidObjectIdException e) { - throw invalidRefAdvertisementLine(line); + PackProtocolException ppe = invalidRefAdvertisementLine(line); + ppe.initCause(e); + throw ppe; } if (name.equals(".have")) { //$NON-NLS-1$ additionalHaves.add(id); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java index 063fb6b8b..afa0a11c2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java @@ -24,8 +24,10 @@ import com.jcraft.jsch.Session; *

* If user interactivity is required by SSH (e.g. to obtain a password), the * connection will immediately fail. + * + * @since 5.7 */ -class DefaultSshSessionFactory extends JschConfigSessionFactory { +public class DefaultSshSessionFactory extends JschConfigSessionFactory { /** {@inheritDoc} */ @Override protected void configure(OpenSshConfig.Host hc, Session session) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index 93800d500..c992bb1cb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -286,7 +286,7 @@ public class PacketLineIn { try { len = RawParseUtils.parseHexInt16(lineBuffer, 0); } catch (ArrayIndexOutOfBoundsException err) { - throw invalidHeader(); + throw invalidHeader(err); } if (len == 0) { @@ -320,6 +320,12 @@ public class PacketLineIn { + (char) lineBuffer[2] + (char) lineBuffer[3])); } + private IOException invalidHeader(Throwable cause) { + IOException ioe = invalidHeader(); + ioe.initCause(cause); + return ioe; + } + /** * IOException thrown by read when the configured input limit is exceeded. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java index 8ca09f8ad..e505e1706 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java @@ -1725,15 +1725,17 @@ public class ReceivePack { * desired status to filter by. * @return a copy of the command list containing only those commands with * the desired status. + * @since 5.7 */ - private List filterCommands(Result want) { + protected List filterCommands(Result want) { return ReceiveCommand.filter(commands, want); } /** * Execute commands to update references. + * @since 5.7 */ - private void executeCommands() { + protected void executeCommands() { List toApply = filterCommands(Result.NOT_ATTEMPTED); if (toApply.isEmpty()) return; @@ -2108,7 +2110,7 @@ public class ReceivePack { } catch (InputOverLimitIOException e) { String msg = JGitText.get().tooManyCommands; fatalError(msg); - throw new PackProtocolException(msg); + throw new PackProtocolException(msg, e); } finally { try { close(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java index 906c4ed2d..e6d204242 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java @@ -13,6 +13,8 @@ package org.eclipse.jgit.transport; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Iterator; +import java.util.ServiceLoader; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.lib.Constants; @@ -31,8 +33,16 @@ import org.eclipse.jgit.util.SystemReader; * SshSessionFactory for the duration of the period they are using the Session. */ public abstract class SshSessionFactory { - private static SshSessionFactory INSTANCE = new DefaultSshSessionFactory(); + private static SshSessionFactory INSTANCE = loadSshSessionFactory(); + private static SshSessionFactory loadSshSessionFactory() { + ServiceLoader loader = ServiceLoader.load(SshSessionFactory.class); + Iterator iter = loader.iterator(); + if(iter.hasNext()) { + return iter.next(); + } + return null; + } /** * Get the currently configured JVM-wide factory. *

@@ -53,10 +63,11 @@ public abstract class SshSessionFactory { * default factory will be restored.s */ public static void setInstance(SshSessionFactory newFactory) { - if (newFactory != null) + if (newFactory != null) { INSTANCE = newFactory; - else - INSTANCE = new DefaultSshSessionFactory(); + } else { + INSTANCE = loadSshSessionFactory(); + } } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java index 13b891fcf..c6ecb3a79 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TestProtocol.java @@ -140,7 +140,7 @@ public class TestProtocol extends TransportProtocol { int n = handles.size(); uri = new URIish(SCHEME + "://test/conn" + n); //$NON-NLS-1$ } catch (URISyntaxException e) { - throw new IllegalStateException(); + throw new IllegalStateException(e); } handles.put(uri, new Handle(req, remote)); return uri; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index 94f36d285..784f56615 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -241,11 +242,14 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { @Override Collection getPackNames() throws IOException { + // s3.list returns most recently modified packs first. + // These are the packs most likely to contain missing refs. + final List packList = s3.list(bucket, resolveKey("pack")); //$NON-NLS-1$ final HashSet have = new HashSet<>(); - have.addAll(s3.list(bucket, resolveKey("pack"))); //$NON-NLS-1$ + have.addAll(packList); final Collection packs = new ArrayList<>(); - for (String n : have) { + for (String n : packList) { if (!n.startsWith("pack-") || !n.endsWith(".pack")) //$NON-NLS-1$ //$NON-NLS-2$ continue; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java index 155c115f8..04ebddb10 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportBundleFile.java @@ -113,7 +113,10 @@ class TransportBundleFile extends Transport implements TransportBundle { try { src = new FileInputStream(bundle); } catch (FileNotFoundException err) { - throw new TransportException(uri, JGitText.get().notFound); + TransportException te = new TransportException(uri, + JGitText.get().notFound); + te.initCause(err); + throw te; } return new BundleFetchConnection(this, src); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java index be17b44d7..403f98d86 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java @@ -143,7 +143,10 @@ class TransportLocal extends Transport implements PackTransport { .setFS(local != null ? local.getFS() : FS.DETECTED) .setGitDir(remoteGitDir).build(); } catch (IOException err) { - throw new TransportException(uri, JGitText.get().notAGitDirectory); + TransportException te = new TransportException(uri, + JGitText.get().notAGitDirectory); + te.initCause(err); + throw te; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index 6ebb668c7..858d1f7b6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -266,7 +266,10 @@ public class URIish implements Serializable { try { val = parseHexByte(c1, c2); } catch (ArrayIndexOutOfBoundsException e) { - throw new URISyntaxException(s, JGitText.get().cannotParseGitURIish); + URISyntaxException use = new URISyntaxException(s, + JGitText.get().cannotParseGitURIish); + use.initCause(e); + throw use; } os[j++] = (byte) val; i += 2; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java index 1880c8b73..df9f11ecf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java @@ -282,9 +282,12 @@ abstract class WalkEncryption { String REGEX_TRANS = "(.+)/(.+)/(.+)"; //$NON-NLS-1$ } - static GeneralSecurityException securityError(String message) { - return new GeneralSecurityException( + static GeneralSecurityException securityError(String message, + Throwable cause) { + GeneralSecurityException e = new GeneralSecurityException( MessageFormat.format(JGitText.get().encryptionError, message)); + e.initCause(cause); + return e; } /** @@ -332,21 +335,21 @@ abstract class WalkEncryption { try { size = Integer.parseInt(keySize); } catch (Exception e) { - throw securityError(X_KEY_SIZE + EMPTY + keySize); + throw securityError(X_KEY_SIZE + EMPTY + keySize, e); } final int iter; try { iter = Integer.parseInt(keyIter); } catch (Exception e) { - throw securityError(X_KEY_ITER + EMPTY + keyIter); + throw securityError(X_KEY_ITER + EMPTY + keyIter, e); } final byte[] salt; try { salt = Hex.decode(keySalt.replaceAll(REGEX_WS, EMPTY)); } catch (Exception e) { - throw securityError(X_KEY_SALT + EMPTY + keySalt); + throw securityError(X_KEY_SALT + EMPTY + keySalt, e); } KeySpec keySpec = new PBEKeySpec(pass.toCharArray(), salt, iter, size); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 02ca86b95..2c3f3e254 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -1159,7 +1159,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { } catch (CharacterCodingException e) { // This should so never happen. throw new RuntimeException(MessageFormat.format( - JGitText.get().unencodeableFile, getName())); + JGitText.get().unencodeableFile, getName()), e); } encodedNameLen = b.limit(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index cd6647c62..415631805 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Shawn O. Pearce and others + * Copyright (C) 2008, 2020 Shawn O. Pearce and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -49,11 +49,15 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -200,27 +204,52 @@ public abstract class FS { public static final FileStoreAttributes FALLBACK_FILESTORE_ATTRIBUTES = new FileStoreAttributes( FALLBACK_TIMESTAMP_RESOLUTION); + private static final String JAVA_VERSION_PREFIX = SystemReader + .getInstance().getHostname() + '|' + + System.getProperty("java.vendor") + '|' //$NON-NLS-1$ + + System.getProperty("java.version") + '|'; //$NON-NLS-1$ + + private static final Duration FALLBACK_MIN_RACY_INTERVAL = Duration + .ofMillis(10); + private static final Map attributeCache = new ConcurrentHashMap<>(); private static final SimpleLruCache attrCacheByPath = new SimpleLruCache<>( 100, 0.2f); - private static AtomicBoolean background = new AtomicBoolean(); + private static final AtomicBoolean background = new AtomicBoolean(); + + private static final Map locks = new ConcurrentHashMap<>(); - private static Map locks = new ConcurrentHashMap<>(); + private static final AtomicInteger threadNumber = new AtomicInteger(1); + + /** + * Don't use the default thread factory of the ForkJoinPool for the + * CompletableFuture; it runs without any privileges, which causes + * trouble if a SecurityManager is present. + *

+ * Instead use normal daemon threads. They'll belong to the + * SecurityManager's thread group, or use the one of the calling thread, + * as appropriate. + *

+ * + * @see java.util.concurrent.Executors#newCachedThreadPool() + */ + private static final Executor FUTURE_RUNNER = new ThreadPoolExecutor(0, + 5, 30L, TimeUnit.SECONDS, new SynchronousQueue(), + runnable -> { + Thread t = new Thread(runnable, "FileStoreAttributeReader-" //$NON-NLS-1$ + + threadNumber.getAndIncrement()); + // Make sure these threads don't prevent application/JVM + // shutdown. + t.setDaemon(true); + return t; + }); private static void setBackground(boolean async) { background.set(async); } - private static final String javaVersionPrefix = SystemReader - .getInstance().getHostname() + '|' - + System.getProperty("java.vendor") + '|' //$NON-NLS-1$ - + System.getProperty("java.version") + '|'; //$NON-NLS-1$ - - private static final Duration FALLBACK_MIN_RACY_INTERVAL = Duration - .ofMillis(10); - /** * Configures size and purge factor of the path-based cache for file * system attributes. Caching of file system attributes avoids recurring @@ -304,8 +333,7 @@ public abstract class FS { // Some earlier future might have set the value // and removed itself since we checked for the // value above. Hence check cache again. - FileStoreAttributes c = attributeCache - .get(s); + FileStoreAttributes c = attributeCache.get(s); if (c != null) { return Optional.of(c); } @@ -339,7 +367,7 @@ public abstract class FS { locks.remove(s); } return attributes; - }); + }, FUTURE_RUNNER); f = f.exceptionally(e -> { LOG.error(e.getLocalizedMessage(), e); return Optional.empty(); @@ -450,6 +478,11 @@ public abstract class FS { LOG.debug("{}: end measure timestamp resolution {} in {}", //$NON-NLS-1$ Thread.currentThread(), s, dir); return Optional.of(fsResolution); + } catch (SecurityException e) { + // Log it here; most likely deleteProbe() below will also run + // into a SecurityException, and then this one will be lost + // without trace. + LOG.warn(e.getLocalizedMessage(), e); } catch (AccessDeniedException e) { LOG.warn(e.getLocalizedMessage(), e); // see bug 548648 } catch (IOException e) { @@ -595,7 +628,7 @@ public abstract class FS { } else { storeKey = s.name(); } - return javaVersionPrefix + storeKey; + return JAVA_VERSION_PREFIX + storeKey; } private static TimeUnit getUnit(long nanos) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java index fa99087fe..4831fbb64 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java @@ -300,7 +300,8 @@ public class FileUtils { } catch (InterruptedException e) { throw new IOException( MessageFormat.format(JGitText.get().renameFileFailed, - src.getAbsolutePath(), dst.getAbsolutePath())); + src.getAbsolutePath(), dst.getAbsolutePath()), + e); } } throw new IOException( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java index 135613600..1947b3bf0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java @@ -70,7 +70,7 @@ public class TimeoutInputStream extends FilterInputStream { beginRead(); return super.read(); } catch (InterruptedIOException e) { - throw readTimedOut(); + throw readTimedOut(e); } finally { endRead(); } @@ -89,7 +89,7 @@ public class TimeoutInputStream extends FilterInputStream { beginRead(); return super.read(buf, off, cnt); } catch (InterruptedIOException e) { - throw readTimedOut(); + throw readTimedOut(e); } finally { endRead(); } @@ -102,7 +102,7 @@ public class TimeoutInputStream extends FilterInputStream { beginRead(); return super.skip(cnt); } catch (InterruptedIOException e) { - throw readTimedOut(); + throw readTimedOut(e); } finally { endRead(); } @@ -116,8 +116,11 @@ public class TimeoutInputStream extends FilterInputStream { myTimer.end(); } - private InterruptedIOException readTimedOut() { - return new InterruptedIOException(MessageFormat.format( - JGitText.get().readTimedOut, Integer.valueOf(timeout))); + private InterruptedIOException readTimedOut(InterruptedIOException e) { + InterruptedIOException interrupted = new InterruptedIOException( + MessageFormat.format(JGitText.get().readTimedOut, + Integer.valueOf(timeout))); + interrupted.initCause(e); + return interrupted; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java index 7532c42b9..3fbf6ffdc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java @@ -72,7 +72,7 @@ public class TimeoutOutputStream extends OutputStream { beginWrite(); dst.write(b); } catch (InterruptedIOException e) { - throw writeTimedOut(); + throw writeTimedOut(e); } finally { endWrite(); } @@ -91,7 +91,7 @@ public class TimeoutOutputStream extends OutputStream { beginWrite(); dst.write(buf, off, len); } catch (InterruptedIOException e) { - throw writeTimedOut(); + throw writeTimedOut(e); } finally { endWrite(); } @@ -104,7 +104,7 @@ public class TimeoutOutputStream extends OutputStream { beginWrite(); dst.flush(); } catch (InterruptedIOException e) { - throw writeTimedOut(); + throw writeTimedOut(e); } finally { endWrite(); } @@ -117,7 +117,7 @@ public class TimeoutOutputStream extends OutputStream { beginWrite(); dst.close(); } catch (InterruptedIOException e) { - throw writeTimedOut(); + throw writeTimedOut(e); } finally { endWrite(); } @@ -131,8 +131,11 @@ public class TimeoutOutputStream extends OutputStream { myTimer.end(); } - private InterruptedIOException writeTimedOut() { - return new InterruptedIOException(MessageFormat.format( - JGitText.get().writeTimedOut, Integer.valueOf(timeout))); + private InterruptedIOException writeTimedOut(InterruptedIOException cause) { + InterruptedIOException e = new InterruptedIOException( + MessageFormat.format(JGitText.get().writeTimedOut, + Integer.valueOf(timeout))); + e.initCause(cause); + return e; } } diff --git a/pom.xml b/pom.xml index 2eeda672d..d0a5c83a1 100644 --- a/pom.xml +++ b/pom.xml @@ -155,27 +155,27 @@ 2.2.0 0.1.55 1.1.1 - 1.1.6 - 4.12 + 1.1.7 + 4.13 1C 2.33 - 1.18 + 1.19 4.3.1 3.1.0 9.4.25.v20191220 - 0.14.1 - 4.5.6 - 4.4.10 + 0.14.3 + 4.5.10 + 4.4.12 1.7.2 1.2.15 3.1.1 - 1.5.1 + 1.6.0 2.8.2 1.64 3.1.12.2 3.0.0 3.0.0 - 3.0.0-M3 + 3.0.0-M4 ${maven-surefire-plugin-version} 3.8.1 @@ -298,7 +298,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.12.0 + 3.13.0 utf-8 100 @@ -775,6 +775,11 @@ ${bouncycastle-version} + + org.assertj + assertj-core + 3.14.0 + @@ -831,9 +836,6 @@ javac-with-errorprone true - - -Xep:ExpectedExceptionChecker:ERROR - org/eclipse/jgit/transport/InsecureCipherFactory.java diff --git a/tools/BUILD b/tools/BUILD index e5931dc8c..2b208744b 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -39,7 +39,6 @@ java_package_configuration( "-Xep:ElementsCountedInLoop:ERROR", "-Xep:EqualsHashCode:ERROR", "-Xep:EqualsIncompatibleType:ERROR", - "-Xep:ExpectedExceptionChecker:ERROR", "-Xep:Finally:WARN", "-Xep:FloatingPointLiteralPrecision:ERROR", "-Xep:FragmentInjection:ERROR", @@ -79,6 +78,7 @@ java_package_configuration( "-Xep:TypeParameterShadowing:ERROR", "-Xep:TypeParameterUnusedInFormals:WARN", "-Xep:URLEqualsHashCode:ERROR", + "-Xep:UnusedException:ERROR", "-Xep:UnsynchronizedOverridesSynchronized:ERROR", "-Xep:WaitNotInLoop:ERROR", ],