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 537e008
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 @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.annotation.Nonnull;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.model.ObjectFactory;
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 537e008

Please sign in to comment.