├── .asf.yaml
├── .git-blame-ignore-revs
├── .github
├── ISSUE_TEMPLATE
│ ├── BUG.yml
│ ├── FEATURE.yml
│ └── config.yml
├── dependabot.yml
├── pull_request_template.md
├── release-drafter-3.x.yml
├── release-drafter.yml
└── workflows
│ ├── maven-verify.yml
│ ├── pr-automation.yml
│ ├── release-drafter.yml
│ └── stale.yml
├── .gitignore
├── Jenkinsfile
├── LICENSE
├── NOTICE
├── README.md
├── deploySite.sh
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── apache
│ │ └── maven
│ │ └── shared
│ │ └── filtering
│ │ ├── AbstractFilterReaderLineEnding.java
│ │ ├── AbstractMavenFilteringRequest.java
│ │ ├── BaseFilter.java
│ │ ├── BoundedReader.java
│ │ ├── DefaultFilterInfo.java
│ │ ├── DefaultMavenFileFilter.java
│ │ ├── DefaultMavenReaderFilter.java
│ │ ├── DefaultMavenResourcesFiltering.java
│ │ ├── FilterWrapper.java
│ │ ├── FilteringUtils.java
│ │ ├── InterpolatorFilterReaderLineEnding.java
│ │ ├── MavenFileFilter.java
│ │ ├── MavenFileFilterRequest.java
│ │ ├── MavenFilteringException.java
│ │ ├── MavenReaderFilter.java
│ │ ├── MavenReaderFilterRequest.java
│ │ ├── MavenResourcesExecution.java
│ │ ├── MavenResourcesFiltering.java
│ │ ├── MultiDelimiterInterpolatorFilterReaderLineEnding.java
│ │ ├── PropertyUtils.java
│ │ └── Resource.java
└── resources
│ └── META-INF
│ └── maven
│ └── org.apache.maven.api.di.Inject
├── site
├── apt
│ ├── index.apt.vm
│ └── usage.apt
├── resources
│ └── download.cgi
├── site.xml
└── xdoc
│ └── download.xml.vm
└── test
├── java
└── org
│ └── apache
│ └── maven
│ └── shared
│ └── filtering
│ ├── AbstractInterpolatorFilterReaderLineEndingTest.java
│ ├── AbstractMavenFilteringRequestTest.java
│ ├── BoundedReaderTest.java
│ ├── DefaultMavenFileFilterTest.java
│ ├── DefaultMavenReaderFilterTest.java
│ ├── DefaultMavenResourcesFilteringTest.java
│ ├── EscapeStringTest.java
│ ├── FilteringUtilsTest.java
│ ├── IOUtils.java
│ ├── IncrementalResourceFilteringTest.java
│ ├── InterpolatorFilterReaderLineEndingTest.java
│ ├── InvalidMarkTest.java
│ ├── MuliLinesMavenResourcesFilteringTest.java
│ ├── MultiDelimiterInterpolatorFilterReaderLineEndingTest.java
│ ├── PropertyUtilsTest.java
│ ├── Providers.java
│ ├── StubSession.java
│ ├── TestIncrementalBuildContext.java
│ └── TestReflectionProperties.java
├── resources
├── META-INF
│ └── maven
│ │ └── org.apache.maven.api.di.Inject
└── pom.xml
└── units-files
├── MRESOURCES-104
└── test.properties
├── MRESOURCES-171
├── test.properties
└── test.txt
├── MRESOURCES-230
├── expected.txt
└── resource.txt
├── MSHARED-1213
└── enunciate.xml
├── MSHARED-161
└── src
│ └── main
│ └── filters
│ ├── buildfilter.properties
│ └── filefilter.properties
├── MSHARED-177
├── first_filter_file.properties
├── second_filter_file.properties
└── third_filter_file.properties
├── MSHARED-325
└── payload
├── MSHARED-81
├── expected-filtered.properties
├── filtered
│ └── filtered.properties
└── resources
│ └── unfiltered.properties
├── edge-cases
├── expected-filtered.properties
├── filtered
│ └── filtered.properties
└── resources
│ └── unfiltered.properties
├── escape-remove-char
└── content.xml
├── includeEmptyDirs
├── dir1
│ └── foo.txt
├── empty-directory-child
│ └── empty-child
│ │ └── .gitignore
└── empty-directory
│ └── .gitignore
├── incremental
├── files
│ ├── file01.txt
│ └── file02.txt
└── filters.txt
├── maven-filename-filtering
└── ${pom.version}.txt
├── maven-resources-filtering
├── empty-maven-resources-filtering.txt
├── excludedir
│ ├── bar.txt
│ └── foo.txt
├── excludefile.txt
├── happy_duke.gif
├── includedir
│ ├── include.txt
│ └── includefile.txt
├── includefile.txt
└── maven-resources-filtering.txt
├── propertyutils-test.properties
├── reflection-test-older.properties
├── reflection-test.properties
└── session-filtering
└── session-filter-target.txt
/.asf.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 | # see https://s.apache.org/asfyaml
18 | github:
19 | description: "Apache Maven Filtering"
20 | homepage: https://maven.apache.org/shared/maven-filtering/
21 | labels:
22 | - java
23 | - build-management
24 | - maven-shared
25 | - maven
26 | enabled_merge_buttons:
27 | squash: true
28 | merge: false
29 | rebase: true
30 | autolink_jira:
31 | - MSHARED
32 | del_branch_on_merge: true
33 | features:
34 | issues: true
35 | notifications:
36 | commits: commits@maven.apache.org
37 | issues: issues@maven.apache.org
38 | pullrequests: issues@maven.apache.org
39 | jira_options: link label comment
40 |
--------------------------------------------------------------------------------
/.git-blame-ignore-revs:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 |
20 | # Change maven code style
21 | 6e125707cfd353d44f2f29f27bb6ace560a7a038
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/BUG.yml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema
19 |
20 | name: Bug Report
21 | description: File a bug report
22 | labels: ["bug"]
23 |
24 | body:
25 | - type: markdown
26 | attributes:
27 | value: |
28 | Thanks for taking the time to fill out this bug report.
29 |
30 | Simple fixes in single PRs do not require issues.
31 |
32 | **Do you use the latest project version?**
33 |
34 | - type: input
35 | id: version
36 | attributes:
37 | label: Affected version
38 | validations:
39 | required: true
40 |
41 | - type: textarea
42 | id: message
43 | attributes:
44 | label: Bug description
45 | validations:
46 | required: true
47 |
48 |
49 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/FEATURE.yml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema
19 |
20 | name: Feature request
21 | description: File a proposal for new feature, improvement
22 | labels: ["enhancement"]
23 |
24 | body:
25 | - type: markdown
26 | attributes:
27 | value: |
28 | Thanks for taking the time to fill out this new feature, improvement proposal.
29 |
30 | - type: textarea
31 | id: message
32 | attributes:
33 | label: New feature, improvement proposal
34 | validations:
35 | required: true
36 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | # https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
19 |
20 | blank_issues_enabled: false
21 |
22 | contact_links:
23 |
24 | - name: Project Mailing Lists
25 | url: https://maven.apache.org/mailing-lists.html
26 | about: Please ask a question or discuss here
27 |
28 | - name: Old JIRA Issues
29 | url: https://issues.apache.org/jira/issues/?jql=project%20%3D%20MSHARED%20AND%20component%20%3D%20maven-filtering
30 | about: Please search old JIRA issues
31 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | version: 2
19 | updates:
20 | - package-ecosystem: "maven"
21 | directory: "/"
22 | schedule:
23 | interval: "daily"
24 | - package-ecosystem: maven
25 | directory: "/"
26 | schedule:
27 | interval: "daily"
28 | target-branch: "maven-filtering-3.x"
29 | labels:
30 | - "mvn3"
31 | - "java"
32 | - "dependencies"
33 | - package-ecosystem: "github-actions"
34 | directory: "/"
35 | schedule:
36 | interval: "daily"
37 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | Following this checklist to help us incorporate your
2 | contribution quickly and easily:
3 |
4 | - [ ] Your pull request should address just one issue, without pulling in other changes.
5 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
6 | - [ ] Each commit in the pull request should have a meaningful subject line and body.
7 | Note that commits might be squashed by a maintainer on merge.
8 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
9 | This may not always be possible but is a best-practice.
10 | - [ ] Run `mvn verify` to make sure basic checks pass.
11 | A more thorough check will be performed on your pull request automatically.
12 | - [ ] You have run the integration tests successfully (`mvn -Prun-its verify`).
13 |
14 | If your pull request is about ~20 lines of code you don't need to sign an
15 | [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
16 | please ask on the developers list.
17 |
18 | To make clear that you license your contribution under
19 | the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
20 | you have to acknowledge this by using the following check-box.
21 |
22 | - [ ] 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)
23 | - [ ] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
24 |
--------------------------------------------------------------------------------
/.github/release-drafter-3.x.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | _extends: maven-gh-actions-shared:.github/release-drafter.yml
19 |
20 | tag-template: maven-filtering-$RESOLVED_VERSION
21 |
--------------------------------------------------------------------------------
/.github/release-drafter.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | _extends: maven-gh-actions-shared
19 |
20 | tag-template: maven-filtering-$RESOLVED_VERSION
21 |
22 | include-pre-releases: true
23 | prerelease: true
24 |
--------------------------------------------------------------------------------
/.github/workflows/maven-verify.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | name: Verify
19 |
20 | on:
21 | push:
22 | pull_request:
23 |
24 | jobs:
25 | build:
26 | name: Verify
27 | uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4
28 | with:
29 | maven4-build: true
30 | ff-goal: verify
31 | verify-goal: verify
32 |
--------------------------------------------------------------------------------
/.github/workflows/pr-automation.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | name: PR Automation
19 | on:
20 | pull_request_target:
21 | types:
22 | - closed
23 |
24 | jobs:
25 | pr-automation:
26 | name: PR Automation
27 | uses: apache/maven-gh-actions-shared/.github/workflows/pr-automation.yml@v4
28 |
--------------------------------------------------------------------------------
/.github/workflows/release-drafter.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | name: Release Drafter
19 | on:
20 | push:
21 | branches:
22 | - master
23 | workflow_dispatch:
24 |
25 | jobs:
26 | update_release_draft:
27 | uses: apache/maven-gh-actions-shared/.github/workflows/release-drafter.yml@v4
28 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | name: Stale
19 |
20 | on:
21 | schedule:
22 | - cron: '38 1 * * *'
23 | issue_comment:
24 | types: [ 'created' ]
25 |
26 | jobs:
27 | stale:
28 | uses: 'apache/maven-gh-actions-shared/.github/workflows/stale.yml@v4'
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .project
3 | .classpath
4 | .settings/
5 | .svn/
6 | bin/
7 | # Intellij
8 | *.ipr
9 | *.iml
10 | *~
11 | .idea
12 | out/
13 | .DS_Store
14 | /bootstrap
15 | /dependencies.xml
16 | .java-version
17 | *.versionsBackup
18 | .checkstyle
19 |
20 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | /**
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | asfMavenTlpStdBuild(jdks:[ "17", "21" ])
21 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | Apache Maven Filtering
2 | Copyright 2007-2024 The Apache Software Foundation
3 |
4 | This product includes software developed at
5 | The Apache Software Foundation (http://www.apache.org/).
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
17 | Contributing to [Apache Maven Filtering](https://maven.apache.org/shared/maven-filtering/)
18 | ======================
19 |
20 | [][license]
21 | [](https://search.maven.org/artifact/org.apache.maven.shared/maven-filtering)
22 | [](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-filtering/README.md)
23 | [][build]
24 | [][test-results]
25 |
26 |
27 | You have found a bug, or you have an idea for a cool new feature? Contributing
28 | code is a great way to give something back to the open source community. Before
29 | you dig right into the code, there are a few guidelines that we need
30 | contributors to follow so that we can have a chance of keeping on top of
31 | things.
32 |
33 | Getting Started
34 | ---------------
35 |
36 | + Make sure you have a [GitHub account](https://github.com/signup/free).
37 | + If you're planning to implement a new feature, it makes sense to discuss your changes
38 | on the [dev list][ml-list] first.
39 | This way you can make sure you're not wasting your time on something that isn't
40 | considered to be in Apache Maven's scope.
41 | + Submit a ticket for your issue, assuming one does not already exist.
42 | + Clearly describe the issue, including steps to reproduce when it is a bug.
43 | + Make sure you fill in the earliest version that you know has the issue.
44 | + Fork the repository on GitHub.
45 |
46 | Making and Submitting Changes
47 | --------------
48 |
49 | We accept Pull Requests via GitHub. The [developer mailing list][ml-list] is the
50 | main channel of communication for contributors.
51 | There are some guidelines which will make applying PRs easier for us:
52 | + Create a topic branch from where you want to base your work (this is usually the master branch).
53 | Push your changes to a topic branch in your fork of the repository.
54 | + Make commits of logical units.
55 | + Respect the original code style: by using the same [codestyle][code-style],
56 | patches should only highlight the actual difference, not being disturbed by any formatting issues:
57 | + Only use spaces for indentation.
58 | + Create minimal diffs - disable on save actions like reformat source code or organize imports.
59 | If you feel the source code should be reformatted, create a separate PR for this change.
60 | + Check for unnecessary whitespace with `git diff --check` before committing.
61 | + Make sure you have added the necessary tests (JUnit/IT) for your changes.
62 | + Run all the tests with `mvn -Prun-its verify` to assure nothing else was accidentally broken.
63 | + Submit a pull request to the repository in the Apache organization.
64 |
65 | If you plan to contribute on a regular basis, please consider filing a [contributor license agreement][cla].
66 |
67 | Additional Resources
68 | --------------------
69 |
70 | + [Contributing patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch)
71 | + [Contributor License Agreement][cla]
72 | + [General GitHub documentation](https://help.github.com/)
73 | + [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
74 | + [Apache Maven X Account](https://x.com/ASFMavenProject)
75 | + [Apache Maven Bluesky Account](https://bsky.app/profile/maven.apache.org)
76 | + [Apache Maven Mastodon Account](https://mastodon.social/deck/@ASFMavenProject@fosstodon.org)
77 |
78 | [license]: https://www.apache.org/licenses/LICENSE-2.0
79 | [ml-list]: https://maven.apache.org/mailing-lists.html
80 | [code-style]: https://maven.apache.org/developers/conventions/code.html
81 | [cla]: https://www.apache.org/licenses/#clas
82 | [maven-wiki]: https://cwiki.apache.org/confluence/display/MAVEN/Index
83 | [test-results]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/job/master/lastCompletedBuild/testReport/
84 | [build]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/job/master/
85 |
--------------------------------------------------------------------------------
/deploySite.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Licensed to the Apache Software Foundation (ASF) under one
5 | # or more contributor license agreements. See the NOTICE file
6 | # distributed with this work for additional information
7 | # regarding copyright ownership. The ASF licenses this file
8 | # to you under the Apache License, Version 2.0 (the
9 | # "License"); you may not use this file except in compliance
10 | # with the License. You may obtain a copy of the License at
11 | #
12 | # http://www.apache.org/licenses/LICENSE-2.0
13 | #
14 | # Unless required by applicable law or agreed to in writing,
15 | # software distributed under the License is distributed on an
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | # KIND, either express or implied. See the License for the
18 | # specific language governing permissions and limitations
19 | # under the License.
20 | #
21 |
22 | mvn -Preporting site site:stage $@
23 | mvn scm-publish:publish-scm $@
24 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 | 4.0.0
22 |
23 |
24 | org.apache.maven.shared
25 | maven-shared-components
26 | 44
27 |
28 |
29 |
30 | maven-filtering
31 | 4.0.0-beta-2-SNAPSHOT
32 |
33 | Apache Maven Filtering
34 | A component to assist in filtering of resource files with properties from a Maven project.
35 |
36 |
37 |
38 | Graham Leggett
39 |
40 |
41 |
42 |
43 | scm:git:https://gitbox.apache.org/repos/asf/maven-filtering.git
44 | scm:git:https://gitbox.apache.org/repos/asf/maven-filtering.git
45 | maven-filtering-4.0.0-beta-1
46 | https://github.com/apache/maven-filtering/tree/${project.scm.tag}
47 |
48 |
49 | GitHub Issues
50 | https://github.com/apache/maven-filtering/issues
51 |
52 |
53 | Jenkins
54 | https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-filtering/
55 |
56 |
57 |
58 | apache.website
59 | scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}
60 |
61 |
62 |
63 |
64 | 17
65 | 4.0.0-rc-2
66 |
67 | 3.0
68 | 5.10.1
69 | 5.18.0
70 | 4.0.0-beta-4
71 | 0.0.7
72 | 1.27
73 | 2.0.13
74 |
75 | 2024-06-26T08:01:47Z
76 |
78 | ParameterNumber,MethodLength,FileLength
79 |
80 |
81 |
82 |
83 | org.apache.maven
84 | maven-api-core
85 | ${mavenVersion}
86 |
87 |
88 | org.apache.maven
89 | maven-api-di
90 | ${mavenVersion}
91 |
92 |
93 | org.apache.maven
94 | maven-api-model
95 | ${mavenVersion}
96 |
97 |
98 | org.apache.maven
99 | maven-api-annotations
100 | ${mavenVersion}
101 |
102 |
103 | org.apache.maven
104 | maven-api-settings
105 | ${mavenVersion}
106 |
107 |
108 | org.slf4j
109 | slf4j-api
110 | ${slf4jVersion}
111 |
112 |
113 | org.sonatype.plexus
114 | plexus-build-api
115 | ${plexusBuildApiVersion}
116 |
117 |
118 | org.codehaus.plexus
119 | plexus-utils
120 |
121 |
122 | org.codehaus.plexus
123 | plexus-interpolation
124 | ${plexusInterpolationVersion}
125 |
126 |
127 |
128 | org.apache.maven.plugin-testing
129 | maven-plugin-testing-harness
130 | ${mavenPluginTestingVersion}
131 | test
132 |
133 |
134 | org.apache.maven
135 | maven-core
136 | ${mavenVersion}
137 | test
138 |
139 |
140 | org.apache.maven
141 | maven-di
142 | ${mavenVersion}
143 | test
144 |
145 |
146 | org.mockito
147 | mockito-junit-jupiter
148 | ${mockitoVersion}
149 | test
150 |
151 |
152 | org.mockito
153 | mockito-core
154 | ${mockitoVersion}
155 | test
156 |
157 |
158 | org.junit.jupiter
159 | junit-jupiter-api
160 | test
161 |
162 |
163 | org.hamcrest
164 | hamcrest
165 | ${hamcrestVersion}
166 | test
167 |
168 |
169 | org.slf4j
170 | slf4j-simple
171 | ${slf4jVersion}
172 | test
173 |
174 |
175 | org.eclipse.sisu
176 | org.eclipse.sisu.plexus
177 | test
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 | org.apache.rat
186 | apache-rat-plugin
187 |
188 |
189 | src/test/units-files/**
190 |
191 |
192 |
193 |
194 | org.apache.maven.plugins
195 | maven-surefire-plugin
196 |
197 | true
198 |
199 |
200 |
201 | org.apache.maven.plugins
202 | maven-enforcer-plugin
203 |
204 |
205 |
206 | ${maven.compiler.target}
207 |
208 | org.jline:jline
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/AbstractFilterReaderLineEnding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.FilterReader;
22 | import java.io.Reader;
23 | import java.util.LinkedHashSet;
24 |
25 | import org.codehaus.plexus.interpolation.multi.DelimiterSpecification;
26 |
27 | /**
28 | * @author Karl Heinz Marbaise khmarbaise@apache.org
29 | */
30 | public abstract class AbstractFilterReaderLineEnding extends FilterReader {
31 |
32 | private String escapeString;
33 |
34 | /**
35 | * using escape or not.
36 | */
37 | protected boolean useEscape = false;
38 |
39 | /**
40 | * if true escapeString will be preserved \{foo} -> \{foo}
41 | */
42 | private boolean preserveEscapeString = false;
43 |
44 | protected final LinkedHashSet delimiters = new LinkedHashSet<>();
45 |
46 | /**
47 | * must always be bigger than escape string plus delimiters, but doesn't need to be exact
48 | */
49 | // CHECKSTYLE_OFF: MagicNumber
50 | protected int markLength = 255;
51 | // CHECKSTYLE_ON: MagicNumber
52 |
53 | protected AbstractFilterReaderLineEnding(Reader in) {
54 | super(in);
55 | }
56 |
57 | /**
58 | * @return the escapce string.
59 | */
60 | public String getEscapeString() {
61 | return escapeString;
62 | }
63 |
64 | /**
65 | * @param escapeString Set the value of the escape string.
66 | */
67 | public void setEscapeString(String escapeString) {
68 | // TODO NPE if escapeString is null ?
69 | if (escapeString != null && !escapeString.isEmpty()) {
70 | this.escapeString = escapeString;
71 | this.useEscape = true;
72 | calculateMarkLength();
73 | }
74 | }
75 |
76 | /**
77 | * @return state of preserve escape string.
78 | */
79 | public boolean isPreserveEscapeString() {
80 | return preserveEscapeString;
81 | }
82 |
83 | /**
84 | * @param preserveEscapeString preserve escape string {@code true} or {@code false}.
85 | */
86 | public void setPreserveEscapeString(boolean preserveEscapeString) {
87 | this.preserveEscapeString = preserveEscapeString;
88 | }
89 |
90 | protected void calculateMarkLength() {
91 | // CHECKSTYLE_OFF: MagicNumber
92 | markLength = 255;
93 | // CHECKSTYLE_ON: MagicNumber
94 |
95 | if (escapeString != null) {
96 | markLength += escapeString.length();
97 | }
98 | for (DelimiterSpecification spec : delimiters) {
99 | markLength += spec.getBegin().length();
100 | markLength += spec.getEnd().length();
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/BoundedReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.IOException;
22 | import java.io.Reader;
23 |
24 | /**
25 | * A reader that imposes a limit to the number of bytes that can be read from an underlying reader, simulating eof when
26 | * this limit is reached. This stream can typically be used to constrain a client with regard to a readAheadLimit of an
27 | * underlying stream, to avoid overrunning this limit and hence lose the opportunity do to reset.
28 | */
29 | public class BoundedReader extends Reader {
30 |
31 | private final Reader target;
32 |
33 | int pos = 0;
34 |
35 | int readAheadLimit;
36 |
37 | /**
38 | * @param target {@link Reader}
39 | * @param readAheadLimit read ahead limit.
40 | * @throws IOException in case of a failure.
41 | */
42 | public BoundedReader(Reader target, int readAheadLimit) throws IOException {
43 | this.target = target;
44 | target.mark(readAheadLimit);
45 | this.readAheadLimit = readAheadLimit;
46 | }
47 |
48 | @Override
49 | public void close() throws IOException {
50 | target.close();
51 | }
52 |
53 | @Override
54 | public void reset() throws IOException {
55 | pos = 0;
56 | target.reset();
57 | }
58 |
59 | @Override
60 | public void mark(int theReadAheadLimit) throws IOException {
61 | this.readAheadLimit = theReadAheadLimit;
62 | target.mark(theReadAheadLimit);
63 | }
64 |
65 | @Override
66 | public int read() throws IOException {
67 | if (pos >= readAheadLimit) {
68 | return -1;
69 | }
70 | pos++;
71 | return target.read();
72 | }
73 |
74 | @Override
75 | public int read(char[] cbuf, int off, int len) throws IOException {
76 | int c;
77 | for (int i = 0; i < len; i++) {
78 | c = read();
79 | if (c == -1) {
80 | return i;
81 | }
82 | cbuf[off + i] = (char) c;
83 | }
84 | return len;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/DefaultFilterInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.util.List;
22 |
23 | import org.apache.maven.api.Project;
24 | import org.apache.maven.api.Session;
25 |
26 | /**
27 | * @author Kristian Rosenvold
28 | */
29 | public interface DefaultFilterInfo {
30 |
31 | /**
32 | * @param mavenProject The maven project
33 | * @param filters The filters to get
34 | * @param escapedBackslashesInFilePath escape backslashes ?
35 | * @param mavenSession The maven session
36 | * @param mavenResourcesExecution The filtering configuration
37 | * @throws MavenFilteringException in case of failure.
38 | * @return {@link java.util.List} of FileUtils.FilterWrapper
39 | * @since 1.0-beta-2
40 | */
41 | List getDefaultFilterWrappers(
42 | Project mavenProject,
43 | List filters,
44 | boolean escapedBackslashesInFilePath,
45 | Session mavenSession,
46 | MavenResourcesExecution mavenResourcesExecution)
47 | throws MavenFilteringException;
48 |
49 | /**
50 | * @param request The filtering request
51 | * @throws org.apache.maven.shared.filtering.MavenFilteringException in case of failure.
52 | * @return {@link java.util.List} of FileUtils.FilterWrapper
53 | * @since 1.0-beta-3
54 | */
55 | List getDefaultFilterWrappers(AbstractMavenFilteringRequest request) throws MavenFilteringException;
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/DefaultMavenFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.IOException;
22 | import java.nio.file.Path;
23 | import java.util.List;
24 |
25 | import org.apache.maven.api.Project;
26 | import org.apache.maven.api.Session;
27 | import org.apache.maven.api.di.Inject;
28 | import org.apache.maven.api.di.Named;
29 | import org.apache.maven.api.di.Singleton;
30 | import org.sonatype.plexus.build.incremental.BuildContext;
31 |
32 | import static java.util.Objects.requireNonNull;
33 |
34 | /**
35 | * @author Olivier Lamy
36 | */
37 | @Singleton
38 | @Named
39 | public class DefaultMavenFileFilter extends BaseFilter implements MavenFileFilter {
40 | private final BuildContext buildContext;
41 |
42 | @Inject
43 | public DefaultMavenFileFilter(BuildContext buildContext) {
44 | this.buildContext = requireNonNull(buildContext);
45 | }
46 |
47 | @Override
48 | public void copyFile(
49 | Path from,
50 | Path to,
51 | boolean filtering,
52 | Project mavenProject,
53 | List filters,
54 | boolean escapedBackslashesInFilePath,
55 | String encoding,
56 | Session mavenSession)
57 | throws MavenFilteringException {
58 | MavenResourcesExecution mre = new MavenResourcesExecution();
59 | mre.setMavenProject(mavenProject);
60 | mre.setFileFilters(filters);
61 | mre.setEscapeWindowsPaths(escapedBackslashesInFilePath);
62 | mre.setMavenSession(mavenSession);
63 | mre.setInjectProjectBuildFilters(true);
64 |
65 | List filterWrappers = getDefaultFilterWrappers(mre);
66 | copyFile(from, to, filtering, filterWrappers, encoding);
67 | }
68 |
69 | @Override
70 | public void copyFile(MavenFileFilterRequest mavenFileFilterRequest) throws MavenFilteringException {
71 | List filterWrappers = getDefaultFilterWrappers(mavenFileFilterRequest);
72 |
73 | copyFile(
74 | mavenFileFilterRequest.getFrom(),
75 | mavenFileFilterRequest.getTo(),
76 | mavenFileFilterRequest.isFiltering(),
77 | filterWrappers,
78 | mavenFileFilterRequest.getEncoding());
79 | }
80 |
81 | @Override
82 | public void copyFile(Path from, Path to, boolean filtering, List filterWrappers, String encoding)
83 | throws MavenFilteringException {
84 | try {
85 | if (filtering) {
86 | getLogger().debug("filtering {} to {}", from, to);
87 | FilterWrapper[] array = filterWrappers.toArray(new FilterWrapper[0]);
88 | FilteringUtils.copyFile(from, to, encoding, array, false);
89 | } else {
90 | getLogger().debug("copy {} to {}", from, to);
91 | FilteringUtils.copyFile(from, to, encoding, new FilterWrapper[0], false);
92 | }
93 |
94 | buildContext.refresh(to.toFile());
95 | } catch (IOException e) {
96 | throw new MavenFilteringException(
97 | (filtering ? "filtering " : "copying ") + from + " to " + to + " failed with "
98 | + e.getClass().getSimpleName() + ": " + e.getMessage(),
99 | e);
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 | import java.util.Collections;
23 | import java.util.List;
24 |
25 | import org.apache.maven.api.Project;
26 | import org.apache.maven.api.Session;
27 | import org.apache.maven.api.di.Named;
28 | import org.apache.maven.api.di.Singleton;
29 |
30 | /**
31 | * @author Kristian Rosenvold
32 | */
33 | @Singleton
34 | @Named
35 | public class DefaultMavenReaderFilter extends BaseFilter implements MavenReaderFilter {
36 | @Override
37 | public Reader filter(
38 | Reader from,
39 | boolean filtering,
40 | Project mavenProject,
41 | List filters,
42 | boolean escapedBackslashesInFilePath,
43 | Session mavenSession)
44 | throws MavenFilteringException {
45 | MavenResourcesExecution mre = new MavenResourcesExecution();
46 | mre.setMavenProject(mavenProject);
47 | mre.setFileFilters(filters);
48 | mre.setEscapeWindowsPaths(escapedBackslashesInFilePath);
49 | mre.setMavenSession(mavenSession);
50 | mre.setInjectProjectBuildFilters(true);
51 |
52 | List filterWrappers = getDefaultFilterWrappers(mre);
53 | return filter(from, filtering, filterWrappers);
54 | }
55 |
56 | @Override
57 | public Reader filter(MavenReaderFilterRequest mavenFileFilterRequest) throws MavenFilteringException {
58 | List filterWrappers = getDefaultFilterWrappers(mavenFileFilterRequest);
59 | return filter(mavenFileFilterRequest.getFrom(), mavenFileFilterRequest.isFiltering(), filterWrappers);
60 | }
61 |
62 | @Override
63 | public Reader filter(Reader from, boolean filtering, List filterWrappers) {
64 | return filterWrap(from, filtering ? filterWrappers : Collections.emptyList());
65 | }
66 |
67 | private static Reader filterWrap(Reader from, Iterable wrappers) {
68 | Reader reader = from;
69 | for (FilterWrapper wrapper : wrappers) {
70 | reader = wrapper.getReader(reader);
71 | }
72 | return reader;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/FilterWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 |
23 | /**
24 | * Wrapper class for Filter.
25 | *
26 | * @since TBD
27 | */
28 | public abstract class FilterWrapper {
29 | /**
30 | * @param fileReader {@link Reader}
31 | * @return the Reader instance
32 | */
33 | public abstract Reader getReader(Reader fileReader);
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/MavenFileFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.nio.file.Path;
22 | import java.util.List;
23 |
24 | import org.apache.maven.api.Project;
25 | import org.apache.maven.api.Session;
26 |
27 | /**
28 | * @author Olivier Lamy
29 | */
30 | public interface MavenFileFilter extends DefaultFilterInfo {
31 |
32 | /**
33 | * Will copy a file with some filtering using defaultFilterWrappers.
34 | *
35 | * @param from file to copy/filter
36 | * @param to destination file
37 | * @param filtering enable or not filtering
38 | * @param mavenProject {@link Project}
39 | * @param mavenSession {@link Session}
40 | * @param escapedBackslashesInFilePath escape backslashes in file path.
41 | * @param filters {@link List} of String which are path to a Property file
42 | * @param encoding The encoding which is used during the filtering process.
43 | * @throws MavenFilteringException in case of failure.
44 | * @see DefaultFilterInfo#getDefaultFilterWrappers(Project, List, boolean, Session, MavenResourcesExecution)
45 | */
46 | void copyFile(
47 | Path from,
48 | Path to,
49 | boolean filtering,
50 | Project mavenProject,
51 | List filters,
52 | boolean escapedBackslashesInFilePath,
53 | String encoding,
54 | Session mavenSession)
55 | throws MavenFilteringException;
56 |
57 | /**
58 | * @param mavenFileFilterRequest the request
59 | * @throws MavenFilteringException in case of failure.
60 | * @since 1.0-beta-3
61 | */
62 | void copyFile(MavenFileFilterRequest mavenFileFilterRequest) throws MavenFilteringException;
63 |
64 | /**
65 | * @param from The source file
66 | * @param to The target file
67 | * @param filtering true to apply filtering
68 | * @param filterWrappers {@link List} of FileUtils.FilterWrapper
69 | * @param encoding The encoding used during the filtering.
70 | * @throws MavenFilteringException In case of an error.
71 | */
72 | void copyFile(Path from, Path to, boolean filtering, List filterWrappers, String encoding)
73 | throws MavenFilteringException;
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/MavenFileFilterRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.nio.file.Path;
22 | import java.util.List;
23 | import java.util.Properties;
24 |
25 | import org.apache.maven.api.Project;
26 | import org.apache.maven.api.Session;
27 |
28 | /**
29 | * @author Olivier Lamy
30 | * @since 1.0-beta-3
31 | */
32 | public class MavenFileFilterRequest extends AbstractMavenFilteringRequest {
33 |
34 | private Path from;
35 |
36 | private Path to;
37 |
38 | private boolean filtering;
39 |
40 | private String encoding;
41 |
42 | /**
43 | * The constructor.
44 | */
45 | public MavenFileFilterRequest() {
46 | // nothing
47 | }
48 |
49 | /**
50 | * @param from The request from where.
51 | * @param to The request to where
52 | * @param filtering Filtering yes {@code true} or no {@code false}
53 | * @param mavenProject The Maven Project.
54 | * @param filters The list of given filters.
55 | * @param escapedBackslashesInFilePath Escape back slashes in file path.
56 | * @param encoding The used encoding during the filtering.
57 | * @param mavenSession The Maven Session.
58 | * @param additionalProperties Supplemental properties.
59 | */
60 | public MavenFileFilterRequest(
61 | Path from,
62 | Path to,
63 | boolean filtering,
64 | Project mavenProject,
65 | List filters,
66 | boolean escapedBackslashesInFilePath,
67 | String encoding,
68 | Session mavenSession,
69 | Properties additionalProperties) {
70 | super(mavenProject, filters, mavenSession);
71 | this.encoding = encoding;
72 | this.from = from;
73 | this.to = to;
74 | this.filtering = filtering;
75 | setAdditionalProperties(additionalProperties);
76 | setEscapeWindowsPaths(escapedBackslashesInFilePath);
77 | }
78 |
79 | /**
80 | * Return the encoding.
81 | *
82 | * @return Current encoding.
83 | */
84 | public String getEncoding() {
85 | return encoding;
86 | }
87 |
88 | /**
89 | * Set the value for encoding.
90 | *
91 | * @param encoding Give the new value for encoding.
92 | */
93 | public void setEncoding(String encoding) {
94 | this.encoding = encoding;
95 | }
96 |
97 | /**
98 | * @return to filter from.
99 | */
100 | public Path getFrom() {
101 | return from;
102 | }
103 |
104 | /**
105 | * @param from set filter from.
106 | */
107 | public void setFrom(Path from) {
108 | this.from = from;
109 | }
110 |
111 | /**
112 | * @return The filter to
113 | */
114 | public Path getTo() {
115 | return to;
116 | }
117 |
118 | /**
119 | * @param to Set the target.
120 | */
121 | public void setTo(Path to) {
122 | this.to = to;
123 | }
124 |
125 | /**
126 | * @return if we are filtering yes {@code true} no {@code false}
127 | */
128 | public boolean isFiltering() {
129 | return filtering;
130 | }
131 |
132 | /**
133 | * @param filtering set filtering yes / no.
134 | */
135 | public void setFiltering(boolean filtering) {
136 | this.filtering = filtering;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/MavenFilteringException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | /**
22 | * @author Olivier Lamy
23 | */
24 | public class MavenFilteringException extends Exception {
25 |
26 | /**
27 | *
28 | */
29 | private static final long serialVersionUID = 1L;
30 |
31 | /**
32 | *
33 | */
34 | public MavenFilteringException() {
35 | // nothing
36 | }
37 |
38 | /**
39 | * @param message the message
40 | */
41 | public MavenFilteringException(String message) {
42 | super(message);
43 | }
44 |
45 | /**
46 | * @param cause the cause of the exception
47 | */
48 | public MavenFilteringException(Throwable cause) {
49 | super(cause);
50 | }
51 |
52 | /**
53 | * @param message a message
54 | * @param cause a worthy cause
55 | */
56 | public MavenFilteringException(String message, Throwable cause) {
57 | super(message, cause);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/MavenReaderFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 | import java.util.List;
23 |
24 | import org.apache.maven.api.Project;
25 | import org.apache.maven.api.Session;
26 |
27 | /**
28 | * @author Olivier Lamy
29 | * @author Kristian Rosenvold
30 | * @since 1.3
31 | */
32 | public interface MavenReaderFilter extends DefaultFilterInfo {
33 | /**
34 | * Provides a new reader that applies filtering using defaultFilterWrappers.
35 | *
36 | * @param from the source reader
37 | * @param filtering enable or not filtering
38 | * @param mavenProject {@link Project}
39 | * @param mavenSession {@link Session}
40 | * @param filters {@link java.util.List} of String which are path to a Property file
41 | * @param escapedBackslashesInFilePath escape backslashes in file path.
42 | * @return an input stream that applies the filter
43 | * @throws org.apache.maven.shared.filtering.MavenFilteringException in case of failure.
44 | */
45 | Reader filter(
46 | Reader from,
47 | boolean filtering,
48 | Project mavenProject,
49 | List filters,
50 | boolean escapedBackslashesInFilePath,
51 | Session mavenSession)
52 | throws MavenFilteringException;
53 |
54 | /**
55 | * Provides a new reader that applies filtering using defaultFilterWrappers.
56 | *
57 | * @param mavenFileFilterRequest The filter request
58 | * @throws org.apache.maven.shared.filtering.MavenFilteringException in case of failure.
59 | * @return an input stream that applies the filter
60 | * @since 1.0-beta-3
61 | */
62 | Reader filter(MavenReaderFilterRequest mavenFileFilterRequest) throws MavenFilteringException;
63 |
64 | /**
65 | * Provides a new reader that applies filtering using defaultFilterWrappers.
66 | *
67 | * @param from the source reader
68 | * @param filtering true to apply filtering
69 | * @param filterWrappers {@link java.util.List} of FileUtils.FilterWrapper
70 | * @return an input stream that applies the filter
71 | */
72 | Reader filter(Reader from, boolean filtering, List filterWrappers);
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/MavenReaderFilterRequest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 | import java.util.List;
23 | import java.util.Properties;
24 |
25 | import org.apache.maven.api.Project;
26 | import org.apache.maven.api.Session;
27 |
28 | /**
29 | * @author Olivier Lamy
30 | * @author Kristian Rosenvold
31 | * @since 1.0-beta-3
32 | */
33 | public class MavenReaderFilterRequest extends AbstractMavenFilteringRequest {
34 |
35 | private Reader from;
36 |
37 | private boolean filtering;
38 |
39 | /**
40 | * Default constructor.
41 | */
42 | public MavenReaderFilterRequest() {
43 | // nothing
44 | }
45 |
46 | /**
47 | * @param from To read from
48 | * @param filtering filter yes/no
49 | * @param mavenProject The Maven Project.
50 | * @param filters The list of filters which will be used.
51 | * @param escapedBackslashesInFilePath escape backslashes in file paths.
52 | * @param mavenSession The Maven Session.
53 | * @param additionalProperties supplemental properties.
54 | */
55 | public MavenReaderFilterRequest(
56 | Reader from,
57 | boolean filtering,
58 | Project mavenProject,
59 | List filters,
60 | boolean escapedBackslashesInFilePath,
61 | Session mavenSession,
62 | Properties additionalProperties) {
63 | super(mavenProject, filters, mavenSession);
64 | this.from = from;
65 | this.filtering = filtering;
66 | setAdditionalProperties(additionalProperties);
67 | setEscapeWindowsPaths(escapedBackslashesInFilePath);
68 | }
69 |
70 | /**
71 | * @return where we read from.
72 | */
73 | public Reader getFrom() {
74 | return from;
75 | }
76 |
77 | /**
78 | * @param from set where to read from.
79 | */
80 | public void setFrom(Reader from) {
81 | this.from = from;
82 | }
83 |
84 | /**
85 | * @return is filtering active ({@code true}) false otherwise.
86 | */
87 | public boolean isFiltering() {
88 | return filtering;
89 | }
90 |
91 | /**
92 | * @param filtering turn filtering on {@code true}) or off ({@code false}).
93 | */
94 | public void setFiltering(boolean filtering) {
95 | this.filtering = filtering;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/MavenResourcesFiltering.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.util.List;
22 |
23 | /**
24 | * @author Olivier Lamy
25 | */
26 | public interface MavenResourcesFiltering {
27 |
28 | /**
29 | * return the List of the non filtered extensions (jpg,jpeg,gif,bmp,png,ico)
30 | *
31 | * @return {@link List} of {@link String}
32 | */
33 | List getDefaultNonFilteredFileExtensions();
34 |
35 | /**
36 | * @param fileName the file name
37 | * @param userNonFilteredFileExtensions an extra list of file extensions
38 | * @return true if filtering can be applied to the file (means extensions.lowerCase is in the default List or in the
39 | * user defined extension List)
40 | */
41 | boolean filteredFileExtension(String fileName, List userNonFilteredFileExtensions);
42 |
43 | /**
44 | * @param mavenResourcesExecution {@link MavenResourcesExecution}
45 | * @throws MavenFilteringException in case of failure.
46 | */
47 | void filterResources(MavenResourcesExecution mavenResourcesExecution) throws MavenFilteringException;
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/PropertyUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.FileNotFoundException;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.nio.file.Files;
25 | import java.nio.file.Path;
26 | import java.util.LinkedList;
27 | import java.util.List;
28 | import java.util.Properties;
29 |
30 | import org.slf4j.Logger;
31 |
32 | import static org.apache.maven.shared.filtering.FilteringUtils.isEmpty;
33 |
34 | /**
35 | * @author Kenney Westerhof
36 | * @author William Ferguson
37 | */
38 | public final class PropertyUtils {
39 | /**
40 | * Private empty constructor to prevent instantiation.
41 | */
42 | private PropertyUtils() {
43 | // prevent instantiation
44 | }
45 |
46 | /**
47 | * Reads a property file, resolving all internal variables, using the supplied base properties.
48 | *
49 | * The properties are resolved iteratively, so if the value of property A refers to property B, then after
50 | * resolution the value of property B will contain the value of property B.
51 | *
52 | *
53 | * @param propFile The property file to load.
54 | * @param baseProps Properties containing the initial values to substitute into the properties file.
55 | * @return Properties object containing the properties in the file with their values fully resolved.
56 | * @throws IOException if profile does not exist, or cannot be read.
57 | */
58 | public static Properties loadPropertyFile(Path propFile, Properties baseProps) throws IOException {
59 | return loadPropertyFile(propFile, baseProps, null);
60 | }
61 |
62 | /**
63 | * Reads a property file, resolving all internal variables, using the supplied base properties.
64 | *
65 | * The properties are resolved iteratively, so if the value of property A refers to property B, then after
66 | * resolution the value of property B will contain the value of property B.
67 | *
68 | *
69 | * @param propFile The property file to load.
70 | * @param baseProps Properties containing the initial values to substitute into the properties file.
71 | * @param logger Logger instance
72 | * @return Properties object containing the properties in the file with their values fully resolved.
73 | * @throws IOException if profile does not exist, or cannot be read.
74 | *
75 | * @since 3.1.2
76 | */
77 | public static Properties loadPropertyFile(Path propFile, Properties baseProps, Logger logger) throws IOException {
78 | if (!Files.exists(propFile)) {
79 | throw new FileNotFoundException(propFile.toString());
80 | }
81 |
82 | final Properties fileProps = new Properties();
83 |
84 | try (InputStream inStream = Files.newInputStream(propFile)) {
85 | fileProps.load(inStream);
86 | }
87 |
88 | final Properties combinedProps = new Properties();
89 | combinedProps.putAll(baseProps == null ? new Properties() : baseProps);
90 | combinedProps.putAll(fileProps);
91 |
92 | // The algorithm iterates only over the fileProps which is all that is required to resolve
93 | // the properties defined within the file. This is slightly different to current, however
94 | // I suspect that this was the actual original intent.
95 | //
96 | // The difference is that #loadPropertyFile(File, boolean, boolean) also resolves System properties
97 | // whose values contain expressions. I believe this is unexpected and is not validated by the test cases,
98 | // as can be verified by replacing the implementation of #loadPropertyFile(File, boolean, boolean)
99 | // with the commented variant I have provided that reuses this method.
100 |
101 | for (Object o : fileProps.keySet()) {
102 | final String k = (String) o;
103 | final String propValue = getPropertyValue(k, combinedProps, logger);
104 | fileProps.setProperty(k, propValue);
105 | }
106 |
107 | return fileProps;
108 | }
109 |
110 | /**
111 | * Reads a property file, resolving all internal variables.
112 | *
113 | * @param propfile The property file to load
114 | * @param fail whether to throw an exception when the file cannot be loaded or to return null
115 | * @param useSystemProps whether to incorporate System.getProperties settings into the returned Properties object.
116 | * @return the loaded and fully resolved Properties object
117 | * @throws IOException if profile does not exist, or cannot be read.
118 | */
119 | public static Properties loadPropertyFile(Path propfile, boolean fail, boolean useSystemProps) throws IOException {
120 | return loadPropertyFile(propfile, fail, useSystemProps, null);
121 | }
122 |
123 | /**
124 | * Reads a property file, resolving all internal variables.
125 | *
126 | * @param propfile The property file to load
127 | * @param fail whether to throw an exception when the file cannot be loaded or to return null
128 | * @param useSystemProps whether to incorporate System.getProperties settings into the returned Properties object.
129 | * @param logger Logger instance
130 | * @return the loaded and fully resolved Properties object
131 | * @throws IOException if profile does not exist, or cannot be read.
132 | *
133 | * @since 3.1.2
134 | */
135 | public static Properties loadPropertyFile(Path propfile, boolean fail, boolean useSystemProps, Logger logger)
136 | throws IOException {
137 |
138 | final Properties baseProps = new Properties();
139 |
140 | if (useSystemProps) {
141 | baseProps.putAll(System.getProperties());
142 | }
143 |
144 | final Properties resolvedProps = new Properties();
145 | try {
146 | resolvedProps.putAll(loadPropertyFile(propfile, baseProps, logger));
147 | } catch (FileNotFoundException e) {
148 | if (fail) {
149 | throw new FileNotFoundException(propfile.toString());
150 | }
151 | }
152 |
153 | if (useSystemProps) {
154 | resolvedProps.putAll(baseProps);
155 | }
156 |
157 | return resolvedProps;
158 | }
159 |
160 | /**
161 | * Retrieves a property value, replacing values like ${token} using the Properties to look them up. It will leave
162 | * unresolved properties alone, trying for System properties, and implements reparsing (in the case that the value
163 | * of a property contains a key), and will not loop endlessly on a pair like test = ${test}.
164 | *
165 | * @param k
166 | * @param p
167 | * @param logger Logger instance
168 | * @return The filtered property value.
169 | */
170 | private static String getPropertyValue(String k, Properties p, Logger logger) {
171 | // This can also be done using InterpolationFilterReader,
172 | // but it requires reparsing the file over and over until
173 | // it doesn't change.
174 |
175 | // for cycle detection
176 | List valueChain = new LinkedList<>();
177 | valueChain.add(k);
178 |
179 | String v = p.getProperty(k);
180 | String defaultValue = v;
181 | StringBuilder ret = new StringBuilder();
182 | int idx, idx2;
183 |
184 | while ((idx = v.indexOf("${")) >= 0) {
185 | // append prefix to result
186 | ret.append(v, 0, idx);
187 |
188 | // strip prefix from original
189 | v = v.substring(idx + 2);
190 |
191 | // if no matching } then bail
192 | idx2 = v.indexOf('}');
193 | if (idx2 < 0) {
194 | break;
195 | }
196 |
197 | // strip out the key and resolve it
198 | // resolve the key/value for the ${statement}
199 | String nk = v.substring(0, idx2);
200 | v = v.substring(idx2 + 1);
201 | String nv = p.getProperty(nk);
202 |
203 | if (valueChain.contains(nk)) {
204 | if (logger != null) {
205 | logCircularDetection(valueChain, nk, logger);
206 | }
207 | return defaultValue;
208 | } else {
209 | valueChain.add(nk);
210 |
211 | // try global environment..
212 | if (nv == null && !isEmpty(nk)) {
213 | nv = System.getProperty(nk);
214 | }
215 |
216 | // if the key cannot be resolved,
217 | // leave it alone ( and don't parse again )
218 | // else prefix the original string with the
219 | // resolved property ( so it can be parsed further )
220 | // taking recursion into account.
221 | if (nv == null || nv.equals(k) || k.equals(nk)) {
222 | ret.append("${").append(nk).append("}");
223 | } else {
224 | v = nv + v;
225 | }
226 | }
227 | }
228 |
229 | return ret + v;
230 | }
231 |
232 | /**
233 | * Logs the detected cycle in properties resolution
234 | * @param valueChain the sequence of properties resolved so far
235 | * @param nk the key the closes the cycle
236 | * @param logger Logger instance
237 | */
238 | private static void logCircularDetection(List valueChain, String nk, Logger logger) {
239 | StringBuilder sb = new StringBuilder("Circular reference between properties detected: ");
240 | for (String key : valueChain) {
241 | sb.append(key).append(" => ");
242 | }
243 | sb.append(nk);
244 | logger.warn(sb.toString());
245 | }
246 | }
247 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/filtering/Resource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | /**
25 | * @author Olivier Lamy
26 | * @since 2.3
27 | *
28 | */
29 | public class Resource {
30 |
31 | List includes;
32 | List excludes;
33 | String directory;
34 | String targetPath;
35 | boolean filtering;
36 | String mergeId;
37 |
38 | public Resource() {}
39 |
40 | public List getIncludes() {
41 | return includes;
42 | }
43 |
44 | public void setIncludes(List includes) {
45 | this.includes = includes;
46 | }
47 |
48 | public List getExcludes() {
49 | return excludes;
50 | }
51 |
52 | public void setExcludes(List excludes) {
53 | this.excludes = excludes;
54 | }
55 |
56 | public String getDirectory() {
57 | return directory;
58 | }
59 |
60 | public void setDirectory(String directory) {
61 | this.directory = directory;
62 | }
63 |
64 | public String getTargetPath() {
65 | return targetPath;
66 | }
67 |
68 | public void setTargetPath(String targetPath) {
69 | this.targetPath = targetPath;
70 | }
71 |
72 | public boolean isFiltering() {
73 | return filtering;
74 | }
75 |
76 | public void setFiltering(boolean filtering) {
77 | this.filtering = filtering;
78 | }
79 |
80 | public String getMergeId() {
81 | return mergeId;
82 | }
83 |
84 | public void setMergeId(String mergeId) {
85 | this.mergeId = mergeId;
86 | }
87 |
88 | public void addInclude(String include) {
89 | if (includes == null) {
90 | includes = new ArrayList<>();
91 | }
92 | includes.add(include);
93 | }
94 |
95 | public void addExclude(String exclude) {
96 | if (excludes == null) {
97 | excludes = new ArrayList<>();
98 | }
99 | excludes.add(exclude);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/maven/org.apache.maven.api.di.Inject:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 | org.apache.maven.shared.filtering.DefaultMavenFileFilter
20 | org.apache.maven.shared.filtering.DefaultMavenReaderFilter
21 | org.apache.maven.shared.filtering.DefaultMavenResourcesFiltering
22 |
--------------------------------------------------------------------------------
/src/site/apt/index.apt.vm:
--------------------------------------------------------------------------------
1 | ------
2 | Introduction
3 | ------
4 | Olivier Lamy
5 | ------
6 | 2013-07-24
7 | ------
8 |
9 | ~~ Licensed to the Apache Software Foundation (ASF) under one
10 | ~~ or more contributor license agreements. See the NOTICE file
11 | ~~ distributed with this work for additional information
12 | ~~ regarding copyright ownership. The ASF licenses this file
13 | ~~ to you under the Apache License, Version 2.0 (the
14 | ~~ "License"); you may not use this file except in compliance
15 | ~~ with the License. You may obtain a copy of the License at
16 | ~~
17 | ~~ http://www.apache.org/licenses/LICENSE-2.0
18 | ~~
19 | ~~ Unless required by applicable law or agreed to in writing,
20 | ~~ software distributed under the License is distributed on an
21 | ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 | ~~ KIND, either express or implied. See the License for the
23 | ~~ specific language governing permissions and limitations
24 | ~~ under the License.
25 |
26 | ${project.name}
27 |
28 | This component has been built from the filtering process/code in Maven Resources Plugin.
29 |
30 | The goal is to provide a shared component for all plugins that needs to filter resources.
31 |
32 |
33 | * MavenResourcesExecution
34 |
35 | ** POM Interpolation
36 |
37 | POM values will be interpolated <> with expressions starting with <<>> or <<>> (it's configurable).
38 | In previous versions something like $\{foo.version\} or $\{version\} was interpolated with the current POM version, but
39 | it won't be interpolated with a POM value any more.
40 |
41 | ** Escaping Interpolation
42 |
43 | It's possible now to define a String which will escape interpolation.
44 | \$\{java.home\} will be interpolated to $\{java.home\}.
45 |
46 | ** <<>> parameter
47 |
48 | It also accepts absolute paths.
49 |
50 | ** <<>> parameter
51 |
52 | The parameter <<>> forces file copy even if the destination file is newer.
53 |
54 |
55 | * MavenResourcesFiltering
56 |
57 | This component will apply filtering on a <<>> of <<>>s.
58 |
59 | If you want to use the default <<>> of <<>> (see below)
60 | you should use the method without the <<>> parameter.
61 |
62 | The component will not filter a predefined set of file extensions (jpg, jpeg, gif, bmp, png).
63 |
64 | <> You can easily add extra file extensions.
65 |
66 |
67 | * MavenFileFilter
68 |
69 | This component has a method which returns the default <<>>s.
70 | These are:
71 |
72 | * Interpolation with token $\{ \} and values from properties files, <<<\>>>/<<<\>>>/<<<\>>, <<>>
73 | and <<>>
74 |
75 | * Interpolation with token @ @ and values from properties files, <<<\>>>/<<<\>>>/<<<\>>, <<>>
76 | and <<>>
77 |
78 | * Interpolation with token $\{ \} and values from <<>> interpolation
79 |
80 | * Interpolation with token @ @ and values from <<>> interpolation
81 |
82 | []
83 |
84 | The values used for interpolation are stored in a <<>> object
85 | and are loaded in the following order:
86 |
87 | * A <<>> of properties files, provided as a parameter to the method
88 |
89 | * Filters defined in the <<<\>>>/<<<\>>> section of the POM
90 |
91 | * Properties defined in the <<<\>>> section of the POM
92 |
93 | * The <<>> from the current <<>>
94 |
95 | []
96 |
97 | <> As it's a <<>> object, the last defined key/value pair wins.
98 |
99 | <> When building the <<>> object and reading the properties files that defines the different filters,
100 | interpolation with the token $\{ \} is supported for these filters with limited properties values coming from
101 | <<>> and <<>>. The last wins here too.
102 |
--------------------------------------------------------------------------------
/src/site/apt/usage.apt:
--------------------------------------------------------------------------------
1 | ------
2 | Usage
3 | ------
4 | Olivier Lamy
5 | ------
6 | 2011-01-05
7 | ------
8 |
9 | ~~ Licensed to the Apache Software Foundation (ASF) under one
10 | ~~ or more contributor license agreements. See the NOTICE file
11 | ~~ distributed with this work for additional information
12 | ~~ regarding copyright ownership. The ASF licenses this file
13 | ~~ to you under the Apache License, Version 2.0 (the
14 | ~~ "License"); you may not use this file except in compliance
15 | ~~ with the License. You may obtain a copy of the License at
16 | ~~
17 | ~~ http://www.apache.org/licenses/LICENSE-2.0
18 | ~~
19 | ~~ Unless required by applicable law or agreed to in writing,
20 | ~~ software distributed under the License is distributed on an
21 | ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 | ~~ KIND, either express or implied. See the License for the
23 | ~~ specific language governing permissions and limitations
24 | ~~ under the License.
25 |
26 | Usage
27 |
28 | * Filter a <<>> of <<>>
29 |
30 | Lookup the component in your Mojo:
31 |
32 | +-----+
33 | @Required
34 | private MavenResourcesFiltering mavenResourcesFiltering;
35 | +-----+
36 |
37 | Apply filtering on your <<>> of resources, see {{{./index.html}Introduction}} for the default <<>>
38 | that are used.
39 |
40 | +-----+
41 | MavenResourcesExecution mavenResourcesExecution =
42 | new MavenResourcesExecution ( resources, outputDirectory, mavenProject,
43 | encoding, fileFilters,
44 | nonFilteredFileExtensions, mavenSession );
45 |
46 | mavenResourcesFiltering.filterResources( mavenResourcesExecution );
47 | +-----+
48 |
49 | * Add a new filtering token
50 |
51 | You must use the other methods from the <<>> component and construct your own <<>> of
52 | <<>>. The following example adds interpolation for the token @ @ using values coming from reflection
53 | with the Maven Project.
54 |
55 | +-----+
56 | // Create your FilterWrapper
57 | FileUtils.FilterWrapper filterWrapper = new FileUtils.FilterWrapper()
58 | {
59 | public Reader getReader( Reader reader )
60 | {
61 | Interpolator propertiesInterpolator =
62 | new RegexBasedInterpolator( "\\@", "(.+?)\\@" );
63 | ValueSource valueSource = new MavenProjectValueSource( mavenProject,
64 | true );
65 | propertiesInterpolator.addValueSource( valueSource );
66 | return new InterpolatorFilterReader( reader,
67 | propertiesInterpolator,
68 | "@", "@" );
69 | }
70 | };
71 |
72 | // Add the new filterWrapper to your MavenResourcesExecution instance
73 | mavenResourcesExecution.addFilterWrapper( filterWrapper );
74 | +-----+
75 |
76 | There is a helper method to simplify this. Here's how you would use it to do what we did above:
77 |
78 | +-----+
79 | mavenResourcesExecution.addFilerWrapper( new MavenProjectValueSource( mavenProject,
80 | true ),
81 | "\\@", "(.+?)\\@", "@", "@" );
82 | +-----+
83 |
84 | <> If <<>> is set to <<>>,
85 | the default <<>>s will be added first.
86 |
87 | Now it's time to filter the resources:
88 |
89 | +-----+
90 | // Apply filtering on your resources
91 | mavenResourcesFiltering.filterResources( mavenResourcesExecution );
92 | +-----+
93 |
94 | <> Maven Filtering uses the
95 | {{{http://codehaus-plexus.github.io/plexus-interpolation/}plexus-interpolation component}}.
96 |
97 |
--------------------------------------------------------------------------------
/src/site/resources/download.cgi:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | #
20 | # Just call the standard mirrors.cgi script. It will use download.html
21 | # as the input template.
22 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $*
--------------------------------------------------------------------------------
/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
21 |
22 |
23 |
24 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/src/site/xdoc/download.xml.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
21 |
22 |
23 |
24 | Download ${project.name} Source
25 |
26 |
27 |
28 |
29 | ${project.name} ${project.version} is distributed in source format. Use a source archive if you intend to build
30 | ${project.name} yourself. Otherwise, simply use the ready-made binary artifacts from central repository.
31 |
32 | You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24
33 | hours to reach all mirrors.
34 |
35 | In order to guard against corrupted downloads/installations, it is highly recommended to
36 | verify the signature
37 | of the release bundles against the public KEYS used by the Apache Maven
38 | developers.
39 |
40 | ${project.name} is distributed under the Apache License, version 2.0.
41 |
42 | We strongly encourage our users to configure a Maven repository mirror closer to their location, please read How to Use Mirrors for Repositories.
43 |
44 |
45 |
46 |
47 |
48 | [if-any logo]
49 |
50 |
52 |
53 | [end]
54 | The currently selected mirror is
55 | [preferred].
56 | If you encounter a problem with this mirror,
57 | please select another mirror.
58 | If all mirrors are failing, there are
59 | backup
60 | mirrors
61 | (at the end of the mirrors list) that should be available.
62 |
63 |
64 |
85 |
86 |
87 | You may also consult the
88 | complete list of
89 | mirrors.
90 |
91 |
92 |
93 |
94 |
95 |
96 | This is the current stable version of ${project.name}.
97 |
98 |
116 |
117 |
118 |
119 |
120 | Older non-recommended releases can be found on our archive site.
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/AbstractInterpolatorFilterReaderLineEndingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.IOException;
22 | import java.io.Reader;
23 | import java.io.StringReader;
24 |
25 | import org.codehaus.plexus.interpolation.Interpolator;
26 | import org.codehaus.plexus.interpolation.RecursionInterceptor;
27 | import org.junit.jupiter.api.Test;
28 | import org.junit.jupiter.api.extension.ExtendWith;
29 | import org.mockito.Mock;
30 | import org.mockito.junit.jupiter.MockitoExtension;
31 |
32 | import static org.junit.jupiter.api.Assertions.assertEquals;
33 | import static org.mockito.ArgumentMatchers.eq;
34 | import static org.mockito.ArgumentMatchers.isA;
35 | import static org.mockito.Mockito.when;
36 |
37 | @ExtendWith(MockitoExtension.class)
38 | public abstract class AbstractInterpolatorFilterReaderLineEndingTest {
39 |
40 | @Mock
41 | private Interpolator interpolator;
42 |
43 | @Test
44 | public void testDefaults() throws Exception {
45 | when(interpolator.interpolate(eq("${a}"), eq(""), isA(RecursionInterceptor.class)))
46 | .thenReturn("DONE_A");
47 |
48 | Reader in = new StringReader("text without expression");
49 | Reader reader = getDollarBracesReader(in, interpolator, "\\");
50 | assertEquals("text without expression", IOUtils.toString(reader));
51 |
52 | in = new StringReader("valid expression ${a}");
53 | reader = getDollarBracesReader(in, interpolator, null);
54 | assertEquals("valid expression DONE_A", IOUtils.toString(reader));
55 |
56 | in = new StringReader("empty expression ${}");
57 | reader = getDollarBracesReader(in, interpolator, null);
58 | assertEquals("empty expression ${}", IOUtils.toString(reader));
59 |
60 | in = new StringReader("dollar space expression $ {a}");
61 | reader = getDollarBracesReader(in, interpolator, "\\");
62 | assertEquals("dollar space expression $ {a}", IOUtils.toString(reader));
63 |
64 | in = new StringReader("space in expression ${ a}");
65 | reader = getDollarBracesReader(in, interpolator, "\\");
66 | assertEquals("space in expression ${ a}", IOUtils.toString(reader));
67 |
68 | in = new StringReader("escape dollar with expression \\${a}");
69 | reader = getDollarBracesReader(in, interpolator, "\\");
70 | assertEquals("escape dollar with expression ${a}", IOUtils.toString(reader));
71 |
72 | // in = new StringReader( "escape escape string before expression \\\\${a}" );
73 | // reader = getDollarBracesReader( in, interpolator, "\\" );
74 | // assertEquals( "escape escape string before expression \\DONE_A", toString( reader ) );
75 | //
76 | // in = new StringReader( "escape escape string and expression \\\\\\${a}" );
77 | // reader = getDollarBracesReader( in, interpolator, "\\" );
78 | // assertEquals( "escape escape string before expression \\${a}", toString( reader ) );
79 |
80 | in = new StringReader("unknown expression ${unknown}");
81 | reader = getDollarBracesReader(in, interpolator, "\\");
82 | assertEquals("unknown expression ${unknown}", IOUtils.toString(reader));
83 | }
84 |
85 | // MSHARED-198: custom delimiters doesn't work as expected
86 | @Test
87 | public void testCustomDelimiters() throws Exception {
88 | when(interpolator.interpolate(eq("aaaFILTER.a.MEaaa"), eq(""), isA(RecursionInterceptor.class)))
89 | .thenReturn("DONE");
90 | when(interpolator.interpolate(eq("abcFILTER.a.MEabc"), eq(""), isA(RecursionInterceptor.class)))
91 | .thenReturn("DONE");
92 |
93 | Reader in = new StringReader("aaaFILTER.a.MEaaa");
94 | Reader reader = getAaaAaaReader(in, interpolator);
95 |
96 | assertEquals("DONE", IOUtils.toString(reader));
97 |
98 | in = new StringReader("abcFILTER.a.MEabc");
99 | reader = getAbcAbcReader(in, interpolator);
100 | assertEquals("DONE", IOUtils.toString(reader));
101 | }
102 |
103 | // MSHARED-235: reader exceeds readAheadLimit
104 | @Test
105 | public void testMarkInvalid() throws IOException {
106 | try (Reader reader = getAtReader(new StringReader("@\").replace(p,\"]\").replace(q,\""), interpolator, "\\")) {
107 | assertEquals("@\").replace(p,\"]\").replace(q,\"", IOUtils.toString(reader));
108 | }
109 | }
110 |
111 | protected abstract Reader getAbcAbcReader(Reader in, Interpolator interpolator);
112 |
113 | protected abstract Reader getAaaAaaReader(Reader in, Interpolator interpolator);
114 |
115 | protected abstract Reader getDollarBracesReader(Reader in, Interpolator interpolator, String escapeString);
116 |
117 | protected abstract Reader getAtReader(Reader in, Interpolator interpolator, String escapeString);
118 | }
119 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/AbstractMavenFilteringRequestTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.util.LinkedHashSet;
22 |
23 | import org.hamcrest.Matchers;
24 | import org.junit.jupiter.api.Test;
25 |
26 | import static org.hamcrest.MatcherAssert.assertThat;
27 |
28 | /**
29 | * @author Karl Heinz Marbaise khmarbaise@apache.org.
30 | */
31 | public class AbstractMavenFilteringRequestTest {
32 |
33 | private final AbstractMavenFilteringRequest request = new AbstractMavenFilteringRequest();
34 | private final LinkedHashSet delimiters = new LinkedHashSet<>();
35 |
36 | @Test
37 | public void setDelimitersShouldNotChangeAnythingIfUsingNull() {
38 | request.setDelimiters(null, false);
39 | assertThat(request.getDelimiters(), Matchers.contains("${*}", "@"));
40 | }
41 |
42 | @Test
43 | public void setDelimitersShouldNotChangeAnythingIfUsingEmpty() {
44 | request.setDelimiters(delimiters, false);
45 | assertThat(request.getDelimiters(), Matchers.contains("${*}", "@"));
46 | }
47 |
48 | @Test
49 | public void setDelimitersShouldAddOnlyTheGivenDelimiter() {
50 | delimiters.add("test");
51 | request.setDelimiters(delimiters, false);
52 | assertThat(request.getDelimiters(), Matchers.contains("test"));
53 | }
54 |
55 | @Test
56 | public void setDelimitersShouldAddDefaultDelimitersForNullElements() {
57 | delimiters.add("test");
58 | delimiters.add(null);
59 | delimiters.add("second");
60 | request.setDelimiters(delimiters, false);
61 | assertThat(request.getDelimiters(), Matchers.contains("test", "${*}", "second"));
62 | }
63 |
64 | @Test
65 | public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNullGiven() {
66 | request.setDelimiters(null, true);
67 | assertThat(request.getDelimiters(), Matchers.contains("${*}", "@"));
68 | }
69 |
70 | @Test
71 | public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfNotNullGiven() {
72 | LinkedHashSet delimiters = new LinkedHashSet<>();
73 | request.setDelimiters(delimiters, true);
74 | assertThat(request.getDelimiters(), Matchers.contains("${*}", "@"));
75 | }
76 |
77 | @Test
78 | public void setDelimitersShouldAddDefaultDelimitersIfUseDefaultDelimitersIfSingleElementIsGiven() {
79 | delimiters.add("test");
80 | request.setDelimiters(delimiters, true);
81 | assertThat(request.getDelimiters(), Matchers.contains("${*}", "@", "test"));
82 | }
83 |
84 | @Test
85 | public void setDelimitersShouldAddDefaultDelimitersForNullElement() {
86 | delimiters.add("test");
87 | delimiters.add(null);
88 | delimiters.add("second");
89 | request.setDelimiters(delimiters, true);
90 | assertThat(request.getDelimiters(), Matchers.contains("${*}", "@", "test", "second"));
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/BoundedReaderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.BufferedReader;
22 | import java.io.IOException;
23 | import java.io.Reader;
24 | import java.io.StringReader;
25 | import java.util.Arrays;
26 |
27 | import org.junit.jupiter.api.Test;
28 |
29 | import static org.junit.jupiter.api.Assertions.assertEquals;
30 |
31 | public class BoundedReaderTest {
32 |
33 | private final Reader sr = new BufferedReader(new StringReader("01234567890"));
34 |
35 | @Test
36 | public void readTillEnd() throws IOException {
37 | try (BoundedReader mr = new BoundedReader(sr, 3)) {
38 | mr.mark(3);
39 | mr.read();
40 | mr.read();
41 | mr.read();
42 | assertEquals(-1, mr.read());
43 | }
44 | }
45 |
46 | @Test
47 | public void readMulti() throws IOException {
48 | char[] cbuf = new char[4];
49 | Arrays.fill(cbuf, 'X');
50 |
51 | try (BoundedReader mr = new BoundedReader(sr, 3)) {
52 | final int read = mr.read(cbuf, 0, 4);
53 | assertEquals(3, read);
54 | }
55 |
56 | assertEquals('0', cbuf[0]);
57 | assertEquals('1', cbuf[1]);
58 | assertEquals('2', cbuf[2]);
59 | assertEquals('X', cbuf[3]);
60 | }
61 |
62 | @Test
63 | public void readMultiWithOffset() throws IOException {
64 |
65 | char[] cbuf = new char[4];
66 | Arrays.fill(cbuf, 'X');
67 |
68 | try (BoundedReader mr = new BoundedReader(sr, 3)) {
69 | final int read = mr.read(cbuf, 1, 2);
70 | assertEquals(2, read);
71 | }
72 |
73 | assertEquals('X', cbuf[0]);
74 | assertEquals('0', cbuf[1]);
75 | assertEquals('1', cbuf[2]);
76 | assertEquals('X', cbuf[3]);
77 | }
78 |
79 | @Test
80 | public void resetWorks() throws IOException {
81 | try (BoundedReader mr = new BoundedReader(sr, 3)) {
82 | mr.read();
83 | mr.read();
84 | mr.read();
85 | mr.reset();
86 | mr.read();
87 | mr.read();
88 | mr.read();
89 | assertEquals(-1, mr.read());
90 | }
91 | }
92 |
93 | @Test
94 | public void skipTest() throws IOException {
95 | try (BoundedReader mr = new BoundedReader(sr, 3)) {
96 | mr.skip(2);
97 | mr.read();
98 | assertEquals(-1, mr.read());
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/DefaultMavenFileFilterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.File;
22 | import java.io.IOException;
23 | import java.io.Reader;
24 | import java.io.StringReader;
25 | import java.nio.file.Files;
26 | import java.nio.file.Path;
27 | import java.nio.file.Paths;
28 | import java.nio.file.attribute.FileTime;
29 | import java.util.ArrayList;
30 | import java.util.Arrays;
31 | import java.util.Collections;
32 | import java.util.LinkedHashSet;
33 | import java.util.List;
34 | import java.util.Properties;
35 |
36 | import org.apache.maven.api.di.Inject;
37 | import org.apache.maven.api.di.testing.MavenDITest;
38 | import org.apache.maven.api.model.Build;
39 | import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
40 | import org.apache.maven.di.Injector;
41 | import org.codehaus.plexus.interpolation.AbstractValueSource;
42 | import org.junit.jupiter.api.BeforeEach;
43 | import org.junit.jupiter.api.Test;
44 | import org.sonatype.plexus.build.incremental.BuildContext;
45 |
46 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
47 | import static org.junit.jupiter.api.Assertions.assertEquals;
48 | import static org.mockito.Mockito.mock;
49 |
50 | /**
51 | * @author Olivier Lamy
52 | *
53 | */
54 | @MavenDITest
55 | public class DefaultMavenFileFilterTest {
56 |
57 | @Inject
58 | Injector container;
59 |
60 | final Path to = Paths.get(getBasedir(), "target/reflection-test.properties");
61 |
62 | @BeforeEach
63 | protected void setUp() throws Exception {
64 | Files.deleteIfExists(to);
65 | }
66 |
67 | @Test
68 | public void testOverwriteFile() throws Exception {
69 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
70 |
71 | Path from = Paths.get(getBasedir(), "src/test/units-files/reflection-test.properties");
72 |
73 | mavenFileFilter.copyFile(from, to, false, null, null);
74 |
75 | from = Paths.get(getBasedir(), "src/test/units-files/reflection-test-older.properties");
76 |
77 | // very old file :-)
78 | Files.setLastModifiedTime(from, FileTime.fromMillis(1));
79 |
80 | Files.setLastModifiedTime(to, FileTime.fromMillis(System.currentTimeMillis()));
81 |
82 | mavenFileFilter.copyFile(from, to, false, null, null);
83 |
84 | Properties properties = PropertyUtils.loadPropertyFile(to, null);
85 | assertEquals("older file", properties.getProperty("version"));
86 | }
87 |
88 | @Test
89 | public void testNullSafeDefaultFilterWrappers() throws Exception {
90 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
91 |
92 | mavenFileFilter.getDefaultFilterWrappers(null, null, false, null, null);
93 |
94 | // shouldn't fail
95 | }
96 |
97 | @Test
98 | public void testMultiFilterFileInheritance() throws Exception {
99 | DefaultMavenFileFilter mavenFileFilter = new DefaultMavenFileFilter(mock(BuildContext.class));
100 |
101 | File testDir = new File(getBasedir(), "src/test/units-files/MSHARED-177");
102 |
103 | List filters = new ArrayList<>();
104 |
105 | filters.add(new File(testDir, "first_filter_file.properties").getAbsolutePath());
106 | filters.add(new File(testDir, "second_filter_file.properties").getAbsolutePath());
107 | filters.add(new File(testDir, "third_filter_file.properties").getAbsolutePath());
108 |
109 | final Properties filterProperties = new Properties();
110 |
111 | mavenFileFilter.loadProperties(filterProperties, Paths.get(getBasedir()), filters, new Properties());
112 |
113 | assertEquals("first and second", filterProperties.getProperty("third_filter_key"));
114 | }
115 |
116 | // MSHARED-161: DefaultMavenFileFilter.getDefaultFilterWrappers loads
117 | // filters from the current directory instead of using basedir
118 | @Test
119 | public void testMavenBasedir() throws Exception {
120 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
121 |
122 | AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest();
123 | req.setFileFilters(Collections.singletonList("src/main/filters/filefilter.properties"));
124 |
125 | ProjectStub mavenProject = new ProjectStub();
126 | mavenProject.setBasedir(Paths.get("src/test/units-files/MSHARED-161"));
127 | List filters = Collections.singletonList("src/main/filters/buildfilter.properties");
128 | mavenProject.setModel(mavenProject
129 | .getModel()
130 | .withBuild(Build.newBuilder().filters(filters).build()));
131 | req.setMavenProject(mavenProject);
132 | req.setInjectProjectBuildFilters(true);
133 |
134 | List wrappers = mavenFileFilter.getDefaultFilterWrappers(req);
135 |
136 | try (Reader reader = wrappers.get(0).getReader(new StringReader("${filefilter} ${buildfilter}"))) {
137 | assertEquals("true true", IOUtils.toString(reader));
138 | }
139 | }
140 |
141 | // MSHARED-198: custom delimiters doesn't work as expected
142 | @Test
143 | public void testCustomDelimiters() throws Exception {
144 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
145 |
146 | AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest();
147 | Properties additionalProperties = new Properties();
148 | additionalProperties.setProperty("FILTER.a.ME", "DONE");
149 | req.setAdditionalProperties(additionalProperties);
150 | req.setDelimiters(new LinkedHashSet<>(Arrays.asList("aaa*aaa", "abc*abc")));
151 |
152 | List wrappers = mavenFileFilter.getDefaultFilterWrappers(req);
153 |
154 | Reader reader = wrappers.get(0).getReader(new StringReader("aaaFILTER.a.MEaaa"));
155 | assertEquals("DONE", IOUtils.toString(reader));
156 |
157 | reader = wrappers.get(0).getReader(new StringReader("abcFILTER.a.MEabc"));
158 | assertEquals("DONE", IOUtils.toString(reader));
159 | }
160 |
161 | // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open
162 | @Test
163 | public void testLineWithSingleAtAndExpression() throws Exception {
164 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
165 |
166 | AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest();
167 | Properties additionalProperties = new Properties();
168 | additionalProperties.setProperty("foo", "bar");
169 | req.setAdditionalProperties(additionalProperties);
170 |
171 | List wrappers = mavenFileFilter.getDefaultFilterWrappers(req);
172 |
173 | try (Reader reader = wrappers.get(0).getReader(new StringReader("toto@titi.com ${foo}"))) {
174 | assertEquals("toto@titi.com bar", IOUtils.toString(reader));
175 | }
176 | }
177 |
178 | @Test
179 | void testInterpolatorCustomizer() throws MavenFilteringException, IOException {
180 | AbstractMavenFilteringRequest req = new AbstractMavenFilteringRequest();
181 | req.setInterpolatorCustomizer(i -> i.addValueSource(new AbstractValueSource(false) {
182 | @Override
183 | public Object getValue(String expression) {
184 | if (expression.equals("foo")) {
185 | return "bar";
186 | }
187 | return null;
188 | }
189 | }));
190 |
191 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
192 | List wrappers = mavenFileFilter.getDefaultFilterWrappers(req);
193 |
194 | try (Reader reader = wrappers.get(0).getReader(new StringReader("toto@titi.com ${foo}"))) {
195 | assertEquals("toto@titi.com bar", IOUtils.toString(reader));
196 | }
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/DefaultMavenReaderFilterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 | import java.io.StringReader;
23 | import java.util.Properties;
24 |
25 | import org.apache.maven.api.di.Inject;
26 | import org.apache.maven.api.di.testing.MavenDITest;
27 | import org.apache.maven.di.Injector;
28 | import org.junit.jupiter.api.Test;
29 |
30 | import static org.junit.jupiter.api.Assertions.assertEquals;
31 |
32 | /**
33 | * @author Kristian Rosenvold
34 | */
35 | @MavenDITest
36 | public class DefaultMavenReaderFilterTest {
37 | @Inject
38 | Injector container;
39 |
40 | @Test
41 | public void testJustDoSomeFiltering() throws Exception {
42 | MavenReaderFilter readerFilter = container.getInstance(MavenReaderFilter.class);
43 |
44 | StringReader src = new StringReader("toto@titi.com ${foo}");
45 | MavenReaderFilterRequest req = new MavenReaderFilterRequest();
46 | Properties additionalProperties = new Properties();
47 | additionalProperties.setProperty("foo", "bar");
48 | req.setFrom(src);
49 | req.setFiltering(true);
50 | req.setAdditionalProperties(additionalProperties);
51 |
52 | try (Reader filter = readerFilter.filter(req)) {
53 | assertEquals("toto@titi.com bar", IOUtils.toString(filter));
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/EscapeStringTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.nio.charset.StandardCharsets;
22 | import java.nio.file.Files;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 | import java.util.ArrayList;
26 | import java.util.Collections;
27 | import java.util.List;
28 |
29 | import org.apache.maven.api.di.Inject;
30 | import org.apache.maven.api.di.testing.MavenDITest;
31 | import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
32 | import org.apache.maven.di.Injector;
33 | import org.junit.jupiter.api.BeforeEach;
34 | import org.junit.jupiter.api.Test;
35 |
36 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
37 | import static org.junit.jupiter.api.Assertions.assertTrue;
38 |
39 | /**
40 | * @author Olivier Lamy
41 | */
42 | @MavenDITest
43 | public class EscapeStringTest {
44 |
45 | @Inject
46 | Injector container;
47 |
48 | final Path outputDirectory = Paths.get(getBasedir(), "target/EscapeStringTest");
49 |
50 | final Path unitDirectory = Paths.get(getBasedir(), "src/test/units-files/escape-remove-char");
51 |
52 | @BeforeEach
53 | protected void setUp() throws Exception {
54 | IOUtils.deleteDirectory(outputDirectory);
55 | Files.createDirectories(outputDirectory);
56 | }
57 |
58 | @Test
59 | public void testEscape() throws Exception {
60 | Path baseDir = Paths.get(getBasedir());
61 | ProjectStub mavenProject = new ProjectStub().setBasedir(baseDir);
62 | mavenProject.setVersion("1.0");
63 | mavenProject.setGroupId("org.apache");
64 | mavenProject.setName("test project");
65 |
66 | mavenProject.addProperty("foo", "bar");
67 | mavenProject.addProperty("java.version", "zloug");
68 | mavenProject.addProperty("replaceThis", "I am the replacement");
69 | MavenResourcesFiltering mavenResourcesFiltering = container.getInstance(MavenResourcesFiltering.class);
70 |
71 | Resource resource = new Resource();
72 | List resources = new ArrayList<>();
73 | resources.add(resource);
74 | resource.setDirectory(unitDirectory.toString());
75 | resource.setFiltering(true);
76 |
77 | List filtersFile = new ArrayList<>();
78 |
79 | List nonFilteredFileExtensions = Collections.singletonList("gif");
80 |
81 | MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
82 | resources,
83 | outputDirectory,
84 | mavenProject,
85 | "UTF-8",
86 | filtersFile,
87 | nonFilteredFileExtensions,
88 | new StubSession());
89 | mavenResourcesExecution.setUseDefaultFilterWrappers(true);
90 |
91 | mavenResourcesExecution.setEscapeString("!");
92 |
93 | mavenResourcesFiltering.filterResources(mavenResourcesExecution);
94 |
95 | Path file = outputDirectory.resolve("content.xml");
96 | String content = Files.readString(file, StandardCharsets.UTF_8);
97 | assertTrue(content.contains("Content with replacement: I am the replacement !"));
98 | assertTrue(
99 | content.contains("Content with escaped replacement: Do not ${replaceThis} !"));
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/FilteringUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.IOException;
22 | import java.io.Reader;
23 | import java.nio.charset.StandardCharsets;
24 | import java.nio.file.Files;
25 | import java.nio.file.Path;
26 | import java.nio.file.Paths;
27 | import java.nio.file.StandardCopyOption;
28 |
29 | import org.junit.jupiter.api.Test;
30 |
31 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
32 | import static org.junit.jupiter.api.Assertions.assertEquals;
33 |
34 | /**
35 | * @author John Casey
36 | * @author Dennis Lundberg
37 | * @since 1.0
38 | *
39 | */
40 | public class FilteringUtilsTest {
41 | private static final Path TEST_DIRECTORY = Paths.get(getBasedir(), "target/test-classes/");
42 |
43 | @Test
44 | public void testMSHARED1213CopyWithTargetAlreadyExisting0ByteFile() throws IOException {
45 | Path fromFile = Paths.get(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml");
46 | Path toFile = TEST_DIRECTORY.resolve("MSHARED-1213-enunciate.xml");
47 | Files.writeString(toFile, "");
48 | FilteringUtils.copyFile(
49 | fromFile,
50 | toFile,
51 | "UTF-8",
52 | new FilterWrapper[] {
53 | new FilterWrapper() {
54 | @Override
55 | public Reader getReader(Reader fileReader) {
56 | return fileReader;
57 | }
58 | }
59 | },
60 | false);
61 | assertEquals(
62 | Files.readAllLines(fromFile, StandardCharsets.UTF_8),
63 | Files.readAllLines(toFile, StandardCharsets.UTF_8));
64 | }
65 |
66 | @Test
67 | public void testMSHARED1213CopyWithTargetAlreadyExistingJunkFile() throws IOException {
68 | Path fromFile = Paths.get(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml");
69 | Path toFile = TEST_DIRECTORY.resolve("MSHARED-1213-enunciate.xml");
70 | Files.writeString(toFile, "junk");
71 | FilteringUtils.copyFile(
72 | fromFile,
73 | toFile,
74 | "UTF-8",
75 | new FilterWrapper[] {
76 | new FilterWrapper() {
77 | @Override
78 | public Reader getReader(Reader fileReader) {
79 | return fileReader;
80 | }
81 | }
82 | },
83 | false);
84 | assertEquals(
85 | Files.readAllLines(fromFile, StandardCharsets.UTF_8),
86 | Files.readAllLines(toFile, StandardCharsets.UTF_8));
87 | }
88 |
89 | @Test
90 | public void testMSHARED1213CopyWithTargetAlreadyExistingSameFile() throws IOException {
91 | Path fromFile = Paths.get(getBasedir() + "/src/test/units-files/MSHARED-1213/enunciate.xml");
92 | Path toFile = TEST_DIRECTORY.resolve("MSHARED-1213-enunciate.xml");
93 | Files.copy(fromFile, toFile, StandardCopyOption.REPLACE_EXISTING);
94 | FilteringUtils.copyFile(
95 | fromFile,
96 | toFile,
97 | "UTF-8",
98 | new FilterWrapper[] {
99 | new FilterWrapper() {
100 | @Override
101 | public Reader getReader(Reader fileReader) {
102 | return fileReader;
103 | }
104 | }
105 | },
106 | false);
107 | assertEquals(
108 | Files.readAllLines(fromFile, StandardCharsets.UTF_8),
109 | Files.readAllLines(toFile, StandardCharsets.UTF_8));
110 | }
111 |
112 | @Test
113 | public void testEscapeWindowsPathStartingWithDrive() {
114 | assertEquals("C:\\\\Users\\\\Administrator", FilteringUtils.escapeWindowsPath("C:\\Users\\Administrator"));
115 | }
116 |
117 | @Test
118 | public void testEscapeWindowsPathMissingDriveLetter() {
119 | assertEquals(":\\Users\\Administrator", FilteringUtils.escapeWindowsPath(":\\Users\\Administrator"));
120 | }
121 |
122 | @Test
123 | public void testEscapeWindowsPathInvalidDriveLetter() {
124 | assertEquals("4:\\Users\\Administrator", FilteringUtils.escapeWindowsPath("4:\\Users\\Administrator"));
125 | }
126 |
127 | // This doesn't work, see MSHARED-121
128 | /*
129 | * public void testEscapeWindowsPathStartingWithDrivelessAbsolutePath()
130 | * {
131 | * assertEquals( "\\\\Users\\\\Administrator", FilteringUtils.escapeWindowsPath( "\\Users\\Administrator" ) );
132 | * }
133 | */
134 |
135 | // This doesn't work, see MSHARED-121
136 | /*
137 | * public void testEscapeWindowsPathStartingWithExpression()
138 | * {
139 | * assertEquals( "${pathExpr}\\\\Documents", FilteringUtils.escapeWindowsPath( "${pathExpr}\\Documents" ) );
140 | * }
141 | */
142 |
143 | // MSHARED-179
144 | @Test
145 | public void testEscapeWindowsPathNotAtBeginning() {
146 | assertEquals(
147 | "jdbc:derby:C:\\\\Users\\\\Administrator/test;create=true",
148 | FilteringUtils.escapeWindowsPath("jdbc:derby:C:\\Users\\Administrator/test;create=true"));
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/IOUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.File;
22 | import java.io.IOException;
23 | import java.io.Reader;
24 | import java.io.StringWriter;
25 | import java.nio.file.Files;
26 | import java.nio.file.Path;
27 | import java.util.Comparator;
28 | import java.util.stream.Stream;
29 |
30 | class IOUtils {
31 |
32 | static String toString(Reader r) throws IOException {
33 | StringWriter sw = new StringWriter();
34 | r.transferTo(sw);
35 | return sw.toString();
36 | }
37 |
38 | public static void deleteDirectory(Path rootPath) throws IOException {
39 | if (Files.isDirectory(rootPath)) {
40 | try (Stream walk = Files.walk(rootPath)) {
41 | walk.sorted(Comparator.reverseOrder())
42 | .map(Path::toFile)
43 | .peek(System.out::println)
44 | .forEach(File::delete);
45 | }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/IncrementalResourceFilteringTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.nio.file.Files;
24 | import java.nio.file.Path;
25 | import java.nio.file.Paths;
26 | import java.util.ArrayList;
27 | import java.util.Collections;
28 | import java.util.HashSet;
29 | import java.util.List;
30 | import java.util.Properties;
31 | import java.util.Set;
32 |
33 | import org.apache.maven.api.di.Inject;
34 | import org.apache.maven.api.di.testing.MavenDITest;
35 | import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
36 | import org.apache.maven.di.Injector;
37 | import org.codehaus.plexus.util.FileUtils;
38 | import org.junit.jupiter.api.AfterEach;
39 | import org.junit.jupiter.api.BeforeEach;
40 | import org.junit.jupiter.api.Test;
41 | import org.sonatype.plexus.build.incremental.ThreadBuildContext;
42 |
43 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
44 | import static org.junit.jupiter.api.Assertions.assertEquals;
45 | import static org.junit.jupiter.api.Assertions.assertFalse;
46 | import static org.junit.jupiter.api.Assertions.assertTrue;
47 |
48 | @MavenDITest
49 | public class IncrementalResourceFilteringTest {
50 |
51 | final Path baseDirectory = Paths.get(getBasedir());
52 | final Path outputDirectory = baseDirectory.resolve("target/IncrementalResourceFilteringTest");
53 | final Path unitDirectory = baseDirectory.resolve("src/test/units-files/incremental");
54 | final Path filters = unitDirectory.resolve("filters.txt");
55 | final Path inputFile01 = unitDirectory.resolve("files/file01.txt");
56 | Path inputFile02 = unitDirectory.resolve("files/file02.txt");
57 | final Path outputFile01 = outputDirectory.resolve("file01.txt");
58 | final Path outputFile02 = outputDirectory.resolve("file02.txt");
59 |
60 | @Inject
61 | Injector container;
62 |
63 | @BeforeEach
64 | protected void setUp() throws Exception {
65 | FileUtils.deleteDirectory(outputDirectory.toFile());
66 | Files.createDirectories(outputDirectory);
67 | }
68 |
69 | @AfterEach
70 | protected void tearDown() {
71 | ThreadBuildContext.setThreadBuildContext(null);
72 | }
73 |
74 | @Test
75 | public void testSimpleIncrementalFiltering() throws Exception {
76 | // run full build first
77 | filter("time");
78 |
79 | assertTime("time", "file01.txt");
80 | assertTime("time", "file02.txt");
81 |
82 | // only one file is expected to change
83 | Set changedFiles = new HashSet<>();
84 | changedFiles.add(inputFile01);
85 |
86 | TestIncrementalBuildContext ctx = new TestIncrementalBuildContext(baseDirectory, changedFiles);
87 | ThreadBuildContext.setThreadBuildContext(ctx);
88 |
89 | filter("notime");
90 | assertTime("notime", "file01.txt");
91 | assertTime("time", "file02.txt"); // this one is unchanged
92 |
93 | assertTrue(ctx.getRefreshFiles().contains(outputFile01));
94 |
95 | // only one file is expected to change
96 | Set deletedFiles = new HashSet<>();
97 | deletedFiles.add(inputFile01);
98 |
99 | ctx = new TestIncrementalBuildContext(baseDirectory, null, deletedFiles);
100 | ThreadBuildContext.setThreadBuildContext(ctx);
101 |
102 | filter("moretime");
103 | assertFalse(outputFile01.toFile().exists());
104 | assertTime("time", "file02.txt"); // this one is unchanged
105 |
106 | assertTrue(ctx.getRefreshFiles().contains(outputFile01));
107 | }
108 |
109 | @Test
110 | public void testOutputChange() throws Exception {
111 | // run full build first
112 | filter("time");
113 |
114 | // all files are reprocessed after contents of output directory changed (e.g. was deleted)
115 | Set changedFiles = new HashSet<>();
116 | changedFiles.add(outputDirectory);
117 | TestIncrementalBuildContext ctx = new TestIncrementalBuildContext(baseDirectory, changedFiles);
118 | ThreadBuildContext.setThreadBuildContext(ctx);
119 |
120 | filter("notime");
121 | assertTime("notime", "file01.txt");
122 | assertTime("notime", "file02.txt");
123 |
124 | assertTrue(ctx.getRefreshFiles().contains(outputFile01));
125 | assertTrue(ctx.getRefreshFiles().contains(outputFile02));
126 | }
127 |
128 | @Test
129 | public void testFilterChange() throws Exception {
130 | // run full build first
131 | filter("time");
132 |
133 | // all files are reprocessed after content of filters changes
134 | Set changedFiles = new HashSet<>();
135 | changedFiles.add(filters);
136 | TestIncrementalBuildContext ctx = new TestIncrementalBuildContext(baseDirectory, changedFiles);
137 | ThreadBuildContext.setThreadBuildContext(ctx);
138 |
139 | filter("notime");
140 | assertTime("notime", "file01.txt");
141 | assertTime("notime", "file02.txt");
142 |
143 | assertTrue(ctx.getRefreshFiles().contains(outputFile01));
144 | assertTrue(ctx.getRefreshFiles().contains(outputFile02));
145 | }
146 |
147 | @Test
148 | public void testFilterDeleted() throws Exception {
149 | // run full build first
150 | filter("time");
151 |
152 | // all files are reprocessed after content of filters changes
153 | Set deletedFiles = new HashSet<>();
154 | deletedFiles.add(filters);
155 | TestIncrementalBuildContext ctx = new TestIncrementalBuildContext(unitDirectory, null, deletedFiles);
156 | ThreadBuildContext.setThreadBuildContext(ctx);
157 |
158 | filter("notime");
159 | assertTime("notime", "file01.txt");
160 | assertTime("notime", "file02.txt");
161 |
162 | assertTrue(ctx.getRefreshFiles().contains(outputFile01));
163 | assertTrue(ctx.getRefreshFiles().contains(outputFile02));
164 | }
165 |
166 | private void assertTime(String time, String relpath) throws IOException {
167 | Properties properties = new Properties();
168 |
169 | try (InputStream is = Files.newInputStream(outputDirectory.resolve(relpath))) {
170 | properties.load(is);
171 | }
172 |
173 | assertEquals(time, properties.getProperty("time"));
174 | }
175 |
176 | private void filter(String time) throws Exception {
177 | Path baseDir = Paths.get(getBasedir());
178 | ProjectStub mavenProject = new ProjectStub().setBasedir(baseDir);
179 | mavenProject.setVersion("1.0");
180 | mavenProject.setGroupId("org.apache");
181 | mavenProject.setName("test project");
182 |
183 | mavenProject.addProperty("time", time);
184 | mavenProject.addProperty("java.version", "zloug");
185 | MavenResourcesFiltering mavenResourcesFiltering = container.getInstance(MavenResourcesFiltering.class);
186 |
187 | String unitFilesDir = unitDirectory.resolve("files").toString();
188 |
189 | Resource resource = new Resource();
190 | List resources = new ArrayList<>();
191 | resources.add(resource);
192 | resource.setDirectory(unitFilesDir);
193 | resource.setFiltering(true);
194 |
195 | List filtersFile = new ArrayList<>();
196 | filtersFile.add(unitDirectory.resolve("filters.txt").toString());
197 |
198 | MavenResourcesExecution mre = new MavenResourcesExecution();
199 | mre.setResources(resources);
200 | mre.setOutputDirectory(outputDirectory);
201 | mre.setEncoding("UTF-8");
202 | mre.setMavenProject(mavenProject);
203 | mre.setFilters(filtersFile);
204 | mre.setNonFilteredFileExtensions(Collections.emptyList());
205 | mre.setMavenSession(new StubSession());
206 | mre.setUseDefaultFilterWrappers(true);
207 |
208 | mavenResourcesFiltering.filterResources(mre);
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/InterpolatorFilterReaderLineEndingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 |
23 | import org.codehaus.plexus.interpolation.Interpolator;
24 |
25 | public class InterpolatorFilterReaderLineEndingTest extends AbstractInterpolatorFilterReaderLineEndingTest {
26 | @Override
27 | protected Reader getAaaAaaReader(Reader in, Interpolator interpolator) {
28 | return new InterpolatorFilterReaderLineEnding(in, interpolator, "aaa", "aaa", true);
29 | }
30 |
31 | @Override
32 | protected Reader getAbcAbcReader(Reader in, Interpolator interpolator) {
33 | return new InterpolatorFilterReaderLineEnding(in, interpolator, "abc", "abc", true);
34 | }
35 |
36 | @Override
37 | protected Reader getDollarBracesReader(Reader in, Interpolator interpolator, String escapeString) {
38 | InterpolatorFilterReaderLineEnding reader =
39 | new InterpolatorFilterReaderLineEnding(in, interpolator, "${", "}", true);
40 | reader.setEscapeString(escapeString);
41 | return reader;
42 | }
43 |
44 | @Override
45 | protected Reader getAtReader(Reader in, Interpolator interpolator, String escapeString) {
46 | InterpolatorFilterReaderLineEnding reader =
47 | new InterpolatorFilterReaderLineEnding(in, interpolator, "@", "@", true);
48 | reader.setEscapeString(escapeString);
49 | return reader;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/InvalidMarkTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.nio.file.Files;
22 | import java.nio.file.Path;
23 | import java.nio.file.Paths;
24 | import java.util.Collections;
25 |
26 | import org.apache.maven.api.di.Inject;
27 | import org.apache.maven.api.di.testing.MavenDITest;
28 | import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
29 | import org.apache.maven.di.Injector;
30 | import org.junit.jupiter.api.BeforeEach;
31 | import org.junit.jupiter.api.Test;
32 |
33 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
34 | import static org.junit.jupiter.api.Assertions.fail;
35 |
36 | /**
37 | * @author Mikolaj Izdebski
38 | */
39 | @MavenDITest
40 | public class InvalidMarkTest {
41 |
42 | @Inject
43 | Injector container;
44 |
45 | final Path outputDirectory = Paths.get(getBasedir(), "target/LongLineTest");
46 |
47 | @BeforeEach
48 | protected void setUp() throws Exception {
49 | if (Files.exists(outputDirectory)) {
50 | IOUtils.deleteDirectory(outputDirectory);
51 | }
52 | Files.createDirectories(outputDirectory);
53 | }
54 |
55 | @Test
56 | public void testEscape() {
57 | MavenResourcesFiltering mavenResourcesFiltering = container.getInstance(MavenResourcesFiltering.class);
58 |
59 | Resource resource = new Resource();
60 | resource.setDirectory("src/test/units-files/MSHARED-325");
61 | resource.setFiltering(true);
62 |
63 | MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
64 | Collections.singletonList(resource),
65 | outputDirectory,
66 | new ProjectStub().setBasedir(Paths.get(".")),
67 | "UTF-8",
68 | Collections.emptyList(),
69 | Collections.emptyList(),
70 | new StubSession());
71 |
72 | try {
73 | mavenResourcesFiltering.filterResources(mavenResourcesExecution);
74 | } catch (MavenFilteringException e) {
75 | fail();
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/MuliLinesMavenResourcesFilteringTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.InputStream;
22 | import java.nio.file.Files;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 | import java.util.ArrayList;
26 | import java.util.Collections;
27 | import java.util.List;
28 | import java.util.Properties;
29 |
30 | import org.apache.maven.api.di.Inject;
31 | import org.apache.maven.api.di.testing.MavenDITest;
32 | import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
33 | import org.apache.maven.di.Injector;
34 | import org.junit.jupiter.api.BeforeEach;
35 | import org.junit.jupiter.api.Test;
36 |
37 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
38 | import static org.junit.jupiter.api.Assertions.assertEquals;
39 |
40 | /**
41 | * @author Olivier Lamy
42 | *
43 | */
44 | @MavenDITest
45 | public class MuliLinesMavenResourcesFilteringTest {
46 |
47 | @Inject
48 | Injector container;
49 |
50 | final Path outputDirectory = Paths.get(getBasedir(), "target/MuliLinesMavenResourcesFilteringTest");
51 |
52 | @BeforeEach
53 | protected void setUp() throws Exception {
54 | IOUtils.deleteDirectory(outputDirectory);
55 | Files.createDirectories(outputDirectory);
56 | }
57 |
58 | /**
59 | */
60 | @Test
61 | public void testFilteringTokenOnce() throws Exception {
62 | Path baseDir = Paths.get(getBasedir());
63 | ProjectStub mavenProject = new ProjectStub().setBasedir(baseDir);
64 | mavenProject.setVersion("1.0");
65 | mavenProject.setGroupId("org.apache");
66 | mavenProject.setName("test project");
67 |
68 | mavenProject.addProperty("foo", "bar");
69 | mavenProject.addProperty("java.version", "zloug");
70 | MavenResourcesFiltering mavenResourcesFiltering = container.getInstance(MavenResourcesFiltering.class);
71 |
72 | String unitFilesDir = getBasedir() + "/src/test/units-files/MRESOURCES-104";
73 |
74 | Resource resource = new Resource();
75 | List resources = new ArrayList<>();
76 | resources.add(resource);
77 | resource.setDirectory(unitFilesDir);
78 | resource.setFiltering(true);
79 |
80 | List filtersFile = new ArrayList<>();
81 | filtersFile.add(getBasedir() + "/src/test/units-files/MRESOURCES-104/test.properties");
82 |
83 | List nonFilteredFileExtensions = Collections.singletonList("gif");
84 |
85 | MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
86 | resources,
87 | outputDirectory,
88 | mavenProject,
89 | "UTF-8",
90 | filtersFile,
91 | nonFilteredFileExtensions,
92 | new StubSession());
93 | mavenResourcesExecution.setUseDefaultFilterWrappers(true);
94 |
95 | mavenResourcesFiltering.filterResources(mavenResourcesExecution);
96 |
97 | Properties result = new Properties();
98 |
99 | try (InputStream in = Files.newInputStream(outputDirectory.resolve("test.properties"))) {
100 | result.load(in);
101 | }
102 |
103 | // email=foo@bar.com
104 | // foo=${project.version}
105 | // bar=@project.version@
106 | assertEquals("1.0", result.get("foo"));
107 | assertEquals("1.0", result.get("bar"));
108 | assertEquals("foo@bar.com", result.get("email"));
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/MultiDelimiterInterpolatorFilterReaderLineEndingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.Reader;
22 | import java.io.StringReader;
23 | import java.util.Arrays;
24 | import java.util.Collections;
25 | import java.util.HashSet;
26 |
27 | import org.codehaus.plexus.interpolation.Interpolator;
28 | import org.codehaus.plexus.interpolation.RecursionInterceptor;
29 | import org.junit.jupiter.api.Test;
30 | import org.junit.jupiter.api.extension.ExtendWith;
31 | import org.mockito.Mock;
32 | import org.mockito.junit.jupiter.MockitoExtension;
33 |
34 | import static org.junit.jupiter.api.Assertions.assertEquals;
35 | import static org.mockito.ArgumentMatchers.eq;
36 | import static org.mockito.ArgumentMatchers.isA;
37 | import static org.mockito.Mockito.when;
38 |
39 | @ExtendWith(MockitoExtension.class)
40 | public class MultiDelimiterInterpolatorFilterReaderLineEndingTest
41 | extends AbstractInterpolatorFilterReaderLineEndingTest {
42 |
43 | @Mock
44 | private Interpolator interpolator;
45 |
46 | @Override
47 | protected Reader getAaaAaaReader(Reader in, Interpolator interpolator) {
48 | MultiDelimiterInterpolatorFilterReaderLineEnding reader =
49 | new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
50 | reader.setDelimiterSpecs(Collections.singleton("aaa*aaa"));
51 | return reader;
52 | }
53 |
54 | @Override
55 | protected Reader getAbcAbcReader(Reader in, Interpolator interpolator) {
56 | MultiDelimiterInterpolatorFilterReaderLineEnding reader =
57 | new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
58 | reader.setDelimiterSpecs(Collections.singleton("abc*abc"));
59 | return reader;
60 | }
61 |
62 | @Override
63 | protected Reader getDollarBracesReader(Reader in, Interpolator interpolator, String escapeString) {
64 | MultiDelimiterInterpolatorFilterReaderLineEnding reader =
65 | new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
66 | reader.setDelimiterSpecs(Collections.singleton("${*}"));
67 | reader.setEscapeString(escapeString);
68 | return reader;
69 | }
70 |
71 | @Override
72 | protected Reader getAtReader(Reader in, Interpolator interpolator, String escapeString) {
73 | MultiDelimiterInterpolatorFilterReaderLineEnding reader =
74 | new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
75 | reader.setDelimiterSpecs(Collections.singleton("@"));
76 | reader.setEscapeString(escapeString);
77 | return reader;
78 | }
79 |
80 | // MSHARED-199: Filtering doesn't work if 2 delimiters are used on the same line, the first one being left open
81 | @Test
82 | public void testLineWithSingleAtAndExpression() throws Exception {
83 | when(interpolator.interpolate(eq("${foo}"), eq(""), isA(RecursionInterceptor.class)))
84 | .thenReturn("bar");
85 |
86 | Reader in = new StringReader("toto@titi.com ${foo}");
87 | MultiDelimiterInterpolatorFilterReaderLineEnding reader =
88 | new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
89 | reader.setDelimiterSpecs(new HashSet<>(Arrays.asList("${*}", "@")));
90 |
91 | assertEquals("toto@titi.com bar", IOUtils.toString(reader));
92 | }
93 |
94 | // http://stackoverflow.com/questions/21786805/maven-war-plugin-customize-filter-delimitters-in-webresources/
95 | @Test
96 | public void testAtDollarExpression() throws Exception {
97 | when(interpolator.interpolate(eq("${db.server}"), eq(""), isA(RecursionInterceptor.class)))
98 | .thenReturn("DB_SERVER");
99 | when(interpolator.interpolate(eq("${db.port}"), eq(""), isA(RecursionInterceptor.class)))
100 | .thenReturn("DB_PORT");
101 | when(interpolator.interpolate(eq("${db.name}"), eq(""), isA(RecursionInterceptor.class)))
102 | .thenReturn("DB_NAME");
103 |
104 | Reader in = new StringReader(" url=\"jdbc:oracle:thin:\\@${db.server}:${db.port}:${db.name}\"");
105 | MultiDelimiterInterpolatorFilterReaderLineEnding reader =
106 | new MultiDelimiterInterpolatorFilterReaderLineEnding(in, interpolator, true);
107 | reader.setEscapeString("\\");
108 | reader.setDelimiterSpecs(new HashSet<>(Arrays.asList("${*}", "@")));
109 |
110 | assertEquals(" url=\"jdbc:oracle:thin:@DB_SERVER:DB_PORT:DB_NAME\"", IOUtils.toString(reader));
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.IOException;
22 | import java.io.Writer;
23 | import java.nio.file.Files;
24 | import java.nio.file.Path;
25 | import java.nio.file.Paths;
26 | import java.util.List;
27 | import java.util.Properties;
28 |
29 | import org.apache.maven.api.di.testing.MavenDITest;
30 | import org.junit.jupiter.api.Test;
31 | import org.mockito.ArgumentCaptor;
32 | import org.slf4j.Logger;
33 |
34 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
35 | import static org.junit.jupiter.api.Assertions.assertEquals;
36 | import static org.junit.jupiter.api.Assertions.assertFalse;
37 | import static org.junit.jupiter.api.Assertions.assertThrows;
38 | import static org.junit.jupiter.api.Assertions.assertTrue;
39 | import static org.mockito.Mockito.mock;
40 | import static org.mockito.Mockito.times;
41 | import static org.mockito.Mockito.verify;
42 |
43 | /**
44 | * @author Olivier Lamy
45 | * @since 1.0-beta-1
46 | */
47 | @MavenDITest
48 | public class PropertyUtilsTest {
49 | private static final Path TEST_DIRECTORY = Paths.get(getBasedir(), "target/test-classes/");
50 |
51 | @Test
52 | public void testBasic() throws Exception {
53 | Path basicProp = TEST_DIRECTORY.resolve("basic.properties");
54 |
55 | Files.deleteIfExists(basicProp);
56 |
57 | try (Writer writer = Files.newBufferedWriter(basicProp)) {
58 | writer.write("ghost=${non_existent}\n");
59 | writer.write("key=${untat_na_damgo}\n");
60 | writer.write("untat_na_damgo=gani_man\n");
61 | writer.flush();
62 | }
63 |
64 | Properties prop = PropertyUtils.loadPropertyFile(basicProp, false, false);
65 | assertEquals("gani_man", prop.getProperty("key"));
66 | assertEquals("${non_existent}", prop.getProperty("ghost"));
67 | }
68 |
69 | @Test
70 | public void testSystemProperties() throws Exception {
71 | Path systemProp = TEST_DIRECTORY.resolve("system.properties");
72 |
73 | Files.deleteIfExists(systemProp);
74 |
75 | try (Writer writer = Files.newBufferedWriter(systemProp)) {
76 | writer.write("key=${user.dir}");
77 | writer.flush();
78 | }
79 |
80 | Properties prop = PropertyUtils.loadPropertyFile(systemProp, false, true);
81 | assertEquals(prop.getProperty("key"), System.getProperty("user.dir"));
82 | }
83 |
84 | @Test
85 | public void testException() {
86 | Path nonExistent = TEST_DIRECTORY.resolve("not_existent_file");
87 |
88 | assertFalse(Files.exists(nonExistent), "property file exist: " + nonExistent);
89 |
90 | assertThrows(Exception.class, () -> PropertyUtils.loadPropertyFile(nonExistent, true, false));
91 | }
92 |
93 | @Test
94 | public void testloadpropertiesFile() throws Exception {
95 | Path propertyFile = Paths.get(getBasedir() + "/src/test/units-files/propertyutils-test.properties");
96 | Properties baseProps = new Properties();
97 | baseProps.put("pom.version", "realVersion");
98 |
99 | Properties interpolated = PropertyUtils.loadPropertyFile(propertyFile, baseProps);
100 | assertEquals("realVersion", interpolated.get("version"));
101 | assertEquals("${foo}", interpolated.get("foo"));
102 | assertEquals("realVersion", interpolated.get("bar"));
103 | assertEquals("none filtered", interpolated.get("none"));
104 | }
105 |
106 | /**
107 | * Test case to reproduce MSHARED-417
108 | *
109 | * @throws IOException if problem writing file
110 | */
111 | @Test
112 | public void testCircularReferences() throws IOException {
113 | Path basicProp = TEST_DIRECTORY.resolve("circular.properties");
114 |
115 | Files.deleteIfExists(basicProp);
116 |
117 | try (Writer writer = Files.newBufferedWriter(basicProp)) {
118 | writer.write("test=${test2}\n");
119 | writer.write("test2=${test2}\n");
120 | writer.flush();
121 | }
122 |
123 | Logger logger = mock(Logger.class);
124 |
125 | Properties prop = PropertyUtils.loadPropertyFile(basicProp, null, logger);
126 | assertEquals("${test2}", prop.getProperty("test"));
127 | assertEquals("${test2}", prop.getProperty("test2"));
128 | assertWarn(
129 | logger,
130 | "Circular reference between properties detected: test2 => test2",
131 | "Circular reference between properties detected: test => test2 => test2");
132 | }
133 |
134 | /**
135 | * Test case to reproduce MSHARED-417
136 | *
137 | * @throws IOException if problem writing file
138 | */
139 | @Test
140 | public void testCircularReferences3Vars() throws IOException {
141 | Path basicProp = TEST_DIRECTORY.resolve("circular.properties");
142 |
143 | Files.deleteIfExists(basicProp);
144 |
145 | try (Writer writer = Files.newBufferedWriter(basicProp)) {
146 | writer.write("test=${test2}\n");
147 | writer.write("test2=${test3}\n");
148 | writer.write("test3=${test}\n");
149 | writer.flush();
150 | }
151 |
152 | Logger logger = mock(Logger.class);
153 |
154 | Properties prop = PropertyUtils.loadPropertyFile(basicProp, null, logger);
155 | assertEquals("${test2}", prop.getProperty("test"));
156 | assertEquals("${test3}", prop.getProperty("test2"));
157 | assertEquals("${test}", prop.getProperty("test3"));
158 | assertWarn(
159 | logger,
160 | "Circular reference between properties detected: test3 => test => test2 => test3",
161 | "Circular reference between properties detected: test2 => test3 => test => test2",
162 | "Circular reference between properties detected: test => test2 => test3 => test");
163 | }
164 |
165 | private void assertWarn(Logger mock, String... expected) {
166 | ArgumentCaptor argument = ArgumentCaptor.forClass(String.class);
167 | verify(mock, times(expected.length)).warn(argument.capture());
168 | List messages = argument.getAllValues();
169 | for (String str : expected) {
170 | assertTrue(messages.contains(str));
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/Providers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import org.apache.maven.api.di.Named;
22 | import org.apache.maven.api.di.Provides;
23 | import org.sonatype.plexus.build.incremental.BuildContext;
24 | import org.sonatype.plexus.build.incremental.ThreadBuildContext;
25 |
26 | @Named
27 | class Providers {
28 |
29 | @Provides
30 | static BuildContext buildContext() {
31 | return new ThreadBuildContext();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/TestIncrementalBuildContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.File;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.io.OutputStream;
25 | import java.nio.file.Path;
26 | import java.util.Collections;
27 | import java.util.Comparator;
28 | import java.util.HashMap;
29 | import java.util.HashSet;
30 | import java.util.List;
31 | import java.util.Map;
32 | import java.util.Optional;
33 | import java.util.Set;
34 |
35 | import org.codehaus.plexus.util.DirectoryScanner;
36 | import org.codehaus.plexus.util.Scanner;
37 | import org.sonatype.plexus.build.incremental.BuildContext;
38 |
39 | /**
40 | * {@link TestIncrementalBuildContext} mock for testing purpose. It allows to
41 | * check build behavior based on {@link #isUptodate(File, File)} return value.
42 | *
43 | * Constructor parameters allow to indicate folder/files to declare files as
44 | * modified / deleted.
45 | *
46 | * hasDelta, isUptodate, newScanner, newDeleteScanner methods output consistent
47 | * values based upon changedFiles / deletedFiles inputs.
48 | *
49 | * getRefreshFiles method allows to check files modified by build.
50 | */
51 | public class TestIncrementalBuildContext implements BuildContext {
52 |
53 | private final Path basedir;
54 | private final Set refresh = new HashSet<>();
55 | private final Set changedFiles = new HashSet<>();
56 | private final Set deletedFiles = new HashSet<>();
57 | private final Map context = new HashMap<>();
58 |
59 | public TestIncrementalBuildContext(Path basedir, Set changedFiles) {
60 | this(basedir, changedFiles, null);
61 | }
62 |
63 | public TestIncrementalBuildContext(Path basedir, Set changedFiles, Set deletedFiles) {
64 | checkPath(basedir);
65 | this.basedir = basedir;
66 | Optional.ofNullable(changedFiles).ifPresent(this.changedFiles::addAll);
67 | Optional.ofNullable(deletedFiles).ifPresent(this.deletedFiles::addAll);
68 | this.changedFiles.forEach(TestIncrementalBuildContext::checkPath);
69 | this.deletedFiles.forEach(TestIncrementalBuildContext::checkPath);
70 | }
71 |
72 | public static void checkPath(Path path) {
73 | if (!path.isAbsolute()) {
74 | throw new IllegalStateException(String.format("Absolute path are expected. Failing path %s", path));
75 | }
76 | }
77 |
78 | public Set getRefreshFiles() {
79 | return Collections.unmodifiableSet(refresh);
80 | }
81 |
82 | /**
83 | * Check that relpath or parent folders of relpath is not listed in modified /
84 | * deleted files.
85 | */
86 | @Override
87 | public boolean hasDelta(String relpath) {
88 | Path candidate = basedir.resolve(relpath);
89 | boolean changed = false;
90 | while (candidate != null) {
91 | changed = changedFiles.contains(candidate) || deletedFiles.contains(candidate);
92 | if (changed || candidate.equals(basedir)) {
93 | break;
94 | }
95 | candidate = candidate.getParent();
96 | }
97 | return changed;
98 | }
99 |
100 | @SuppressWarnings("unchecked")
101 | @Override
102 | public boolean hasDelta(List relpaths) {
103 | return ((List) relpaths).stream().anyMatch(this::hasDelta);
104 | }
105 |
106 | @Override
107 | public boolean hasDelta(File file) {
108 | return hasDelta(file.getAbsolutePath());
109 | }
110 |
111 | @Override
112 | public boolean isIncremental() {
113 | return true;
114 | }
115 |
116 | @Override
117 | public Scanner newDeleteScanner(File basedir) {
118 | return new TestScanner(basedir, deletedFiles);
119 | }
120 |
121 | @Override
122 | public OutputStream newFileOutputStream(File file) throws IOException {
123 | refresh(file);
124 | return new FileOutputStream(file);
125 | }
126 |
127 | @Override
128 | public Scanner newScanner(final File basedir) {
129 | return new TestScanner(basedir, changedFiles);
130 | }
131 |
132 | @Override
133 | public Scanner newScanner(File basedir, boolean ignoreDelta) {
134 | if (ignoreDelta) {
135 | DirectoryScanner directoryScanner = new DirectoryScanner();
136 | directoryScanner.setBasedir(basedir);
137 | return directoryScanner;
138 | }
139 |
140 | return newScanner(basedir);
141 | }
142 |
143 | @Override
144 | public void refresh(File file) {
145 | refresh.add(file.toPath());
146 | }
147 |
148 | @Override
149 | public Object getValue(String key) {
150 | return context.get(key);
151 | }
152 |
153 | @Override
154 | public void setValue(String key, Object value) {
155 | context.put(key, value);
156 | }
157 |
158 | @Override
159 | public void addError(File file, int line, int column, String message, Throwable cause) {}
160 |
161 | @Override
162 | public void addWarning(File file, int line, int column, String message, Throwable cause) {}
163 |
164 | @Override
165 | public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {}
166 |
167 | @Override
168 | public void removeMessages(File file) {}
169 |
170 | @Override
171 | public boolean isUptodate(File target, File source) {
172 | return target != null
173 | && target.exists()
174 | && !hasDelta(target)
175 | && source != null
176 | && source.exists()
177 | && !hasDelta(source)
178 | && target.lastModified() > source.lastModified();
179 | }
180 |
181 | private static final class TestScanner implements Scanner {
182 | private final Path basedir;
183 | private final Set files = new HashSet<>();
184 |
185 | private TestScanner(File basedir, Set files) {
186 | this.basedir = basedir.toPath().toAbsolutePath();
187 | Optional.ofNullable(files).ifPresent(this.files::addAll);
188 | }
189 |
190 | @Override
191 | public void addDefaultExcludes() {}
192 |
193 | @Override
194 | public String[] getIncludedDirectories() {
195 | return new String[0];
196 | }
197 |
198 | @Override
199 | public String[] getIncludedFiles() {
200 | return files.stream()
201 | .filter(p -> p.startsWith(basedir))
202 | .map(basedir::relativize)
203 | .map(Path::toString)
204 | .toArray(String[]::new);
205 | }
206 |
207 | @Override
208 | public void scan() {}
209 |
210 | @Override
211 | public void setExcludes(String[] excludes) {}
212 |
213 | @Override
214 | public void setIncludes(String[] includes) {}
215 |
216 | @Override
217 | public File getBasedir() {
218 | return basedir.toFile();
219 | }
220 |
221 | @Override
222 | public void setFilenameComparator(Comparator filenameComparator) {}
223 | }
224 | }
225 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/filtering/TestReflectionProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | package org.apache.maven.shared.filtering;
20 |
21 | import java.io.InputStream;
22 | import java.nio.file.Files;
23 | import java.nio.file.Path;
24 | import java.nio.file.Paths;
25 | import java.util.HashMap;
26 | import java.util.Map;
27 | import java.util.Properties;
28 |
29 | import org.apache.maven.api.di.Inject;
30 | import org.apache.maven.api.di.testing.MavenDITest;
31 | import org.apache.maven.api.plugin.testing.stubs.ProjectStub;
32 | import org.apache.maven.di.Injector;
33 | import org.junit.jupiter.api.Test;
34 |
35 | import static org.apache.maven.api.di.testing.MavenDIExtension.getBasedir;
36 | import static org.junit.jupiter.api.Assertions.assertEquals;
37 |
38 | /**
39 | * @author Olivier Lamy
40 | * @since 1.0-beta-1
41 | *
42 | */
43 | @MavenDITest
44 | public class TestReflectionProperties {
45 |
46 | @Inject
47 | Injector container;
48 |
49 | @Test
50 | public void testSimpleFiltering() throws Exception {
51 | ProjectStub mavenProject = new ProjectStub();
52 | mavenProject.setVersion("1.0");
53 | mavenProject.setGroupId("org.apache");
54 | Map userProperties = new HashMap<>();
55 | userProperties.put("foo", "bar");
56 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
57 |
58 | Path from = Paths.get(getBasedir() + "/src/test/units-files/reflection-test.properties");
59 | Path to = Paths.get(getBasedir() + "/target/reflection-test.properties");
60 |
61 | Files.deleteIfExists(to);
62 |
63 | mavenFileFilter.copyFile(from, to, true, mavenProject, null, false, null, new StubSession(userProperties));
64 |
65 | Properties reading = new Properties();
66 |
67 | try (InputStream readFileInputStream = Files.newInputStream(to)) {
68 | reading.load(readFileInputStream);
69 | }
70 |
71 | assertEquals("1.0", reading.get("version"));
72 | assertEquals("org.apache", reading.get("groupId"));
73 | assertEquals("bar", reading.get("foo"));
74 | assertEquals("none filtered", reading.get("none"));
75 | }
76 |
77 | @Test
78 | public void testSimpleNonFiltering() throws Exception {
79 |
80 | ProjectStub mavenProject = new ProjectStub();
81 | mavenProject.setVersion("1.0");
82 | mavenProject.setGroupId("org.apache");
83 | Map userProperties = new HashMap<>();
84 | userProperties.put("foo", "bar");
85 | MavenFileFilter mavenFileFilter = container.getInstance(MavenFileFilter.class);
86 |
87 | Path from = Paths.get(getBasedir() + "/src/test/units-files/reflection-test.properties");
88 | Path to = Paths.get(getBasedir() + "/target/reflection-test.properties");
89 |
90 | Files.deleteIfExists(to);
91 |
92 | mavenFileFilter.copyFile(from, to, false, mavenProject, null, false, null, new StubSession(userProperties));
93 |
94 | Properties reading = new Properties();
95 |
96 | try (InputStream readFileInputStream = Files.newInputStream(to)) {
97 | reading.load(readFileInputStream);
98 | }
99 |
100 | assertEquals("${pom.version}", reading.get("version"));
101 | assertEquals("${pom.groupId}", reading.get("groupId"));
102 | assertEquals("${foo}", reading.get("foo"));
103 | assertEquals("none filtered", reading.get("none"));
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/test/resources/META-INF/maven/org.apache.maven.api.di.Inject:
--------------------------------------------------------------------------------
1 | #
2 | # Licensed to the Apache Software Foundation (ASF) under one
3 | # or more contributor license agreements. See the NOTICE file
4 | # distributed with this work for additional information
5 | # regarding copyright ownership. The ASF licenses this file
6 | # to you under the Apache License, Version 2.0 (the
7 | # "License"); you may not use this file except in compliance
8 | # with the License. You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing,
13 | # software distributed under the License is distributed on an
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # KIND, either express or implied. See the License for the
16 | # specific language governing permissions and limitations
17 | # under the License.
18 | #
19 | org.apache.maven.shared.filtering.Providers
20 |
--------------------------------------------------------------------------------
/src/test/resources/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
23 | org.apache.maven.shared
24 | maven-shared-components
25 | 8
26 |
27 |
28 | 4.0.0
29 | org.apache.maven.shared
30 | maven-filtering
31 | jar
32 | 1.0-alpha-1-SNAPSHOT
33 |
34 | Maven Files Filtering
35 |
36 |
37 | scm:svn:https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-interpolation
38 | scm:svn:https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-interpolation
39 | http://svn.apache.org/viewcvs.cgi/maven/sandbox/trunk/shared/maven-interpolation
40 |
41 |
42 |
43 |
44 |
45 | org.codehaus.plexus
46 | plexus-maven-plugin
47 | 1.3.4
48 |
49 |
50 |
51 | descriptor
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.apache.maven
62 | maven-project
63 | 2.0.6
64 |
65 |
66 | org.codehaus.plexus
67 | plexus-utils
68 | 3.0.24
69 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/src/test/units-files/MRESOURCES-104/test.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | email=foo@bar.com
19 | foo=${project.version}
20 | bar=@project.version@
21 |
--------------------------------------------------------------------------------
/src/test/units-files/MRESOURCES-171/test.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-filtering/04d709a9d286fa3f263d7376caf702f10c178948/src/test/units-files/MRESOURCES-171/test.properties
--------------------------------------------------------------------------------
/src/test/units-files/MRESOURCES-171/test.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | Some text encoded in UTF-8 containing non-ascii characters conexión.
19 |
--------------------------------------------------------------------------------
/src/test/units-files/MRESOURCES-230/expected.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | \
19 | \\
20 | \\\
21 | \\\DONE_A
22 | \\\${a}
23 |
--------------------------------------------------------------------------------
/src/test/units-files/MRESOURCES-230/resource.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | \\
19 | \\\\
20 | \\\\\\
21 | \\\\\\${a}
22 | \\\\\\\${a}
23 |
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-1213/enunciate.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-161/src/main/filters/buildfilter.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | buildfilter=true
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-161/src/main/filters/filefilter.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | filefilter=true
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-177/first_filter_file.properties:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | # under the License.
13 | first_filter_key=first
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-177/second_filter_file.properties:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | # under the License.
13 | second_filter_key=second
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-177/third_filter_file.properties:
--------------------------------------------------------------------------------
1 | # Licensed under the Apache License, Version 2.0 (the "License");
2 | # you may not use this file except in compliance with the License.
3 | # You may obtain a copy of the License at
4 | #
5 | # http://www.apache.org/licenses/LICENSE-2.0
6 | #
7 | # Unless required by applicable law or agreed to in writing, software
8 | # distributed under the License is distributed on an "AS IS" BASIS,
9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | # See the License for the specific language governing permissions and
11 | # limitations under the License.
12 | # under the License.
13 | third_filter_key=${first_filter_key} and ${second_filter_key}
14 |
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-325/payload:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | @").replace(p,"]").replace(q,
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-81/expected-filtered.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | escaped=${escaped}
20 | escaped.at=@escaped.at@
21 | foo=this is foo
22 | project.foo=${project.foo}
23 | bar=this is bar
24 | project.bar=@project.bar@
25 | not.a.property=${not.a.property}
26 | not.a.property.at=@not.a.property@
27 | version=1.0
28 | version.at=1.0
29 | project.version=1.0
30 | project.version.at=1.0
31 | target=@target@
32 | target.at=@target.at@
33 | project.target=@project.target@
34 | project.target.at=@project.target@
35 |
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-81/filtered/filtered.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | escaped=\${escaped}
20 | escaped.at=\@escaped.at@
21 | foo=${foo}
22 | project.foo=${project.foo}
23 | bar=@bar@
24 | project.bar=@project.bar@
25 | not.a.property=${not.a.property}
26 | not.a.property.at=@not.a.property@
27 | version=${version}
28 | version.at=@version@
29 | project.version=${project.version}
30 | project.version.at=@project.version@
31 | target=@target@
32 | target.at=@target.at@
33 | project.target=@project.target@
34 | project.target.at=@project.target@
35 |
--------------------------------------------------------------------------------
/src/test/units-files/MSHARED-81/resources/unfiltered.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | escaped=\${escaped}
20 | escaped.at=\@escaped.at@
21 | foo=${foo}
22 | project.foo=${project.foo}
23 | bar=@bar@
24 | project.bar=@project.bar@
25 | not.a.property=${not.a.property}
26 | not.a.property.at=@not.a.property@
27 | version=${version}
28 | version.at=@version@
29 | project.version=${project.version}
30 | project.version.at=@project.version@
31 | target=@target@
32 | target.at=@target.at@
33 | project.target=@project.target@
34 | project.target.at=@project.target@
35 |
--------------------------------------------------------------------------------
/src/test/units-files/edge-cases/expected-filtered.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | edge.escape.token.hanging=user@this.is.domain.com with extra stuff
20 | edge.escape.token.start=$1.0$1.0
21 | edge.escape.property=${wrapped:1.0}
22 | edge.escape.token.twice=${1.0${1.0
23 | edge.escape.not.a.property=${wrapped:${not.a.property}}
24 | edge.escape.hanging=\\
25 | edge.token.hanging=${
26 | edge.long=longpropvalue
27 |
--------------------------------------------------------------------------------
/src/test/units-files/edge-cases/filtered/filtered.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | edge.escape.property=\${wrapped:${version}}
20 | edge.escape.not.a.property=\${wrapped:${not.a.property}}
21 | edge.escape.token.start=\$${version}\$${version}
22 | edge.escape.token.twice=\${${version}\${${version}
23 | edge.escape.token.hanging=user\@@domain@ with extra stuff
24 | edge.escape.hanging=\\
25 | edge.token.hanging=${
26 | edge.long=${com.xxxxxxx.xxxx.root.build.environment.CLOUD_AZURE_AKS_KUBERNETES_NODE_LABEL_AGENTPOOL_VALUE_PRODUCTION_XXXXXXXXXXX_NODE_IMPL_PRODUCT_SEGMENT_PROCESSOR}
27 |
--------------------------------------------------------------------------------
/src/test/units-files/edge-cases/resources/unfiltered.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | edge.escape.property=\${wrapped:${version}}
20 | edge.escape.not.a.property=\${wrapped:${not.a.property}}
21 | edge.escape.token.start=\$${version}\$${version}
22 | edge.escape.token.twice=\${${version}\${${version}
23 | edge.escape.token.hanging=user\@@domain@ with extra stuff
24 | edge.escape.hanging=\\
25 | edge.token.hanging=${
26 |
--------------------------------------------------------------------------------
/src/test/units-files/escape-remove-char/content.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 | Why is my !\${\}\! static.content broken if the escapeString occurs ?!?
23 | Content with replacement: ${replaceThis} !
24 | Content with escaped replacement: Do not !${replaceThis} !
25 |
26 |
--------------------------------------------------------------------------------
/src/test/units-files/includeEmptyDirs/dir1/foo.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | foo.
--------------------------------------------------------------------------------
/src/test/units-files/includeEmptyDirs/empty-directory-child/empty-child/.gitignore:
--------------------------------------------------------------------------------
1 | # just here to make the directory non-empty
2 |
--------------------------------------------------------------------------------
/src/test/units-files/includeEmptyDirs/empty-directory/.gitignore:
--------------------------------------------------------------------------------
1 | # just here to make the directory non-empty
2 |
--------------------------------------------------------------------------------
/src/test/units-files/incremental/files/file01.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | time=${time}
19 | foo=${foo}
20 |
--------------------------------------------------------------------------------
/src/test/units-files/incremental/files/file02.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | time=${time}
19 | foo=${foo}
20 |
--------------------------------------------------------------------------------
/src/test/units-files/incremental/filters.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | foo=bar\ No newline at end of file
19 |
--------------------------------------------------------------------------------
/src/test/units-files/maven-filename-filtering/${pom.version}.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/empty-maven-resources-filtering.txt:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/excludedir/bar.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | excluded
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/excludedir/foo.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | excluded
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/excludefile.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/happy_duke.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-filtering/04d709a9d286fa3f263d7376caf702f10c178948/src/test/units-files/maven-resources-filtering/happy_duke.gif
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/includedir/include.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/includedir/includefile.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/includefile.txt:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
--------------------------------------------------------------------------------
/src/test/units-files/maven-resources-filtering/maven-resources-filtering.txt:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | version=${pom.version}
20 | groupId=${pom.groupId}
21 | foo=${foo}
22 | none=none filtered
23 | userDir=@user.dir@
24 | base=${pom.basedir}
25 | emptyexpression=@@
26 | emptyexpression2=${}
27 | javaVersion=${java.version}
28 | pomName=@pom.name@
29 | fooVersion=${foo.version}
30 |
31 | escapeJavaVersion=\${java.version}
32 | escapeuserDir=\@user.dir@
33 |
34 | userHome=${user.home}
35 |
36 | goodDate=${greatDate}
--------------------------------------------------------------------------------
/src/test/units-files/propertyutils-test.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | version=${pom.version}
20 | groupId=${pom.groupId}
21 | foo=${foo}
22 | none=none filtered
23 | bar=${version}
--------------------------------------------------------------------------------
/src/test/units-files/reflection-test-older.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | version=older file
--------------------------------------------------------------------------------
/src/test/units-files/reflection-test.properties:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | version=${pom.version}
20 | groupId=${pom.groupId}
21 | foo=${foo}
22 | none=none filtered
--------------------------------------------------------------------------------
/src/test/units-files/session-filtering/session-filter-target.txt:
--------------------------------------------------------------------------------
1 | #/*
2 | # * Licensed to the Apache Software Foundation (ASF) under one
3 | # * or more contributor license agreements. See the NOTICE file
4 | # * distributed with this work for additional information
5 | # * regarding copyright ownership. The ASF licenses this file
6 | # * to you under the Apache License, Version 2.0 (the
7 | # * "License"); you may not use this file except in compliance
8 | # * with the License. You may obtain a copy of the License at
9 | # *
10 | # * http://www.apache.org/licenses/LICENSE-2.0
11 | # *
12 | # * Unless required by applicable law or agreed to in writing,
13 | # * software distributed under the License is distributed on an
14 | # * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | # * KIND, either express or implied. See the License for the
16 | # * specific language governing permissions and limitations
17 | # * under the License.
18 | # */
19 | local.repo=${localRepository}
20 | settings.local.repo=${settings.localRepository}
21 | session.settings.local.repo=${session.settings.localRepository}
22 |
--------------------------------------------------------------------------------