Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stylistic changes and GSON update #1

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ maven.install(
"com.google.auto.value:auto-value:1.8.2",
"com.google.auto.value:auto-value-annotations:1.9",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.9.0",
"com.google.code.gson:gson:2.10.1",
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0",
"com.google.errorprone:error_prone_annotation:2.23.0",
"com.google.errorprone:error_prone_annotations:2.23.0",
Expand Down
21 changes: 5 additions & 16 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions maven_install.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": -1536314734,
"__RESOLVED_ARTIFACTS_HASH": -1123103492,
"__INPUT_ARTIFACTS_HASH": 1275969355,
"__RESOLVED_ARTIFACTS_HASH": -209014774,
"conflict_resolution": {
"com.google.auto.value:auto-value-annotations:1.9": "com.google.auto.value:auto-value-annotations:1.10.4",
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.9.0",
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.10.1",
"com.google.errorprone:error_prone_annotations:2.23.0": "com.google.errorprone:error_prone_annotations:2.24.1",
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.24.1",
"com.google.guava:failureaccess:1.0.1": "com.google.guava:failureaccess:1.0.2",
Expand Down Expand Up @@ -122,9 +122,9 @@
},
"com.google.code.gson:gson": {
"shasums": {
"jar": "c96d60551331a196dac54b745aa642cd078ef89b6f267146b705f2c2cbef052d"
"jar": "4241c14a7727c34feea6507ec801318a3d4a90f070e4525681079fb94ee4c593"
},
"version": "2.9.0"
"version": "2.10.1"
},
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": {
"shasums": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package com.google.devtools.build.lib.bazel.bzlmod;

import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -86,12 +86,14 @@ public ArchiveRepoSpecBuilder setRemotePatches(ImmutableMap<String, String> remo

@CanIgnoreReturnValue
public ArchiveRepoSpecBuilder setOverlay(ImmutableMap<String, RemoteFile> overlay) {
final Map<String, List<String>> remoteFiles = overlay.entrySet().stream().collect(toMap(
Entry::getKey,
e -> e.getValue().urls().stream().map(URL::toString).collect(toList())
));
final Map<String, String> remoteFilesIntegrity = overlay.entrySet().stream()
.collect(toMap(Entry::getKey, e -> e.getValue().integrity()));
Map<String, List<String>> remoteFiles =
overlay.entrySet().stream()
.collect(
toMap(
Entry::getKey,
e -> e.getValue().urls().stream().map(URL::toString).collect(toList())));
Map<String, String> remoteFilesIntegrity =
overlay.entrySet().stream().collect(toMap(Entry::getKey, e -> e.getValue().integrity()));
attrBuilder.put("remote_file_urls", remoteFiles);
attrBuilder.put("remote_file_integrity", remoteFilesIntegrity);
return this;
Expand All @@ -118,4 +120,10 @@ public RepoSpec build() {
.setAttributes(AttributeValues.create(attrBuilder.buildOrThrow()))
.build();
}

/**
* A simple pojo to track remote files that are offered at multiple urls (mirrors) with a single
* integrity. We split up the file here to simplify the dependency.
*/
public record RemoteFile(String integrity, List<URL> urls) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ java_library(
"GitRepoSpecBuilder.java",
"ModuleFile.java",
"ModuleKey.java",
"RemoteFile.java",
"RepoSpec.java",
"Version.java",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.reflect.TypeToken;
import com.google.devtools.build.lib.bazel.bzlmod.Version.ParseException;
import com.google.devtools.build.lib.bazel.repository.downloader.Checksum;
import com.google.devtools.build.lib.bazel.repository.downloader.Checksum.MissingChecksumException;
Expand All @@ -36,18 +35,12 @@
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Type;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
Expand Down Expand Up @@ -95,18 +88,6 @@ public IndexRegistry(
this.gson =
new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
// record types in JDK15+ causes issues with GSON since fields are now final
// create custom deserializer
// https://github.com/google/gson/issues/1794#issuecomment-706532333
.registerTypeAdapter(RemoteFile.class, new JsonDeserializer<RemoteFile>() {
@Override
public RemoteFile deserialize(JsonElement json, Type type,
JsonDeserializationContext ctxt) throws JsonParseException {
final JsonObject object = json.getAsJsonObject();
return new RemoteFile(object.get("integrity").getAsString(),
ctxt.deserialize(object.get("urls"), new TypeToken<List<URL>>(){}.getType()));
}
})
.create();
this.knownFileHashes = knownFileHashes;
this.knownFileHashesMode = knownFileHashesMode;
Expand Down Expand Up @@ -215,7 +196,7 @@ private static class ArchiveSourceJson {
String integrity;
String stripPrefix;
Map<String, String> patches;
Map<String, RemoteFile> overlay;
Map<String, ArchiveRepoSpecBuilder.RemoteFile> overlay;
int patchStrip;
String archiveType;
}
Expand Down Expand Up @@ -406,15 +387,15 @@ private RepoSpec createArchiveRepoSpec(
}
}

var overlay = sourceJson.overlay != null ?
ImmutableMap.copyOf(sourceJson.overlay) : ImmutableMap.<String, RemoteFile>of();

return new ArchiveRepoSpecBuilder()
.setUrls(urls.build())
.setIntegrity(sourceJson.integrity)
.setStripPrefix(Strings.nullToEmpty(sourceJson.stripPrefix))
.setRemotePatches(remotePatches.buildOrThrow())
.setOverlay(overlay)
.setOverlay(
sourceJson.overlay != null
? ImmutableMap.copyOf(sourceJson.overlay)
: ImmutableMap.of())
.setRemotePatchStrip(sourceJson.patchStrip)
.setArchiveType(sourceJson.archiveType)
.build();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -198,7 +198,7 @@ public void testGetArchiveRepoSpec() throws Exception {
"integrity": "sha256-bleh-overlay"
}
}
}
}
""");
server.start();

Expand Down Expand Up @@ -249,12 +249,12 @@ public void testGetArchiveRepoSpec() throws Exception {
.setStripPrefix("")
.setOverlay(
ImmutableMap.of(
"BUILD.bazel", new RemoteFile(
"BUILD.bazel",
new ArchiveRepoSpecBuilder.RemoteFile(
"sha256-bleh-overlay",
List.of(new URL("http://mirror1"), new URL("http://mirror2"))
)
)
)
ImmutableList.of(
URI.create("http://mirror1").toURL(),
URI.create("http://mirror2").toURL()))))
.setRemotePatches(ImmutableMap.of())
.setRemotePatchStrip(0)
.build());
Expand Down
Loading