Skip to content

Commit

Permalink
Move object to parameters logic into helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
emmileaf committed Aug 24, 2022
1 parent bd9183d commit 11d9dd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.Project;
Expand Down Expand Up @@ -95,10 +96,7 @@ public List<ExtraDirectoryParameters> getPaths() {
* @param paths paths to set.
*/
public void setPaths(Object paths) {
this.paths.set(
project.files(paths).getFiles().stream()
.map(file -> new ExtraDirectoryParameters(objects, project, file.toPath(), "/"))
.collect(Collectors.toList()));
this.paths.set(transformObjectToParametersList(paths));
}

/**
Expand All @@ -108,13 +106,15 @@ public void setPaths(Object paths) {
* @see #setPaths(Object)
*/
public void setPaths(Provider<Object> paths) {
// Convert Provider<Object> to Provider<List<ExtraDirectoryParameters>>
this.paths.set(
paths.map(
obj ->
project.files(paths).getFiles().stream()
.map(file -> new ExtraDirectoryParameters(objects, project, file.toPath(), "/"))
.collect(Collectors.toList())));
this.paths.set(paths.map(this::transformObjectToParametersList));
}

/** Helper method to convert Object to List<ExtraDirectoryParameters> in {@code setFrom} */
@Nonnull
private List<ExtraDirectoryParameters> transformObjectToParametersList(Object obj) {
return project.files(obj).getFiles().stream()
.map(file -> new ExtraDirectoryParameters(objects, project, file.toPath(), "/"))
.collect(Collectors.toList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public void setFrom(Object from) {
}

public void setFrom(Provider<Object> from) {
// Convert Provider<Object> to Provider<Path>
this.from.set(from.map(obj -> project.file(obj).toPath()));
}

Expand Down

0 comments on commit 11d9dd1

Please sign in to comment.