[Git][java-team/maven-filtering][master] 11 commits: Converted debian/watch to the version 5 format
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Mon Oct 26 22:15:16 GMT 2026
Emmanuel Bourg pushed to branch master at Debian Java Maintainers / maven-filtering
Commits:
33aba388 by Emmanuel Bourg at 2026-10-26T00:30:36+01:00
Converted debian/watch to the version 5 format
- - - - -
09149d6c by Emmanuel Bourg at 2026-10-26T00:30:50+01:00
New upstream version 3.5.0
- - - - -
cd5a27a1 by Emmanuel Bourg at 2026-10-26T00:30:51+01:00
New upstream version 3.5.1
- - - - -
3b71f0c3 by Emmanuel Bourg at 2026-10-26T00:30:51+01:00
Update upstream source from tag 'upstream/3.5.1'
Update to upstream version '3.5.1'
with Debian dir 2f7d67f4beacc1eb7797d4ec19e9c78a6b4ba74c
- - - - -
172615af by Emmanuel Bourg at 2026-10-26T00:31:42+01:00
Updated the Maven rules
- - - - -
c448c03e by Emmanuel Bourg at 2026-10-26T00:31:43+01:00
Removed the dependency on libplexus-xml-java
- - - - -
d39e2143 by Emmanuel Bourg at 2026-10-26T00:31:43+01:00
Standards-Version updated to 4.7.4
- - - - -
1d8d6e72 by Emmanuel Bourg at 2026-10-26T00:31:43+01:00
Removed the Priority field
- - - - -
edbf06c7 by Emmanuel Bourg at 2026-10-26T22:54:57+01:00
Removed Torsten Werner from the Uploaders list (Closes: #1139073)
- - - - -
20d27f57 by Emmanuel Bourg at 2026-10-26T22:56:22+01:00
Added myself to Uploaders
- - - - -
c33644de by Emmanuel Bourg at 2026-10-26T23:01:28+01:00
Upload to unstable
- - - - -
29 changed files:
- .github/pull_request_template.md
- .github/workflows/maven-verify.yml
- + .github/workflows/pr-automation.yml
- .github/workflows/release-drafter.yml
- README.md
- debian/changelog
- debian/control
- debian/maven.rules
- debian/watch
- pom.xml
- src/main/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequest.java
- + src/main/java/org/apache/maven/shared/filtering/ChangeDetection.java
- src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java
- src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
- src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java
- src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java
- src/main/java/org/apache/maven/shared/filtering/MavenResourcesExecution.java
- src/site/site.xml
- src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java
- src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java
- src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java
- src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
- src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java
- src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java
- + src/test/java/org/apache/maven/shared/filtering/OverlappingResourcesFilteringTest.java
- src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
- + src/test/units-files/MRP-471/config/filtered.xml
- + src/test/units-files/MRP-471/static/keep-as-is.txt
- src/test/units-files/maven-filename-filtering/${pom.version}.txt → src/test/units-files/maven-filename-filtering/subfolder/${pom.version}.txt
Changes:
=====================================
.github/pull_request_template.md
=====================================
@@ -1,28 +1,23 @@
-Following this checklist to help us incorporate your
+Following this checklist to help us incorporate your
contribution quickly and easily:
- - [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/MSHARED) filed
- for the change (usually before you start working on it). Trivial changes like typos do not
- require a JIRA issue. Your pull request should address just this issue, without
- pulling in other changes.
- - [ ] Each commit in the pull request should have a meaningful subject line and body.
- - [ ] Format the pull request title like `[MSHARED-XXX] - Fixes bug in ApproximateQuantiles`,
- where you replace `MSHARED-XXX` with the appropriate JIRA issue. Best practice
- is to use the JIRA issue title in the pull request title and in the first line of the
- commit message.
- - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- - [ ] Run `mvn clean verify -Prun-its` to make sure basic checks pass. A more thorough check will
- be performed on your pull request automatically.
+- [ ] Your pull request should address just one issue, without pulling in other changes.
+- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
+- [ ] Each commit in the pull request should have a meaningful subject line and body.
+ Note that commits might be squashed by a maintainer on merge.
+- [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
+ This may not always be possible but is a best-practice.
+- [ ] Run `mvn verify` to make sure basic checks pass.
+ A more thorough check will be performed on your pull request automatically.
+- [ ] You have run the integration tests successfully (`mvn -Prun-its verify`).
If your pull request is about ~20 lines of code you don't need to sign an
[Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
please ask on the developers list.
-To make clear that you license your contribution under
+To make clear that you license your contribution under
the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
you have to acknowledge this by using the following check-box.
- - [ ] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
-
- - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
-
+- [ ] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
+- [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
=====================================
.github/workflows/maven-verify.yml
=====================================
@@ -25,3 +25,7 @@ jobs:
build:
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml at v4
+ with:
+ maven4-enabled: true
+ ff-goal: verify
+ verify-goal: verify
\ No newline at end of file
=====================================
.github/workflows/pr-automation.yml
=====================================
@@ -0,0 +1,27 @@
+# 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.
+
+name: PR Automation
+on:
+ pull_request_target:
+ types:
+ - closed
+
+jobs:
+ pr-automation:
+ name: PR Automation
+ uses: apache/maven-gh-actions-shared/.github/workflows/pr-automation.yml at v4
=====================================
.github/workflows/release-drafter.yml
=====================================
@@ -19,11 +19,11 @@ name: Release Drafter
on:
push:
branches:
- - master
+ - maven-filtering-3.x
+ workflow_dispatch:
+
jobs:
update_release_draft:
- runs-on: ubuntu-latest
- steps:
- - uses: release-drafter/release-drafter at v6
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml at v4
+ with:
+ config-name: 'release-drafter-3.x.yml'
=====================================
README.md
=====================================
@@ -17,15 +17,20 @@
Contributing to [Apache Maven Filtering](https://maven.apache.org/shared/maven-filtering/)
======================
-[][jira]
[][license]
+[](https://search.maven.org/artifact/org.apache.maven.shared/maven-filtering)
+[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-filtering/README.md)
+[][build-3]
+[][test-results-3]
+
+Maven 4: [master](https://github.com/apache/maven-filtering/tree/master)
[](https://search.maven.org/artifact/org.apache.maven.shared/maven-filtering)
-[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-filtering/README.md)
+[](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-filtering/README.md)
[][build]
[][test-results]
-You have found a bug or you have an idea for a cool new feature? Contributing
+You have found a bug, or you have an idea for a cool new feature? Contributing
code is a great way to give something back to the open source community. Before
you dig right into the code, there are a few guidelines that we need
contributors to follow so that we can have a chance of keeping on top of
@@ -34,7 +39,6 @@ things.
Getting Started
---------------
-+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
+ Make sure you have a [GitHub account](https://github.com/signup/free).
+ If you're planning to implement a new feature, it makes sense to discuss your changes
on the [dev list][ml-list] first.
@@ -60,41 +64,29 @@ There are some guidelines which will make applying PRs easier for us:
+ Create minimal diffs - disable on save actions like reformat source code or organize imports.
If you feel the source code should be reformatted, create a separate PR for this change.
+ Check for unnecessary whitespace with `git diff --check` before committing.
-+ Make sure your commit messages are in the proper format. Your commit message should contain the key of the JIRA issue.
-```
-[MSHARED-XXX] - Subject of the JIRA Ticket
- Optional supplemental description.
-```
+ Make sure you have added the necessary tests (JUnit/IT) for your changes.
+ Run all the tests with `mvn -Prun-its verify` to assure nothing else was accidentally broken.
+ Submit a pull request to the repository in the Apache organization.
-+ Update your JIRA ticket and include a link to the pull request in the ticket.
If you plan to contribute on a regular basis, please consider filing a [contributor license agreement][cla].
-Making Trivial Changes
-----------------------
-
-For changes of a trivial nature to comments and documentation, it is not always
-necessary to create a new ticket in JIRA. In this case, it is appropriate to
-start the first line of a commit with '(doc)' instead of a ticket number.
-
Additional Resources
--------------------
+ [Contributing patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch)
-+ [Apache Maven Shared Components project page][jira]
+ [Contributor License Agreement][cla]
+ [General GitHub documentation](https://help.github.com/)
+ [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
-+ [Apache Maven Twitter Account](https://twitter.com/ASFMavenProject)
-+ #Maven IRC channel on freenode.org
++ [Apache Maven X Account](https://x.com/ASFMavenProject)
++ [Apache Maven Bluesky Account](https://bsky.app/profile/maven.apache.org)
++ [Apache Maven Mastodon Account](https://mastodon.social/deck/@ASFMavenProject@fosstodon.org)
-[jira]: https://issues.apache.org/jira/projects/MSHARED/
[license]: https://www.apache.org/licenses/LICENSE-2.0
[ml-list]: https://maven.apache.org/mailing-lists.html
[code-style]: https://maven.apache.org/developers/conventions/code.html
[cla]: https://www.apache.org/licenses/#clas
[maven-wiki]: https://cwiki.apache.org/confluence/display/MAVEN/Index
[test-results]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/job/master/lastCompletedBuild/testReport/
+[test-results-3]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/job/maven-filtering-3.x/lastCompletedBuild/testReport/
[build]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/job/master/
+[build-3]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/job/maven-filtering-3.x/
=====================================
debian/changelog
=====================================
@@ -1,3 +1,16 @@
+maven-filtering (3.5.1-1) unstable; urgency=medium
+
+ * New upstream release
+ - Updated the Maven rules
+ - Removed the dependency on libplexus-xml-java
+ * Standards-Version updated to 4.7.4
+ * Removed the Priority field
+ * Removed Torsten Werner from the Uploaders list (Closes: #1139073)
+ * Added myself to Uploaders
+ * Converted debian/watch to the version 5 format
+
+ -- Emmanuel Bourg <ebourg at apache.org> Mon, 26 Oct 2026 23:01:28 +0100
+
maven-filtering (3.4.0-1) unstable; urgency=medium
* Team upload.
=====================================
debian/control
=====================================
@@ -1,9 +1,7 @@
Source: maven-filtering
Section: java
-Priority: optional
Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.org>
-Uploaders:
- Torsten Werner <twerner at debian.org>
+Uploaders: Emmanuel Bourg <ebourg at apache.org>
Build-Depends:
debhelper-compat (= 13),
default-jdk,
@@ -17,9 +15,8 @@ Build-Depends:
libplexus-build-api-java,
libplexus-interpolation-java (>= 1.12),
libplexus-utils-java (>= 1.5.15),
- libplexus-xml-java,
maven-debian-helper (>= 2.2~)
-Standards-Version: 4.7.0
+Standards-Version: 4.7.4
Vcs-Git: https://salsa.debian.org/java-team/maven-filtering.git
Vcs-Browser: https://salsa.debian.org/java-team/maven-filtering
Homepage: http://maven.apache.org/shared/maven-filtering/
=====================================
debian/maven.rules
=====================================
@@ -3,3 +3,4 @@ org.apache.maven maven-core * s/.*/3.x/ * *
org.apache.maven maven-model * s/.*/3.x/ * *
org.apache.maven maven-settings * s/.*/3.x/ * *
org.apache.maven.shared maven-shared-components pom s/.*/debian/ * *
+s/org.codehaus.plexus/org.sonatype.plexus/ plexus-build-api * s/.*/debian/ * *
=====================================
debian/watch
=====================================
@@ -1,2 +1,5 @@
-version=4
-https://github.com/apache/maven-filtering/tags .*/maven-filtering-([\d\.]+).tar.gz
+Version: 5
+Mode: git
+Source: https://github.com/apache/maven-filtering.git
+Matching-Pattern: refs/tags/maven-filtering-([\d.]+)
+Compression: xz
=====================================
pom.xml
=====================================
@@ -23,12 +23,12 @@
<parent>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-components</artifactId>
- <version>43</version>
+ <version>49</version>
<relativePath />
</parent>
<artifactId>maven-filtering</artifactId>
- <version>3.4.0</version>
+ <version>3.5.1</version>
<name>Apache Maven Filtering</name>
<description>A component to assist in filtering of resource files with properties from a Maven project.</description>
@@ -42,12 +42,12 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-filtering.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-filtering.git</developerConnection>
- <tag>maven-filtering-3.4.0</tag>
+ <tag>maven-filtering-3.5.1</tag>
<url>https://github.com/apache/maven-filtering/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
- <system>JIRA</system>
- <url>https://issues.apache.org/jira/issues/?jql=project%20%3D%20MSHARED%20AND%20component%20%3D%20maven-filtering</url>
+ <system>GitHub Issues</system>
+ <url>https://github.com/apache/maven-filtering/issues</url>
</issueManagement>
<ciManagement>
<system>Jenkins</system>
@@ -61,30 +61,41 @@
</distributionManagement>
<properties>
- <mavenVersion>3.6.3</mavenVersion>
+ <mavenVersion>3.9.16</mavenVersion>
<slf4jVersion>1.7.36</slf4jVersion>
- <plexusBuildApiVersion>0.0.7</plexusBuildApiVersion>
- <project.build.outputTimestamp>2024-08-28T15:27:34Z</project.build.outputTimestamp>
+ <version.plexus-utils>3.6.1</version.plexus-utils>
+ <project.build.outputTimestamp>2026-06-30T14:34:01Z</project.build.outputTimestamp>
<!-- don't fail check for some rules that are too hard to enforce (could even be told broken for some)
and those that are enforced by the formatting checks from spotless -->
<checkstyle.violation.ignore>ParameterNumber,MethodLength,FileLength</checkstyle.violation.ignore>
</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>
@@ -104,29 +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-xml</artifactId>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-interpolation</artifactId>
- <version>1.27</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.16.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.16.0</version>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -137,13 +125,13 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-testing</artifactId>
- <version>1.3.0</version>
+ <version>2.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
- <version>2.2</version>
+ <version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -167,7 +155,12 @@
<artifactId>org.eclipse.sisu.inject</artifactId>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.22.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
=====================================
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);
+ }
}
=====================================
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;
+}
=====================================
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);
- }
}
=====================================
src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java
=====================================
@@ -27,19 +27,23 @@ import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
+import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
-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 +97,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);
}
@@ -142,6 +146,13 @@ public class DefaultMavenResourcesFiltering implements MavenResourcesFiltering {
boolean isFilteringUsed = false;
List<File> propertiesFiles = new ArrayList<>();
+ // Destinations already written by a previous <resource> entry in this call.
+ // Used to preserve "first <resource> entry wins" semantics for overlapping
+ // declarations — the behaviour 3.3.1 produced as a side effect of the
+ // timestamp-based overwrite gate in FilteringUtils.copyFile, lost in
+ // MSHARED-1216 / GH-333.
+ Set<Path> alreadyCopied = new HashSet<>();
+
for (Resource resource : mavenResourcesExecution.getResources()) {
if (LOGGER.isDebugEnabled()) {
@@ -279,8 +290,22 @@ public class DefaultMavenResourcesFiltering implements MavenResourcesFiltering {
File destinationFile = getDestinationFile(outputDirectory, targetPath, name, mavenResourcesExecution);
+ // Track destinations already written by a previous <resource> entry so we
+ // can preserve "first <resource> entry wins" semantics for overlapping
+ // declarations. The flatten case has its own collision policy below
+ // (warn-or-throw based on overwrite), so we deliberately do not suppress
+ // it here.
+ Path destinationPath = destinationFile.getAbsoluteFile().toPath();
+ boolean firstOccurrence = alreadyCopied.add(destinationPath);
+ if (!firstOccurrence
+ && !mavenResourcesExecution.isFlatten()
+ && mavenResourcesExecution.getChangeDetection() != ChangeDetection.ALWAYS) {
+ LOGGER.debug("skipping {} — destination already written by a previous <resource> entry", name);
+ continue;
+ }
+
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 +328,7 @@ public class DefaultMavenResourcesFiltering implements MavenResourcesFiltering {
resource.isFiltering() && filteredExt,
mavenResourcesExecution.getFilterWrappers(),
encoding,
- mavenResourcesExecution.isOverwrite());
+ mavenResourcesExecution.getChangeDetection());
}
// deal with deleted source files
@@ -501,21 +526,33 @@ public class DefaultMavenResourcesFiltering implements MavenResourcesFiltering {
*/
private String filterFileName(String name, List<FilterWrapper> wrappers) throws MavenFilteringException {
- Reader reader = new StringReader(name);
- for (FilterWrapper wrapper : wrappers) {
- reader = wrapper.getReader(reader);
- }
+ StringBuilder sb = new StringBuilder();
+ Path path = Paths.get(name);
+ Iterator<Path> iterator = path.iterator();
+ while (iterator.hasNext()) {
+ String component = iterator.next().toString();
+ Reader reader = new StringReader(component);
+ for (FilterWrapper wrapper : wrappers) {
+ reader = wrapper.getReader(reader);
+ }
- try (StringWriter writer = new StringWriter()) {
- IOUtils.copy(reader, writer);
- String filteredFilename = writer.toString();
+ try (StringWriter writer = new StringWriter()) {
+ IOUtil.copy(reader, writer);
+ String filteredComponent = writer.toString();
+ sb.append(filteredComponent);
+ if (iterator.hasNext()) {
+ sb.append(FileSystems.getDefault().getSeparator());
+ }
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("renaming filename " + name + " to " + filteredFilename);
+ } catch (IOException e) {
+ throw new MavenFilteringException("Failed filtering filename" + name, e);
}
- return filteredFilename;
- } catch (IOException e) {
- throw new MavenFilteringException("Failed filtering filename" + name, e);
}
+ String filteredFilename = sb.toString();
+
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("renaming filename " + name + " to " + filteredFilename);
+ }
+ return filteredFilename;
}
}
=====================================
src/main/java/org/apache/maven/shared/filtering/FilteringUtils.java
=====================================
@@ -24,6 +24,8 @@ import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
+import java.nio.charset.MalformedInputException;
+import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.attribute.PosixFilePermission;
@@ -31,7 +33,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;
@@ -40,6 +41,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.
*/
@@ -114,7 +121,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 {
@@ -305,12 +312,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 {
@@ -320,17 +382,51 @@ 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) {
writer.write(buffer, 0, nRead);
}
}
+ } catch (MalformedInputException e) {
+ throw new IOException(e.getMessage() + " - using encoding " + charset.name(), e);
}
}
+ 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();
+ }
+ } catch (MalformedInputException e) {
+ throw new IOException(e.getMessage() + " - using encoding " + charset.name(), e);
+ }
+ }
copyFilePermissions(from, to);
+ return copied;
}
/**
@@ -343,12 +439,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);
}
/**
@@ -367,7 +463,7 @@ public final class FilteringUtils {
Files.setPosixFilePermissions(destination.toPath(), Files.getPosixFilePermissions(source.toPath()));
} catch (NoSuchFileException nsfe) {
// ignore if destination file or symlink does not exist
- } catch (UnsupportedOperationException e) {
+ } catch (UnsupportedOperationException | FileSystemException e) {
// fallback to setting partial permissions
destination.setExecutable(source.canExecute());
destination.setReadable(source.canRead());
=====================================
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;
}
=====================================
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());
=====================================
src/site/site.xml
=====================================
@@ -19,7 +19,8 @@ specific language governing permissions and limitations
under the License.
-->
-<project xmlns="http://maven.apache.org/DECORATION/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd">
+<site xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
<body>
<menu name="Overview">
<item name="Introduction" href="index.html"/>
@@ -32,4 +33,4 @@ under the License.
<item name="Download" href="download.html"/>
</menu>
</body>
-</project>
+</site>
=====================================
src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java
=====================================
@@ -18,7 +18,6 @@
*/
package org.apache.maven.shared.filtering;
-import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
@@ -96,26 +95,26 @@ public abstract class AbstractInterpolatorFilterReaderLineEndingTest {
.thenReturn("DONE");
Reader in = new StringReader("aaaFILTER.a.MEaaa");
- Reader reader = getAaa_AaaReader(in, interpolator);
+ Reader reader = getAaaAaaReader(in, interpolator);
assertEquals("DONE", IOUtils.toString(reader));
in = new StringReader("abcFILTER.a.MEabc");
- reader = getAbc_AbcReader(in, interpolator);
+ reader = getAbcAbcReader(in, interpolator);
assertEquals("DONE", IOUtils.toString(reader));
}
// MSHARED-235: reader exceeds readAheadLimit
@Test
- void markInvalid() throws IOException {
+ void markInvalid() throws Exception {
try (Reader reader = getAtReader(new StringReader("@\").replace(p,\"]\").replace(q,\""), interpolator, "\\")) {
assertEquals("@\").replace(p,\"]\").replace(q,\"", IOUtils.toString(reader));
}
}
- protected abstract Reader getAbc_AbcReader(Reader in, Interpolator interpolator);
+ protected abstract Reader getAbcAbcReader(Reader in, Interpolator interpolator);
- protected abstract Reader getAaa_AaaReader(Reader in, Interpolator interpolator);
+ protected abstract Reader getAaaAaaReader(Reader in, Interpolator interpolator);
protected abstract Reader getDollarBracesReader(Reader in, Interpolator interpolator, String escapeString);
=====================================
src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java
=====================================
@@ -19,7 +19,6 @@
package org.apache.maven.shared.filtering;
import java.io.BufferedReader;
-import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
@@ -32,7 +31,7 @@ class BoundedReaderTest {
private final Reader sr = new BufferedReader(new StringReader("01234567890"));
@Test
- void readTillEnd() throws IOException {
+ void readTillEnd() throws Exception {
try (BoundedReader mr = new BoundedReader(sr, 3)) {
mr.mark(3);
mr.read();
@@ -43,7 +42,7 @@ class BoundedReaderTest {
}
@Test
- void readMulti() throws IOException {
+ void readMulti() throws Exception {
char[] cbuf = new char[4];
for (int i = 0; i < cbuf.length; i++) {
cbuf[i] = 'X';
@@ -61,7 +60,7 @@ class BoundedReaderTest {
}
@Test
- void readMultiWithOffset() throws IOException {
+ void readMultiWithOffset() throws Exception {
char[] cbuf = new char[4];
for (int i = 0; i < cbuf.length; i++) {
@@ -80,7 +79,7 @@ class BoundedReaderTest {
}
@Test
- void resetWorks() throws IOException {
+ void resetWorks() throws Exception {
try (BoundedReader mr = new BoundedReader(sr, 3)) {
mr.read();
mr.read();
@@ -94,7 +93,7 @@ class BoundedReaderTest {
}
@Test
- void skipTest() throws IOException {
+ void skipTest() throws Exception {
try (BoundedReader mr = new BoundedReader(sr, 3)) {
mr.skip(2);
mr.read();
=====================================
src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java
=====================================
@@ -21,7 +21,6 @@ package org.apache.maven.shared.filtering;
import javax.inject.Inject;
import java.io.File;
-import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.nio.file.Files;
@@ -158,7 +157,7 @@ class DefaultMavenFileFilterTest {
}
@Test
- void testInterpolatorCustomizer() throws MavenFilteringException, IOException {
+ void interpolatorCustomizer() throws Exception {
AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest();
req.setInterpolatorCustomizer(i -> {
i.addValueSource(new AbstractValueSource(false) {
=====================================
src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java
=====================================
@@ -23,6 +23,7 @@ import javax.inject.Inject;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
@@ -991,7 +992,7 @@ class DefaultMavenResourcesFilteringTest {
Resource resource = new Resource();
resource.setDirectory(unitFilesDir);
resource.setFiltering(true);
- resource.addInclude("${pom.version}*");
+ resource.addInclude("**/${pom.version}*");
resource.setTargetPath("testTargetPath");
MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
@@ -1009,6 +1010,49 @@ class DefaultMavenResourcesFilteringTest {
File[] files = targetPathFile.listFiles();
assertEquals(1, files.length);
+ assertEquals("subfolder", files[0].getName());
+ assertTrue(files[0].isDirectory());
+
+ files = files[0].listFiles();
+ assertEquals(1, files.length);
+ assertEquals("1.0.txt", files[0].getName());
+ }
+
+ @Test
+ void filterFileNameWithFileSeparatorAsEscape() throws Exception {
+
+ String unitFilesDir = getBasedir() + "/src/test/units-files/maven-filename-filtering";
+
+ Resource resource = new Resource();
+ resource.setDirectory(unitFilesDir);
+ resource.setFiltering(true);
+ resource.addInclude("**/${pom.version}*");
+ resource.setTargetPath("testTargetPath");
+
+ MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
+ Collections.singletonList(resource),
+ outputDirectory,
+ mavenProject,
+ "UTF-8",
+ Collections.<String>emptyList(),
+ Collections.<String>emptyList(),
+ new StubMavenSession());
+ mavenResourcesExecution.setFilterFilenames(true);
+
+ // more likely to occur on windows, where the file
+ // separator is the same as the common escape string "\"
+ mavenResourcesExecution.setEscapeString(FileSystems.getDefault().getSeparator());
+ mavenResourcesFiltering.filterResources(mavenResourcesExecution);
+
+ File targetPathFile = new File(outputDirectory, "testTargetPath");
+
+ File[] files = targetPathFile.listFiles();
+ assertEquals(1, files.length);
+ assertEquals("subfolder", files[0].getName());
+ assertTrue(files[0].isDirectory());
+
+ files = files[0].listFiles();
+ assertEquals(1, files.length);
assertEquals("1.0.txt", files[0].getName());
}
@@ -1068,4 +1112,50 @@ class DefaultMavenResourcesFilteringTest {
assertFalse(DefaultMavenResourcesFiltering.isPropertiesFile(new File("file.xml")));
assertFalse(DefaultMavenResourcesFiltering.isPropertiesFile(new File("some/parent/path", "file.xml")));
}
+
+ /**
+ * Regression guard for the maven-resources-plugin issue 471 / GH-333 scenario: when the same
+ * destination is reached by a later <resource> entry while overwrite is explicitly enabled,
+ * the later entry must still be allowed to replace the earlier one — the "first entry wins"
+ * skip introduced for the default case must not apply here.
+ */
+ @Test
+ void overlappingEntriesWithExplicitOverwriteStillReplace() throws Exception {
+ Properties projectProperties = new Properties();
+ projectProperties.put("repro.value", "REPLACED_BY_FILTERING");
+ mavenProject.setProperties(projectProperties);
+
+ String unitFilesDir = getBasedir() + "/src/test/units-files/MRP-471";
+
+ Resource filtered = new Resource();
+ filtered.setDirectory(unitFilesDir);
+ filtered.setFiltering(true);
+ filtered.addInclude("config/filtered.xml");
+
+ Resource unfiltered = new Resource();
+ unfiltered.setDirectory(unitFilesDir);
+ unfiltered.setFiltering(false);
+ unfiltered.addInclude("**");
+
+ MavenResourcesExecution execution = new MavenResourcesExecution(
+ Arrays.asList(filtered, unfiltered),
+ outputDirectory,
+ mavenProject,
+ "UTF-8",
+ Collections.emptyList(),
+ Collections.emptyList(),
+ new StubMavenSession());
+ execution.setUseDefaultFilterWrappers(true);
+ execution.setOverwrite(true);
+
+ mavenResourcesFiltering.filterResources(execution);
+
+ File filteredOut = new File(outputDirectory, "config/filtered.xml");
+ String content = new String(java.nio.file.Files.readAllBytes(filteredOut.toPath()), "UTF-8");
+ // With overwrite=true the unfiltered second pass still wins — preserve the historical
+ // 3.3.1 behaviour for callers that opt in to ChangeDetection.ALWAYS.
+ assertTrue(
+ content.contains("${repro.value}"),
+ "with overwrite=true the second <resource> entry must still clobber; got:\n" + content);
+ }
}
=====================================
src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java
=====================================
@@ -24,12 +24,12 @@ import org.codehaus.plexus.interpolation.Interpolator;
public class InterpolatorFilterReaderLineEndingTest extends AbstractInterpolatorFilterReaderLineEndingTest {
@Override
- protected Reader getAaa_AaaReader(Reader in, Interpolator interpolator) {
+ protected Reader getAaaAaaReader(Reader in, Interpolator interpolator) {
return new InterpolatorFilterReaderLineEnding(in, interpolator, "aaa", "aaa", true);
}
@Override
- protected Reader getAbc_AbcReader(Reader in, Interpolator interpolator) {
+ protected Reader getAbcAbcReader(Reader in, Interpolator interpolator) {
return new InterpolatorFilterReaderLineEnding(in, interpolator, "abc", "abc", true);
}
=====================================
src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java
=====================================
@@ -49,7 +49,7 @@ class MultiDelimiterInterpolatorFilterReaderLineEndingTest extends AbstractInter
}
@Override
- protected Reader getAaa_AaaReader(Reader in, Interpolator interpolator) {
+ protected Reader getAaaAaaReader(Reader in, Interpolator interpolator) {
MultiDelimiterInterpolatorFilterReaderLineEnding reader =
new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
reader.setDelimiterSpecs(Collections.singleton("aaa*aaa"));
@@ -57,7 +57,7 @@ class MultiDelimiterInterpolatorFilterReaderLineEndingTest extends AbstractInter
}
@Override
- protected Reader getAbc_AbcReader(Reader in, Interpolator interpolator) {
+ protected Reader getAbcAbcReader(Reader in, Interpolator interpolator) {
MultiDelimiterInterpolatorFilterReaderLineEnding reader =
new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
reader.setDelimiterSpecs(Collections.singleton("abc*abc"));
=====================================
src/test/java/org/apache/maven/shared/filtering/OverlappingResourcesFilteringTest.java
=====================================
@@ -0,0 +1,148 @@
+/*
+ * 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;
+
+import javax.inject.Inject;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.model.Resource;
+import org.codehaus.plexus.testing.PlexusTest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Reproduces the regression first reported against
+ * <a href="https://github.com/apache/maven-resources-plugin/issues/471">
+ * maven-resources-plugin issue #471</a>.
+ *
+ * <p>When a single source directory is covered by two {@link Resource} entries — one with
+ * {@code filtering=true} and a narrow {@code <include>}, the other with {@code filtering=false}
+ * and a broad {@code <include>**</include>} — the file selected by the first entry must still be
+ * filtered. From {@code maven-filtering 3.3.2} onwards (pulled in by
+ * {@code maven-resources-plugin 3.4.0}), the placeholder is left as the literal {@code ${...}}
+ * text instead of being replaced.</p>
+ *
+ * <p>The {@code static/keep-as-is.txt} file, only matched by the second (unfiltered) entry, is
+ * expected to keep its placeholder verbatim — the test asserts both halves so a future fix
+ * cannot trivially "always filter everything".</p>
+ */
+ at PlexusTest
+class OverlappingResourcesFilteringTest {
+
+ private final File outputDirectory = new File(getBasedir(), "target/OverlappingResourcesFilteringTest");
+ private final File baseDir = new File(getBasedir());
+ private final StubMavenProject mavenProject = new StubMavenProject(baseDir);
+
+ @Inject
+ private MavenResourcesFiltering mavenResourcesFiltering;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ if (outputDirectory.exists()) {
+ FileUtils.deleteDirectory(outputDirectory);
+ }
+ outputDirectory.mkdirs();
+
+ mavenProject.setVersion("1.0");
+ mavenProject.setGroupId("org.apache");
+ mavenProject.setName("MRP-471 repro");
+ }
+
+ @Test
+ void overlappingResourceEntriesShouldStillFilter() throws Exception {
+ Properties projectProperties = new Properties();
+ projectProperties.put("repro.value", "REPLACED_BY_FILTERING");
+ mavenProject.setProperties(projectProperties);
+
+ String unitFilesDir = getBasedir() + "/src/test/units-files/MRP-471";
+
+ // Mirrors the failing POM configuration:
+ // <resource>
+ // <filtering>true</filtering>
+ // <directory>src/main/resources</directory>
+ // <includes><include>config/filtered.xml</include></includes>
+ // </resource>
+ // <resource>
+ // <filtering>false</filtering>
+ // <directory>src/main/resources</directory>
+ // <includes><include>**</include></includes>
+ // </resource>
+ Resource filtered = new Resource();
+ filtered.setDirectory(unitFilesDir);
+ filtered.setFiltering(true);
+ filtered.addInclude("config/filtered.xml");
+
+ Resource unfiltered = new Resource();
+ unfiltered.setDirectory(unitFilesDir);
+ unfiltered.setFiltering(false);
+ unfiltered.addInclude("**");
+
+ List<Resource> resources = Arrays.asList(filtered, unfiltered);
+
+ MavenResourcesExecution execution = new MavenResourcesExecution(
+ resources,
+ outputDirectory,
+ mavenProject,
+ "UTF-8",
+ Collections.emptyList(),
+ Collections.emptyList(),
+ new StubMavenSession());
+ execution.setUseDefaultFilterWrappers(true);
+
+ mavenResourcesFiltering.filterResources(execution);
+
+ File filteredOut = new File(outputDirectory, "config/filtered.xml");
+ File unfilteredOut = new File(outputDirectory, "static/keep-as-is.txt");
+ assertTrue(filteredOut.isFile(), "expected " + filteredOut + " to be copied");
+ assertTrue(unfilteredOut.isFile(), "expected " + unfilteredOut + " to be copied");
+
+ String filteredContent = new String(Files.readAllBytes(filteredOut.toPath()), StandardCharsets.UTF_8);
+ String unfilteredContent = new String(Files.readAllBytes(unfilteredOut.toPath()), StandardCharsets.UTF_8);
+
+ // The placeholder targeted by the filtered <resource> entry must be replaced.
+ // Regression on maven-filtering >= 3.3.2: the literal ${repro.value} is left in place.
+ assertTrue(
+ filteredContent.contains("REPLACED_BY_FILTERING"),
+ "config/filtered.xml should have ${repro.value} replaced; got:\n" + filteredContent);
+ assertFalse(
+ filteredContent.contains("${repro.value}"),
+ "config/filtered.xml still contains the literal placeholder — see "
+ + "https://github.com/apache/maven-resources-plugin/issues/471\n"
+ + filteredContent);
+
+ // The second (unfiltered) entry must leave files matched only by it untouched —
+ // this guards against a fix that just turns filtering on for everything.
+ assertTrue(
+ unfilteredContent.contains("${repro.value}"),
+ "static/keep-as-is.txt is matched by filtering=false and must keep the literal " + "placeholder; got:\n"
+ + unfilteredContent);
+ }
+}
=====================================
src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java
=====================================
@@ -29,7 +29,9 @@ import java.util.Properties;
import org.junit.jupiter.api.Test;
import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Olivier Lamy
@@ -102,7 +104,7 @@ class PropertyUtilsTest {
* @throws IOException if problem writing file
*/
@Test
- void circularReferences() throws IOException {
+ void circularReferences() throws Exception {
File circularProperties = File.createTempFile("circular", ".properties");
circularProperties.deleteOnExit();
@@ -123,7 +125,7 @@ class PropertyUtilsTest {
* @throws IOException if problem writing file
*/
@Test
- void circularReferences3Vars() throws IOException {
+ void circularReferences3Vars() throws Exception {
File circularProperties = File.createTempFile("circular", ".properties");
circularProperties.deleteOnExit();
=====================================
src/test/units-files/MRP-471/config/filtered.xml
=====================================
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+ <property name="value">${repro.value}</property>
+</config>
=====================================
src/test/units-files/MRP-471/static/keep-as-is.txt
=====================================
@@ -0,0 +1 @@
+Not filtered. Placeholder must stay verbatim: ${repro.value}
=====================================
src/test/units-files/maven-filename-filtering/${pom.version}.txt → src/test/units-files/maven-filename-filtering/subfolder/${pom.version}.txt
=====================================
View it on GitLab: https://salsa.debian.org/java-team/maven-filtering/-/compare/cf403768e35469de266ecd42be9d70a16e70a89d...c33644de310e9cf0533a95441600dc20a21e0b9c
--
View it on GitLab: https://salsa.debian.org/java-team/maven-filtering/-/compare/cf403768e35469de266ecd42be9d70a16e70a89d...c33644de310e9cf0533a95441600dc20a21e0b9c
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20261026/13c7622b/attachment.htm>
More information about the pkg-java-commits
mailing list