Skip to content

Commit

Permalink
Refactor the logic picking the settings file
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tk3y committed Nov 12, 2024
1 parent 984be52 commit ba07ca2
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.gradle.tooling.model.gradle.GradleBuild;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class GetDeclarativeResourcesModel implements BuildAction<DeclarativeResourcesModel> {
Expand Down Expand Up @@ -104,13 +105,14 @@ public File getRootDir() {
@Override
public File getSettingsFile() {
// TODO: this is an assumption about the location of the settings file – get it from Gradle instead.
List<File> candidateFiles = Stream.of("settings.gradle.dcl", "settings.gradle.kts")
.map(it -> new File(getRootDir(), "settings.gradle.dcl"))
.collect(Collectors.toList());
return candidateFiles.stream()
List<String> candidateFileNames = Arrays.asList("settings.gradle.dcl", "settings.gradle.kts");
Function<String, File> asFileInRootDirectory = it -> new File(getRootDir(), it);

return candidateFileNames.stream()
.map(asFileInRootDirectory)
.filter(File::exists)
.findFirst()
.orElse(candidateFiles.get(0));
.orElse(asFileInRootDirectory.apply(candidateFileNames.get(0)));
}

@Override
Expand Down

0 comments on commit ba07ca2

Please sign in to comment.