Skip to content

Commit

Permalink
Bump Bazel version to 7.1.1
Browse files Browse the repository at this point in the history
In Bazel 7.x release line, the bzlmod feature is activated per default,
so that we need to disable it. See this issue for more details: [1].

This requires fixing quite some error prone bug patterns. This change
should be separated in single changes to address issues flagged by error
prone.

Test plan:

  $> bazel test //...

[1] bazelbuild/bazel#18958
Change-Id: I2526d93020c5d82314a09206907ebeed6f1a1700
  • Loading branch information
davido committed Apr 28, 2024
1 parent 567315a commit e1ba93d
Show file tree
Hide file tree
Showing 47 changed files with 176 additions and 171 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TODO(davido): Migrate all dependencies from WORKSPACE to MODULE.bazel
# https://issues.gerritcodereview.com/issues/303819949
common --noenable_bzlmod

build --workspace_status_command="python ./tools/workspace_status.py"
build --repository_cache=~/.gerritcodereview/bazel-cache/repository
build --experimental_strict_action_env
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.2
7.1.1
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO(davido): Migrate all dependencies from WORKSPACE to MODULE.bazel
# https://issues.gerritcodereview.com/issues/303819949
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class OCBPBEProtectionRemoverFactory
}

@Override
@SuppressWarnings("InsecureCryptoUsage")
public PBESecretKeyDecryptor createDecryptor(String protection)
throws PGPException {
return new PBESecretKeyDecryptor(passphrase, calculatorProvider) {
Expand Down Expand Up @@ -122,4 +123,4 @@ public byte[] recoverKeyData(int encAlgorithm, byte[] key,
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void testCreate_EmptyStringUser() throws ServiceNotEnabledException {
}

@Test
@SuppressWarnings("UndefinedEquals")
public void testCreate_AuthUser() throws ServiceNotEnabledException,
ServiceNotAuthorizedException {
ReceivePack rp;
Expand Down Expand Up @@ -142,6 +143,7 @@ public void testCreate_Disabled() throws ServiceNotAuthorizedException,
}

@Test
@SuppressWarnings("UndefinedEquals")
public void testCreate_Enabled() throws ServiceNotEnabledException,
ServiceNotAuthorizedException, IOException {
final StoredConfig cfg = db.getConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void testExportOk() throws IOException {
try {
resolver.open(null, name).close();
} catch (ServiceNotEnabledException e) {
fail("did not honor export-all flag");
throw new AssertionError("did not honor export-all flag", e);
}

FileUtils.createNewFile(export);
Expand All @@ -99,7 +99,7 @@ public void testExportOk() throws IOException {
try {
resolver.open(null, name).close();
} catch (ServiceNotEnabledException e) {
fail("did not honor git-daemon-export-ok");
throw new AssertionError("did not honor git-daemon-export-ok", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ protected List<SubsystemFactory> configureSubsystems() {
server.setFileSystemFactory(new VirtualFileSystemFactory(repository
.getDirectory().getParentFile().getAbsoluteFile().toPath()));
return Collections
.singletonList((new SftpSubsystemFactory.Builder()).build());
.singletonList(new SftpSubsystemFactory.Builder().build());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void testCloneBare() throws Exception {

File gitDir = db.getDirectory();
String sourcePath = gitDir.getAbsolutePath();
String targetPath = (new File(sourcePath)).getParentFile()
String targetPath = new File(sourcePath).getParentFile()
.getParentFile().getAbsolutePath()
+ File.separator + "target.git";
String cmd = "git clone --bare " + shellQuote(sourcePath) + " "
Expand All @@ -207,7 +207,7 @@ public void testCloneMirror() throws Exception {

File gitDir = db.getDirectory();
String sourcePath = gitDir.getAbsolutePath();
String targetPath = (new File(sourcePath)).getParentFile()
String targetPath = new File(sourcePath).getParentFile()
.getParentFile().getAbsolutePath() + File.separator
+ "target.git";
String cmd = "git clone --mirror " + shellQuote(sourcePath) + " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public void testListConfig() throws Exception {
Map<String, String> options = parseOptions(output);

assertEquals(!isWindows, Boolean.valueOf(options.get("core.filemode")));
assertTrue((Boolean.valueOf(options.get("core.logallrefupdates"))));
assertTrue(Boolean.valueOf(options.get("core.logallrefupdates")));
if (isMac) {
assertTrue(
(Boolean.valueOf(options.get("core.precomposeunicode"))));
Boolean.valueOf(options.get("core.precomposeunicode")));
}
assertEquals(Integer.valueOf(0),
Integer.valueOf(options.get("core.repositoryformatversion")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.util.FileUtils.RECURSIVE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -613,7 +614,7 @@ public void testAddExistingSingleFileTwice() throws IOException,
writer.print("other content");
}

dc = git.add().addFilepattern("a.txt").call();
git.add().addFilepattern("a.txt").call();

assertEquals(
"[a.txt, mode:100644, content:other content]",
Expand All @@ -640,7 +641,7 @@ public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
writer.print("other content");
}

dc = git.add().addFilepattern("a.txt").call();
git.add().addFilepattern("a.txt").call();

assertEquals(
"[a.txt, mode:100644, content:other content]",
Expand All @@ -663,7 +664,7 @@ public void testAddRemovedFile() throws Exception {
FileUtils.delete(file);

// is supposed to do nothing
dc = git.add().addFilepattern("a.txt").call();
git.add().addFilepattern("a.txt").call();

assertEquals(
"[a.txt, mode:100644, content:content]",
Expand All @@ -688,7 +689,7 @@ public void testAddRemovedCommittedFile() throws Exception {
FileUtils.delete(file);

// is supposed to do nothing
dc = git.add().addFilepattern("a.txt").call();
git.add().addFilepattern("a.txt").call();

assertEquals(
"[a.txt, mode:100644, content:content]",
Expand Down Expand Up @@ -878,7 +879,7 @@ public void testAddAllNoRenormalize() throws Exception {
}
}
// Help null pointer analysis.
assert lastFile != null;
assertNotNull(lastFile);
// Wait a bit. If entries are "racily clean", we'll recompute
// hashes from the disk files, and then the second add is also slow.
// We want to test the normal case.
Expand Down Expand Up @@ -1259,7 +1260,7 @@ public void testAddGitlink() throws Exception {
"[git-link-dir, mode:160000]",
indexState(0));
Set<String> untrackedFiles = git.status().call().getUntracked();
assert (untrackedFiles.isEmpty());
assertTrue(untrackedFiles.isEmpty());
}

}
Expand All @@ -1274,7 +1275,7 @@ public void testAddSubrepoWithDirNoGitlinks() throws Exception {
ConfigConstants.CONFIG_KEY_DIRNOGITLINKS, true);
config.save();

assert (db.getConfig().get(WorkingTreeOptions.KEY).isDirNoGitLinks());
assertTrue(db.getConfig().get(WorkingTreeOptions.KEY).isDirNoGitLinks());

try (Git git = new Git(db)) {
git.add().addFilepattern("nested-repo").call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ public void testInsertChangeId() throws Exception {
// template)
chars = commit.getFullMessage().getBytes(UTF_8);
int lineStart = 0;
int lineEnd = 0;
for (int i = 0; i < 4; i++) {
lineStart = RawParseUtils.nextLF(chars, lineStart);
}
lineEnd = RawParseUtils.nextLF(chars, lineStart);
int lineEnd = RawParseUtils.nextLF(chars, lineStart);

String line = RawParseUtils.decode(chars, lineStart, lineEnd);

Expand All @@ -302,15 +301,9 @@ public void testInsertChangeId() throws Exception {
.setInsertChangeId(false).call();
// we should find the untouched template
chars = commit.getFullMessage().getBytes(UTF_8);
lineStart = 0;
lineEnd = 0;
for (int i = 0; i < 4; i++) {
lineStart = RawParseUtils.nextLF(chars, lineStart);
}
lineEnd = RawParseUtils.nextLF(chars, lineStart);

line = RawParseUtils.decode(chars, lineStart, lineEnd);

assertTrue(commit.getFullMessage()
.contains("Change-Id: I" + ObjectId.zeroId().getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ public void t1DominatesT2() throws Exception {
/**
* When t1 annotated dominates t2 lightweight tag
*
* <pre>
* {@code
* t1 -+-> t2 -
* | |
* +-> c3 -+-> c4
* </pre>
* }
*
* @throws Exception
*/
Expand Down Expand Up @@ -440,11 +440,11 @@ public void testDescribeUseAllRefsMaster() throws Exception {
/**
* Branch off from master and then tag
*
* <pre>
* {@code
* c1 -+ -> c2
* |
* +-> t1
* </pre>
* }
* @throws Exception
* */
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ public void testCheckoutMultiple() throws Exception {
@Test
public void testUpdateWorkingDirectoryFromIndex() throws Exception {
CheckoutCommand co = git.checkout();
File written = writeTrashFile(FILE1, "3a");
writeTrashFile(FILE1, "3a");
git.add().addFilepattern(FILE1).call();
written = writeTrashFile(FILE1, "");
File written = writeTrashFile(FILE1, "");
assertEquals("", read(written));
co.addPath(FILE1).call();
assertEquals("3a", read(written));
Expand All @@ -185,9 +185,9 @@ public void testUpdateWorkingDirectoryFromIndex() throws Exception {
public void testUpdateWorkingDirectoryFromHeadWithIndexChange()
throws Exception {
CheckoutCommand co = git.checkout();
File written = writeTrashFile(FILE1, "3a");
writeTrashFile(FILE1, "3a");
git.add().addFilepattern(FILE1).call();
written = writeTrashFile(FILE1, "");
File written = writeTrashFile(FILE1, "");
assertEquals("", read(written));
co.addPath(FILE1).setStartPoint("HEAD").call();
assertEquals("3", read(written));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.junit.Before;
import org.junit.Test;

@SuppressWarnings("AssertionFailureIgnored")
public class RebaseCommandTest extends RepositoryTestCase {
private static final String GIT_REBASE_TODO = "rebase-merge/git-rebase-todo";

Expand Down Expand Up @@ -2650,7 +2651,7 @@ public void testRebaseShouldTryToParseValidLineMarkedAsComment()
assertEquals("1111111", firstLine.getCommit().name());
assertEquals("pick", firstLine.getAction().toToken());
} catch (Exception e) {
fail("Valid parsable RebaseTodoLine that has been commented out should allow to change the action, but failed");
throw new AssertionError("Valid parsable RebaseTodoLine that has been commented out should allow to change the action, but failed", e);
}

assertEquals("2222222", steps.get(1).getCommit().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void dropWithInvalidLogIndex() throws Exception {
assertNull(stashRef);
RevCommit stashed = git.stashCreate().call();
assertNotNull(stashed);
stashRef = git.getRepository().exactRef(Constants.R_STASH);
git.getRepository().exactRef(Constants.R_STASH);
assertEquals(stashed,
git.getRepository().exactRef(Constants.R_STASH).getObjectId());
try {
Expand All @@ -87,7 +87,7 @@ public void dropSingleStashedCommit() throws Exception {
assertNull(stashRef);
RevCommit stashed = git.stashCreate().call();
assertNotNull(stashed);
stashRef = git.getRepository().exactRef(Constants.R_STASH);
git.getRepository().exactRef(Constants.R_STASH);
assertEquals(stashed,
git.getRepository().exactRef(Constants.R_STASH).getObjectId());
assertNull(git.stashDrop().call());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ private LinkedHashMap<String, Attributes> cgitAttributes(
UTF_8))) {
r.lines().forEach(line -> {
// Parse the line and add to result map
int start = 0;
int i = line.indexOf(':');
String path = line.substring(0, i).trim();
start = i + 1;
int start = i + 1;
i = line.indexOf(':', start);
String key = line.substring(start, i).trim();
String value = line.substring(i + 1).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ private static Set<Attribute> asSet(Collection<Attribute> attributes) {
for (Attribute a : attributes) {
ret.add(a);
}
return (ret);
return ret;
}

private File writeAttributesFile(String name, String... rules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.junit.Test;

@SuppressWarnings("CatchAndPrintStackTrace")
public class MergeGitAttributeTest extends RepositoryTestCase {

private static final String REFS_HEADS_RIGHT = "refs/heads/right";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ final class ReceivedEventMarkerException extends RuntimeException {
try {
b.commit();
} catch (ReceivedEventMarkerException e) {
fail("unexpected IndexChangedEvent");
throw new AssertionError("unexpected IndexChangedEvent", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public void parse_writeObjSizeIdx() throws IOException {
.fromString("2e65efe2a145dda7ee51d1741299f848e5bf752e");

pack.header(2);
pack.write((Constants.OBJ_BLOB) << 4 | 1);
pack.write(Constants.OBJ_BLOB << 4 | 1);
pack.deflate(new byte[] { 'a' });

pack.write((Constants.OBJ_REF_DELTA) << 4 | 4);
pack.write(Constants.OBJ_REF_DELTA << 4 | 4);
pack.copyRaw(blobA);
pack.deflate(new byte[] { 0x1, 0x1, 0x1, 'b' });
pack.digest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

package org.eclipse.jgit.internal.storage.file;

import static java.lang.Integer.valueOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
Expand Down Expand Up @@ -73,7 +72,7 @@ public Integer call() throws Exception {
try {
gc.setProgressMonitor(this);
gc.repack();
return valueOf(0);
return Integer.valueOf(0);
} catch (IOException e) {
// leave the syncPoint in broken state so any awaiting
// threads and any threads that call await in the future get
Expand All @@ -84,7 +83,7 @@ public Integer call() throws Exception {
} catch (InterruptedException ignored) {
//
}
return valueOf(1);
return Integer.valueOf(1);
}
}
}
Expand Down
Loading

0 comments on commit e1ba93d

Please sign in to comment.