Skip to content

Commit 4271ed1

Browse files
committed
Use Java 17 language features for streams
1 parent 852e2b7 commit 4271ed1

13 files changed

Lines changed: 20 additions & 32 deletions

File tree

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/dependencies/aether/AetherMavenArtifactPathResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Collection;
3131
import java.util.List;
3232
import java.util.Set;
33-
import java.util.stream.Collectors;
3433
import java.util.stream.Stream;
3534
import javax.inject.Inject;
3635
import javax.inject.Named;
@@ -143,6 +142,6 @@ public List<Path> resolveDependencies(
143142
.map(aetherArtifactMapper::mapEclipseArtifactToPath)
144143
// Order matters here, so don't convert to an unordered container in the
145144
// future. We make assumptions on the order of this elsewhere.
146-
.collect(Collectors.toUnmodifiableList());
145+
.toList();
147146
}
148147
}

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/generation/ProtobufBuildOrchestrator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.Objects;
4444
import java.util.Optional;
4545
import java.util.TreeSet;
46-
import java.util.stream.Collectors;
4746
import java.util.stream.Stream;
4847
import javax.inject.Inject;
4948
import javax.inject.Named;
@@ -226,7 +225,7 @@ private void createOutputDirectories(
226225
.filter(Objects::nonNull)
227226
)
228227
.flatMap(identity())
229-
.collect(Collectors.toUnmodifiableList());
228+
.toList();
230229

