From 2fed62528a598a16bb9c5cd1df861aa8ab7f820a Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 12 Jan 2022 01:52:26 +0100 Subject: [PATCH 1/5] [errorprone] Suppress FutureReturnValueIgnored in FileRepository#autoGc Ignore the FutureReturnValueIgnored warning for the unused return value of #gc. Change-Id: I4e7a2f85d404962c01726f9a1d079fe4a6430a1b --- .../org/eclipse/jgit/internal/storage/file/FileRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index 9cdea597f..53a1cd639 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -594,6 +594,7 @@ private boolean shouldAutoDetach() { } /** {@inheritDoc} */ + @SuppressWarnings("FutureReturnValueIgnored") @Override public void autoGC(ProgressMonitor monitor) { GC gc = new GC(this); From 8b00cb9324edff469788c81c0f0423a58a8f12f1 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 12 Jan 2022 02:02:35 +0100 Subject: [PATCH 2/5] [errorprone] Fix implicit use of default charset in FileBasedConfigTest Change-Id: I83332efc498a5bce242915a1eec2346e6e1f58fd --- .../org/eclipse/jgit/storage/file/FileBasedConfigTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java index 7f0bfefbe..b964e9775 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java @@ -19,6 +19,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; @@ -276,7 +277,8 @@ public void testSavedConfigFileShouldNotReadUserGitConfig() throws IOException { AtomicBoolean userConfigTimeRead = new AtomicBoolean(false); - Path userConfigFile = createFile(CONTENT1.getBytes(), "home"); + Path userConfigFile = createFile( + CONTENT1.getBytes(StandardCharsets.UTF_8), "home"); mockSystemReader.setUserGitConfig( new FileBasedConfig(userConfigFile.toFile(), FS.DETECTED) { @@ -289,7 +291,8 @@ public long getTimeUnit(String section, String subsection, } }); - Path file = createFile(CONTENT2.getBytes(), "repo"); + Path file = createFile(CONTENT2.getBytes(StandardCharsets.UTF_8), + "repo"); FileBasedConfig fileBasedConfig = new FileBasedConfig(file.toFile(), FS.DETECTED); fileBasedConfig.save(); From 6fde4d3a6c4cc0dbf649d2721bebf35678656f9f Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 12 Jan 2022 17:45:26 +0100 Subject: [PATCH 3/5] [errorprone] Suppress Finally error in ObjectDownloadListener Change-Id: I20af1d8d931608e93fbc52e127f1b7bafd2f917c --- .../org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java index cc57947a7..d42701125 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/ObjectDownloadListener.java @@ -81,6 +81,7 @@ public ObjectDownloadListener(FileLfsRepository repository, * * Write file content */ + @SuppressWarnings("Finally") @Override public void onWritePossible() throws IOException { while (out.isReady()) { From a268faf729abae09d677d4e465e68c432dfb8a7f Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 12 Jan 2022 02:00:41 +0100 Subject: [PATCH 4/5] [errorprone] Fix InfiniteRecursion error in RecordingLogger Change-Id: I092389e428232a4fe7613d846c288d285ae9102c --- .../src/org/eclipse/jgit/junit/http/RecordingLogger.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java index 9c3c980ad..af63084e9 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/RecordingLogger.java @@ -180,11 +180,15 @@ public void warn(String msg) { @Override public void warn(String format, Object arg) { - warn(format, Collections.singleton(arg)); + addWarnings(format, Collections.singleton(arg)); } @Override public void warn(String format, Object... arguments) { + addWarnings(format, arguments); + } + + private void addWarnings(String format, Object... arguments) { synchronized (warnings) { int i = 0; int index = format.indexOf("{}"); From b33133497fac512bf2fc3ce9cae75639eca2030c Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 12 Jan 2022 23:45:34 +0100 Subject: [PATCH 5/5] [bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory Move this test to another class and skip it when running tests with bazel since the bazel test runner does not allow to create files in the home directory. FS#userHome retrieves the home directory on the first call and caches it for subsequent calls to avoid overhead in case path translation is required (currently on cygwin). This prevents that the test can mock the home directory using MockSystemReader like SshTestHarness does. Change-Id: I6a22f37f4a19eb4b4935509eae508a23e56db7aa --- org.eclipse.jgit.test/BUILD | 1 + .../jgit/lib/CommitTemplateConfigTest.java | 60 +++++++++++++++++++ .../tst/org/eclipse/jgit/lib/ConfigTest.java | 27 +-------- 3 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD index c9b5d3726..9e787fee7 100644 --- a/org.eclipse.jgit.test/BUILD +++ b/org.eclipse.jgit.test/BUILD @@ -42,6 +42,7 @@ DATA = [ EXCLUDED = [ PKG + "api/SecurityManagerTest.java", PKG + "api/SecurityManagerMissingPermissionsTest.java", + PKG + "lib/CommitTemplateConfigTest.java", ] tests(tests = glob( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java new file mode 100644 index 000000000..6dbe30af2 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 SAP SE 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; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.junit.JGitTestUtil; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/* + * This test was moved from ConfigTest to allow skipping it when running the + * test using bazel which doesn't allow tests to create files in the home + * directory + */ +public class CommitTemplateConfigTest { + + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + + @Test + public void testCommitTemplatePathInHomeDirecory() + throws ConfigInvalidException, IOException { + Config config = new Config(null); + File tempFile = tmp.newFile("testCommitTemplate-"); + File workTree = tmp.newFolder("dummy-worktree"); + Repository repo = FileRepositoryBuilder.create(workTree); + String templateContent = "content of the template"; + JGitTestUtil.write(tempFile, templateContent); + // proper evaluation of the ~/ directory + String homeDir = System.getProperty("user.home"); + File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder", + ".tmp", new File(homeDir)); + tempFileInHomeDirectory.deleteOnExit(); + JGitTestUtil.write(tempFileInHomeDirectory, templateContent); + String expectedTemplatePath = tempFileInHomeDirectory.getPath() + .replace(homeDir, "~"); + config = ConfigTest + .parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); + String templatePath = config.get(CommitConfig.KEY) + .getCommitTemplatePath(); + assertEquals(expectedTemplatePath, templatePath); + assertEquals(templateContent, + config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); + } +} 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 9ee54d5b6..9b82c2afd 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 @@ -1177,7 +1177,7 @@ private static void assertReadLong(long exp, String act) assertEquals(exp, c.getLong("s", null, "a", 0L)); } - private static Config parse(String content) + static Config parse(String content) throws ConfigInvalidException { return parse(content, null); } @@ -1546,31 +1546,6 @@ public void testCommitTemplateEncoding() "utf-8", commitEncoding); } - @Test - public void testCommitTemplatePathInHomeDirecory() - throws ConfigInvalidException, IOException { - Config config = new Config(null); - File tempFile = tmp.newFile("testCommitTemplate-"); - File workTree = tmp.newFolder("dummy-worktree"); - Repository repo = FileRepositoryBuilder.create(workTree); - String templateContent = "content of the template"; - JGitTestUtil.write(tempFile, templateContent); - // proper evaluation of the ~/ directory - String homeDir = System.getProperty("user.home"); - File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder", - ".tmp", new File(homeDir)); - tempFileInHomeDirectory.deleteOnExit(); - JGitTestUtil.write(tempFileInHomeDirectory, templateContent); - String expectedTemplatePath = tempFileInHomeDirectory.getPath() - .replace(homeDir, "~"); - config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); - String templatePath = config.get(CommitConfig.KEY) - .getCommitTemplatePath(); - assertEquals(expectedTemplatePath, templatePath); - assertEquals(templateContent, - config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); - } - @Test(expected = ConfigInvalidException.class) public void testCommitTemplateWithInvalidEncoding() throws ConfigInvalidException, IOException {