├── .asf.yaml
├── .github
├── ISSUE_TEMPLATE
│ ├── BUG.yml
│ ├── FEATURE.yml
│ └── config.yml
├── dependabot.yml
├── release-drafter.yml
└── workflows
│ ├── maven-verify.yml
│ ├── pr-automation.yml
│ ├── release-drafter.yml
│ └── stale.yml
├── .gitignore
├── Jenkinsfile
├── README.md
├── deploySite.sh
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── apache
│ │ └── maven
│ │ └── shared
│ │ └── utils
│ │ ├── Os.java
│ │ ├── PathTool.java
│ │ ├── PropertyUtils.java
│ │ ├── ReaderFactory.java
│ │ ├── StringUtils.java
│ │ ├── WriterFactory.java
│ │ ├── cli
│ │ ├── AbstractStreamHandler.java
│ │ ├── Arg.java
│ │ ├── CommandLineCallable.java
│ │ ├── CommandLineException.java
│ │ ├── CommandLineTimeOutException.java
│ │ ├── CommandLineUtils.java
│ │ ├── Commandline.java
│ │ ├── DefaultConsumer.java
│ │ ├── ShutdownHookUtils.java
│ │ ├── StreamConsumer.java
│ │ ├── StreamPollFeeder.java
│ │ ├── StreamPumper.java
│ │ ├── WriterStreamConsumer.java
│ │ ├── javatool
│ │ │ ├── AbstractJavaTool.java
│ │ │ ├── AbstractJavaToolRequest.java
│ │ │ ├── JavaTool.java
│ │ │ ├── JavaToolException.java
│ │ │ ├── JavaToolRequest.java
│ │ │ └── JavaToolResult.java
│ │ └── shell
│ │ │ ├── BourneShell.java
│ │ │ ├── CmdShell.java
│ │ │ ├── CommandShell.java
│ │ │ └── Shell.java
│ │ ├── introspection
│ │ ├── ClassMap.java
│ │ ├── IntrospectionException.java
│ │ ├── MethodMap.java
│ │ └── ReflectionValueExtractor.java
│ │ ├── io
│ │ ├── DirectoryScanResult.java
│ │ ├── DirectoryScanner.java
│ │ ├── DirectoryWalkListener.java
│ │ ├── FileUtils.java
│ │ ├── IOUtil.java
│ │ ├── Java7Support.java
│ │ ├── MatchPattern.java
│ │ ├── MatchPatterns.java
│ │ ├── ScanConductor.java
│ │ ├── SelectorUtils.java
│ │ └── WalkCollector.java
│ │ ├── logging
│ │ ├── AnsiMessageBuilder.java
│ │ ├── LoggerLevelRenderer.java
│ │ ├── MessageBuilder.java
│ │ ├── MessageUtils.java
│ │ ├── PlainMessageBuilder.java
│ │ ├── Style.java
│ │ └── package-info.java
│ │ └── xml
│ │ ├── PrettyPrintXMLWriter.java
│ │ ├── XMLEncode.java
│ │ ├── XMLWriter.java
│ │ ├── XmlStreamReader.java
│ │ ├── XmlStreamWriter.java
│ │ ├── XmlWriterUtil.java
│ │ ├── Xpp3Dom.java
│ │ ├── Xpp3DomBuilder.java
│ │ ├── Xpp3DomUtils.java
│ │ ├── Xpp3DomWriter.java
│ │ └── pull
│ │ └── XmlPullParserException.java
└── resources
│ ├── META-INF
│ └── NOTICE
│ └── org
│ └── apache
│ └── maven
│ └── shared
│ └── utils
│ └── annotations.xml
├── site
├── apt
│ └── index.apt.vm
├── resources
│ └── download.cgi
├── site.xml
└── xdoc
│ └── download.xml.vm
└── test
├── java
└── org
│ └── apache
│ └── maven
│ └── shared
│ └── utils
│ ├── CaseTest.java
│ ├── OsTest.java
│ ├── PathToolTest.java
│ ├── PropertyUtilsTest.java
│ ├── StringUtilsTest.java
│ ├── XmlStreamReaderTest.java
│ ├── cli
│ ├── CommandLineUtilsTest.java
│ ├── StreamPollFeederTest.java
│ └── shell
│ │ └── BourneShellTest.java
│ ├── exceptionutils
│ ├── TestException.java
│ └── TestExceptionWithDetail.java
│ ├── introspection
│ └── ReflectionValueExtractorTest.java
│ ├── io
│ ├── DirectoryScannerTest.java
│ ├── FileUtilsTest.java
│ ├── IOUtilTest.java
│ ├── MatchPatternTest.java
│ ├── MatchPatternsTest.java
│ ├── SelectorUtilsTest.java
│ └── SymlinkTestSetup.java
│ ├── logging
│ ├── AnsiMessageBuilderTest.java
│ └── MessageUtilsTest.java
│ ├── testhelpers
│ └── FileTestHelper.java
│ └── xml
│ ├── PrettyPrintXmlWriterTest.java
│ ├── XmlWriterUtilTest.java
│ ├── Xpp3DomBuilderTest.java
│ └── pull
│ └── Xpp3DomTest.java
└── resources
├── directorywalker
├── directory1
│ └── file1.txt
├── directory2
│ ├── directory21
│ │ └── file21.txt
│ └── file2.txt
└── file.txt
├── executable
├── expand
└── expand_test.zip
└── symlinks
├── dirOnTheOutside
└── FileInDirOnTheOutside.txt
├── onTheOutside.txt
├── regen.sh
├── src
├── aRegularDir
│ └── aRegularFile.txt
├── fileR.txt
├── fileW.txt
├── fileX.txt
├── symDir
├── symLinkToDirOnTheOutside
├── symLinkToFileOnTheOutside
├── symR
├── symW
├── symX
└── targetDir
│ └── targetFile.txt
├── symlinks.tar
└── symlinks.zip
/.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 Shared Utils"
20 | homepage: https://maven.apache.org/shared/maven-shared-utils/
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 |
--------------------------------------------------------------------------------
/.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/browse/?jql=project%20%3D%20MSHARED%20AND%20component%20%3D%20maven-shared-utils
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: "github-actions"
25 | directory: "/"
26 | schedule:
27 | interval: "daily"
28 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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 | .idea
11 | out/
12 | .DS_Store
13 | /bootstrap
14 | /dependencies.xml
15 | .java-version
16 | .checkstyle
17 |
18 |
--------------------------------------------------------------------------------
/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()
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
17 | Contributing to [Apache Maven Shared Utils](https://maven.apache.org/shared/maven-shared-utils/)
18 | ======================
19 |
20 | [][license]
21 | [](https://search.maven.org/artifact/org.apache.maven.shared/maven-shared-utils)
22 | [](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/apache/maven/shared/maven-shared-utils/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-shared-utils/job/master/lastCompletedBuild/testReport/
84 | [build]: https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-shared-utils/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 | maven-shared-utils
30 | 3.4.3-SNAPSHOT
31 |
32 | Apache Maven Shared Utils
33 | Shared utilities for use by Maven core and plugins
34 |
35 |
36 |
37 | Kathryn Newbould
38 |
39 |
40 |
41 |
42 | scm:git:https://gitbox.apache.org/repos/asf/maven-shared-utils.git
43 | scm:git:https://gitbox.apache.org/repos/asf/maven-shared-utils.git
44 | HEAD
45 | https://github.com/apache/maven-shared-utils/tree/${project.scm.tag}
46 |
47 |
48 | GitHub Issues
49 | https://github.com/apache/maven-shared-utils/issues
50 |
51 |
52 | Jenkins
53 | https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-shared-utils/
54 |
55 |
56 |
57 | apache.website
58 | scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}
59 |
60 |
61 |
62 |
63 | RedundantThrows,NewlineAtEndOfFile,ParameterNumber,MethodLength,FileLength,ModifierOrder
64 | 2023-05-11T20:50:20Z
65 | 8
66 | 3.2.5
67 |
68 |
69 |
70 |
71 |
72 | org.hamcrest
73 | hamcrest-core
74 | 3.0
75 |
76 |
77 |
78 |
79 |
80 |
81 | org.slf4j
82 | slf4j-api
83 | 1.7.36
84 |
85 |
86 |
87 | org.fusesource.jansi
88 | jansi
89 | 2.4.2
90 | true
91 |
92 |
93 |
94 | commons-io
95 | commons-io
96 | 2.19.0
97 |
98 |
99 |
100 | org.hamcrest
101 | hamcrest
102 | 3.0
103 | test
104 |
105 |
106 | junit
107 | junit
108 | 4.13.2
109 | test
110 |
111 |
112 | com.google.code.findbugs
113 | jsr305
114 | 3.0.2
115 | provided
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 | org.apache.maven.plugins
124 | maven-resources-plugin
125 | 3.3.1
126 |
127 |
128 | org.apache.maven.plugins
129 | maven-assembly-plugin
130 | 3.7.1
131 |
132 |
133 |
134 |
135 |
136 |
137 | org.apache.rat
138 | apache-rat-plugin
139 |
140 |
141 | src/test/resources/directorywalker/**/*
142 | src/test/resources/symlinks/**/*
143 | src/test/resources/executable
144 |
145 |
146 |
147 |
148 | org.apache.maven.plugins
149 | maven-surefire-plugin
150 |
151 | false
152 |
153 | TestValue
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/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.utils;
20 |
21 | import javax.annotation.Nonnull;
22 | import javax.annotation.Nullable;
23 |
24 | import java.io.File;
25 | import java.io.FileInputStream;
26 | import java.io.IOException;
27 | import java.io.InputStream;
28 | import java.net.URL;
29 | import java.util.Properties;
30 |
31 | /**
32 | * Static utility methods for loading properties.
33 | */
34 | public class PropertyUtils {
35 |
36 | /**
37 | * The constructor.
38 | *
39 | * @deprecated This is a utility class with only static methods. Don't create instances of it.
40 | */
41 | @Deprecated
42 | public PropertyUtils() {}
43 |
44 | /**
45 | * @param url the URL which should be used to load the properties
46 | * @return the loaded properties
47 | * @deprecated use {@link #loadOptionalProperties(java.net.URL)} instead. This method should not
48 | * be used as it suppresses exceptions silently when loading properties fails and returns {@code null}
49 | * instead of an empty {@code Properties} instance when the given {@code URL} is {@code null}.
50 | */
51 | @Deprecated
52 | public static java.util.Properties loadProperties(@Nonnull URL url) {
53 | try (InputStream in = url.openStream()) {
54 | return loadProperties(in);
55 | } catch (Exception e) {
56 | // ignore
57 | }
58 | return null;
59 | }
60 |
61 | /**
62 | * @param file the file from which the properties will be loaded
63 | * @return the loaded properties
64 | * @deprecated use {@link #loadOptionalProperties(java.io.File)} instead. This method should not
65 | * be used as it suppresses exceptions silently when loading properties fails and returns {@code null}
66 | * instead of an empty {@code Properties} instance when the given {@code File} is {@code null}.
67 | */
68 | @Deprecated
69 | public static Properties loadProperties(@Nonnull File file) {
70 | try (InputStream in = new FileInputStream(file)) {
71 | return loadProperties(in);
72 | } catch (Exception e) {
73 | // ignore
74 | }
75 | return null;
76 | }
77 |
78 | /**
79 | * Loads {@code Properties} from an {@code InputStream} and closes the stream.
80 | * In a future release, this will no longer close the stream, so callers
81 | * should close the stream themselves.
82 | *
83 | * @param is {@link InputStream}
84 | * @return the loaded properties
85 | * @deprecated use {@link #loadOptionalProperties(java.io.InputStream)} instead. This method
86 | * should not be used as it suppresses exceptions silently when loading properties fails.
87 | */
88 | @Deprecated
89 | public static Properties loadProperties(@Nullable InputStream is) {
90 | try {
91 | Properties result = new Properties();
92 | if (is != null) {
93 | try (InputStream in = is) {
94 | result.load(in);
95 | } catch (IOException e) {
96 | // ignore
97 | }
98 | }
99 | return result;
100 | } catch (Exception e) {
101 | // ignore
102 | }
103 | return null;
104 | }
105 |
106 | /**
107 | * Loads {@code Properties} from a given {@code URL}.
108 | *
109 | * If the given {@code URL} is {@code null} or the properties can't be read, an empty properties object is returned.
110 | *
111 | *
112 | * @param url the {@code URL} of the properties resource to load or {@code null}
113 | * @return the loaded properties or an empty {@code Properties} instance if properties fail to load
114 | * @since 3.1.0
115 | */
116 | @Nonnull
117 | public static Properties loadOptionalProperties(final @Nullable URL url) {
118 |
119 | Properties properties = new Properties();
120 | if (url != null) {
121 | try (InputStream in = url.openStream()) {
122 | properties.load(in);
123 | } catch (IllegalArgumentException | IOException ex) {
124 | // ignore and return empty properties
125 | }
126 | }
127 | return properties;
128 | }
129 |
130 | /**
131 | * Loads {@code Properties} from a {@code File}.
132 | *
133 | * If the given {@code File} is {@code null} or the properties file can't be read, an empty properties object is
134 | * returned.
135 | *
136 | *
137 | * @param file the {@code File} of the properties resource to load or {@code null}
138 | * @return the loaded properties or an empty {@code Properties} instance if properties fail to load
139 | * @since 3.1.0
140 | */
141 | @Nonnull
142 | public static Properties loadOptionalProperties(final @Nullable File file) {
143 | Properties properties = new Properties();
144 | if (file != null) {
145 | try (InputStream in = new FileInputStream(file)) {
146 | properties.load(in);
147 | } catch (IllegalArgumentException | IOException ex) {
148 | // ignore and return empty properties
149 | }
150 | }
151 |
152 | return properties;
153 | }
154 |
155 | /**
156 | * Loads {@code Properties} from an {@code InputStream} and closes the stream.
157 | * If the given {@code InputStream} is {@code null} or the properties can't be read, an empty properties object is
158 | * returned. In a future release, this will no longer close the stream, so callers
159 | * should close the stream themselves.
160 | *
161 | * @param inputStream the properties resource to load or {@code null}
162 | * @return the loaded properties or an empty {@code Properties} instance if properties fail to load
163 | * @since 3.1.0
164 | */
165 | @Nonnull
166 | public static Properties loadOptionalProperties(final @Nullable InputStream inputStream) {
167 |
168 | Properties properties = new Properties();
169 |
170 | if (inputStream != null) {
171 | try (InputStream in = inputStream) // reassign inputStream to autoclose
172 | {
173 | properties.load(in);
174 | } catch (IllegalArgumentException | IOException ex) {
175 | // ignore and return empty properties
176 | }
177 | }
178 |
179 | return properties;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.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.utils.cli;
20 |
21 | /**
22 | * @author Kristian Rosenvold
23 | */
24 | class AbstractStreamHandler extends Thread {
25 | private volatile boolean done;
26 |
27 | private volatile boolean disabled;
28 |
29 | boolean isDone() {
30 | return done;
31 | }
32 |
33 | public synchronized void waitUntilDone() throws InterruptedException {
34 | while (!isDone()) {
35 | wait();
36 | }
37 | }
38 |
39 | boolean isDisabled() {
40 | return disabled;
41 | }
42 |
43 | public void disable() {
44 | disabled = true;
45 | }
46 |
47 | protected void setDone() {
48 | done = true;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/Arg.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.utils.cli;
20 |
21 | import java.io.File;
22 |
23 | /**
24 | *
25 | */
26 | public interface Arg {
27 | /**
28 | * @param value the value to be set
29 | */
30 | void setValue(String value);
31 |
32 | /**
33 | * @param line the line of arguments
34 | * @throws CommandLineException in case of unbalanced quotes.
35 | */
36 | void setLine(String line) throws CommandLineException;
37 |
38 | /**
39 | * @param file the file to be set
40 | */
41 | void setFile(File file);
42 |
43 | /**
44 | * Whether to hide the argument value when a command line prints the arguments.
45 | *
46 | * @param mask new state of the {@code mask} property
47 | * @since 0.6
48 | */
49 | void setMask(boolean mask);
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/CommandLineCallable.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.utils.cli;
20 |
21 | import java.util.concurrent.Callable;
22 |
23 | /**
24 | * Callable wrapper that exposes the proper exception type to the client.
25 | *
26 | * @author Kristian Rosenvold
27 | */
28 | public interface CommandLineCallable extends Callable {
29 | /**
30 | * {@inheritDoc}
31 | */
32 | Integer call() throws CommandLineException;
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/CommandLineException.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.utils.cli;
20 |
21 | /**
22 | * @author Trygve Laugstøl
23 | */
24 | public class CommandLineException extends Exception {
25 | /**
26 | *
27 | */
28 | private static final long serialVersionUID = 1344773066470228441L;
29 |
30 | /**
31 | * @param message The message of the exception.
32 | */
33 | public CommandLineException(String message) {
34 | super(message);
35 | }
36 |
37 | /**
38 | * @param message The message of the exception.
39 | * @param cause The problem which caused the exception.
40 | */
41 | public CommandLineException(String message, Throwable cause) {
42 | super(message, cause);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/CommandLineTimeOutException.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.utils.cli;
20 |
21 | /**
22 | * Report a timeout for executing process.
23 | *
24 | * @author Olivier Lamy
25 | *
26 | */
27 | public class CommandLineTimeOutException extends CommandLineException {
28 |
29 | private static final long serialVersionUID = 7322428741683224481L;
30 |
31 | /**
32 | * @param message The message of the exception.
33 | * @param cause The cause of the exception.
34 | */
35 | public CommandLineTimeOutException(String message, Throwable cause) {
36 | super(message, cause);
37 | }
38 |
39 | /**
40 | * @param message The message of the exception.
41 | */
42 | public CommandLineTimeOutException(String message) {
43 | super(message);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/DefaultConsumer.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.utils.cli;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * @author Emmanuel Venisse
25 | */
26 | public class DefaultConsumer implements StreamConsumer {
27 |
28 | /**
29 | * {@inheritDoc}
30 | */
31 | @Override
32 | public void consumeLine(String line) throws IOException {
33 | System.out.println(line);
34 | if (System.out.checkError()) {
35 | throw new IOException(String.format("Failure writing line '%s' to stdout.", line));
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/ShutdownHookUtils.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.utils.cli;
20 |
21 | import java.security.AccessControlException;
22 |
23 | /**
24 | * A shutdown hook that does not throw any exceptions upon container startup/shutdown or security manager
25 | * restrictions.
26 | *
27 | * Incorrect usage of the hook itself may still throw an exception.
28 | *
29 | * @author Kristian Rosenvold
30 | */
31 | public class ShutdownHookUtils {
32 |
33 | /**
34 | * @param hook The thread hook.
35 | */
36 | public static void addShutDownHook(Thread hook) {
37 | try {
38 | Runtime.getRuntime().addShutdownHook(hook);
39 | } catch (IllegalStateException ignore) {
40 | // ignore
41 | } catch (AccessControlException ignore) {
42 | // ignore
43 | }
44 | }
45 |
46 | /**
47 | * @param hook The hook which should be removed.
48 | */
49 | public static void removeShutdownHook(Thread hook) {
50 | try {
51 | Runtime.getRuntime().removeShutdownHook(hook);
52 | } catch (IllegalStateException ignore) {
53 | // ignore
54 | } catch (AccessControlException ignore) {
55 | // ignore
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/StreamConsumer.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.utils.cli;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * Works in concert with the StreamPumper class to
25 | * allow implementations to gain access to the lines being
26 | * "Pumped".
27 | * Please note that implementations of this interface can be expected to be
28 | * called from arbitrary threads and must therefore be threadsafe.
29 | *
30 | * @author Florin Vancea
31 | * @author Paul Julius
32 | */
33 | public interface StreamConsumer {
34 | /**
35 | * Called when the StreamPumper pumps a line from the Stream.
36 | * @param line The line to be consumed.
37 | * @throws IOException if consuming {@code line} fails.
38 | */
39 | void consumeLine(String line) throws IOException;
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/StreamPollFeeder.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.utils.cli;
20 |
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.OutputStream;
24 | import java.util.Objects;
25 |
26 | /**
27 | * Poll InputStream for available data and write the output to an OutputStream.
28 | *
29 | * @author Trygve Laugstøl
30 | */
31 | class StreamPollFeeder extends Thread {
32 |
33 | public static final int BUF_LEN = 80;
34 |
35 | private final InputStream input;
36 | private final OutputStream output;
37 |
38 | private Throwable exception;
39 |
40 | private boolean done;
41 | private final Object lock = new Object();
42 |
43 | /**
44 | * Create a new StreamPollFeeder
45 | *
46 | * @param input Stream to read from
47 | * @param output Stream to write to
48 | */
49 | StreamPollFeeder(InputStream input, OutputStream output) {
50 | this.input = Objects.requireNonNull(input);
51 | this.output = Objects.requireNonNull(output);
52 | this.done = false;
53 | }
54 |
55 | @Override
56 | public void run() {
57 |
58 | byte[] buf = new byte[BUF_LEN];
59 |
60 | try {
61 | while (!done) {
62 | if (input.available() > 0) {
63 | int i = input.read(buf);
64 | if (i > 0) {
65 | output.write(buf, 0, i);
66 | output.flush();
67 | } else {
68 | done = true;
69 | }
70 | } else {
71 | synchronized (lock) {
72 | if (!done) {
73 | lock.wait(100);
74 | }
75 | }
76 | }
77 | }
78 | } catch (IOException e) {
79 | exception = e;
80 | } catch (InterruptedException e) {
81 | Thread.currentThread().interrupt();
82 | } finally {
83 | close();
84 | }
85 | }
86 |
87 | private void close() {
88 | try {
89 | output.close();
90 | } catch (IOException e) {
91 | if (exception == null) {
92 | exception = e;
93 | }
94 | }
95 | }
96 |
97 | /**
98 | * @since 3.2.0
99 | */
100 | public Throwable getException() {
101 | return this.exception;
102 | }
103 |
104 | public void waitUntilDone() {
105 |
106 | synchronized (lock) {
107 | done = true;
108 | lock.notifyAll();
109 | }
110 |
111 | try {
112 | join();
113 | } catch (InterruptedException e) {
114 | Thread.currentThread().interrupt();
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.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.utils.cli;
20 |
21 | import javax.annotation.Nullable;
22 |
23 | import java.io.BufferedReader;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.io.InputStreamReader;
27 | import java.io.Reader;
28 | import java.nio.charset.Charset;
29 |
30 | /**
31 | * Class to pump the error stream during Process's runtime. Copied from the Ant built-in task.
32 | *
33 | * @author Florin Vancea
34 | * @author Paul Julius
35 | */
36 | public class StreamPumper extends AbstractStreamHandler {
37 | private final BufferedReader in;
38 |
39 | private final StreamConsumer consumer;
40 |
41 | private volatile Exception exception = null;
42 |
43 | private static final int SIZE = 1024;
44 |
45 | /**
46 | * @param in {@link InputStream}
47 | * @param consumer {@link StreamConsumer}
48 | */
49 | public StreamPumper(InputStream in, StreamConsumer consumer) {
50 | this(new InputStreamReader(in), consumer);
51 | }
52 |
53 | /**
54 | * @param in {@link InputStream}
55 | * @param consumer {@link StreamConsumer}
56 | * @param charset {@link Charset}
57 | */
58 | public StreamPumper(InputStream in, StreamConsumer consumer, @Nullable Charset charset) {
59 | this(null == charset ? new InputStreamReader(in) : new InputStreamReader(in, charset), consumer);
60 | }
61 |
62 | /**
63 | * @param in {@link Reader}
64 | * @param consumer {@link StreamConsumer}
65 | */
66 | private StreamPumper(Reader in, StreamConsumer consumer) {
67 | super();
68 | this.in = new BufferedReader(in, SIZE);
69 | this.consumer = consumer;
70 | }
71 |
72 | /** run it. */
73 | public void run() {
74 | try {
75 | for (String line = in.readLine(); line != null; line = in.readLine()) {
76 | try {
77 | if (exception == null) {
78 | consumeLine(line);
79 | }
80 | } catch (Exception t) {
81 | exception = t;
82 | }
83 | }
84 | } catch (IOException e) {
85 | exception = e;
86 | } finally {
87 | try {
88 | in.close();
89 | } catch (final IOException e2) {
90 | if (this.exception == null) {
91 | this.exception = e2;
92 | }
93 | }
94 |
95 | synchronized (this) {
96 | setDone();
97 |
98 | this.notifyAll();
99 | }
100 | }
101 | }
102 |
103 | /**
104 | * flush.
105 | *
106 | * @deprecated As of 3.2.0, removed without replacement.
107 | */
108 | @Deprecated
109 | public void flush() {
110 | // Nothing to flush.
111 | }
112 |
113 | /**
114 | * Close it.
115 | *
116 | * @deprecated As of 3.2.0, removed without replacement.
117 | */
118 | @Deprecated
119 | public void close() {
120 | // Nothing to close.
121 | }
122 |
123 | /**
124 | * @return {@link Exception}
125 | */
126 | public Exception getException() {
127 | return exception;
128 | }
129 |
130 | private void consumeLine(String line) throws IOException {
131 | if (consumer != null && !isDisabled()) {
132 | consumer.consumeLine(line);
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/WriterStreamConsumer.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.utils.cli;
20 |
21 | import java.io.BufferedWriter;
22 | import java.io.IOException;
23 | import java.io.Writer;
24 |
25 | /**
26 | * @author Jason van Zyl
27 | *
28 | */
29 | public class WriterStreamConsumer implements StreamConsumer {
30 |
31 | private final BufferedWriter writer;
32 |
33 | /**
34 | * @param writer {@link Writer}
35 | */
36 | public WriterStreamConsumer(Writer writer) {
37 | super();
38 | this.writer = new BufferedWriter(writer);
39 | }
40 |
41 | /**
42 | * {@inheritDoc}
43 | */
44 | @Override
45 | public void consumeLine(String line) throws IOException {
46 | this.writer.append(line);
47 | this.writer.newLine();
48 | this.writer.flush();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaToolRequest.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.utils.cli.javatool;
20 |
21 | import org.apache.maven.shared.utils.cli.StreamConsumer;
22 |
23 | /**
24 | * Abstract implementation of a {@link JavaToolRequest}.
25 | *
26 | * @author Tony Chemit
27 | * @since 0.5
28 | */
29 | public class AbstractJavaToolRequest implements JavaToolRequest {
30 |
31 | /**
32 | * Optional system out stream consumer used by the commandline execution.
33 | */
34 | private StreamConsumer systemOutStreamConsumer;
35 |
36 | /**
37 | * Optional system error stream consumer used by the commandline execution.
38 | */
39 | private StreamConsumer systemErrorStreamConsumer;
40 |
41 | /**
42 | * {@inheritDoc}
43 | */
44 | public StreamConsumer getSystemOutStreamConsumer() {
45 | return systemOutStreamConsumer;
46 | }
47 |
48 | /**
49 | * {@inheritDoc}
50 | */
51 | public StreamConsumer getSystemErrorStreamConsumer() {
52 | return systemErrorStreamConsumer;
53 | }
54 |
55 | /**
56 | * {@inheritDoc}
57 | */
58 | public void setSystemOutStreamConsumer(StreamConsumer systemOutStreamConsumer) {
59 | this.systemOutStreamConsumer = systemOutStreamConsumer;
60 | }
61 |
62 | /**
63 | * {@inheritDoc}
64 | */
65 | public void setSystemErrorStreamConsumer(StreamConsumer systemErrorStreamConsumer) {
66 | this.systemErrorStreamConsumer = systemErrorStreamConsumer;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.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.utils.cli.javatool;
20 |
21 | /**
22 | * Describes a java tool, means a executable available in the jdk.
23 | * The name of the tool ({@link #getJavaToolName()}) reflects the name of the executable that should exists as an
24 | * executable in the jdk, like {@code jarsigner, keytool, javadoc, ...}.
25 | * An abstract implementation of the {@link JavaTool} named {@link AbstractJavaTool} use the command line API to
26 | * execute any user requests of this tool.
27 | *
28 | * @author Tony Chemit
29 | * @since 0.5
30 | * @param Tool-specific request type
31 | */
32 | public interface JavaTool {
33 |
34 | /**
35 | * Return the name of the java tool. This is exactly the name (without his extension) of the executable to
36 | * find in the {@code jdk/bin} directory.
37 | * For example: {@code jarsigner, keytool, javadoc, ...}
38 | *
39 | * @return the name of the java tool.
40 | */
41 | String getJavaToolName();
42 |
43 | /**
44 | * Set an optional tool chain to find out the java tool executable location.
45 | *
46 | * @param toolchain optional tool chain to find out the java tool executable location.
47 | * To avoid direct dependency on Maven core, this parameter is an Object that will be
48 | * used as Toolchain through reflection
49 | */
50 | void setToolchain(Object toolchain);
51 |
52 | /**
53 | * Execute the input request and then returns the result of the execution.
54 | * If could not create the java tool invocation, a {@link JavaToolException} will be thrown.
55 | * If execution fails, then the result will have a none-zero {@link JavaToolResult#getExitCode()} and his
56 | * {@link JavaToolResult#getExecutionException()} will be filled with the error, otherwise the exist code will be
57 | * zero.
58 | *
59 | * @param request the request to perform
60 | * @return the result of the tool execution
61 | * @throws JavaToolException if could not create the java tool invocation
62 | */
63 | JavaToolResult execute(Request request) throws JavaToolException;
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolException.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.utils.cli.javatool;
20 |
21 | /**
22 | * Signals an error during the construction of the command line used to invoke java tool, e.g. illegal invocation
23 | * arguments.
24 | * This should not be confused with a failure of the invoked java tool build itself which will be reported by means
25 | * of a non-zero exit code.
26 | *
27 | * @author Tony Chemit
28 | *
29 | * @see JavaToolResult#getExitCode()
30 | * @since 0.5
31 | */
32 | public class JavaToolException extends Exception {
33 | private static final long serialVersionUID = 1L;
34 |
35 | /**
36 | * @param message The message of the exception.
37 | */
38 | public JavaToolException(String message) {
39 | super(message);
40 | }
41 |
42 | /**
43 | * @param message The message of the exception.
44 | * @param cause The cause of the exception.
45 | */
46 | public JavaToolException(String message, Throwable cause) {
47 | super(message, cause);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolRequest.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.utils.cli.javatool;
20 |
21 | import org.apache.maven.shared.utils.cli.StreamConsumer;
22 |
23 | /**
24 | * Specifies the minimum parameters used to control a {@link JavaTool} invocation.
25 | *
26 | * @author Tony Chemit
27 | * @since 0.5
28 | */
29 | public interface JavaToolRequest {
30 |
31 | /**
32 | * Gets the value of the {@code systemOutStreamConsumer} field.
33 | * This option field if filled is used by the commandline tool to consume system ouput stream of the jarsigner
34 | * command.
35 | *
36 | * @return the value of the {@code systemOutStreamConsumer} field.
37 | */
38 | StreamConsumer getSystemOutStreamConsumer();
39 |
40 | /**
41 | * Gets the value of the {@code systemErrorStreamConsumer} field.
42 | * This option field if filled is used by the commandline tool to consume system error stream of the jarsigner
43 | * command.
44 | *
45 | * @return the value of the {@code systemErrorStreamConsumer} field.
46 | */
47 | StreamConsumer getSystemErrorStreamConsumer();
48 |
49 | /**
50 | * Sets the new given value to the field {@code systemOutStreamConsumer} of the request.
51 | *
52 | * @param systemOutStreamConsumer the new value of the field {@code systemOutStreamConsumer}.
53 | */
54 | void setSystemOutStreamConsumer(StreamConsumer systemOutStreamConsumer);
55 |
56 | /**
57 | * Sets the new given value to the field {@code systemErrorStreamConsumer} of the request.
58 | *
59 | * @param systemErrorStreamConsumer the new value of the field {@code systemErrorStreamConsumer}.
60 | */
61 | void setSystemErrorStreamConsumer(StreamConsumer systemErrorStreamConsumer);
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolResult.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.utils.cli.javatool;
20 |
21 | import org.apache.maven.shared.utils.cli.CommandLineException;
22 | import org.apache.maven.shared.utils.cli.Commandline;
23 |
24 | /**
25 | * Describes the result of a {@link JavaTool} invocation.
26 | *
27 | * @author Tony Chemit
28 | * @since 0.5
29 | */
30 | public class JavaToolResult {
31 | /**
32 | * The exception that prevented to execute the command line, will be null
if jarSigner could be
33 | * successfully started.
34 | */
35 | private CommandLineException executionException;
36 |
37 | /**
38 | * The exit code reported by the Maven invocation.
39 | */
40 | private int exitCode = Integer.MIN_VALUE;
41 |
42 | /**
43 | * The command line used to obtain this result.
44 | */
45 | private Commandline commandline;
46 |
47 | /**
48 | * Gets the exit code from the tool invocation. A non-zero value indicates a build failure. Note:
49 | * This value is undefined if {@link #getExecutionException()} reports an exception.
50 | *
51 | * @return The exit code from the tool invocation.
52 | */
53 | public int getExitCode() {
54 | return exitCode;
55 | }
56 |
57 | /**
58 | * Gets the command line used.
59 | *
60 | * @return The command line used
61 | */
62 | public Commandline getCommandline() {
63 | return commandline;
64 | }
65 |
66 | /**
67 | * Gets the exception that possibly occurred during the execution of the command line.
68 | *
69 | * @return The exception that prevented to invoke tool or null
if the command line was successfully
70 | * processed by the operating system.
71 | */
72 | public CommandLineException getExecutionException() {
73 | return executionException;
74 | }
75 |
76 | /**
77 | * Sets the exit code reported by the tool invocation.
78 | *
79 | * @param exitCode The exit code reported by the tool invocation.
80 | */
81 | public void setExitCode(int exitCode) {
82 | this.exitCode = exitCode;
83 | }
84 |
85 | /**
86 | * Sets the exception that prevented to execute the command line.
87 | *
88 | * @param executionException The exception that prevented to execute the command line, may be null
.
89 | */
90 | public void setExecutionException(CommandLineException executionException) {
91 | this.executionException = executionException;
92 | }
93 |
94 | /**
95 | * Set the commandline used to obtain this result.
96 | *
97 | * @param commandline the commandline used to obtain this result
98 | */
99 | public void setCommandline(Commandline commandline) {
100 | this.commandline = commandline;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/shell/BourneShell.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.utils.cli.shell;
20 |
21 | import java.util.ArrayList;
22 | import java.util.List;
23 |
24 | import org.apache.maven.shared.utils.Os;
25 |
26 | /**
27 | * @author Jason van Zyl
28 | */
29 | public class BourneShell extends Shell {
30 |
31 | /**
32 | * Create instance of BourneShell.
33 | */
34 | public BourneShell() {
35 | setUnconditionalQuoting(true);
36 | setShellCommand("/bin/sh");
37 | setArgumentQuoteDelimiter('\'');
38 | setExecutableQuoteDelimiter('\'');
39 | setSingleQuotedArgumentEscaped(true);
40 | setSingleQuotedExecutableEscaped(false);
41 | setQuotedExecutableEnabled(true);
42 | }
43 |
44 | /**
45 | * {@inheritDoc}
46 | */
47 | public String getExecutable() {
48 | if (Os.isFamily(Os.FAMILY_WINDOWS)) {
49 | return super.getExecutable();
50 | }
51 |
52 | return quoteOneItem(super.getExecutable(), true);
53 | }
54 |
55 | /** {@inheritDoc} */
56 | public List getShellArgsList() {
57 | List shellArgs = new ArrayList<>();
58 | List existingShellArgs = super.getShellArgsList();
59 |
60 | if ((existingShellArgs != null) && !existingShellArgs.isEmpty()) {
61 | shellArgs.addAll(existingShellArgs);
62 | }
63 |
64 | shellArgs.add("-c");
65 |
66 | return shellArgs;
67 | }
68 |
69 | /** {@inheritDoc} */
70 | public String[] getShellArgs() {
71 | String[] shellArgs = super.getShellArgs();
72 | if (shellArgs == null) {
73 | shellArgs = new String[0];
74 | }
75 |
76 | if ((shellArgs.length > 0) && !shellArgs[shellArgs.length - 1].equals("-c")) {
77 | String[] newArgs = new String[shellArgs.length + 1];
78 |
79 | System.arraycopy(shellArgs, 0, newArgs, 0, shellArgs.length);
80 | newArgs[shellArgs.length] = "-c";
81 |
82 | shellArgs = newArgs;
83 | }
84 |
85 | return shellArgs;
86 | }
87 |
88 | /** {@inheritDoc} */
89 | protected String getExecutionPreamble() {
90 | if (getWorkingDirectoryAsString() == null) {
91 | return null;
92 | }
93 |
94 | String dir = getWorkingDirectoryAsString();
95 |
96 | return "cd " + quoteOneItem(dir, false) + " && ";
97 | }
98 |
99 | /**
100 | * Unify quotes in a path for the Bourne Shell.
101 | *
102 | * BourneShell.quoteOneItem(null) = null
103 | * BourneShell.quoteOneItem("") = ''
104 | * BourneShell.quoteOneItem("/test/quotedpath'abc") = '/test/quotedpath'"'"'abc'
105 | * BourneShell.quoteOneItem("/test/quoted path'abc") = '/test/quoted pat'"'"'habc'
106 | * BourneShell.quoteOneItem("/test/quotedpath\"abc") = '/test/quotedpath"abc'
107 | * BourneShell.quoteOneItem("/test/quoted path\"abc") = '/test/quoted path"abc'
108 | * BourneShell.quoteOneItem("/test/quotedpath\"'abc") = '/test/quotedpath"'"'"'abc'
109 | * BourneShell.quoteOneItem("/test/quoted path\"'abc") = '/test/quoted path"'"'"'abc'
110 | *
111 | *
112 | * @param path not null path.
113 | * @return the path unified correctly for the Bourne shell.
114 | */
115 | protected String quoteOneItem(String path, boolean isExecutable) {
116 | if (path == null) {
117 | return null;
118 | }
119 |
120 | return "'" + path.replace("'", "'\"'\"'") + "'";
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/shell/CmdShell.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.utils.cli.shell;
20 |
21 | import java.util.Arrays;
22 | import java.util.List;
23 |
24 | /**
25 | * Implementation to call the CMD Shell present on Windows NT, 2000, XP, 7, 8, and 10.
26 | *
27 | * @author Carlos Sanchez
28 | *
29 | */
30 | public class CmdShell extends Shell {
31 | /**
32 | * Create an instance of CmdShell.
33 | */
34 | public CmdShell() {
35 | setShellCommand("cmd.exe");
36 | setQuotedExecutableEnabled(true);
37 | setShellArgs(new String[] {"/X", "/C"});
38 | }
39 |
40 | /**
41 | *
42 | * Specific implementation that quotes all the command line.
43 | *
44 | *
45 | * Workaround for http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6468220
46 | *
47 | *
48 | * From cmd.exe /? output:
49 | *
50 | *
51 | * If /C or /K is specified, then the remainder of the command line after
52 | * the switch is processed as a command line, where the following logic is
53 | * used to process quote (") characters:
54 | *
55 | * 1. If all of the following conditions are met, then quote characters
56 | * on the command line are preserved:
57 | *
58 | * - no /S switch
59 | * - exactly two quote characters
60 | * - no special characters between the two quote characters,
61 | * where special is one of: &<>()@ˆ|
62 | * - there are one or more whitespace characters between the
63 | * the two quote characters
64 | * - the string between the two quote characters is the name
65 | * of an executable file.
66 | *
67 | * 2. Otherwise, old behavior is to see if the first character is
68 | * a quote character and if so, strip the leading character and
69 | * remove the last quote character on the command line, preserving
70 | * any text after the last quote character.
71 | *
72 | *
73 | * Always quoting the entire command line, regardless of these conditions
74 | * appears to make Windows processes invoke successfully.
75 | *
76 | *
77 | * @param executable The executable.
78 | * @param arguments The arguments for the executable.
79 | * @return The resulting command line.
80 | */
81 | public List getCommandLine(String executable, String... arguments) {
82 | StringBuilder sb = new StringBuilder();
83 | sb.append('"');
84 | sb.append(super.getCommandLine(executable, arguments).get(0));
85 | sb.append('"');
86 |
87 | return Arrays.asList(sb.toString());
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/cli/shell/CommandShell.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.utils.cli.shell;
20 |
21 | /**
22 | * Implementation to call the Command.com Shell present on Windows 95, 98 and Me
23 | *
24 | * @author Carlos Sanchez
25 | * @deprecated Windows ME is long dead. Update to Windows 10 and use {@link CmdShell}.
26 | */
27 | @Deprecated
28 | public class CommandShell extends Shell {
29 | /**
30 | * Create an instance.
31 | */
32 | public CommandShell() {
33 | setShellCommand("command.com");
34 | setShellArgs(new String[] {"/C"});
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/introspection/IntrospectionException.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.utils.introspection;
20 |
21 | class IntrospectionException extends Exception {
22 |
23 | /**
24 | *
25 | */
26 | private static final long serialVersionUID = -6090771282553728784L;
27 |
28 | IntrospectionException(String message) {
29 | super(message);
30 | }
31 |
32 | IntrospectionException(Throwable cause) {
33 | super(cause);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/DirectoryScanResult.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.utils.io;
20 |
21 | /**
22 | * Scan for files in a directory at a given time and reports removed and added files
23 | * between captures.
24 | *
25 | * @deprecated use {@code java.nio.file.DirectoryStream} and related classes
26 | */
27 | @Deprecated
28 | public class DirectoryScanResult {
29 | private final String[] filesAdded;
30 |
31 | private final String[] filesRemoved;
32 |
33 | /**
34 | * @param filesAdded Added files.
35 | * @param filesRemoved Removed files.
36 | */
37 | public DirectoryScanResult(String[] filesAdded, String[] filesRemoved) {
38 | this.filesAdded = filesAdded;
39 | this.filesRemoved = filesRemoved;
40 | }
41 |
42 | /**
43 | * @return all files which got detected as being added between 2 capture calls
44 | */
45 | public String[] getFilesAdded() {
46 | return filesAdded;
47 | }
48 |
49 | /**
50 | * @return all files which got detected as being removed between 2 capture calls
51 | */
52 | public String[] getFilesRemoved() {
53 | return filesRemoved;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/DirectoryWalkListener.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.utils.io;
20 |
21 | import java.io.File;
22 |
23 | /**
24 | * DirectoryWalkListener.
25 | *
26 | * @deprecated use {@code java.nio.file.FileVisitor} and related classes
27 | */
28 | @Deprecated
29 | public interface DirectoryWalkListener {
30 | /**
31 | * The directory walking has begun.
32 | *
33 | * @param basedir the basedir that walk started in
34 | */
35 | void directoryWalkStarting(File basedir);
36 |
37 | /**
38 | * The included entry that was encountered.
39 | *
40 | * @param percentage rough percentage of the walk completed. (inaccurate)
41 | * @param file the file that was included
42 | */
43 | void directoryWalkStep(int percentage, File file);
44 |
45 | /**
46 | * The directory walking has finished.
47 | */
48 | void directoryWalkFinished();
49 |
50 | /**
51 | * @param message the message for the debugging output
52 | */
53 | void debug(String message);
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/Java7Support.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.utils.io;
20 |
21 | import javax.annotation.Nonnull;
22 |
23 | import java.io.File;
24 | import java.io.IOException;
25 | import java.nio.file.Files;
26 |
27 | /**
28 | * Java7 feature detection
29 | *
30 | * @author Kristian Rosenvold
31 | *
32 | * @deprecated no longer needed, prefer to use {@link java.nio.file.Files} methods directly.
33 | */
34 | @Deprecated
35 | public class Java7Support {
36 | /**
37 | * @param file The file to check for being a symbolic link.
38 | * @return true if the file is a symlink false otherwise.
39 | */
40 | public static boolean isSymLink(@Nonnull File file) {
41 | return Files.isSymbolicLink(file.toPath());
42 | }
43 |
44 | /**
45 | * @param symlink The sym link.
46 | * @return The file.
47 | * @throws IOException in case of error.
48 | */
49 | @Nonnull
50 | public static File readSymbolicLink(@Nonnull File symlink) throws IOException {
51 | return Files.readSymbolicLink(symlink.toPath()).toFile();
52 | }
53 |
54 | /**
55 | * @param file The file to check.
56 | * @return true if exist false otherwise.
57 | * @throws IOException in case of failure.
58 | */
59 | public static boolean exists(@Nonnull File file) throws IOException {
60 | return Files.exists(file.toPath());
61 | }
62 |
63 | /**
64 | * @param symlink The link name.
65 | * @param target The target.
66 | * @return The linked file.
67 | * @throws IOException in case of an error.
68 | */
69 | @Nonnull
70 | public static File createSymbolicLink(@Nonnull File symlink, @Nonnull File target) throws IOException {
71 | return FileUtils.createSymbolicLink(symlink, target);
72 | }
73 |
74 | /**
75 | * Performs a nio delete
76 | * @param file the file to delete
77 | * @throws IOException in case of error.
78 | */
79 | public static void delete(@Nonnull File file) throws IOException {
80 | Files.delete(file.toPath());
81 | }
82 |
83 | /**
84 | * @return true in case of Java 7.
85 | */
86 | public static boolean isJava7() {
87 | return true;
88 | }
89 |
90 | /**
91 | * @return true in case of Java7 or greater.
92 | */
93 | public static boolean isAtLeastJava7() {
94 | return true;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/MatchPattern.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.utils.io;
20 |
21 | import javax.annotation.Nonnull;
22 |
23 | import java.io.File;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 | import java.util.StringTokenizer;
27 | import java.util.regex.Pattern;
28 |
29 | /**
30 | * Describes a match target for SelectorUtils.
31 | *
32 | * Significantly more efficient than using strings, since re-evaluation and re-tokenizing is avoided.
33 | *
34 | * @author Kristian Rosenvold
35 | * @deprecated use {@code java.nio.file.DirectoryStream.Filter} and related classes
36 | */
37 | @Deprecated
38 | public class MatchPattern {
39 | private final String source;
40 |
41 | private final String regexPattern;
42 |
43 | private final Pattern regexPatternRegex;
44 |
45 | private final String separator;
46 |
47 | private final String[] tokenized;
48 |
49 | private MatchPattern(@Nonnull String source, @Nonnull String separator) {
50 | regexPattern = SelectorUtils.isRegexPrefixedPattern(source)
51 | ? source.substring(
52 | SelectorUtils.REGEX_HANDLER_PREFIX.length(),
53 | source.length() - SelectorUtils.PATTERN_HANDLER_SUFFIX.length())
54 | : null;
55 | regexPatternRegex = regexPattern != null ? Pattern.compile(regexPattern) : null;
56 | this.source = SelectorUtils.isAntPrefixedPattern(source)
57 | ? source.substring(
58 | SelectorUtils.ANT_HANDLER_PREFIX.length(),
59 | source.length() - SelectorUtils.PATTERN_HANDLER_SUFFIX.length())
60 | : source;
61 | this.separator = separator;
62 | tokenized = tokenizePathToString(this.source, separator);
63 | }
64 |
65 | /**
66 | * @param str The string to match for.
67 | * @param isCaseSensitive case sensitive true false otherwise.
68 | * @return true if matches false otherwise.
69 | */
70 | public boolean matchPath(String str, boolean isCaseSensitive) {
71 | if (regexPattern != null) {
72 | return regexPatternRegex.matcher(str).matches();
73 | } else {
74 | return SelectorUtils.matchAntPathPattern(this, str, separator, isCaseSensitive);
75 | }
76 | }
77 |
78 | boolean matchPath(String str, String[] strDirs, boolean isCaseSensitive) {
79 | if (regexPattern != null) {
80 | return regexPatternRegex.matcher(str).matches();
81 | } else {
82 | return SelectorUtils.matchAntPathPattern(getTokenizedPathString(), strDirs, isCaseSensitive);
83 | }
84 | }
85 |
86 | /**
87 | * @param str The string to check.
88 | * @param isCaseSensitive Check case sensitive or not.
89 | * @return true in case of matching pattern.
90 | */
91 | public boolean matchPatternStart(@Nonnull String str, boolean isCaseSensitive) {
92 | if (regexPattern != null) {
93 | // FIXME: ICK! But we can't do partial matches for regex, so we have to reserve judgment until we have
94 | // a file to deal with, or we can definitely say this is an exclusion...
95 | return true;
96 | } else {
97 | String altStr = source.replace('\\', '/');
98 |
99 | return SelectorUtils.matchAntPathPatternStart(this, str, File.separator, isCaseSensitive)
100 | || SelectorUtils.matchAntPathPatternStart(this, altStr, "/", isCaseSensitive);
101 | }
102 | }
103 |
104 | /**
105 | * @return Tokenized string.
106 | */
107 | public String[] getTokenizedPathString() {
108 | return tokenized;
109 | }
110 |
111 | /**
112 | * @param string The part which will be checked to start with.
113 | * @return true in case of starting with the string false otherwise.
114 | */
115 | public boolean startsWith(String string) {
116 | return source.startsWith(string);
117 | }
118 |
119 | static String[] tokenizePathToString(@Nonnull String path, @Nonnull String separator) {
120 | List ret = new ArrayList<>();
121 | StringTokenizer st = new StringTokenizer(path, separator);
122 | while (st.hasMoreTokens()) {
123 | ret.add(st.nextToken());
124 | }
125 | return ret.toArray(new String[ret.size()]);
126 | }
127 |
128 | /**
129 | * @param source The source.
130 | * @return The match pattern.
131 | */
132 | public static MatchPattern fromString(String source) {
133 | return new MatchPattern(source, File.separator);
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/MatchPatterns.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.utils.io;
20 |
21 | import javax.annotation.Nonnull;
22 |
23 | import java.io.File;
24 |
25 | /**
26 | * A list of patterns to be matched
27 | *
28 | * @author Kristian Rosenvold
29 | * @deprecated use {@code java.nio.file.DirectoryStream.Filter} and related classes
30 | */
31 | @Deprecated
32 | public class MatchPatterns {
33 | private final MatchPattern[] patterns;
34 |
35 | private MatchPatterns(@Nonnull MatchPattern... patterns) {
36 | this.patterns = patterns;
37 | }
38 |
39 | /**
40 | * Checks these MatchPatterns against a specified string.
41 | * Uses far less string tokenization than any of the alternatives.
42 | *
43 | * @param name The name to look for
44 | * @param isCaseSensitive If the comparison is case sensitive
45 | * @return true if any of the supplied patterns match
46 | */
47 | public boolean matches(@Nonnull String name, boolean isCaseSensitive) {
48 | String[] tokenized = MatchPattern.tokenizePathToString(name, File.separator);
49 | for (MatchPattern pattern : patterns) {
50 | if (pattern.matchPath(name, tokenized, isCaseSensitive)) {
51 | return true;
52 | }
53 | }
54 | return false;
55 | }
56 |
57 | /**
58 | * @param name The name.
59 | * @param isCaseSensitive being case sensetive.
60 | * @return true if any of the supplied patterns match start.
61 | */
62 | public boolean matchesPatternStart(@Nonnull String name, boolean isCaseSensitive) {
63 | for (MatchPattern includesPattern : patterns) {
64 | if (includesPattern.matchPatternStart(name, isCaseSensitive)) {
65 | return true;
66 | }
67 | }
68 | return false;
69 | }
70 |
71 | /**
72 | * @param sources The sources
73 | * @return Converted match patterns.
74 | */
75 | public static MatchPatterns from(@Nonnull String... sources) {
76 | final int length = sources.length;
77 | MatchPattern[] result = new MatchPattern[length];
78 | for (int i = 0; i < length; i++) {
79 | result[i] = MatchPattern.fromString(sources[i]);
80 | }
81 | return new MatchPatterns(result);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/ScanConductor.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.utils.io;
20 |
21 | import java.io.File;
22 |
23 | /**
24 | * Visitor pattern for the DirectoryScanner. A ScanConductor controls the scanning process.
25 | * Create an instance and pass it to
26 | * {@link org.apache.maven.shared.utils.io.DirectoryScanner#setScanConductor(ScanConductor)}.
27 | * You will get notified about every visited directory and file. You can use the {@link ScanAction}
28 | * to control what should happen next.
29 | * A ScanConductor might also store own information but users must make sure that the state gets
30 | * cleaned between two scan() invocations.
31 | *
32 | * @author Mark Struberg
33 | *
34 | * @deprecated use {@code java.nio.file.Files.walkFileTree()} and related classes
35 | */
36 | @Deprecated
37 | public interface ScanConductor {
38 | /**
39 | *
40 | */
41 | enum ScanAction {
42 | /**
43 | * Abort the whole scanning process. The current file will not
44 | * be added anymore.
45 | */
46 | ABORT,
47 |
48 | /**
49 | * Continue the scanning with the next item in the list.
50 | */
51 | CONTINUE,
52 |
53 | /**
54 | * This response is only valid for {@link ScanConductor#visitDirectory(String, java.io.File)}.
55 | * Do not recurse into the current directory. The current directory will not be added
56 | * and the processing will be continued with the next item in the list.
57 | */
58 | NO_RECURSE,
59 |
60 | /**
61 | * Abort processing the current directory.
62 | * The current file will not be added.
63 | * The processing will continue it's scan in the parent directory if any.
64 | */
65 | ABORT_DIRECTORY
66 | }
67 |
68 | /**
69 | * This method will get invoked for every detected directory.
70 | *
71 | * @param name the directory name (contains parent folders up to the pwd)
72 | * @param directory The directory.
73 | * @return the ScanAction to control how to proceed with the scanning
74 | */
75 | ScanAction visitDirectory(String name, File directory);
76 |
77 | /**
78 | * This method will get invoked for every detected file.
79 | *
80 | * @param name the file name (contains parent folders up to the pwd)
81 | * @param file The file.
82 | * @return the ScanAction to control how to proceed with the scanning
83 | */
84 | ScanAction visitFile(String name, File file);
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/io/WalkCollector.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.utils.io;
20 |
21 | import java.io.File;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | /**
26 | * @deprecated use {@code java.nio.file.FileVisitor} and related classes
27 | */
28 | @Deprecated
29 | public class WalkCollector implements DirectoryWalkListener {
30 | final List steps;
31 |
32 | File startingDir;
33 |
34 | int startCount;
35 |
36 | int finishCount;
37 |
38 | int percentageLow;
39 |
40 | int percentageHigh;
41 |
42 | /**
43 | * Create an instance.
44 | */
45 | public WalkCollector() {
46 | steps = new ArrayList<>();
47 | startCount = 0;
48 | finishCount = 0;
49 | percentageLow = 0;
50 | percentageHigh = 0;
51 | }
52 |
53 | /** {@inheritDoc} */
54 | public void debug(String message) {
55 | // can be used to set some message
56 | }
57 |
58 | /** {@inheritDoc} */
59 | public void directoryWalkStarting(File basedir) {
60 | startingDir = basedir;
61 | startCount++;
62 | }
63 |
64 | /** {@inheritDoc} */
65 | public void directoryWalkStep(int percentage, File file) {
66 | steps.add(file);
67 | percentageLow = Math.min(percentageLow, percentage);
68 | percentageHigh = Math.max(percentageHigh, percentage);
69 | }
70 |
71 | /** {@inheritDoc} */
72 | public void directoryWalkFinished() {
73 | finishCount++;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilder.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.utils.logging;
20 |
21 | import org.fusesource.jansi.Ansi;
22 |
23 | /**
24 | * Message builder implementation that supports ANSI colors through
25 | * Jansi with configurable styles through {@link Style}.
26 | */
27 | class AnsiMessageBuilder implements MessageBuilder, LoggerLevelRenderer {
28 | private Ansi ansi;
29 |
30 | AnsiMessageBuilder() {
31 | this(Ansi.ansi());
32 | }
33 |
34 | AnsiMessageBuilder(StringBuilder builder) {
35 | this(Ansi.ansi(builder));
36 | }
37 |
38 | AnsiMessageBuilder(int size) {
39 | this(Ansi.ansi(size));
40 | }
41 |
42 | AnsiMessageBuilder(Ansi ansi) {
43 | this.ansi = ansi;
44 | }
45 |
46 | public String debug(String message) {
47 | return Style.DEBUG.apply(ansi).a(message).reset().toString();
48 | }
49 |
50 | public String info(String message) {
51 | return Style.INFO.apply(ansi).a(message).reset().toString();
52 | }
53 |
54 | public String warning(String message) {
55 | return Style.WARNING.apply(ansi).a(message).reset().toString();
56 | }
57 |
58 | public String error(String message) {
59 | return Style.ERROR.apply(ansi).a(message).reset().toString();
60 | }
61 |
62 | public AnsiMessageBuilder success(Object message) {
63 | Style.SUCCESS.apply(ansi).a(message).reset();
64 | return this;
65 | }
66 |
67 | public AnsiMessageBuilder warning(Object message) {
68 | Style.WARNING.apply(ansi).a(message).reset();
69 | return this;
70 | }
71 |
72 | public AnsiMessageBuilder failure(Object message) {
73 | Style.FAILURE.apply(ansi).a(message).reset();
74 | return this;
75 | }
76 |
77 | public AnsiMessageBuilder strong(Object message) {
78 | Style.STRONG.apply(ansi).a(message).reset();
79 | return this;
80 | }
81 |
82 | public AnsiMessageBuilder mojo(Object message) {
83 | Style.MOJO.apply(ansi).a(message).reset();
84 | return this;
85 | }
86 |
87 | public AnsiMessageBuilder project(Object message) {
88 | Style.PROJECT.apply(ansi).a(message).reset();
89 | return this;
90 | }
91 |
92 | public AnsiMessageBuilder a(char[] value, int offset, int len) {
93 | ansi.a(value, offset, len);
94 | return this;
95 | }
96 |
97 | public AnsiMessageBuilder a(char[] value) {
98 | ansi.a(value);
99 | return this;
100 | }
101 |
102 | public AnsiMessageBuilder a(CharSequence value, int start, int end) {
103 | ansi.a(value, start, end);
104 | return this;
105 | }
106 |
107 | public AnsiMessageBuilder a(CharSequence value) {
108 | ansi.a(value);
109 | return this;
110 | }
111 |
112 | public AnsiMessageBuilder a(Object value) {
113 | ansi.a(value);
114 | return this;
115 | }
116 |
117 | public AnsiMessageBuilder newline() {
118 | ansi.newline();
119 | return this;
120 | }
121 |
122 | public AnsiMessageBuilder format(String pattern, Object... args) {
123 | ansi.format(pattern, args);
124 | return this;
125 | }
126 |
127 | @Override
128 | public String toString() {
129 | return build();
130 | }
131 |
132 | @Override
133 | public String build() {
134 | return ansi.toString();
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/logging/LoggerLevelRenderer.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.utils.logging;
20 |
21 | /**
22 | * Logger level renderer, intended for Maven slf4j logging provider implementers to render
23 | * logger level.
24 | *
25 | * @since 3.2.0
26 | */
27 | public interface LoggerLevelRenderer {
28 | /**
29 | * Render a message at DEBUG level.
30 | * @param message the message to render.
31 | * @return the formatted message.
32 | */
33 | String debug(String message);
34 |
35 | /**
36 | * Render a message at INFO level.
37 | * @param message the message to render.
38 | * @return the formatted message.
39 | */
40 | String info(String message);
41 |
42 | /**
43 | * Render a message at WARNING level.
44 | * @param message the message to render.
45 | * @return the formatted message.
46 | */
47 | String warning(String message);
48 |
49 | /**
50 | * Render a message at ERROR level.
51 | * @param message the message to render.
52 | * @return the formatted message.
53 | */
54 | String error(String message);
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/logging/MessageBuilder.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.utils.logging;
20 |
21 | import java.util.Formatter;
22 |
23 | /**
24 | * Message builder that supports configurable styling.
25 | * An instance of this interface can be retrieved with {@link MessageUtils#buffer()}.
26 | * After the message has been constructed with any of the append methods its content can be retrieved
27 | * with {@link #build()}.
28 | *
29 | * @see MessageUtils
30 | * @since 3.1.0
31 | */
32 | public interface MessageBuilder {
33 | /**
34 | * Append message content in success style.
35 | * By default, bold green
36 | * @param message the message to append
37 | * @return the current builder
38 | */
39 | MessageBuilder success(Object message);
40 |
41 | /**
42 | * Append message content in warning style.
43 | * By default, bold yellow
44 | * @param message the message to append
45 | * @return the current builder
46 | */
47 | MessageBuilder warning(Object message);
48 |
49 | /**
50 | * Append message content in failure style.
51 | * By default, bold red
52 | * @param message the message to append
53 | * @return the current builder
54 | */
55 | MessageBuilder failure(Object message);
56 |
57 | /**
58 | * Append message content in strong style.
59 | * By default, bold
60 | * @param message the message to append
61 | * @return the current builder
62 | */
63 | MessageBuilder strong(Object message);
64 |
65 | /**
66 | * Append message content in mojo style.
67 | * By default, green
68 | * @param message the message to append
69 | * @return the current builder
70 | */
71 | MessageBuilder mojo(Object message);
72 |
73 | /**
74 | * Append message content in project style.
75 | * By default, cyan
76 | * @param message the message to append
77 | * @return the current builder
78 | */
79 | MessageBuilder project(Object message);
80 |
81 | //
82 | // message building methods modelled after Ansi methods
83 | //
84 | /**
85 | * Append content to the message buffer.
86 | * @param value the content to append
87 | * @param offset the index of the first {@code char} to append
88 | * @param len the number of {@code char}s to append
89 | * @return the current builder
90 | */
91 | MessageBuilder a(char[] value, int offset, int len);
92 |
93 | /**
94 | * Append content to the message buffer.
95 | * @param value the content to append
96 | * @return the current builder
97 | */
98 | MessageBuilder a(char[] value);
99 |
100 | /**
101 | * Append content to the message buffer.
102 | * @param value the content to append
103 | * @param start the starting index of the subsequence to be appended
104 | * @param end the end index of the subsequence to be appended
105 | * @return the current builder
106 | */
107 | MessageBuilder a(CharSequence value, int start, int end);
108 |
109 | /**
110 | * Append content to the message buffer.
111 | * @param value the content to append
112 | * @return the current builder
113 | */
114 | MessageBuilder a(CharSequence value);
115 |
116 | /**
117 | * Append content to the message buffer.
118 | * @param value the content to append
119 | * @return the current builder
120 | */
121 | MessageBuilder a(Object value);
122 |
123 | /**
124 | * Append newline to the message buffer.
125 | * @return the current builder
126 | */
127 | MessageBuilder newline();
128 |
129 | /**
130 | * Append formatted content to the buffer.
131 | * @see String#format(String, Object...)
132 | * @param pattern a format string according to the {@link Formatter} syntax
133 | * @param args arguments referenced by the format specifiers in the format string.
134 | * @return the current builder
135 | */
136 | MessageBuilder format(String pattern, Object... args);
137 |
138 | /**
139 | * Get the message constructed by this builder.
140 | * The underlying buffer is not reset with this method, i.e. if you continue using this builder you just
141 | * append content to the existing one.
142 | * @return the message
143 | * @since 4.0.0
144 | */
145 | String build();
146 |
147 | /**
148 | * Same as {@link MessageBuilder#build()}.
149 | * @deprecated Rather use {@link MessageBuilder#build()}
150 | */
151 | @Deprecated
152 | String toString();
153 | }
154 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/logging/PlainMessageBuilder.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.utils.logging;
20 |
21 | /**
22 | * Message builder implementation that just ignores styling, for Maven version earlier than 3.5.0.
23 | */
24 | class PlainMessageBuilder implements MessageBuilder, LoggerLevelRenderer {
25 | private StringBuilder buffer;
26 |
27 | PlainMessageBuilder() {
28 | buffer = new StringBuilder();
29 | }
30 |
31 | PlainMessageBuilder(StringBuilder builder) {
32 | buffer = builder;
33 | }
34 |
35 | PlainMessageBuilder(int size) {
36 | buffer = new StringBuilder(size);
37 | }
38 |
39 | public String debug(String message) {
40 | return a(message).toString();
41 | }
42 |
43 | public String info(String message) {
44 | return a(message).toString();
45 | }
46 |
47 | public String warning(String message) {
48 | return a(message).toString();
49 | }
50 |
51 | public String error(String message) {
52 | return a(message).toString();
53 | }
54 |
55 | public PlainMessageBuilder success(Object message) {
56 | return a(message);
57 | }
58 |
59 | public PlainMessageBuilder warning(Object message) {
60 | return a(message);
61 | }
62 |
63 | public PlainMessageBuilder failure(Object message) {
64 | return a(message);
65 | }
66 |
67 | public PlainMessageBuilder strong(Object message) {
68 | return a(message);
69 | }
70 |
71 | public PlainMessageBuilder mojo(Object message) {
72 | return a(message);
73 | }
74 |
75 | public PlainMessageBuilder project(Object message) {
76 | return a(message);
77 | }
78 |
79 | public PlainMessageBuilder a(char[] value, int offset, int len) {
80 | buffer.append(value, offset, len);
81 | return this;
82 | }
83 |
84 | public PlainMessageBuilder a(char[] value) {
85 | buffer.append(value);
86 | return this;
87 | }
88 |
89 | public PlainMessageBuilder a(CharSequence value, int start, int end) {
90 | buffer.append(value, start, end);
91 | return this;
92 | }
93 |
94 | public PlainMessageBuilder a(CharSequence value) {
95 | buffer.append(value);
96 | return this;
97 | }
98 |
99 | public PlainMessageBuilder a(Object value) {
100 | buffer.append(value);
101 | return this;
102 | }
103 |
104 | public PlainMessageBuilder newline() {
105 | buffer.append(System.lineSeparator());
106 | return this;
107 | }
108 |
109 | public PlainMessageBuilder format(String pattern, Object... args) {
110 | buffer.append(String.format(pattern, args));
111 | return this;
112 | }
113 |
114 | @Override
115 | public String toString() {
116 | return build();
117 | }
118 |
119 | @Override
120 | public String build() {
121 | return buffer.toString();
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/logging/Style.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.utils.logging;
20 |
21 | import java.util.Locale;
22 |
23 | import org.fusesource.jansi.Ansi;
24 | import org.fusesource.jansi.Ansi.Color;
25 |
26 | /**
27 | * Configurable message styles.
28 | * @since 3.1.0
29 | */
30 | enum Style {
31 | DEBUG("bold,cyan"),
32 | INFO("bold,blue"),
33 | WARNING("bold,yellow"),
34 | ERROR("bold,red"),
35 | SUCCESS("bold,green"),
36 | FAILURE("bold,red"),
37 | STRONG("bold"),
38 | MOJO("green"),
39 | PROJECT("cyan");
40 |
41 | private final boolean bold;
42 |
43 | private final boolean bright;
44 |
45 | private final Color color;
46 |
47 | private final boolean bgBright;
48 |
49 | private final Color bgColor;
50 |
51 | Style(String defaultValue) {
52 | boolean currentBold = false;
53 | boolean currentBright = false;
54 | Color currentColor = null;
55 | boolean currentBgBright = false;
56 | Color currentBgColor = null;
57 |
58 | String value = System.getProperty("style." + name().toLowerCase(Locale.ENGLISH), defaultValue)
59 | .toLowerCase(Locale.ENGLISH);
60 |
61 | for (String token : value.split(",")) {
62 | if ("bold".equals(token)) {
63 | currentBold = true;
64 | } else if (token.startsWith("bg")) {
65 | token = token.substring(2);
66 | if (token.startsWith("bright")) {
67 | currentBgBright = true;
68 | token = token.substring(6);
69 | }
70 | currentBgColor = toColor(token);
71 | } else {
72 | if (token.startsWith("bright")) {
73 | currentBright = true;
74 | token = token.substring(6);
75 | }
76 | currentColor = toColor(token);
77 | }
78 | }
79 |
80 | this.bold = currentBold;
81 | this.bright = currentBright;
82 | this.color = currentColor;
83 | this.bgBright = currentBgBright;
84 | this.bgColor = currentBgColor;
85 | }
86 |
87 | private static Color toColor(String token) {
88 | for (Color color : Color.values()) {
89 | if (color.toString().equalsIgnoreCase(token)) {
90 | return color;
91 | }
92 | }
93 | return null;
94 | }
95 |
96 | Ansi apply(Ansi ansi) {
97 | if (bold) {
98 | ansi.bold();
99 | }
100 | if (color != null) {
101 | if (bright) {
102 | ansi.fgBright(color);
103 | } else {
104 | ansi.fg(color);
105 | }
106 | }
107 | if (bgColor != null) {
108 | if (bgBright) {
109 | ansi.bgBright(bgColor);
110 | } else {
111 | ansi.bg(bgColor);
112 | }
113 | }
114 | return ansi;
115 | }
116 |
117 | @Override
118 | public String toString() {
119 | if (!bold && color == null && bgColor == null) {
120 | return name();
121 | }
122 | StringBuilder sb = new StringBuilder(name() + '=');
123 | if (bold) {
124 | sb.append("bold");
125 | }
126 | if (color != null) {
127 | if (sb.length() > 0) {
128 | sb.append(',');
129 | }
130 | if (bright) {
131 | sb.append("bright");
132 | }
133 | sb.append(color.name());
134 | }
135 | if (bgColor != null) {
136 | if (sb.length() > 0) {
137 | sb.append(',');
138 | }
139 | sb.append("bg");
140 | if (bgBright) {
141 | sb.append("bright");
142 | }
143 | sb.append(bgColor.name());
144 | }
145 | return sb.toString();
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/logging/package-info.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 |
20 | /**
21 | * An API to write Maven messages to console with styled color content, consistently across whole
22 | * Maven ecosystem (Maven itself or any plugin or extension).
23 | *
24 | * Messages are built with instances of {@code MessageBuilder}
25 | * which provides a fluent API, while error level are colored by slf4j provider with
26 | * {@code LoggerLevelRenderer}.
27 | *
28 | * {@code MessageUtils} gives access to these builders.
29 | *
30 | * Plugins can use this API with any Maven version: color
31 | * just won't be activated when run with Maven versions older than 3.5.0.
32 | *
33 | * Styles are:
34 | * debug
, info
, warning
and error
for
35 | * logger level rendering,
36 | * success
, warning
, failure
, strong
, mojo
37 | * and project
for message content
38 | *
39 | * Default styles colors can be overridden through system properties, that can be set in MAVEN_OPTS
40 | * environment variable (eventually in .mavenrc
script):
41 | * - system properties are named
style.<style name>
,
42 | * - values are comma separated combination of
bold
, <color>
and
43 | * bg<color>
(for background), where <color>
is
44 | * an ANSI color: black
,
45 | * red
, green
, yellow
, blue
, magenta
,
46 | * cyan
or white
, eventually with bright
prefix
47 | *
48 | *
49 | * @since 3.1.0
50 | */
51 | package org.apache.maven.shared.utils.logging;
52 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/XMLEncode.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.utils.xml;
20 |
21 | import java.io.IOException;
22 | import java.io.Writer;
23 |
24 | /**
25 | * Collection of XML encoding/decoding helpers.
26 | * This is all about the special characters & and <, and for attributes
27 | * " and '. These must be encoded/decoded from/to XML.
28 | */
29 | final class XMLEncode {
30 |
31 | private static final int CDATA_BLOCK_THRESHOLD_LENGTH = 12;
32 |
33 | private static final char DEFAULT_QUOTE_CHAR = '"';
34 |
35 | static void xmlEncodeText(String text, Writer writer) throws IOException {
36 | if (text == null) {
37 | return;
38 | }
39 |
40 | if (!needsEncoding(text)) {
41 | writer.write(text);
42 | return;
43 | } else {
44 | // only encode as cdata if is is longer than CDATA block overhead:
45 | if (text.length() > CDATA_BLOCK_THRESHOLD_LENGTH) {
46 | String cdata = xmlEncodeTextAsCDATABlock(text);
47 | if (cdata != null) {
48 | writer.write(cdata);
49 | return;
50 | }
51 | }
52 | }
53 |
54 | // if every thing else fails, do it the save way...
55 | xmlEncodeTextAsPCDATA(text, false, DEFAULT_QUOTE_CHAR, writer);
56 | }
57 |
58 | static void xmlEncodeTextAsPCDATA(String text, boolean forAttribute, char quoteChar, Writer n) throws IOException {
59 | if (text == null) {
60 | return;
61 | }
62 |
63 | int length = text.length();
64 | if (forAttribute) {
65 | n.append(quoteChar);
66 | }
67 |
68 | for (int i = 0; i < length; i++) {
69 | char c = text.charAt(i);
70 | switch (c) {
71 | case '&':
72 | n.append("&");
73 | break;
74 | case '<':
75 | n.append("<");
76 | break;
77 | case '>': // FIX for sourceforge bug #802520 ("]]>" needs encoding)
78 | n.append(">");
79 | break;
80 | case '"':
81 | if (forAttribute) {
82 | n.append(""");
83 | } else {
84 | n.append(c);
85 | }
86 | break;
87 | case '\'':
88 | if (forAttribute) {
89 | n.append("'");
90 | } else {
91 | n.append(c);
92 | }
93 | break;
94 | case '\r':
95 | if (forAttribute) {
96 | if (i == (length - 1) || text.charAt(i + 1) != '\n') {
97 | n.append("
");
98 | }
99 | } else {
100 | n.append(c);
101 | }
102 | // but skip the \r in \r\n
103 |
104 | break;
105 | case '\n':
106 | if (forAttribute) {
107 | n.append("
");
108 | }
109 | break;
110 |
111 | default:
112 | n.append(c);
113 | break;
114 | }
115 | }
116 |
117 | if (forAttribute) {
118 | n.append(quoteChar);
119 | }
120 | }
121 |
122 | /**
123 | * Returns string as CDATA block if possible, otherwise null.
124 | */
125 | private static String xmlEncodeTextAsCDATABlock(String text) {
126 | if (text == null) {
127 | return null;
128 | }
129 | if (!text.contains("]]>")) {
130 | return "";
131 | } else {
132 | return null;
133 | }
134 | }
135 |
136 | /**
137 | * Checks if this text needs encoding in order to be represented in XML.
138 | */
139 | private static boolean needsEncoding(String text) {
140 | if (text == null) {
141 | return false;
142 | }
143 | for (int i = 0; i < text.length(); i++) {
144 | char c = text.charAt(i);
145 | if (c == '&' || c == '<') {
146 | return true;
147 | }
148 | }
149 | return false;
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/XMLWriter.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.utils.xml;
20 |
21 | import java.io.IOException;
22 |
23 | /**
24 | * Interface for tools writing XML files.
25 | * XMLWriters are not thread safe and must not be accessed concurrently.
26 | */
27 | @Deprecated
28 | public interface XMLWriter {
29 |
30 | /**
31 | * Sets the encoding of the document.
32 | * If not set, UTF-8 is used.
33 | *
34 | * @param encoding the encoding
35 | * @throws IllegalStateException if the generation of the document has already started
36 | */
37 | void setEncoding(String encoding);
38 |
39 | /**
40 | * Sets the DOCTYPE of the document.
41 | *
42 | * @param docType the docType
43 | * @throws IllegalStateException if the generation of the document has already started
44 | */
45 | void setDocType(String docType);
46 |
47 | /**
48 | * Start an XML Element tag.
49 | *
50 | * @param name the name of the tag
51 | * @throws IOException if starting the element fails
52 | */
53 | void startElement(String name) throws IOException;
54 |
55 | /**
56 | * Add a XML attribute to the current XML Element.
57 | * This method must get called immediately after {@link #startElement(String)}.
58 | *
59 | * @param key The key of the attribute.
60 | * @param value The value of the attribute.
61 | * @throws IllegalStateException if no element tag is currently in process
62 | * @throws IOException if adding the attribute fails.
63 | */
64 | void addAttribute(String key, String value) throws IOException;
65 |
66 | /**
67 | * Add text to the current element tag.
68 | * This performs XML escaping to guarantee well-formed content.
69 | *
70 | * @param text The text which should be written.
71 | * @throws IllegalStateException if no element tag got started yet
72 | * @throws IOException if writing the text fails.
73 | */
74 | void writeText(String text) throws IOException;
75 |
76 | /**
77 | * Add preformatted markup to the current element tag.
78 | *
79 | * @param text the text which should be written
80 | * @throws IllegalStateException if no element tag is started yet
81 | * @throws IOException if writing the markup fails
82 | */
83 | void writeMarkup(String text) throws IOException;
84 |
85 | /**
86 | * End the previously opened element.
87 | * @see #startElement(String)
88 | * @throws IOException if ending the element fails.
89 | */
90 | void endElement() throws IOException;
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamReader.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.utils.xml;
20 |
21 | import java.io.File;
22 | import java.io.FileInputStream;
23 | import java.io.IOException;
24 | import java.io.InputStream;
25 | import java.io.Reader;
26 | import java.net.URL;
27 | import java.net.URLConnection;
28 | import java.util.regex.Pattern;
29 |
30 | /**
31 | * @deprecated use org.apache.commons.io.input.XmlStreamReader instead
32 | */
33 | @Deprecated
34 | public class XmlStreamReader extends Reader {
35 | private final org.apache.commons.io.input.XmlStreamReader reader;
36 |
37 | private static String staticDefaultEncoding = null;
38 |
39 | /**
40 | * @param encoding define the default encoding.
41 | */
42 | public static void setDefaultEncoding(String encoding) {
43 | staticDefaultEncoding = encoding;
44 | }
45 |
46 | /**
47 | * @return the default encoding.
48 | */
49 | public static String getDefaultEncoding() {
50 | return staticDefaultEncoding;
51 | }
52 |
53 | /**
54 | * @param file The file to create it from.
55 | * @throws IOException in case of an error
56 | */
57 | public XmlStreamReader(File file) throws IOException {
58 | this(new FileInputStream(file));
59 | }
60 |
61 | /**
62 | * @param is {@link InputStream}
63 | * @throws IOException in case of an error
64 | */
65 | public XmlStreamReader(InputStream is) throws IOException {
66 | this(is, true);
67 | }
68 |
69 | /**
70 | * @param is {@link InputStream}
71 | * @param lenient yes/no
72 | * @throws IOException in case of an error
73 | */
74 | public XmlStreamReader(InputStream is, boolean lenient) throws IOException {
75 | reader = new org.apache.commons.io.input.XmlStreamReader(is, lenient, staticDefaultEncoding);
76 | }
77 |
78 | /**
79 | * @param url {@link URL}
80 | * @throws IOException in case of error
81 | */
82 | public XmlStreamReader(URL url) throws IOException {
83 | this(url.openConnection());
84 | }
85 |
86 | /**
87 | * @param conn The URL connection {@link URLConnection}
88 | * @throws IOException in case of error
89 | */
90 | public XmlStreamReader(URLConnection conn) throws IOException {
91 | reader = new org.apache.commons.io.input.XmlStreamReader(conn, staticDefaultEncoding);
92 | }
93 |
94 | /**
95 | * @param is {@link InputStream}
96 | * @param httpContentType content type
97 | * @throws IOException in case of error
98 | */
99 | public XmlStreamReader(InputStream is, String httpContentType) throws IOException {
100 | this(is, httpContentType, true);
101 | }
102 |
103 | /**
104 | * @param is {@link InputStream}
105 | * @param httpContentType content type
106 | * @param lenient yes/no
107 | * @param defaultEncoding the default encoding
108 | * @throws IOException in case of error
109 | */
110 | public XmlStreamReader(InputStream is, String httpContentType, boolean lenient, String defaultEncoding)
111 | throws IOException {
112 | reader = new org.apache.commons.io.input.XmlStreamReader(
113 | is, httpContentType, lenient, (defaultEncoding == null) ? staticDefaultEncoding : defaultEncoding);
114 | }
115 |
116 | /**
117 | * @param is {@link InputStream}
118 | * @param httpContentType content type
119 | * @param lenient yes/no
120 | * @throws IOException in case of error
121 | */
122 | public XmlStreamReader(InputStream is, String httpContentType, boolean lenient) throws IOException {
123 | this(is, httpContentType, lenient, null);
124 | }
125 |
126 | /**
127 | * @return the current encoding
128 | */
129 | public String getEncoding() {
130 | return reader.getEncoding();
131 | }
132 |
133 | /** {@inheritDoc} */
134 | public int read(char[] buf, int offset, int len) throws IOException {
135 | return reader.read(buf, offset, len);
136 | }
137 |
138 | /** {@inheritDoc} */
139 | public void close() throws IOException {
140 | reader.close();
141 | }
142 |
143 | static final Pattern ENCODING_PATTERN =
144 | Pattern.compile("<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))", Pattern.MULTILINE);
145 | }
146 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/XmlStreamWriter.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.utils.xml;
20 |
21 | import java.io.File;
22 | import java.io.FileNotFoundException;
23 | import java.io.OutputStream;
24 |
25 | /**
26 | * @deprecated use org.apache.commons.io.input.XmlStreamWriter instead
27 | */
28 | @Deprecated
29 | public class XmlStreamWriter extends org.apache.commons.io.output.XmlStreamWriter {
30 | /**
31 | * @param out {@link OutputStream}
32 | */
33 | public XmlStreamWriter(OutputStream out) {
34 | super(out);
35 | }
36 |
37 | /**
38 | * @param file The file to use.
39 | * @throws FileNotFoundException in case of not found file.
40 | */
41 | public XmlStreamWriter(File file) throws FileNotFoundException {
42 | super(file);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomUtils.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.utils.xml;
20 |
21 | import java.util.HashMap;
22 | import java.util.Iterator;
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | /**
27 | * @deprecated use org.w3c.dom, JDOM, XOM, or SAX
28 | */
29 | @Deprecated
30 | public class Xpp3DomUtils {
31 | /**
32 | * @param dominant {@link Xpp3Dom}
33 | * @param recessive {@link Xpp3Dom}
34 | * @param childMergeOverride true/false.
35 | * @return Merged dom.
36 | */
37 | public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
38 | return dominant != null ? merge(dominant, recessive, childMergeOverride) : recessive;
39 | }
40 |
41 | /**
42 | * @param dominant {@link Xpp3Dom}
43 | * @param recessive {@link Xpp3Dom}
44 | * @return Merged dom.
45 | */
46 | public static Xpp3Dom mergeXpp3Dom(Xpp3Dom dominant, Xpp3Dom recessive) {
47 | return dominant != null ? merge(dominant, recessive, null) : recessive;
48 | }
49 |
50 | /**
51 | * @param dominant {@link Xpp3Dom}
52 | * @param recessive {@link Xpp3Dom}
53 | * @param childMergeOverride true/false.
54 | * @return Merged dom.
55 | */
56 | public static Xpp3Dom merge(Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride) {
57 | if (recessive == null || isCombineSelfOverride(dominant)) {
58 | return dominant;
59 | }
60 |
61 | if (isEmpty(dominant.getValue())) {
62 | dominant.setValue(recessive.getValue());
63 | }
64 |
65 | for (String attr : recessive.getAttributeNames()) {
66 | if (isEmpty(dominant.getAttribute(attr))) {
67 | dominant.setAttribute(attr, recessive.getAttribute(attr));
68 | }
69 | }
70 |
71 | if (recessive.getChildCount() > 0) {
72 | boolean mergeChildren = isMergeChildren(dominant, childMergeOverride);
73 |
74 | if (mergeChildren) {
75 | Map> commonChildren = getCommonChildren(dominant, recessive);
76 | for (Xpp3Dom recessiveChild : recessive) {
77 | Iterator it = commonChildren.get(recessiveChild.getName());
78 | if (it == null) {
79 | dominant.addChild(new Xpp3Dom(recessiveChild));
80 | } else if (it.hasNext()) {
81 | Xpp3Dom dominantChild = it.next();
82 | merge(dominantChild, recessiveChild, childMergeOverride);
83 | }
84 | }
85 | } else {
86 | Xpp3Dom[] dominantChildren = dominant.getChildren();
87 | dominant.childList.clear();
88 | for (Xpp3Dom child : recessive) {
89 | dominant.addChild(new Xpp3Dom(child));
90 | }
91 |
92 | for (Xpp3Dom aDominantChildren : dominantChildren) {
93 | dominant.addChild(aDominantChildren);
94 | }
95 | }
96 | }
97 | return dominant;
98 | }
99 |
100 | private static Map> getCommonChildren(Xpp3Dom dominant, Xpp3Dom recessive) {
101 | Map> commonChildren = new HashMap<>();
102 |
103 | for (String childName : recessive.childMap.keySet()) {
104 | List dominantChildren = dominant.getChildrenList(childName);
105 | if (dominantChildren.size() > 0) {
106 | commonChildren.put(childName, dominantChildren.iterator());
107 | }
108 | }
109 | return commonChildren;
110 | }
111 |
112 | private static boolean isCombineSelfOverride(Xpp3Dom xpp3Dom) {
113 | String selfMergeMode = xpp3Dom.getAttribute(Xpp3Dom.SELF_COMBINATION_MODE_ATTRIBUTE);
114 | return Xpp3Dom.SELF_COMBINATION_OVERRIDE.equals(selfMergeMode);
115 | }
116 |
117 | private static boolean isMergeChildren(Xpp3Dom dominant, Boolean override) {
118 | return override != null ? override : !isMergeChildren(dominant);
119 | }
120 |
121 | private static boolean isMergeChildren(Xpp3Dom dominant) {
122 | return Xpp3Dom.CHILDREN_COMBINATION_APPEND.equals(
123 | dominant.getAttribute(Xpp3Dom.CHILDREN_COMBINATION_MODE_ATTRIBUTE));
124 | }
125 |
126 | /**
127 | * @deprecated use str == null || String.isBlank(str)
(Java 11+)
128 | * or org.apache.commons.lang3.StringUtils.isBlank(str)
129 | * @param str the string to be checked
130 | * @return true
if the string is null, empty, or whitespace only; false
otherwise
131 | */
132 | @Deprecated
133 | public static boolean isEmpty(String str) {
134 | return str == null || str.trim().length() == 0;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomWriter.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.utils.xml;
20 |
21 | import java.io.IOException;
22 | import java.io.PrintWriter;
23 | import java.io.Writer;
24 |
25 | /**
26 | * @author Brett Porter
27 | * @deprecated use org.w3c.dom, JDOM, XOM, or SAX
28 | */
29 | @Deprecated
30 | public class Xpp3DomWriter {
31 | /**
32 | * @param writer {@link Writer}
33 | * @param dom {@link Xpp3Dom}
34 | * @throws IOException if writing fails.
35 | */
36 | public static void write(Writer writer, Xpp3Dom dom) throws IOException {
37 | write(new PrettyPrintXMLWriter(writer), dom);
38 | }
39 |
40 | /**
41 | * @param writer {@link PrintWriter}
42 | * @param dom {@link Xpp3Dom}
43 | * @throws IOException if writing fails.
44 | */
45 | public static void write(PrintWriter writer, Xpp3Dom dom) throws IOException {
46 | write(new PrettyPrintXMLWriter(writer), dom);
47 | }
48 |
49 | /**
50 | * @param xmlWriter {@link XMLWriter}
51 | * @param dom {@link Xpp3Dom}
52 | * @throws IOException if writing fails.
53 | */
54 | public static void write(XMLWriter xmlWriter, Xpp3Dom dom) throws IOException {
55 | write(xmlWriter, dom, true);
56 | }
57 |
58 | /**
59 | * @param xmlWriter {@link XMLWriter}
60 | * @param dom {@link Xpp3Dom}
61 | * @param escape true/false.
62 | * @throws IOException if writing fails.
63 | */
64 | public static void write(XMLWriter xmlWriter, Xpp3Dom dom, boolean escape) throws IOException {
65 | xmlWriter.startElement(dom.getName());
66 | String[] attributeNames = dom.getAttributeNames();
67 | for (String attributeName : attributeNames) {
68 | xmlWriter.addAttribute(attributeName, dom.getAttribute(attributeName));
69 | }
70 | Xpp3Dom[] children = dom.getChildren();
71 | for (Xpp3Dom aChildren : children) {
72 | write(xmlWriter, aChildren, escape);
73 | }
74 |
75 | String value = dom.getValue();
76 | if (value != null) {
77 | if (escape) {
78 | xmlWriter.writeText(value);
79 | } else {
80 | xmlWriter.writeMarkup(value);
81 | }
82 | }
83 | xmlWriter.endElement();
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/maven/shared/utils/xml/pull/XmlPullParserException.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.utils.xml.pull;
20 |
21 | import java.io.IOException;
22 |
23 | import org.xml.sax.SAXException;
24 |
25 | /**
26 | * @deprecated use org.w3c.dom, JDOM, XOM, or SAX
27 | */
28 | @Deprecated
29 | public class XmlPullParserException extends RuntimeException {
30 |
31 | private static final long serialVersionUID = 117075811816936575L;
32 |
33 | /**
34 | * @param e the root cause
35 | */
36 | public XmlPullParserException(IOException e) {
37 | super(e);
38 | }
39 |
40 | /**
41 | * @param e the root cause
42 | */
43 | public XmlPullParserException(SAXException e) {
44 | super(e);
45 | }
46 |
47 | /**
48 | * @param message the message
49 | */
50 | public XmlPullParserException(String message) {
51 | super(message);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/NOTICE:
--------------------------------------------------------------------------------
1 | This product includes software developed by
2 | The Apache Software Foundation (http://www.apache.org/).
3 |
--------------------------------------------------------------------------------
/src/site/apt/index.apt.vm:
--------------------------------------------------------------------------------
1 | ------
2 | Introduction
3 | ------
4 | Kristian Rosenvold
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 | ~~ NOTE: For help with the syntax of this file, see:
27 | ~~ http://maven.apache.org/doxia/references/apt-format.html
28 |
29 |
30 | ${project.name}
31 |
32 | This project aims to be a functional replacement for
33 | {{{http://codehaus-plexus.github.io/plexus-utils/}plexus-utils}} in Maven.
34 |
35 | It is not a 100% API compatible replacement though but a replacement :
36 | lots of methods got cleaned up, generics got added and we dropped a lot of unused code.
37 |
38 | Then there are additions, like
39 | {{{./apidocs/org/apache/maven/shared/utils/logging/package-summary.html}styled message API}}.
40 |
41 | Why?
42 |
43 | plexus-utils consisted mostly of code that was forked from various Apache projects.
44 | maven-shared-utils is based on the original from the Apache sources.
45 |
46 | Why not commons?
47 |
48 | We would prefer code to use commons-* where appropriate, but the plexus-utils became
49 | slightly incompatible (different) from the commons over the years, so migrating is not
50 | always a 1:1 operation. Migrating to maven-shared-utils is a 1:1 operation in most cases.
51 |
52 | []
53 |
--------------------------------------------------------------------------------
/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 |
25 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/site/xdoc/download.xml.vm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
21 |
22 |
23 |
24 | Download ${project.name} Source
25 |
26 |
27 |
28 |
29 |
30 | ${project.name} ${project.version} is distributed in source format.
31 |
32 | Use a source archive if you intend to build ${project.name} yourself.
33 |
34 | Otherwise, simply use the ready-made binary artifacts from central repository.
35 |
36 | ${project.name} is distributed under the Apache License, version 2.0.
37 |
38 |
39 |
40 | This is the current stable version of ${project.name}.
41 |
42 |
60 |
61 | It is essential that you verify the integrity of the downloaded file
62 | using the checksum (.sha512 file)
63 | or using the signature (.asc file) against the public KEYS used by the Apache Maven developers.
64 |
65 |
66 |
67 |
68 |
69 | It is strongly recommended to use the latest release version of ${project.name} to take advantage of the newest features and bug fixes.
70 | Older non-recommended releases can be found on our archive site.
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/OsTest.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.utils;
20 |
21 | import java.util.Set;
22 |
23 | import org.junit.After;
24 | import org.junit.Assert;
25 | import org.junit.Before;
26 | import org.junit.Test;
27 |
28 | import static org.hamcrest.CoreMatchers.is;
29 | import static org.hamcrest.MatcherAssert.assertThat;
30 |
31 | /**
32 | * Tests the 'Os' class which evaluates operation system specific settings.
33 | *
34 | * @author Mark Struberg
35 | */
36 | public class OsTest {
37 | private String origOsName;
38 | private String origOsArch;
39 | private String origOsVersion;
40 |
41 | @Before
42 | public void setUp() {
43 | origOsName = System.getProperty("os.name");
44 | origOsArch = System.getProperty("os.arch");
45 | origOsVersion = System.getProperty("os.version");
46 |
47 | // and now set some special settings ;)
48 | System.setProperty("os.name", "os/2");
49 | System.setProperty("os.arch", "i386");
50 | System.setProperty("os.version", "2.1.32");
51 | }
52 |
53 | @After
54 | public void tearDown() {
55 | // set the original OS settings again
56 | System.setProperty("os.name", origOsName);
57 | System.setProperty("os.arch", origOsArch);
58 | System.setProperty("os.version", origOsVersion);
59 | }
60 |
61 | @Test
62 | public void testConstructor() {
63 | Os os = new Os();
64 | os.eval();
65 |
66 | Assert.assertTrue(Os.isName(Os.FAMILY_OS2));
67 |
68 | Assert.assertFalse(Os.isName(Os.FAMILY_DOS));
69 | Assert.assertFalse(Os.isName(Os.FAMILY_MAC));
70 | Assert.assertFalse(Os.isName(Os.FAMILY_NETWARE));
71 | Assert.assertFalse(Os.isName(Os.FAMILY_OPENVMS));
72 | Assert.assertFalse(Os.isName(Os.FAMILY_OS400));
73 | Assert.assertFalse(Os.isName(Os.FAMILY_TANDEM));
74 | Assert.assertFalse(Os.isName(Os.FAMILY_UNIX));
75 | Assert.assertFalse(Os.isName(Os.FAMILY_WIN9X));
76 | Assert.assertFalse(Os.isName(Os.FAMILY_WINDOWS));
77 | Assert.assertFalse(Os.isName(Os.FAMILY_ZOS));
78 | }
79 |
80 | @Test
81 | public void testFamilyNames() {
82 | Assert.assertEquals(Os.FAMILY_DOS, "dos");
83 | Assert.assertEquals(Os.FAMILY_MAC, "mac");
84 | Assert.assertEquals(Os.FAMILY_NETWARE, "netware");
85 | Assert.assertEquals(Os.FAMILY_OPENVMS, "openvms");
86 | Assert.assertEquals(Os.FAMILY_OS2, "os/2");
87 | Assert.assertEquals(Os.FAMILY_OS400, "os/400");
88 | Assert.assertEquals(Os.FAMILY_TANDEM, "tandem");
89 | Assert.assertEquals(Os.FAMILY_UNIX, "unix");
90 | Assert.assertEquals(Os.FAMILY_WIN9X, "win9x");
91 | Assert.assertEquals(Os.FAMILY_WINDOWS, "windows");
92 | Assert.assertEquals(Os.FAMILY_ZOS, "z/os");
93 | }
94 |
95 | @Test
96 | public void testGetValidFamilies() {
97 | Set osFamilies = Os.getValidFamilies();
98 |
99 | Assert.assertTrue("OsFamilies Set size", osFamilies.size() >= 11);
100 |
101 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_DOS));
102 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_MAC));
103 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_NETWARE));
104 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_OPENVMS));
105 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_OS2));
106 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_OS400));
107 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_TANDEM));
108 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_UNIX));
109 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_WIN9X));
110 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_WINDOWS));
111 | Assert.assertTrue(osFamilies.contains(Os.FAMILY_ZOS));
112 | }
113 |
114 | @Test
115 | public void testIsArch() {
116 | assertThat("Arch is i386", Os.isArch("i386"), is(true));
117 |
118 | assertThat("Os is not Mac", Os.isArch("x86_64"), is(false));
119 | }
120 |
121 | @Test
122 | public void testIsFamily() {
123 | assertThat("Family is os/2", Os.isFamily(Os.FAMILY_OS2), is(true));
124 |
125 | assertThat("Family is not mac", Os.isFamily(Os.FAMILY_MAC), is(false));
126 | }
127 |
128 | @Test
129 | public void testIsName() {
130 | assertThat("Name is os/2", Os.isName("os/2"), is(true));
131 |
132 | assertThat("Name is not Mac OS X", Os.isName("Mac OS X"), is(false));
133 | }
134 |
135 | @Test
136 | public void testIsValidFamily() {
137 | assertThat("os/2 isValidFamily", Os.isValidFamily(Os.FAMILY_OS2), is(true));
138 |
139 | assertThat("iPone != isValidFamily", Os.isValidFamily("iPhone"), is(false));
140 | }
141 |
142 | @Test
143 | public void testIsVersion() {
144 | assertThat("isVersion", Os.isVersion("2.1.32"), is(true));
145 |
146 | assertThat("isVersion", Os.isVersion("2.1"), is(false));
147 |
148 | assertThat("isVersion", Os.isVersion("4.5"), is(false));
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/PathToolTest.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.utils;
20 |
21 | import java.io.File;
22 |
23 | import org.hamcrest.CoreMatchers;
24 | import org.junit.Assume;
25 | import org.junit.Rule;
26 | import org.junit.Test;
27 | import org.junit.rules.TemporaryFolder;
28 |
29 | import static org.hamcrest.CoreMatchers.is;
30 | import static org.hamcrest.MatcherAssert.assertThat;
31 |
32 | /**
33 | * Test the {@link PathTool} class.
34 | *
35 | * @author Mark Struberg
36 | */
37 | public class PathToolTest {
38 |
39 | @Rule
40 | public TemporaryFolder tempFolder = new TemporaryFolder();
41 |
42 | @Test
43 | // Keep in sync with testGetRelativeFilePathWindows()
44 | public void testGetRelativeFilePathNonWindows() {
45 | Assume.assumeThat(File.separatorChar, is('/'));
46 |
47 | assertThat(PathTool.getRelativeFilePath(null, null), is(""));
48 |
49 | assertThat(PathTool.getRelativeFilePath(null, "/usr/local/java/bin"), is(""));
50 |
51 | assertThat(PathTool.getRelativeFilePath("/usr/local", null), is(""));
52 |
53 | assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin"), is("java/bin"));
54 |
55 | assertThat(PathTool.getRelativeFilePath("/usr/local", "/usr/local/java/bin/"), is("java/bin/"));
56 |
57 | assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin", "/usr/local/"), is("../../"));
58 |
59 | assertThat(PathTool.getRelativeFilePath("/usr/local/", "/usr/local/java/bin/java.sh"), is("java/bin/java.sh"));
60 |
61 | assertThat(PathTool.getRelativeFilePath("/usr/local/java/bin/java.sh", "/usr/local/"), is("../../../"));
62 |
63 | assertThat(PathTool.getRelativeFilePath("/usr/local/", "/bin"), is("../../bin"));
64 |
65 | assertThat(PathTool.getRelativeFilePath("/bin", "/usr/local/"), is("../usr/local/"));
66 | }
67 |
68 | @Test
69 | // Keep in sync with testGetRelativeFilePathNonWindows()
70 | public void testGetRelativeFilePathWindows() {
71 | Assume.assumeThat(File.separatorChar, is('\\'));
72 |
73 | assertThat(PathTool.getRelativeFilePath(null, null), is(""));
74 |
75 | assertThat(PathTool.getRelativeFilePath(null, "c:\\usr\\local\\java\\bin"), is(""));
76 |
77 | assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", null), is(""));
78 |
79 | assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin"), is("java\\bin"));
80 |
81 | assertThat(PathTool.getRelativeFilePath("c:\\usr\\local", "c:\\usr\\local\\java\\bin\\"), is("java\\bin\\"));
82 |
83 | assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin", "c:\\usr\\local\\"), is("..\\..\\"));
84 |
85 | assertThat(
86 | PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\usr\\local\\java\\bin\\java.sh"),
87 | is("java\\bin\\java.sh"));
88 |
89 | assertThat(
90 | PathTool.getRelativeFilePath("c:\\usr\\local\\java\\bin\\java.sh", "c:\\usr\\local\\"),
91 | is("..\\..\\..\\"));
92 |
93 | assertThat(PathTool.getRelativeFilePath("c:\\usr\\local\\", "c:\\bin"), is("..\\..\\bin"));
94 |
95 | assertThat(PathTool.getRelativeFilePath("c:\\bin", "c:\\usr\\local\\"), is("..\\usr\\local\\"));
96 | }
97 |
98 | @Test
99 | public void testGetRelativePath2Parm() {
100 | assertThat(PathTool.getRelativePath(null, null), is(""));
101 |
102 | assertThat(PathTool.getRelativePath(null, "/usr/local/java/bin"), is(""));
103 |
104 | assertThat(PathTool.getRelativePath("/usr/local/", null), is(""));
105 |
106 | assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin"), is(".."));
107 |
108 | assertThat(PathTool.getRelativePath("/usr/local/", "/usr/local/java/bin/java.sh"), is("../.."));
109 |
110 | assertThat(PathTool.getRelativePath("/usr/local/java/bin/java.sh", "/usr/local/"), is(""));
111 | }
112 |
113 | @Test
114 | public void testUppercaseDrive() {
115 | assertThat(PathTool.uppercaseDrive(null), CoreMatchers.nullValue());
116 |
117 | assertThat(PathTool.uppercaseDrive("d:"), is("D:"));
118 |
119 | assertThat(PathTool.uppercaseDrive("D:"), is("D:"));
120 |
121 | assertThat(PathTool.uppercaseDrive("/notadrive"), is("/notadrive"));
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/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.utils;
20 |
21 | import java.io.ByteArrayInputStream;
22 | import java.io.File;
23 | import java.io.FileOutputStream;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.io.OutputStream;
27 | import java.io.UnsupportedEncodingException;
28 | import java.lang.annotation.ElementType;
29 | import java.lang.annotation.Retention;
30 | import java.lang.annotation.RetentionPolicy;
31 | import java.lang.annotation.Target;
32 | import java.net.URL;
33 | import java.util.Properties;
34 |
35 | import org.junit.Rule;
36 | import org.junit.Test;
37 | import org.junit.rules.TemporaryFolder;
38 |
39 | import static org.hamcrest.CoreMatchers.is;
40 | import static org.hamcrest.CoreMatchers.nullValue;
41 | import static org.hamcrest.MatcherAssert.assertThat;
42 |
43 | public class PropertyUtilsTest {
44 |
45 | @Retention(RetentionPolicy.RUNTIME)
46 | @Target(ElementType.METHOD)
47 | @interface NeedsTemporaryFolder {}
48 |
49 | @Rule
50 | public TemporaryFolder tempFolder = new TemporaryFolder();
51 |
52 | @Test
53 | @SuppressWarnings("deprecation")
54 | // @ReproducesPlexusBug( "Should return null on error like url and file do" )
55 | public void loadNullInputStream() throws Exception {
56 | assertThat(PropertyUtils.loadProperties((InputStream) null), is(new Properties()));
57 | }
58 |
59 | @Test
60 | public void loadOptionalNullInputStream() throws Exception {
61 | assertThat(PropertyUtils.loadOptionalProperties((InputStream) null), is(new Properties()));
62 | }
63 |
64 | @Test
65 | public void loadOptionalPropertiesIoException() throws Exception {
66 | URL url = new URL("https://nonesuch12344.foo.bar.com");
67 | assertThat(PropertyUtils.loadOptionalProperties(url), is(new Properties()));
68 | }
69 |
70 | @Test
71 | @SuppressWarnings("deprecation")
72 | public void loadNullURL() throws Exception {
73 | assertThat(PropertyUtils.loadProperties((URL) null), nullValue(Properties.class));
74 | }
75 |
76 | @Test
77 | public void loadOptionalNullURL() throws Exception {
78 | assertThat(PropertyUtils.loadOptionalProperties((URL) null), is(new Properties()));
79 | }
80 |
81 | @Test
82 | @SuppressWarnings("deprecation")
83 | public void loadNullFile() throws Exception {
84 | assertThat(PropertyUtils.loadProperties((File) null), nullValue(Properties.class));
85 | }
86 |
87 | @Test
88 | public void loadOptionalNullFile() throws Exception {
89 | assertThat(PropertyUtils.loadOptionalProperties((File) null), is(new Properties()));
90 | }
91 |
92 | @Test
93 | @SuppressWarnings("deprecation")
94 | public void loadEmptyInputStream() throws Exception {
95 | assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream(new byte[0])), is(new Properties()));
96 |
97 | assertThat(PropertyUtils.loadOptionalProperties(new ByteArrayInputStream(new byte[0])), is(new Properties()));
98 | }
99 |
100 | @Test
101 | @NeedsTemporaryFolder
102 | @SuppressWarnings("deprecation")
103 | public void loadEmptyFile() throws Exception {
104 | assertThat(PropertyUtils.loadProperties(tempFolder.newFile("empty")), is(new Properties()));
105 | assertThat(PropertyUtils.loadOptionalProperties(tempFolder.newFile("optional")), is(new Properties()));
106 | }
107 |
108 | @Test
109 | @NeedsTemporaryFolder
110 | @SuppressWarnings("deprecation")
111 | public void loadEmptyURL() throws Exception {
112 | assertThat(
113 | PropertyUtils.loadProperties(tempFolder.newFile("empty").toURI().toURL()), is(new Properties()));
114 |
115 | assertThat(
116 | PropertyUtils.loadOptionalProperties(
117 | tempFolder.newFile("optional").toURI().toURL()),
118 | is(new Properties()));
119 | }
120 |
121 | @Test
122 | @SuppressWarnings("deprecation")
123 | public void loadValidInputStream() throws UnsupportedEncodingException {
124 | Properties value = new Properties();
125 | value.setProperty("a", "b");
126 |
127 | assertThat(PropertyUtils.loadProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))), is(value));
128 |
129 | assertThat(
130 | PropertyUtils.loadOptionalProperties(new ByteArrayInputStream("a=b".getBytes("ISO-8859-1"))),
131 | is(value));
132 | }
133 |
134 | @Test
135 | @NeedsTemporaryFolder
136 | @SuppressWarnings("deprecation")
137 | public void loadValidFile() throws IOException {
138 | File valid = tempFolder.newFile("valid");
139 | Properties value = new Properties();
140 | value.setProperty("a", "b");
141 | try (OutputStream out = new FileOutputStream(valid)) {
142 | value.store(out, "a test");
143 | assertThat(PropertyUtils.loadProperties(valid), is(value));
144 | assertThat(PropertyUtils.loadOptionalProperties(valid), is(value));
145 | }
146 | }
147 |
148 | @Test
149 | @NeedsTemporaryFolder
150 | @SuppressWarnings("deprecation")
151 | public void loadValidURL() throws IOException {
152 | File valid = tempFolder.newFile("valid");
153 | Properties value = new Properties();
154 | value.setProperty("a", "b");
155 | try (OutputStream out = new FileOutputStream(valid)) {
156 | value.store(out, "a test");
157 | assertThat(PropertyUtils.loadProperties(valid.toURI().toURL()), is(value));
158 | assertThat(PropertyUtils.loadOptionalProperties(valid.toURI().toURL()), is(value));
159 | }
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.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.utils.cli;
20 |
21 | import java.io.ByteArrayInputStream;
22 | import java.io.ByteArrayOutputStream;
23 | import java.io.IOException;
24 |
25 | import org.junit.Test;
26 |
27 | import static org.junit.Assert.assertEquals;
28 | import static org.junit.Assert.assertNull;
29 |
30 | public class StreamPollFeederTest {
31 |
32 | @Test
33 | public void waitUntilFeederDoneOnInputStream() throws Exception {
34 |
35 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
36 | StreamPollFeeder streamPollFeeder = new StreamPollFeeder(System.in, outputStream);
37 |
38 | // start thread
39 | streamPollFeeder.start();
40 |
41 | // wait a moment
42 | Thread.sleep(100);
43 |
44 | // wait until process finish
45 | streamPollFeeder.waitUntilDone();
46 | assertNull(streamPollFeeder.getException());
47 | }
48 |
49 | @Test
50 | public void dataShouldBeCopied() throws InterruptedException, IOException {
51 |
52 | StringBuilder testData = new StringBuilder();
53 | for (int i = 0; i < 100; i++) {
54 | testData.append("TestData");
55 | }
56 |
57 | ByteArrayInputStream inputStream =
58 | new ByteArrayInputStream(testData.toString().getBytes());
59 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
60 |
61 | StreamPollFeeder streamPollFeeder = new StreamPollFeeder(inputStream, outputStream);
62 |
63 | streamPollFeeder.start();
64 |
65 | // wait until all data from steam will be read
66 | while (outputStream.size() < testData.length()) {
67 | Thread.sleep(100);
68 | }
69 |
70 | // wait until process finish
71 | streamPollFeeder.waitUntilDone();
72 | assertNull(streamPollFeeder.getException());
73 |
74 | assertEquals(testData.toString(), outputStream.toString());
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestException.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.utils.exceptionutils;
20 |
21 | /**
22 | *
23 | * @author Mark Struberg
24 | */
25 | public class TestException extends Exception {
26 | private Throwable cause;
27 | private Throwable specialCause;
28 |
29 | public TestException() {
30 | super();
31 | }
32 |
33 | public void setSourceException(Throwable cause) {
34 | this.cause = cause;
35 | }
36 |
37 | public Throwable getSourceException() {
38 | return cause;
39 | }
40 |
41 | public Throwable getSpecialCause() {
42 | return specialCause;
43 | }
44 |
45 | public void setSpecialCause(Throwable specialCause) {
46 | this.specialCause = specialCause;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/exceptionutils/TestExceptionWithDetail.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.utils.exceptionutils;
20 |
21 | /**
22 | * This test exception has a 'detail' field.
23 | *
24 | * @author Mark Struberg
25 | */
26 | public class TestExceptionWithDetail extends Exception {
27 | private Throwable detail;
28 |
29 | public TestExceptionWithDetail() {
30 | super();
31 | }
32 |
33 | public Throwable getDetail() {
34 | return detail;
35 | }
36 |
37 | public void setDetail(Throwable detail) {
38 | this.detail = detail;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/io/MatchPatternTest.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.utils.io;
20 |
21 | import org.junit.Test;
22 |
23 | import static org.junit.Assert.assertTrue;
24 |
25 | /**
26 | * @author Kristian Rosenvold
27 | */
28 | @SuppressWarnings("deprecation")
29 | public class MatchPatternTest {
30 | @Test
31 | public void matchPath() {
32 | MatchPattern mp = MatchPattern.fromString("ABC*");
33 | assertTrue(mp.matchPath("ABCD", true));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/io/MatchPatternsTest.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.utils.io;
20 |
21 | import org.junit.Test;
22 |
23 | import static org.junit.Assert.assertFalse;
24 | import static org.junit.Assert.assertTrue;
25 |
26 | /**
27 | * @author Kristian Rosenvold
28 | */
29 | @SuppressWarnings("deprecation")
30 | public class MatchPatternsTest {
31 | @Test
32 | public void matches() {
33 | MatchPatterns from = MatchPatterns.from("ABC**", "CDE**");
34 | assertTrue(from.matches("ABCDE", true));
35 | assertTrue(from.matches("CDEF", true));
36 | assertFalse(from.matches("XYZ", true));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/io/SelectorUtilsTest.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.utils.io;
20 |
21 | import java.io.File;
22 |
23 | import org.junit.Test;
24 |
25 | import static org.junit.Assert.assertFalse;
26 | import static org.junit.Assert.assertTrue;
27 |
28 | /**
29 | * Test the {@link SelectorUtils} class.
30 | */
31 | @SuppressWarnings("deprecation")
32 | public class SelectorUtilsTest {
33 |
34 | @Test(expected = NullPointerException.class)
35 | public void testMatchPatternStart() {
36 | SelectorUtils.matchPatternStart(null, null);
37 | }
38 |
39 | @Test
40 | public void testEmptyStrings() {
41 | assertTrue(SelectorUtils.matchPatternStart("", ""));
42 | }
43 |
44 | @Test
45 | public void testRegexPrefix() throws Exception {
46 | assertTrue(SelectorUtils.matchPatternStart(
47 | SelectorUtils.REGEX_HANDLER_PREFIX + File.separator + "aaa" + SelectorUtils.PATTERN_HANDLER_SUFFIX,
48 | ""));
49 | }
50 |
51 | @Test
52 | public void testAntPatternStrings() {
53 | assertAntDoesNotMatch("/aaa", "");
54 | assertAntDoesNotMatch("\\aaa", "");
55 | assertAntMatch("aaa", "");
56 | assertAntMatch("/aaa/bbb", "/aaa/bbb");
57 | assertAntMatch("/aaa/**", "/aaa/bbb");
58 | assertAntDoesNotMatch("/aaa/**", "/ccc/bbb");
59 | assertAntMatch("/aaa/**", "\\aaa\\bbb");
60 | assertAntDoesNotMatch("/aaa/**", "\\ccc\\bbb");
61 | assertAntDoesNotMatch("/aaa/", "\\aaa\\bbb");
62 | }
63 |
64 | private void assertAntDoesNotMatch(String pattern, String target) {
65 | assertFalse(SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target));
66 | }
67 |
68 | private void assertAntMatch(String pattern, String target) {
69 | assertTrue(SelectorUtils.matchPatternStart(wrapWithAntHandler(pattern), target));
70 | }
71 |
72 | private String wrapWithAntHandler(String val) {
73 | return SelectorUtils.ANT_HANDLER_PREFIX + val + SelectorUtils.PATTERN_HANDLER_SUFFIX;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.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.utils.io;
20 |
21 | import java.io.File;
22 | import java.io.IOException;
23 | import java.nio.charset.StandardCharsets;
24 |
25 | import static org.apache.commons.io.FileUtils.write;
26 |
27 | public class SymlinkTestSetup {
28 | /**
29 | * Creates a standard directory layout with symlinks and files.
30 | */
31 | public static File createStandardSymlinkTestDir(File root) throws IOException {
32 | File srcDir = new File(root, "/src");
33 | srcDir.mkdirs();
34 | File target = new File(srcDir, "targetDir");
35 | target.mkdirs();
36 | write(new File(target, "targetFile.txt"), "a regular File payload", StandardCharsets.UTF_8);
37 | File aRegularDir = new File(srcDir, "aRegularDir");
38 | aRegularDir.mkdirs();
39 | write(new File(aRegularDir, "aRegularFile.txt"), "a regular File payload", StandardCharsets.UTF_8);
40 |
41 | File dirOnTheOutside = new File(root, "dirOnTheOutside");
42 | dirOnTheOutside.mkdirs();
43 | write(
44 | new File(dirOnTheOutside, "FileInDirOnTheOutside.txt"),
45 | "a file in dir on the outside",
46 | StandardCharsets.UTF_8);
47 | write(new File(root, "onTheOutside.txt"), "A file on the outside", StandardCharsets.UTF_8);
48 | write(new File(srcDir, "fileR.txt"), "FileR payload", StandardCharsets.UTF_8);
49 | write(new File(srcDir, "fileW.txt"), "FileW payload", StandardCharsets.UTF_8);
50 | write(new File(srcDir, "fileX.txt"), "FileX payload", StandardCharsets.UTF_8);
51 | // todo: set file attributes (not used here)
52 |
53 | FileUtils.createSymbolicLink(new File(srcDir, "symDir"), new File("targetDir"));
54 | FileUtils.createSymbolicLink(new File(srcDir, "symLinkToDirOnTheOutside"), new File("../dirOnTheOutside"));
55 | FileUtils.createSymbolicLink(new File(srcDir, "symLinkToFileOnTheOutside"), new File("../onTheOutside.txt"));
56 | FileUtils.createSymbolicLink(new File(srcDir, "symR"), new File("fileR.txt"));
57 | FileUtils.createSymbolicLink(new File(srcDir, "symW"), new File("fileW.txt"));
58 | FileUtils.createSymbolicLink(new File(srcDir, "symX"), new File("fileX.txt"));
59 | return srcDir;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilderTest.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.utils.logging;
20 |
21 | import org.junit.Before;
22 | import org.junit.Test;
23 |
24 | import static org.hamcrest.CoreMatchers.equalTo;
25 | import static org.hamcrest.MatcherAssert.assertThat;
26 |
27 | public class AnsiMessageBuilderTest {
28 |
29 | private AnsiMessageBuilder ansiMessageBuilder;
30 |
31 | @Before
32 | public void initializeAnsiMessageBuffer() {
33 | this.ansiMessageBuilder = new AnsiMessageBuilder();
34 | }
35 |
36 | @Test
37 | public void shouldColorDebug() {
38 | ansiMessageBuilder.debug("DEBUG");
39 |
40 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;36mDEBUG\u001B[m"));
41 | }
42 |
43 | @Test
44 | public void shouldColorInfo() {
45 | ansiMessageBuilder.info("INFO");
46 |
47 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;34mINFO\u001B[m"));
48 | }
49 |
50 | @Test
51 | public void shouldColorWarningAndReset() {
52 | ansiMessageBuilder.warning("WARNING");
53 |
54 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;33mWARNING\u001B[m"));
55 | }
56 |
57 | @Test
58 | public void shouldColorError() {
59 | ansiMessageBuilder.error("ERROR");
60 |
61 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31mERROR\u001B[m"));
62 | }
63 |
64 | @Test
65 | public void shouldColorSuccessWithMessage() {
66 | ansiMessageBuilder.success("a success message");
67 |
68 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;32ma success message\u001B[m"));
69 | }
70 |
71 | @Test
72 | public void shouldColorFailureAndReset() {
73 | ansiMessageBuilder.failure("a failure message");
74 |
75 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1;31ma failure message\u001B[m"));
76 | }
77 |
78 | @Test
79 | public void shouldColorStrongAndReset() {
80 | ansiMessageBuilder.strong("a strong message");
81 |
82 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[1ma strong message\u001B[m"));
83 | }
84 |
85 | @Test
86 | public void shouldColorMojoAndReset() {
87 | ansiMessageBuilder.mojo("a mojo");
88 |
89 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[32ma mojo\u001B[m"));
90 | }
91 |
92 | @Test
93 | public void shouldColorProjectAndReset() {
94 | ansiMessageBuilder.project("a project");
95 |
96 | assertThat(ansiMessageBuilder.toString(), equalTo("\u001B[36ma project\u001B[m"));
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/logging/MessageUtilsTest.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.utils.logging;
20 |
21 | import java.io.ByteArrayOutputStream;
22 | import java.io.PrintStream;
23 | import java.nio.charset.StandardCharsets;
24 |
25 | import org.fusesource.jansi.AnsiColors;
26 | import org.fusesource.jansi.AnsiConsole;
27 | import org.fusesource.jansi.AnsiMode;
28 | import org.fusesource.jansi.AnsiPrintStream;
29 | import org.fusesource.jansi.AnsiType;
30 | import org.fusesource.jansi.io.AnsiOutputStream;
31 | import org.junit.Test;
32 |
33 | import static org.hamcrest.CoreMatchers.not;
34 | import static org.hamcrest.CoreMatchers.sameInstance;
35 | import static org.hamcrest.MatcherAssert.assertThat;
36 | import static org.junit.Assert.assertEquals;
37 | import static org.junit.Assume.assumeNoException;
38 |
39 | public class MessageUtilsTest {
40 | @Test
41 | public void testSystem() {
42 | PrintStream currentOut = System.out;
43 | try {
44 | MessageUtils.systemInstall();
45 | assertThat(System.out, not(sameInstance(currentOut)));
46 | } catch (LinkageError e) {
47 | assumeNoException("JAnsi not supported for this platform", e);
48 | } finally {
49 | try {
50 | // uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242
51 | // but might throw exceptions
52 | MessageUtils.systemUninstall();
53 | } catch (Throwable t) {
54 | // ignore any thrown exception like NPE here
55 | }
56 | }
57 | assertThat(System.out, sameInstance(currentOut));
58 | }
59 |
60 | @Test
61 | public void testTerminalWidth() {
62 | AnsiOutputStream.WidthSupplier width = new AnsiOutputStream.WidthSupplier() {
63 | @Override
64 | public int getTerminalWidth() {
65 | return 33;
66 | }
67 | };
68 | AnsiOutputStream aos = new AnsiOutputStream(
69 | new ByteArrayOutputStream(),
70 | width,
71 | AnsiMode.Default,
72 | null,
73 | AnsiType.Emulation,
74 | AnsiColors.Colors256,
75 | StandardCharsets.UTF_8,
76 | null,
77 | null,
78 | false);
79 | try {
80 | AnsiConsole.systemInstall();
81 | AnsiConsole.out = new AnsiPrintStream(aos, true);
82 | assertEquals(33, MessageUtils.getTerminalWidth());
83 | } catch (LinkageError e) {
84 | assumeNoException("JAnsi not supported for this platform", e);
85 | } finally {
86 | try {
87 | // uninstall is always necessary due to https://github.com/fusesource/jansi/issues/242
88 | // but might throw exceptions
89 | AnsiConsole.systemUninstall();
90 | } catch (Throwable t) {
91 | // ignore any thrown exception like NPE here
92 | }
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.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.utils.testhelpers;
20 |
21 | import java.io.File;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.io.OutputStream;
25 | import java.io.OutputStreamWriter;
26 | import java.io.Writer;
27 |
28 | import org.apache.commons.io.FileUtils;
29 | import org.junit.rules.TemporaryFolder;
30 |
31 | /**
32 | * A few utility methods for file based tests.
33 | */
34 | public final class FileTestHelper {
35 |
36 | private FileTestHelper() {
37 | // utility function doesn't need a public constructor
38 | }
39 |
40 | public static void generateTestData(OutputStream out, long size) throws IOException {
41 | for (int i = 0; i < size; i++) {
42 | // nice varied byte pattern compatible with Readers and Writers
43 | out.write((byte) ((i % 127) + 1));
44 | }
45 | }
46 |
47 | public static void generateTestFile(File testfile, int size) throws IOException {
48 | if (testfile.exists()) {
49 | //noinspection ResultOfMethodCallIgnored
50 | testfile.delete();
51 | }
52 |
53 | try (OutputStream os = new FileOutputStream(testfile)) {
54 | generateTestData(os, size);
55 | os.flush();
56 | }
57 | }
58 |
59 | public static void createLineBasedFile(File file, String[] data) throws IOException {
60 | if (file.getParentFile() != null && !file.getParentFile().exists()) {
61 | throw new IOException("Cannot create file " + file + " as the parent directory does not exist");
62 | }
63 |
64 | try (Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
65 | for (String aData : data) {
66 | out.write(aData);
67 | out.write(System.lineSeparator());
68 | }
69 | }
70 | }
71 |
72 | /**
73 | * Check if the given file exists in the given folder and remove it.
74 | *
75 | * @return the File object for a new file
76 | * @throws IOException
77 | */
78 | public static File newFile(TemporaryFolder folder, String filename) throws IOException {
79 | File destination = folder.newFile(filename);
80 |
81 | if (destination.exists()) {
82 | FileUtils.deleteQuietly(destination);
83 | }
84 | return destination;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.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.utils.xml;
20 |
21 | import java.io.ByteArrayInputStream;
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.io.StringReader;
25 | import java.io.StringWriter;
26 | import java.io.UnsupportedEncodingException;
27 | import java.nio.charset.StandardCharsets;
28 |
29 | import org.apache.maven.shared.utils.xml.pull.XmlPullParserException;
30 | import org.junit.Assert;
31 | import org.junit.Test;
32 |
33 | import static org.junit.Assert.assertEquals;
34 | import static org.junit.Assert.assertTrue;
35 | import static org.junit.Assert.fail;
36 |
37 | /**
38 | * @author Kristian Rosenvold
39 | */
40 | public class Xpp3DomBuilderTest {
41 |
42 | private static final String XML_DECLARATION = "\n";
43 |
44 | @Test
45 | public void selfClosingTag() throws Exception {
46 |
47 | String domString = selfClosingTagSource();
48 |
49 | Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString));
50 |
51 | String expected = expectedSelfClosingTag();
52 | String dom1Str = dom.toString();
53 | assertEquals("check DOMs match", expected, dom1Str);
54 | }
55 |
56 | @Test
57 | public void testUnrecognizedEncoding() {
58 |
59 | byte[] data = "".getBytes(StandardCharsets.UTF_8);
60 | InputStream in = new ByteArrayInputStream(data);
61 | try {
62 | Xpp3DomBuilder.build(in, "nosuch encoding");
63 | fail();
64 | } catch (XmlPullParserException expected) {
65 | assertTrue(expected.getCause() instanceof UnsupportedEncodingException);
66 | }
67 | }
68 |
69 | @Test
70 | public void trimming() throws Exception {
71 | String domString = createDomString();
72 |
73 | Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(domString), true);
74 | assertEquals(" element1value\n ", dom.getChild("element1").getValue());
75 | assertEquals(" preserve space ", dom.getChild("element6").getValue());
76 | dom = Xpp3DomBuilder.build(new StringReader(domString), false);
77 | assertEquals(" element1value\n ", dom.getChild("element1").getValue());
78 | assertEquals(" preserve space ", dom.getChild("element6").getValue());
79 | }
80 |
81 | @Test
82 | public void testMalformedXml() {
83 | try {
84 | Xpp3DomBuilder.build(new StringReader("" + createDomString()));
85 | fail("We're supposed to fail");
86 | } catch (XmlPullParserException ex) {
87 | Assert.assertNotNull(ex.getMessage());
88 | }
89 | }
90 |
91 | @Test
92 | public void attributeEscaping() throws IOException, XmlPullParserException {
93 | String s = getAttributeEncodedString();
94 | Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(s));
95 |
96 | assertEquals("", dom.getChild("el").getAttribute("att"));
97 | StringWriter w = new StringWriter();
98 | Xpp3DomWriter.write(w, dom);
99 | String newString = w.toString();
100 | assertEquals(newString, s);
101 | }
102 |
103 | @Test
104 | public void contentEscaping() throws IOException, XmlPullParserException {
105 | Xpp3Dom dom = Xpp3DomBuilder.build(new StringReader(getEncodedString()));
106 |
107 | assertEquals("\"msg\"", dom.getChild("a1").getValue());
108 | assertEquals("\"msg\"", dom.getChild("a2").getValue());
109 | assertEquals("\"msg\"", dom.getChild("a3").getValue());
110 |
111 | StringWriter w = new StringWriter();
112 | Xpp3DomWriter.write(w, dom);
113 | assertEquals(getExpectedString(), w.toString());
114 | }
115 |
116 | private static String getAttributeEncodedString() {
117 | StringBuilder domString = new StringBuilder();
118 | domString.append("");
119 | domString.append("\n");
120 | domString.append(" bar");
121 | domString.append("\n");
122 | domString.append("");
123 |
124 | return domString.toString();
125 | }
126 |
127 | private static String getEncodedString() {
128 | StringBuilder domString = new StringBuilder();
129 | domString.append("\n");
130 | domString.append(" \"msg\"\n");
131 | domString.append(" \"msg\"]]>\n");
132 | domString.append(" <b>"msg"</b>\n");
133 | domString.append("");
134 |
135 | return domString.toString();
136 | }
137 |
138 | private static String getExpectedString() {
139 | StringBuilder domString = new StringBuilder();
140 | domString.append("");
141 | domString.append("\n");
142 | domString.append(" \"msg\"");
143 | domString.append("\n");
144 | domString.append(" <b>\"msg\"</b>");
145 | domString.append("\n");
146 | domString.append(" <b>\"msg\"</b>");
147 | domString.append("\n");
148 | domString.append("");
149 | return domString.toString();
150 | }
151 |
152 | private static String createDomString() {
153 | StringBuilder buf = new StringBuilder();
154 | buf.append("\n");
155 | buf.append(" element1value\n \n");
156 | buf.append(" \n");
157 | buf.append(" element3value\n");
158 | buf.append(" \n");
159 | buf.append(" \n");
160 | buf.append(" \n");
161 | buf.append(" preserve space \n");
162 | buf.append("\n");
163 |
164 | return buf.toString();
165 | }
166 |
167 | private static String selfClosingTagSource() {
168 | StringBuilder buf = new StringBuilder();
169 | buf.append("\n");
170 | buf.append(" \n");
171 | buf.append(" \n");
172 | buf.append("");
173 | return buf.toString();
174 | }
175 |
176 | private static String expectedSelfClosingTag() {
177 | return XML_DECLARATION + selfClosingTagSource();
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/src/test/resources/directorywalker/directory1/file1.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/directorywalker/directory1/file1.txt
--------------------------------------------------------------------------------
/src/test/resources/directorywalker/directory2/directory21/file21.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/directorywalker/directory2/directory21/file21.txt
--------------------------------------------------------------------------------
/src/test/resources/directorywalker/directory2/file2.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/directorywalker/directory2/file2.txt
--------------------------------------------------------------------------------
/src/test/resources/directorywalker/file.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/directorywalker/file.txt
--------------------------------------------------------------------------------
/src/test/resources/executable:
--------------------------------------------------------------------------------
1 | noop
2 |
--------------------------------------------------------------------------------
/src/test/resources/expand/expand_test.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/expand/expand_test.zip
--------------------------------------------------------------------------------
/src/test/resources/symlinks/dirOnTheOutside/FileInDirOnTheOutside.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 | I am on the outside...
20 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/onTheOutside.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 |
20 | I am on the outside of the src
21 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/regen.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
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 | rm symlinks.zip
19 | rm symlinks.tar
20 | cd src
21 | zip --symlinks ../symlinks.zip file* targetDir sym*
22 | tar -cvf ../symlinks.tar file* targetDir sym*
23 |
24 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/aRegularDir/aRegularFile.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 | I am just an ordinary file
20 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/fileR.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 |
20 | This file is a source. r r r filemode
21 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/fileW.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 | all w
20 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/fileX.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 | xxx
20 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/symDir:
--------------------------------------------------------------------------------
1 | targetDir/
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/symLinkToDirOnTheOutside:
--------------------------------------------------------------------------------
1 | ../dirOnTheOutside/
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/symLinkToFileOnTheOutside:
--------------------------------------------------------------------------------
1 | ../onTheOutside.txt
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/symR:
--------------------------------------------------------------------------------
1 | fileR.txt
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/symW:
--------------------------------------------------------------------------------
1 | fileW.txt
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/symX:
--------------------------------------------------------------------------------
1 | fileX.txt
--------------------------------------------------------------------------------
/src/test/resources/symlinks/src/targetDir/targetFile.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 | This is a target file
20 |
--------------------------------------------------------------------------------
/src/test/resources/symlinks/symlinks.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/symlinks/symlinks.tar
--------------------------------------------------------------------------------
/src/test/resources/symlinks/symlinks.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/apache/maven-shared-utils/0f643d77012570213fef93e1c16104bcfe32af50/src/test/resources/symlinks/symlinks.zip
--------------------------------------------------------------------------------