This is an automated email from the ASF dual-hosted git repository. mbenson pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push: new 62a4647 terse w/ Optional 62a4647 is described below commit 62a464710e666e5972fa2775a097e80ca217c9ee Author: Matt Benson <mben...@apache.org> AuthorDate: Tue Mar 29 17:25:04 2022 -0500 terse w/ Optional --- .../org/apache/tools/ant/util/ResourceUtils.java | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/ResourceUtils.java b/src/main/org/apache/tools/ant/util/ResourceUtils.java index 748fb17..e284def 100644 --- a/src/main/org/apache/tools/ant/util/ResourceUtils.java +++ b/src/main/org/apache/tools/ant/util/ResourceUtils.java @@ -380,16 +380,11 @@ public class ResourceUtils { && filters.hasFilters()); final boolean filterChainsAvailable = (filterChains != null && !filterChains.isEmpty()); - String effectiveInputEncoding; - if (source instanceof StringResource) { - effectiveInputEncoding = ((StringResource) source).getEncoding(); - } else { - effectiveInputEncoding = inputEncoding; - } - File destFile = null; - if (dest.as(FileProvider.class) != null) { - destFile = dest.as(FileProvider.class).getFile(); - } + final String effectiveInputEncoding = source.asOptional(StringResource.class) + .map(StringResource::getEncoding).orElse(inputEncoding); + + File destFile = dest.asOptional(FileProvider.class).map(FileProvider::getFile).orElse(null); + if (destFile != null && destFile.isFile() && !destFile.canWrite()) { if (!force) { throw new ReadOnlyTargetFileException(destFile); @@ -399,7 +394,6 @@ public class ResourceUtils { "failed to delete read-only destination file " + destFile); } } - if (filterSetsAvailable) { copyWithFilterSets(source, dest, filters, filterChains, append, effectiveInputEncoding, @@ -438,10 +432,8 @@ public class ResourceUtils { } } if (preserveLastModified) { - final Touchable t = dest.as(Touchable.class); - if (t != null) { - setLastModified(t, source.getLastModified()); - } + dest.asOptional(Touchable.class) + .ifPresent(t -> setLastModified(t, source.getLastModified())); } } // CheckStyle:ParameterNumberCheck ON