This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch maven-filtering-3.x
in repository https://gitbox.apache.org/repos/asf/maven-filtering.git
The following commit(s) were added to refs/heads/maven-filtering-3.x by this
push:
new d9bc10a Introduce ChangeDetection (#323)
d9bc10a is described below
commit d9bc10a1fe817a6dd7fb2baa31f1bb5321878ce2
Author: Tamas Cservenak <[email protected]>
AuthorDate: Thu Feb 26 13:19:53 2026 +0100
Introduce ChangeDetection (#323)
Instead to jump between ways how to perform "change detection"
(decide should existing target file be overwritten), make it
a configurable strategy.
Before 3.4.0 it was timestamp, post 3.4.0 it was content, but
in any case users were left short.
Fixes
https://github.com/apache/maven-resources-plugin/issues/453
https://github.com/apache/maven-resources-plugin/issues/453
#321
#271
---
pom.xml | 52 +++++------
.../filtering/AbstractMavenFilteringRequest.java | 28 ++++++
.../maven/shared/filtering/ChangeDetection.java | 47 ++++++++++
.../shared/filtering/DefaultMavenFileFilter.java | 81 ++++++++++++----
.../filtering/DefaultMavenResourcesFiltering.java | 14 +--
.../maven/shared/filtering/FilteringUtils.java | 104 +++++++++++++++++++--
.../maven/shared/filtering/MavenFileFilter.java | 51 +++++++++-
.../shared/filtering/MavenResourcesExecution.java | 19 ++--
8 files changed, 324 insertions(+), 72 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5d1e6d7..cbb9e12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,6 @@
<properties>
<mavenVersion>3.9.12</mavenVersion>
<slf4jVersion>1.7.36</slf4jVersion>
- <plexusBuildApiVersion>0.0.7</plexusBuildApiVersion>
<version.plexus-utils>3.6.0</version.plexus-utils>
<project.build.outputTimestamp>2024-08-28T15:27:52Z</project.build.outputTimestamp>
<!-- don't fail check for some rules that are too hard to enforce (could
even be told broken for some)
@@ -72,20 +71,31 @@
</properties>
<dependencies>
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <version>1</version>
- </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
<dependency>
- <groupId>org.sonatype.plexus</groupId>
+ <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
- <version>${plexusBuildApiVersion}</version>
+ <version>1.2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ <version>1.29</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
@@ -105,25 +115,6 @@
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-interpolation</artifactId>
- <version>1.29</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.21.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.20.0</version>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -164,7 +155,12 @@
<artifactId>org.eclipse.sisu.inject</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.21.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/src/main/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequest.java
b/src/main/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequest.java
index 6daebd8..e94c9d4 100644
---
a/src/main/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequest.java
+++
b/src/main/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequest.java
@@ -28,6 +28,8 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.interpolation.Interpolator;
+import static java.util.Objects.requireNonNull;
+
/**
* @since 1.0-beta-3
*/
@@ -83,6 +85,13 @@ public class AbstractMavenFilteringRequest {
private Consumer<Interpolator> interpolatorCustomizer;
+ /**
+ * Change detection strategy to determine whether an existing file should
be overwritten.
+ *
+ * @since 3.5.0
+ */
+ private ChangeDetection changeDetection = ChangeDetection.CONTENT;
+
/**
* Create instance.
*/
@@ -360,4 +369,23 @@ public class AbstractMavenFilteringRequest {
public void setInterpolatorCustomizer(Consumer<Interpolator>
interpolatorCustomizer) {
this.interpolatorCustomizer = interpolatorCustomizer;
}
+
+ /**
+ * Change detection strategy to determine whether an existing file should
be overwritten.
+ *
+ * @since 3.5.0
+ */
+ public ChangeDetection getChangeDetection() {
+ return changeDetection;
+ }
+
+ /**
+ * Sets the change detection strategy to determine whether an existing
file should be overwritten.
+ *
+ * @param changeDetection the change detection strategy to use, must not
be {@code null}.
+ * @since 3.5.0
+ */
+ public void setChangeDetection(ChangeDetection changeDetection) {
+ this.changeDetection = requireNonNull(changeDetection);
+ }
}
diff --git
a/src/main/java/org/apache/maven/shared/filtering/ChangeDetection.java
b/src/main/java/org/apache/maven/shared/filtering/ChangeDetection.java
new file mode 100644
index 0000000..98ef9a9
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/filtering/ChangeDetection.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.shared.filtering;
+
+/**
+ * Change detection strategies: to decide whether an <strong>existing target
file</strong> needs to be overwritten or not.
+ *
+ * @since 3.5.0
+ */
+public enum ChangeDetection {
+ /**
+ * Only consider the file timestamp to determine is overwrite of existing
file needed. This was default before 3.4.0.
+ */
+ TIMESTAMP,
+ /**
+ * Only consider the content of the file to determine is overwrite of
existing file needed. This is the default since 3.4.0.
+ */
+ CONTENT,
+ /**
+ * Combine timestamp and content change detection for existing file.
+ */
+ TIMESTAMP_AND_CONTENT,
+ /**
+ * Disable change detection; always overwrite existing file.
+ */
+ ALWAYS,
+ /**
+ * Disable change detection; never overwrite existing file.
+ */
+ NEVER;
+}
diff --git
a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
index c6b0354..3a22ca2 100644
---
a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
+++
b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
@@ -45,6 +45,7 @@ public class DefaultMavenFileFilter extends BaseFilter
implements MavenFileFilte
this.buildContext = requireNonNull(buildContext);
}
+ @Deprecated
@Override
public void copyFile(
File from,
@@ -56,15 +57,40 @@ public class DefaultMavenFileFilter extends BaseFilter
implements MavenFileFilte
String encoding,
MavenSession mavenSession)
throws MavenFilteringException {
+ copyFile(
+ from,
+ to,
+ filtering,
+ mavenProject,
+ filters,
+ escapedBackslashesInFilePath,
+ encoding,
+ mavenSession,
+ ChangeDetection.CONTENT);
+ }
+
+ @Override
+ public void copyFile(
+ File from,
+ File to,
+ boolean filtering,
+ MavenProject mavenProject,
+ List<String> filters,
+ boolean escapedBackslashesInFilePath,
+ String encoding,
+ MavenSession mavenSession,
+ ChangeDetection changeDetection)
+ throws MavenFilteringException {
MavenResourcesExecution mre = new MavenResourcesExecution();
mre.setMavenProject(mavenProject);
mre.setFileFilters(filters);
mre.setEscapeWindowsPaths(escapedBackslashesInFilePath);
mre.setMavenSession(mavenSession);
mre.setInjectProjectBuildFilters(true);
+ mre.setChangeDetection(changeDetection);
List<FilterWrapper> filterWrappers = getDefaultFilterWrappers(mre);
- copyFile(from, to, filtering, filterWrappers, encoding);
+ copyFile(from, to, filtering, filterWrappers, encoding,
changeDetection);
}
@Override
@@ -76,24 +102,57 @@ public class DefaultMavenFileFilter extends BaseFilter
implements MavenFileFilte
mavenFileFilterRequest.getTo(),
mavenFileFilterRequest.isFiltering(),
filterWrappers,
- mavenFileFilterRequest.getEncoding());
+ mavenFileFilterRequest.getEncoding(),
+ mavenFileFilterRequest.getChangeDetection());
}
+ @Deprecated
@Override
public void copyFile(File from, File to, boolean filtering,
List<FilterWrapper> filterWrappers, String encoding)
throws MavenFilteringException {
+ copyFile(from, to, filtering, filterWrappers, encoding,
ChangeDetection.CONTENT);
+ }
+
+ @Override
+ @Deprecated
+ public void copyFile(
+ File from,
+ File to,
+ boolean filtering,
+ List<FilterWrapper> filterWrappers,
+ String encoding,
+ boolean overwrite)
+ throws MavenFilteringException {
+ copyFile(
+ from,
+ to,
+ filtering,
+ filterWrappers,
+ encoding,
+ overwrite ? ChangeDetection.ALWAYS : ChangeDetection.CONTENT);
+ }
+
+ @Override
+ public void copyFile(
+ File from,
+ File to,
+ boolean filtering,
+ List<FilterWrapper> filterWrappers,
+ String encoding,
+ ChangeDetection changeDetection)
+ throws MavenFilteringException {
try {
if (filtering) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("filtering " + from.getPath() + " to " +
to.getPath());
}
FilterWrapper[] array = filterWrappers.toArray(new
FilterWrapper[0]);
- FilteringUtils.copyFile(from, to, encoding, array, false);
+ FilteringUtils.copyFile(from, to, encoding, array,
changeDetection);
} else {
if (getLogger().isDebugEnabled()) {
getLogger().debug("copy " + from.getPath() + " to " +
to.getPath());
}
- FilteringUtils.copyFile(from, to, encoding, new
FilterWrapper[0], false);
+ FilteringUtils.copyFile(from, to, encoding, new
FilterWrapper[0], changeDetection);
}
buildContext.refresh(to);
@@ -104,18 +163,4 @@ public class DefaultMavenFileFilter extends BaseFilter
implements MavenFileFilte
e);
}
}
-
- @Override
- @Deprecated
- public void copyFile(
- File from,
- File to,
- boolean filtering,
- List<FilterWrapper> filterWrappers,
- String encoding,
- boolean overwrite)
- throws MavenFilteringException {
- // overwrite forced to false to preserve backward comp
- copyFile(from, to, filtering, filterWrappers, encoding);
- }
}
diff --git
a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
index 0c8688f..47c7171 100644
---
a/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
+++
b/src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
@@ -34,12 +34,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.maven.model.Resource;
import org.codehaus.plexus.util.DirectoryScanner;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.Scanner;
+import org.codehaus.plexus.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.plexus.build.incremental.BuildContext;
@@ -93,7 +93,7 @@ public class DefaultMavenResourcesFiltering implements
MavenResourcesFiltering {
}
private static String getExtension(String fileName) {
- String rawExt = FilenameUtils.getExtension(fileName);
+ String rawExt = FileUtils.getExtension(fileName);
return rawExt == null ? null : rawExt.toLowerCase(Locale.ROOT);
}
@@ -280,7 +280,7 @@ public class DefaultMavenResourcesFiltering implements
MavenResourcesFiltering {
File destinationFile = getDestinationFile(outputDirectory,
targetPath, name, mavenResourcesExecution);
if (mavenResourcesExecution.isFlatten() &&
destinationFile.exists()) {
- if (mavenResourcesExecution.isOverwrite()) {
+ if (mavenResourcesExecution.getChangeDetection() ==
ChangeDetection.ALWAYS) {
LOGGER.warn("existing file " +
destinationFile.getName() + " will be overwritten by " + name);
} else {
throw new MavenFilteringException("existing file " +
destinationFile.getName()
@@ -303,7 +303,7 @@ public class DefaultMavenResourcesFiltering implements
MavenResourcesFiltering {
resource.isFiltering() && filteredExt,
mavenResourcesExecution.getFilterWrappers(),
encoding,
- mavenResourcesExecution.isOverwrite());
+ mavenResourcesExecution.getChangeDetection());
}
// deal with deleted source files
@@ -507,7 +507,7 @@ public class DefaultMavenResourcesFiltering implements
MavenResourcesFiltering {
}
try (StringWriter writer = new StringWriter()) {
- IOUtils.copy(reader, writer);
+ IOUtil.copy(reader, writer);
String filteredFilename = writer.toString();
if (LOGGER.isDebugEnabled()) {
diff --git
a/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java
b/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java
index b68e3cd..74be18a 100644
--- a/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java
+++ b/src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java
@@ -32,7 +32,6 @@ import java.util.EnumSet;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
-import org.apache.commons.lang3.SystemUtils;
import org.codehaus.plexus.util.io.CachingOutputStream;
import org.codehaus.plexus.util.io.CachingWriter;
@@ -41,6 +40,12 @@ import org.codehaus.plexus.util.io.CachingWriter;
* @author Dennis Lundberg
*/
public final class FilteringUtils {
+ /**
+ * Logic borrowed from Commons-Lang3: we really need only this, to decide
is it Windows.
+ * It is nonsense to import whole commons-lang3 just for this test.
+ */
+ private static final boolean IS_WINDOWS =
+ System.getProperty("os.name", "unknown").startsWith("Windows");
/**
* The number of bytes in a kilobyte.
*/
@@ -115,7 +120,7 @@ public final class FilteringUtils {
}
// deal with absolute files
- if (filenm.startsWith(File.separator) || (SystemUtils.IS_OS_WINDOWS &&
filenm.indexOf(":") > 0)) {
+ if (filenm.startsWith(File.separator) || (IS_WINDOWS &&
filenm.indexOf(":") > 0)) {
File file = new File(filenm);
try {
@@ -306,12 +311,67 @@ public final class FilteringUtils {
* @param encoding the file output encoding (only if wrappers is not empty)
* @param wrappers array of {@link FilterWrapper}
* @throws IOException if an IO error occurs during copying or filtering
+ * @deprecated Use {@link #copyFile(File, File, String, FilterWrapper[],
ChangeDetection)} instead.
*/
+ @Deprecated
public static void copyFile(File from, File to, String encoding,
FilterWrapper[] wrappers) throws IOException {
- setReadWritePermissions(to);
+ copyFile(from, to, encoding, wrappers, ChangeDetection.CONTENT);
+ }
+
+ /**
+ * Copies a file from the source to the destination, applying the
specified filters if provided.
+ *
+ * @param from the file to copy
+ * @param to the destination file
+ * @param encoding the file output encoding (only if wrappers is not empty)
+ * @param wrappers array of {@link FilterWrapper}
+ * @param changeDetection the strategy to apply if to is existing file
+ * @throws IOException if an IO error occurs during copying or filtering
+ * @return {@code true} if the file was copied.
+ */
+ public static boolean copyFile(
+ File from, File to, String encoding, FilterWrapper[] wrappers,
ChangeDetection changeDetection)
+ throws IOException {
+ boolean needsCopy = false;
+ boolean unconditionally = false;
+ switch (changeDetection) {
+ case NEVER:
+ needsCopy = !to.isFile();
+ unconditionally = true;
+ break;
+ case ALWAYS:
+ needsCopy = true;
+ unconditionally = true;
+ break;
+ case TIMESTAMP:
+ needsCopy = to.lastModified() < from.lastModified();
+ unconditionally = true;
+ break;
+ case CONTENT:
+ needsCopy = true;
+ break;
+ case TIMESTAMP_AND_CONTENT:
+ needsCopy = to.lastModified() < from.lastModified();
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported change
detection mode: " + changeDetection);
+ }
+ boolean copied = false;
+ if (needsCopy) {
+ if (unconditionally) {
+ copied = copyUnconditionally(from, to, encoding, wrappers);
+ } else {
+ copied = copyIfContentsChanged(from, to, encoding, wrappers);
+ }
+ }
+ return copied;
+ }
+ private static boolean copyUnconditionally(File from, File to, String
encoding, FilterWrapper[] wrappers)
+ throws IOException {
+ setReadWritePermissions(to);
if (wrappers == null || wrappers.length == 0) {
- try (OutputStream os = new CachingOutputStream(to.toPath())) {
+ try (OutputStream os = Files.newOutputStream(to.toPath())) {
Files.copy(from.toPath(), os);
}
} else {
@@ -321,7 +381,7 @@ public final class FilteringUtils {
for (FilterWrapper wrapper : wrappers) {
wrapped = wrapper.getReader(wrapped);
}
- try (Writer writer = new CachingWriter(to.toPath(), charset)) {
+ try (Writer writer = Files.newBufferedWriter(to.toPath(),
charset)) {
char[] buffer = new char[COPY_BUFFER_LENGTH];
int nRead;
while ((nRead = wrapped.read(buffer, 0,
COPY_BUFFER_LENGTH)) >= 0) {
@@ -330,8 +390,38 @@ public final class FilteringUtils {
}
}
}
+ copyFilePermissions(from, to);
+ return true;
+ }
+ private static boolean copyIfContentsChanged(File from, File to, String
encoding, FilterWrapper[] wrappers)
+ throws IOException {
+ setReadWritePermissions(to);
+ boolean copied = false;
+ if (wrappers == null || wrappers.length == 0) {
+ try (CachingOutputStream os = new
CachingOutputStream(to.toPath())) {
+ Files.copy(from.toPath(), os);
+ copied = os.isModified();
+ }
+ } else {
+ Charset charset = charset(encoding);
+ try (Reader fileReader = Files.newBufferedReader(from.toPath(),
charset)) {
+ Reader wrapped = fileReader;
+ for (FilterWrapper wrapper : wrappers) {
+ wrapped = wrapper.getReader(wrapped);
+ }
+ try (CachingWriter writer = new CachingWriter(to.toPath(),
charset)) {
+ char[] buffer = new char[COPY_BUFFER_LENGTH];
+ int nRead;
+ while ((nRead = wrapped.read(buffer, 0,
COPY_BUFFER_LENGTH)) >= 0) {
+ writer.write(buffer, 0, nRead);
+ }
+ copied = writer.isModified();
+ }
+ }
+ }
copyFilePermissions(from, to);
+ return copied;
}
/**
@@ -344,12 +434,12 @@ public final class FilteringUtils {
* @param wrappers array of {@link FilterWrapper}
* @param overwrite unused
* @throws IOException if an IO error occurs during copying or filtering
- * @deprecated use {@link #copyFile(File, File, String, FilterWrapper[])}
instead
+ * @deprecated use {@link #copyFile(File, File, String, FilterWrapper[],
ChangeDetection)} instead
*/
@Deprecated
public static void copyFile(File from, File to, String encoding,
FilterWrapper[] wrappers, boolean overwrite)
throws IOException {
- copyFile(from, to, encoding, wrappers);
+ copyFile(from, to, encoding, wrappers, overwrite ?
ChangeDetection.ALWAYS : ChangeDetection.CONTENT);
}
/**
diff --git
a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
index a68db1d..272e5ec 100644
--- a/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
+++ b/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
@@ -42,6 +42,7 @@ public interface MavenFileFilter extends DefaultFilterInfo {
* @param encoding The encoding which is used during the filtering process.
* @throws MavenFilteringException in case of failure.
* @see DefaultFilterInfo#getDefaultFilterWrappers(MavenProject, List,
boolean,MavenSession, MavenResourcesExecution)
+ * @deprecated Use {@link #copyFile(File, File, boolean, MavenProject,
List, boolean, String, MavenSession, ChangeDetection)} instead.
*/
void copyFile(
File from,
@@ -54,6 +55,33 @@ public interface MavenFileFilter extends DefaultFilterInfo {
MavenSession mavenSession)
throws MavenFilteringException;
+ /**
+ * Will copy a file with some filtering using defaultFilterWrappers.
+ *
+ * @param from file to copy/filter
+ * @param to destination file
+ * @param filtering enable or not filtering
+ * @param mavenProject {@link MavenProject}
+ * @param mavenSession {@link MavenSession}
+ * @param escapedBackslashesInFilePath escape backslashes in file path.
+ * @param filters {@link List} of String which are path to a Property file
+ * @param encoding The encoding which is used during the filtering process.
+ * @throws MavenFilteringException in case of failure.
+ * @see DefaultFilterInfo#getDefaultFilterWrappers(MavenProject, List,
boolean,MavenSession, MavenResourcesExecution)
+ * @since 3.5.0
+ */
+ void copyFile(
+ File from,
+ File to,
+ boolean filtering,
+ MavenProject mavenProject,
+ List<String> filters,
+ boolean escapedBackslashesInFilePath,
+ String encoding,
+ MavenSession mavenSession,
+ ChangeDetection changeDetection)
+ throws MavenFilteringException;
+
/**
* @param mavenFileFilterRequest the request
* @throws MavenFilteringException in case of failure.
@@ -68,7 +96,9 @@ public interface MavenFileFilter extends DefaultFilterInfo {
* @param filterWrappers {@link List} of FileUtils.FilterWrapper
* @param encoding The encoding used during the filtering.
* @throws MavenFilteringException In case of an error.
+ * @deprecated use {@link #copyFile(File, File, boolean, List, String,
ChangeDetection)} instead
*/
+ @Deprecated
void copyFile(File from, File to, boolean filtering, List<FilterWrapper>
filterWrappers, String encoding)
throws MavenFilteringException;
@@ -81,7 +111,7 @@ public interface MavenFileFilter extends DefaultFilterInfo {
* @param overwrite unused
* @throws MavenFilteringException In case of an error.
* @since 1.0-beta-2
- * @deprecated use {@link #copyFile(File, File, boolean, List, String)}
instead
+ * @deprecated use {@link #copyFile(File, File, boolean, List, String,
ChangeDetection)} instead
*/
@Deprecated
void copyFile(
@@ -92,4 +122,23 @@ public interface MavenFileFilter extends DefaultFilterInfo {
String encoding,
boolean overwrite)
throws MavenFilteringException;
+
+ /**
+ * @param from The source file
+ * @param to The destination file
+ * @param filtering true to apply filtering
+ * @param filterWrappers The filters to be applied.
+ * @param encoding The encoding to use
+ * @param changeDetection The change detection mode to use to determine if
the file should be copied/filtered.
+ * @throws MavenFilteringException In case of an error.
+ * @since 3.5.0
+ */
+ void copyFile(
+ File from,
+ File to,
+ boolean filtering,
+ List<FilterWrapper> filterWrappers,
+ String encoding,
+ ChangeDetection changeDetection)
+ throws MavenFilteringException;
}
diff --git
a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
index 460aeea..8cd052a 100644
---
a/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
+++
b/src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
@@ -86,13 +86,6 @@ public class MavenResourcesExecution extends
AbstractMavenFilteringRequest {
*/
private boolean addDefaultExcludes = true;
- /**
- * Overwrite existing files even if the destination files are newer.
<code>false</code> by default.
- *
- * @since 1.0-beta-2
- */
- private boolean overwrite = false;
-
/**
* Copy any empty directories included in the Resources.
*
@@ -352,11 +345,13 @@ public class MavenResourcesExecution extends
AbstractMavenFilteringRequest {
/**
* Overwrite existing files even if the destination files are newer.
*
- * @return {@link #overwrite}
+ * @return {@code true} if operation always overwrites.
* @since 1.0-beta-2
+ * @deprecated Use #getChangeDetection() instead.
*/
+ @Deprecated
public boolean isOverwrite() {
- return overwrite;
+ return getChangeDetection() == ChangeDetection.ALWAYS;
}
/**
@@ -364,9 +359,11 @@ public class MavenResourcesExecution extends
AbstractMavenFilteringRequest {
*
* @param overwrite overwrite true or false.
* @since 1.0-beta-2
+ * @deprecated Use #setChangeDetection(ChangeDetection) instead.
*/
+ @Deprecated
public void setOverwrite(boolean overwrite) {
- this.overwrite = overwrite;
+ setChangeDetection(overwrite ? ChangeDetection.ALWAYS :
ChangeDetection.CONTENT);
}
/**
@@ -440,7 +437,7 @@ public class MavenResourcesExecution extends
AbstractMavenFilteringRequest {
mre.setMavenSession(this.getMavenSession());
mre.setNonFilteredFileExtensions(copyList(this.getNonFilteredFileExtensions()));
mre.setOutputDirectory(this.getOutputDirectory());
- mre.setOverwrite(this.isOverwrite());
+ mre.setChangeDetection(this.getChangeDetection());
mre.setProjectStartExpressions(copyList(this.getProjectStartExpressions()));
mre.setResources(copyList(this.getResources()));
mre.setResourcesBaseDirectory(this.getResourcesBaseDirectory());