231230
if (!incrementalCompilation && request.isCleanOutputDirectories()) {
232231
for (var outputDirectory : outputDirectories) {
@@ -376,12 +375,12 @@ private ProtocInvocation createProtocInvocation(
376375
.of(projectInputs.getCompilableProtoSources(), projectInputs.getDependencyProtoSources())
377376
.flatMap(Collection::stream)
378377
.map(SourceListing::getSourceRoot)
379-
.collect(Collectors.toUnmodifiableList());
378+
.toList();
380379

381380
var inputDescriptorFiles = projectInputs.getCompilableDescriptorFiles()
382381
.stream()
383382
.map(DescriptorListing::getDescriptorFilePath)
384-
.collect(Collectors.toUnmodifiableList());
383+
.toList();
385384

386385
return ImmutableProtocInvocation.builder()
387386
.arguments(request.getArguments())

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/mojo/AbstractGenerateMojo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.Optional;
4040
import java.util.Set;
4141
import java.util.function.Supplier;
42-
import java.util.stream.Collectors;
4342
import javax.inject.Inject;
4443
import org.apache.maven.plugin.AbstractMojo;
4544
import org.apache.maven.plugin.MojoExecutionException;
@@ -1166,15 +1165,15 @@ private Collection<Path> determinePaths(
11661165
.filter(not(Collection::isEmpty))
11671166
.stream()
11681167
.flatMap(Collection::stream)
1169-
.collect(Collectors.toUnmodifiableList());
1168+
.toList();
11701169

11711170
var finalValue = transformed.isEmpty()
11721171
? defaultIfMissing.get()
11731172
: transformed;
11741173

11751174
return finalValue.stream()
11761175
.filter(Files::exists)
1177-
.collect(Collectors.toUnmodifiableList());
1176+
.toList();
11781177
}
11791178

11801179
private <L> List<L> nonNullList(@Nullable List<L> list) {

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/plugins/JvmPluginResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.Set;
4444
import java.util.function.Predicate;
4545
import java.util.jar.Manifest;
46-
import java.util.stream.Collectors;
4746
import javax.inject.Inject;
4847
import javax.inject.Named;
4948
import org.apache.maven.execution.scope.MojoExecutionScoped;
@@ -173,7 +172,7 @@ private ArgumentFileBuilder buildArgLine(MavenProtocPlugin plugin) throws Resolu
173172
false
174173
)
175174
.stream()
176-
.collect(Collectors.toUnmodifiableList());
175+
.toList();
177176

178177
var args = new ArgumentFileBuilder();
179178

@@ -301,7 +300,7 @@ private List<Path> findJavaModules(List<Path> paths) {
301300
.map(FileUtils::normalize)
302301
// Sort as the order of output is arbitrary, and this ensures reproducible builds.
303302
.sorted(Comparator.comparing(Path::toString))
304-
.collect(Collectors.toUnmodifiableList());
303+
.toList();
305304
}
306305

307306
private Predicate<String> checkValidJvmConfigArg(MavenProtocPlugin plugin) {

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/sources/DescriptorListing.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.nio.file.Path;
1919
import java.util.Collection;
2020
import java.util.Set;
21-
import java.util.stream.Collectors;
2221
import org.immutables.value.Value.Immutable;
2322

2423
/**
@@ -37,6 +36,6 @@ static Collection<String> flatten(Collection<? extends DescriptorListing> listin
3736
return listings.stream()
3837
.map(DescriptorListing::getSourceFiles)
3938
.flatMap(Collection::stream)
40-
.collect(Collectors.toUnmodifiableList());
39+
.toList();
4140
}
4241
}

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/sources/ProjectInputResolver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.github.ascopes.protobufmavenplugin.sources.filter.ProtoFileFilter;
2424
import io.github.ascopes.protobufmavenplugin.utils.ResolutionException;
2525
import java.util.Collection;
26-
import java.util.stream.Collectors;
2726
import java.util.stream.Stream;
2827
import javax.inject.Inject;
2928
import javax.inject.Named;
@@ -100,7 +99,7 @@ private Collection<SourceListing> resolveCompilableProtoSources(
10099
return Stream
101100
.concat(sourcePathsListings.stream(), sourceDependencyListings.stream())
102101
.distinct()
103-
.collect(Collectors.toUnmodifiableList());
102+
.toList();
104103
}
105104

106105
private Collection<SourceListing> resolveDependencyProtoSources(
@@ -121,7 +120,7 @@ private Collection<SourceListing> resolveDependencyProtoSources(
121120
var importPaths = Stream
122121
.concat(request.getImportPaths().stream(), artifactPaths.stream())
123122
.distinct()
124-
.collect(Collectors.toUnmodifiableList());
123+
.toList();
125124

126125
return sourceResolver.resolveSources(importPaths, filter);
127126
}
@@ -144,7 +143,7 @@ private Collection<DescriptorListing> resolveCompilableDescriptorSources(
144143
var descriptorFilePaths = Stream
145144
.concat(request.getSourceDescriptorPaths().stream(), artifactPaths.stream())
146145
.distinct()
147-
.collect(Collectors.toUnmodifiableList());
146+
.toList();
148147

149148
return sourceResolver.resolveDescriptors(descriptorFilePaths, filter);
150149
}

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/sources/ProtoSourceResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Collection<DescriptorListing> resolveDescriptors(
9090
.collect(concurrentExecutor.awaiting())
9191
.stream()
9292
.flatMap(Optional::stream)
93-
.collect(Collectors.toUnmodifiableList());
93+
.toList();
9494
}
9595

9696
private Optional<DescriptorListing> resolveDescriptor(
@@ -150,7 +150,7 @@ Collection<SourceListing> resolveSources(
150150
.collect(concurrentExecutor.awaiting())
151151
.stream()
152152
.flatMap(Optional::stream)
153-
.collect(Collectors.toUnmodifiableList());
153+
.toList();
154154
}
155155

156156
private Optional<SourceListing> resolveSources(

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/sources/SourceListing.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.nio.file.Path;
1919
import java.util.Collection;
2020
import java.util.Set;
21-
import java.util.stream.Collectors;
2221
import org.immutables.value.Value.Immutable;
2322

2423
/**
@@ -37,6 +36,6 @@ static Collection<Path> flatten(Collection<? extends SourceListing> listings) {
3736
return listings.stream()
3837
.map(SourceListing::getSourceFiles)
3938
.flatMap(Collection::stream)
40-
.collect(Collectors.toUnmodifiableList());
39+
.toList();
4140
}
4241
}

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/sources/filter/IncludesExcludesGlobFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.nio.file.PathMatcher;
2121
import java.util.List;
2222
import java.util.function.Predicate;
23-
import java.util.stream.Collectors;
2423

2524
/**
2625
* File filter that handles inclusion and exclusion glob lists.
@@ -56,7 +55,7 @@ private static List<PathMatcher> compile(List<String> globs) {
5655
return globs.stream()
5756
.map("glob:"::concat)
5857
.map(FileSystems.getDefault()::getPathMatcher)
59-
.collect(Collectors.toUnmodifiableList());
58+
.toList();
6059
}
6160

6261
private static Predicate<PathMatcher> path(Path path) {

protobuf-maven-plugin/src/main/java/io/github/ascopes/protobufmavenplugin/urls/AbstractUrlStreamHandlerFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.net.URLStreamHandler;
2222
import java.net.URLStreamHandlerFactory;
2323
import java.util.List;
24-
import java.util.stream.Collectors;
2524
import java.util.stream.Stream;
2625
import org.jspecify.annotations.Nullable;
2726

@@ -39,7 +38,7 @@ abstract class AbstractUrlStreamHandlerFactory implements URLStreamHandlerFactor
3938
// Two args to enforce at least one protocol at any time.
4039
this.protocols = Stream
4140
.concat(Stream.of(protocol), Stream.of(protocols))
42-
.collect(Collectors.toUnmodifiableList());
41+
.toList();
4342
streamHandler = new UrlStreamHandlerImpl();
4443
}
4544

0 commit comments

Comments
 (0)