Skip to content

Commit

Permalink
Replace all List.of() calls with new ArrayList().
Browse files Browse the repository at this point in the history
Replace all toList() stream calls with Collectors.
  • Loading branch information
marchermans committed Feb 15, 2025
1 parent d73f884 commit a05dd0c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
import java.util.List;
import java.util.stream.Collectors;

/**
* The Git extension for the Tableau project.
Expand Down Expand Up @@ -256,7 +257,7 @@ public List<Developer> obtain() {
final int count = Integer.parseInt(line.substring(0, nameStart).trim());

return new Developer(count, name, email);
}).toList();
}).collect(Collectors.toList());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static List<ModDependency> getModInfos(final Project project, final Prob
try (final FileSystem fileSystem = FileSystems.newFileSystem(data.file().toPath())) {
final Path path = fileSystem.getPath("META-INF/neoforge.mods.toml");
if (!Files.exists(path)) {
return List.of();
return new ArrayList<>();
}

final FileConfig fileConfig = FileConfig.builder(path).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.gradle.api.tasks.bundling.Jar;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -80,7 +81,7 @@ public NeoGradleExtension(final Project project) {
});

//Default to no additional data gen mods.
getAdditionalDataGenMods().convention(List.of());
getAdditionalDataGenMods().convention(new ArrayList<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
*/
package com.ldtteam.tableau.neogradle;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.inject.Inject;
Expand Down Expand Up @@ -186,13 +188,15 @@ private void configureRuns(@NotNull Project target) {
runManager.named("client", run -> {
run.getArguments().addAll(
extension.getUseRandomPlayerNames().map(useRandomPlayerNames -> {
final List<String> randomPlayerNames = new ArrayList<>();

if (useRandomPlayerNames) {
final String randomAppendix = String.valueOf((Math.abs(new Random().nextInt() % 600) + 1));
return List.of("--username", "Dev%s".formatted(randomAppendix));
} else {
//When not using random player names, we don't need to add any arguments.
return List.of();
randomPlayerNames.add("--username");
randomPlayerNames.add("Dev%s".formatted(randomAppendix));
}

return randomPlayerNames;
})
);
});
Expand All @@ -208,27 +212,32 @@ private void configureRuns(@NotNull Project target) {
//Add the arguments for the data gen run.
//By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory.
run.getArguments().addAll(
projectExtension.getModId().map(modId -> List.of(
"--mod", modId,
"--all",
"--output", target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath(),
"--existing", target.file("src/main/resources/").getAbsolutePath()
))
projectExtension.getModId().map(modId -> {
List<String> dataRunArguments = new ArrayList<>();
dataRunArguments.add("--mod");
dataRunArguments.add(modId);
dataRunArguments.add("--all");
dataRunArguments.add("--output");
dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath());
dataRunArguments.add("--existing");
dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath());
return dataRunArguments;
})
);

//Add the arguments for the additional data gen mods.
run.getArguments().addAll(
extension.getAdditionalDataGenMods().map(mods -> {
if (mods.isEmpty()) {
//When no additional data gen mods are set, we don't need to add any arguments.
return List.of();
return new ArrayList<>();
}

//When additional data gen mods are set, we need to add the arguments for each mod.
//Per mod, we need to add the "--existing-mod" argument followed by the mod id.
return mods.stream()
.flatMap(modId -> Stream.of("--existing-mod", modId))
.toList();
.collect(Collectors.toList());
})
);
});
Expand Down Expand Up @@ -257,7 +266,7 @@ private void configureRuns(@NotNull Project target) {
.stream()
.filter(sourceSet -> NeoGradleSourceSetConfigurationExtension.get(sourceSet).getIsModSource().get())
.map(sourceSet -> sourceSetContainer.getByName(sourceSet.getName()))
.toList();
.collect(Collectors.toList());

final Multimap<String, SourceSet> modSources = HashMultimap.create();
modSources.putAll(modId, sourceSets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import org.gradle.api.Plugin;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.DependencyCollector;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.bundling.Jar;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;

/**
Expand Down Expand Up @@ -121,7 +123,9 @@ private void configureShadowJarTask(Project project) {
shadowJar.from(sourceSet.getOutput());
});

shadowJar.setConfigurations(List.of(project.getConfigurations().getByName(CONTAINED_CONFIGURATION_NAME)));
List<FileCollection> configurations = new ArrayList<>();
configurations.add(project.getConfigurations().getByName(CONTAINED_CONFIGURATION_NAME));
shadowJar.setConfigurations(configurations);

shadowing.getRenamedNamespaces().get().forEach(shadowJar::relocate);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ldtteam.tableau.sourceset.management.extensions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -124,7 +125,9 @@ public SourceSetExtension(final Project project) {

final SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
getUniversalJarSourceSets().add(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME));
getPublishedSourceSets().convention(List.of(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)));
List<SourceSet> elements = new ArrayList<>();
elements.add(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME));
getPublishedSourceSets().convention(elements);

project.afterEvaluate(p -> {
//Run this in an afterEval, because we need a group configured, which is not available at apply and construction time.
Expand Down

0 comments on commit a05dd0c

Please sign in to comment.