Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,32 @@ under the License.
</distributionManagement>

<properties>
<mavenFilteringVersion>3.4.0</mavenFilteringVersion>
<mavenFilteringVersion>3.4.1-SNAPSHOT</mavenFilteringVersion>
<mavenVersion>3.9.12</mavenVersion>
<javaVersion>8</javaVersion>
<project.build.outputTimestamp>2025-11-22T21:31:20Z</project.build.outputTimestamp>
<version.plexus-utils>3.6.0</version.plexus-utils>

<version.maven-invoker-plugin>3.9.1</version.maven-invoker-plugin>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>${mavenFilteringVersion}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand All @@ -104,27 +121,7 @@ under the License.
<version>${version.maven-plugin-tools}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>${mavenFilteringVersion}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.20.0</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
Expand All @@ -142,11 +139,6 @@ under the License.
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
Expand All @@ -39,9 +38,11 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.filtering.ChangeDetection;
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.apache.maven.shared.filtering.MavenResourcesExecution;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;
import org.codehaus.plexus.util.StringUtils;

/**
* Copy resources for the main source code to the main output directory. Always uses the project.build.resources element
Expand Down Expand Up @@ -156,10 +157,32 @@ public class ResourcesMojo extends AbstractMojo {
* Overwrite existing files even if the destination files are newer.
*
* @since 2.3
* @deprecated Use {@link #changeDetection} instead.
*/
@Deprecated
@Parameter(defaultValue = "false")
private boolean overwrite;

/**
* The strategy to use for change detection. Supported values are listed below. If this parameter is configured,
* it will override the value of {@link #overwrite}.
*
* Strategies and their behavior are as follows:
* <ul>
* <li><strong>content</strong>: This is the default strategy since version 3.4.0. Overwrites existing target file only if content differs.</li>
* <li><strong>timestamp</strong>: This was the default strategy before version 3.4.0. Overwrites existing target file only if target timestamp is older than source timestamp.</li>
* <li><strong>timestamp+content</strong>: Combines the two strategies above; if timestamp is older and if content differs, existing target file will be overwritten.</li>
* <li><strong>always</strong>: Always overwrites existing target file. Equivalent of {@code overwrite=true}.</li>
* <li><strong>never</strong>: Never overwrites existing target file.</li>
* </ul>
*
* Note: default value of this parameter is handled programmatically (as "content") for programmatic detection reasons.
*
* @since 3.5.0
*/
@Parameter
private String changeDetection;

/**
* Copy any empty directories included in the Resources.
*
Expand Down Expand Up @@ -323,7 +346,7 @@ public void execute() throws MojoExecutionException {
mavenResourcesExecution.setInjectProjectBuildFilters(false);

mavenResourcesExecution.setEscapeString(escapeString);
mavenResourcesExecution.setOverwrite(overwrite);
mavenResourcesExecution.setChangeDetection(getChangeDetection());
mavenResourcesExecution.setIncludeEmptyDirs(includeEmptyDirs);
mavenResourcesExecution.setSupportMultiLineFiltering(supportMultiLineFiltering);
mavenResourcesExecution.setFilterFilenames(fileNameFiltering);
Expand All @@ -350,6 +373,29 @@ public void execute() throws MojoExecutionException {
}
}

private ChangeDetection getChangeDetection() {
if (changeDetection != null) {
switch (changeDetection) {
case "content":
return ChangeDetection.CONTENT;
case "timestamp":
return ChangeDetection.TIMESTAMP;
case "timestamp+content":
return ChangeDetection.TIMESTAMP_AND_CONTENT;
case "always":
return ChangeDetection.ALWAYS;
case "never":
return ChangeDetection.NEVER;
default:
throw new IllegalArgumentException("Invalid value for changeDetection: " + changeDetection);
}
} else if (overwrite) {
return ChangeDetection.ALWAYS;
} else {
return ChangeDetection.CONTENT;
}
}

/**
* This solves https://issues.apache.org/jira/browse/MRESOURCES-99.<br/>
* BUT:<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -31,8 +33,6 @@
import org.apache.maven.shared.filtering.MavenResourcesExecution;
import org.apache.maven.shared.filtering.MavenResourcesFiltering;

import static org.apache.commons.io.FileUtils.writeLines;

/**
* @author Olivier Lamy
* @since 2.5
Expand Down Expand Up @@ -73,7 +73,9 @@ public void filterResources(MavenResourcesExecution mavenResourcesExecution) thr
.getMavenSession()
.getSystemProperties()
.getProperty("toto"));
writeLines(f, lines);
Path target = f.toPath();
Files.createDirectories(target.getParent());
Files.write(target, lines);
} catch (IOException e) {
throw new MavenFilteringException(e.getMessage(), e);
}
Expand Down
Loading