Skip to content

Commit

Permalink
Upgrade Google Java Formatter (GoogleContainerTools#3459)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Sep 13, 2021
1 parent 6844d3a commit 5e9a65f
Show file tree
Hide file tree
Showing 36 changed files with 75 additions and 210 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ subprojects {

/* GOOGLE JAVA FORMAT */
googleJavaFormat {
toolVersion = '1.6'
toolVersion = '1.7'
}
check.dependsOn verifyGoogleJavaFormat
/* GOOGLE JAVA FORMAT */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ private static JibContainerBuilder createJibContainerBuilder(
BaseImageSpec baseImageSpec, CommonCliOptions commonCliOptions, ConsoleLogger logger)
throws InvalidImageReferenceException, FileNotFoundException {
LinkedHashSet<Platform> platforms =
baseImageSpec
.getPlatforms()
.stream()
baseImageSpec.getPlatforms().stream()
.map(platformSpec -> new Platform(platformSpec.getArchitecture(), platformSpec.getOs()))
.collect(Collectors.toCollection(LinkedHashSet::new));
return ContainerBuilders.create(baseImageSpec.getImage(), platforms, commonCliOptions, logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,11 @@ static List<FileEntriesLayer> toLayers(Path buildRoot, LayersSpec layersSpec) th
filePropertiesStack.getOwnership());
} else if (Files.isDirectory(src)) { // directory
List<PathMatcher> excludes =
copySpec
.getExcludes()
.stream()
copySpec.getExcludes().stream()
.map(Layers::toPathMatcher)
.collect(Collectors.toList());
List<PathMatcher> includes =
copySpec
.getIncludes()
.stream()
copySpec.getIncludes().stream()
.map(Layers::toPathMatcher)
.collect(Collectors.toList());
try (Stream<Path> dirWalk = Files.walk(src)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ static List<FileEntriesLayer> getDependenciesLayers(Path jarPath, ProcessingMode
Predicate<String> isSnapshot = name -> name.contains("SNAPSHOT");
List<String> allDependencies = Splitter.onPattern("\\s+").splitToList(classPath.trim());
List<Path> nonSnapshots =
allDependencies
.stream()
allDependencies.stream()
.filter(isSnapshot.negate())
.map(Paths::get)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public void testCreateLayers_layered_allListed() throws IOException, URISyntaxEx

assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
assertThat(
nonSnapshotLayer
.getEntries()
.stream()
nonSnapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand All @@ -87,9 +85,7 @@ public void testCreateLayers_layered_allListed() throws IOException, URISyntaxEx

assertThat(loaderLayer.getName()).isEqualTo("spring-boot-loader");
assertThat(
loaderLayer
.getEntries()
.stream()
loaderLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand All @@ -98,18 +94,14 @@ public void testCreateLayers_layered_allListed() throws IOException, URISyntaxEx

assertThat(snapshotLayer.getName()).isEqualTo("snapshot-dependencies");
assertThat(
snapshotLayer
.getEntries()
.stream()
snapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(AbsoluteUnixPath.get("/app/BOOT-INF/lib/dependency3-SNAPSHOT.jar"));

assertThat(applicationLayer.getName()).isEqualTo("application");
assertThat(
applicationLayer
.getEntries()
.stream()
applicationLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand Down Expand Up @@ -147,9 +139,7 @@ public void testCreateLayers_layered_singleEmptyLayerListed()

assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
assertThat(
nonSnapshotLayer
.getEntries()
.stream()
nonSnapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand All @@ -158,9 +148,7 @@ public void testCreateLayers_layered_singleEmptyLayerListed()

assertThat(loaderLayer.getName()).isEqualTo("spring-boot-loader");
assertThat(
loaderLayer
.getEntries()
.stream()
loaderLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand All @@ -169,9 +157,7 @@ public void testCreateLayers_layered_singleEmptyLayerListed()

assertThat(applicationLayer.getName()).isEqualTo("application");
assertThat(
applicationLayer
.getEntries()
.stream()
applicationLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand Down Expand Up @@ -218,9 +204,7 @@ public void testCreateLayers_nonLayered() throws IOException, URISyntaxException

assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
assertThat(
nonSnapshotLayer
.getEntries()
.stream()
nonSnapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand All @@ -229,9 +213,7 @@ public void testCreateLayers_nonLayered() throws IOException, URISyntaxException

assertThat(loaderLayer.getName()).isEqualTo("spring-boot-loader");
assertThat(
loaderLayer
.getEntries()
.stream()
loaderLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand All @@ -248,9 +230,7 @@ public void testCreateLayers_nonLayered() throws IOException, URISyntaxException

assertThat(classesLayer.getName()).isEqualTo("classes");
assertThat(
classesLayer
.getEntries()
.stream()
classesLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.containsExactly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public void testCreateLayers_withClassPathInManifest() throws IOException, URISy
// Validate dependencies layers.
assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
assertThat(
nonSnapshotLayer
.getEntries()
.stream()
nonSnapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.isEqualTo(
Expand All @@ -105,9 +103,7 @@ public void testCreateLayers_withClassPathInManifest() throws IOException, URISy
// Validate resources layer.
assertThat(resourcesLayer.getName()).isEqualTo("resources");
List<AbsoluteUnixPath> actualResourcesPaths =
resourcesLayer
.getEntries()
.stream()
resourcesLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList());
assertThat(actualResourcesPaths)
Expand All @@ -121,9 +117,7 @@ public void testCreateLayers_withClassPathInManifest() throws IOException, URISy
// Validate classes layer.
assertThat(classesLayer.getName()).isEqualTo("classes");
List<AbsoluteUnixPath> actualClassesPaths =
classesLayer
.getEntries()
.stream()
classesLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList());
assertThat(actualClassesPaths)
Expand Down Expand Up @@ -153,9 +147,7 @@ public void testCreateLayers_withoutClassPathInManifest() throws IOException, UR
// Validate resources layer.
assertThat(resourcesLayer.getName()).isEqualTo("resources");
List<AbsoluteUnixPath> actualResourcesPaths =
resourcesLayer
.getEntries()
.stream()
resourcesLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList());
assertThat(actualResourcesPaths)
Expand All @@ -169,9 +161,7 @@ public void testCreateLayers_withoutClassPathInManifest() throws IOException, UR
// Validate classes layer.
assertThat(classesLayer.getName()).isEqualTo("classes");
List<AbsoluteUnixPath> actualClassesPaths =
classesLayer
.getEntries()
.stream()
classesLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList());
assertThat(actualClassesPaths)
Expand Down Expand Up @@ -205,9 +195,7 @@ public void testCreateLayers_withoutClassPathInManifest_containsOnlyClasses()

// Validate classes layer.
List<AbsoluteUnixPath> actualClassesPath =
classesLayer
.getEntries()
.stream()
classesLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList());
assertThat(actualClassesPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public void testCreateLayers_withClassPathInManifest() throws IOException, URISy
// Validate dependencies layers.
assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
assertThat(
nonSnapshotLayer
.getEntries()
.stream()
nonSnapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.isEqualTo(
Expand All @@ -88,9 +86,7 @@ public void testCreateLayers_withClassPathInManifest() throws IOException, URISy
AbsoluteUnixPath.get("/app/directory/dependency4")));
assertThat(snapshotLayer.getName()).isEqualTo("snapshot dependencies");
assertThat(
snapshotLayer
.getEntries()
.stream()
snapshotLayer.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.isEqualTo(ImmutableList.of(AbsoluteUnixPath.get("/app/dependency3-SNAPSHOT-1.jar")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,7 @@ public JibContainerBuilder toContainerBuilder() throws IOException {
.map(path -> path.getFileName().toString())
.collect(Collectors.groupingBy(filename -> filename, Collectors.counting()));
List<String> duplicates =
occurrences
.entrySet()
.stream()
occurrences.entrySet().stream()
.filter(entry -> entry.getValue() > 1)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ public JibContainerBuilder addFileEntriesLayer(FileEntriesLayer layer) {
@Deprecated
public JibContainerBuilder setLayers(List<LayerConfiguration> layerConfigurations) {
return setFileEntriesLayers(
layerConfigurations
.stream()
layerConfigurations.stream()
.map(LayerConfiguration::toFileEntriesLayer)
.collect(Collectors.toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ static ImmutableList<BuildAndCacheApplicationLayerStep> makeList(
TimerEventDispatcher ignored =
new TimerEventDispatcher(
buildContext.getEventHandlers(), "Preparing application layer builders")) {
return layerConfigurations
.stream()
return layerConfigurations.stream()
// Skips the layer if empty.
.filter(layerConfiguration -> !layerConfiguration.getEntries().isEmpty())
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ List<Image> getCachedBaseImages()
lookUpPlatformSpecificImageManifest((V22ManifestListTemplate) manifestList, platform);

Optional<ManifestAndConfigTemplate> manifestAndConfigFound =
manifestsAndConfigs
.stream()
manifestsAndConfigs.stream()
.filter(entry -> manifestDigest.equals(entry.getManifestDigest()))
.findFirst();
if (!manifestAndConfigFound.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ static ImmutableList<PushImageStep> makeList(

Set<String> imageQualifiers =
singlePlatform ? tags : Collections.singleton(manifestDigest.toString());
return imageQualifiers
.stream()
return imageQualifiers.stream()
.map(
qualifier ->
new PushImageStep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ static ImmutableList<PushLayerStep> makeList(
progressEventDispatcherFactory.create("launching layer pushers", cachedLayers.size())) {

// Constructs a PushBlobStep for each layer.
return cachedLayers
.stream()
return cachedLayers.stream()
.map(
layer ->
new PushLayerStep(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ boolean updateProgress(Allocation allocation, long units) {
*/
@VisibleForTesting
List<Allocation> getUnfinishedAllocations() {
return completionMap
.values()
.stream()
return completionMap.values().stream()
.filter(IndexedRemainingUnits::isUnfinished)
.sorted()
.map(remainingUnits -> remainingUnits.allocation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ static ImmutableList<String> environmentMapToList(@Nullable Map<String, String>
Preconditions.checkArgument(
environment.keySet().stream().noneMatch(key -> key.contains("=")),
"Illegal environment variable: name cannot contain '='");
return environment
.entrySet()
.stream()
return environment.entrySet().stream()
.map(entry -> entry.getKey() + "=" + entry.getValue())
.collect(ImmutableList.toImmutableList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public List<ManifestDescriptorTemplate> getManifests() {
* @return a list of matching digests
*/
public List<String> getDigestsForPlatform(String architecture, String os) {
return getManifests()
.stream()
return getManifests().stream()
.filter(
manifest ->
manifest.platform != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ static Multimap<String, String> decodeTokenRepositoryGrants(String token) {
if (payload.access == null) {
return null;
}
return payload
.access
.stream()
return payload.access.stream()
.filter(claim -> "repository".equals(claim.type))
.collect(
ImmutableSetMultimap.<AccessClaim, String, String>flatteningToImmutableSetMultimap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class DockerConfig {
@Nullable
private static <K, T> Map.Entry<K, T> findFirstInMapByKey(
Map<K, T> map, List<Predicate<K>> keyMatches) {
return keyMatches
.stream()
return keyMatches.stream()
.map(keyMatch -> findFirstInMapByKey(map, keyMatch))
.filter(Objects::nonNull)
.findFirst()
Expand All @@ -47,8 +46,7 @@ private static <K, T> Map.Entry<K, T> findFirstInMapByKey(
/** Returns the first entry matching the given key predicate. */
@Nullable
private static <K, T> Map.Entry<K, T> findFirstInMapByKey(Map<K, T> map, Predicate<K> keyMatch) {
return map.entrySet()
.stream()
return map.entrySet().stream()
.filter(entry -> keyMatch.test(entry.getKey()))
.findFirst()
.orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ private static Path getResource(String directory) throws URISyntaxException {
/** Gets the extraction paths in the specified layer of a give {@link BuildContext}. */
private static List<AbsoluteUnixPath> getExtractionPaths(
BuildContext buildContext, String layerName) {
return buildContext
.getLayerConfigurations()
.stream()
return buildContext.getLayerConfigurations().stream()
.filter(layerConfiguration -> layerConfiguration.getName().equals(layerName))
.findFirst()
.map(
layerConfiguration ->
layerConfiguration
.getEntries()
.stream()
layerConfiguration.getEntries().stream()
.map(FileEntry::getExtractionPath)
.collect(Collectors.toList()))
.orElse(ImmutableList.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ public void testWriteMetadata_v22()
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
savedManifest2
.getLayers()
.stream()
savedManifest2.getLayers().stream()
.map(layer -> layer.getDigest().getHash())
.collect(Collectors.toList()));

Expand Down
Loading

0 comments on commit 5e9a65f

Please sign in to comment.