diff --git a/.gitattributes b/.gitattributes
index 3bb3b5ea..ccd9f864 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -6,3 +6,7 @@
*.css text
*.js text
*.sql text
+
+# some files require the correct eol for proper testing
+*-DOS.xml text eol=crlf
+*-UNIX.xml text eol=lf
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..b76b8957
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,10 @@
+version: 2
+updates:
+ - package-ecosystem: "maven"
+ directory: "/"
+ schedule:
+ interval: "daily"
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "daily"
diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml
new file mode 100644
index 00000000..c7f59480
--- /dev/null
+++ b/.github/release-drafter.yml
@@ -0,0 +1,2 @@
+_extends: .github
+tag-template: plexus-utils-$NEXT_MINOR_VERSION
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 00000000..6ede3405
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,64 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL"
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [ master ]
+ schedule:
+ - cron: '16 8 * * 5'
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [ 'java' ]
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3.0.2
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v2
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v2
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 https://git.io/JvXDl
+
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v2
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 00000000..776d2439
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: GitHub CI
+
+on: [push, pull_request]
+
+jobs:
+ build:
+ name: Build it
+ uses: codehaus-plexus/.github/.github/workflows/maven.yml@v0.0.1
diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml
new file mode 100644
index 00000000..4000f8c4
--- /dev/null
+++ b/.github/workflows/release-drafter.yml
@@ -0,0 +1,12 @@
+name: Release Drafter
+on:
+ push:
+ branches:
+ - master
+jobs:
+ update_release_draft:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: release-drafter/release-drafter@v5
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 94a20491..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-language: java
-jdk:
- - openjdk7
- - openjdk8
- - openjdk11
-# - openjdk12 add once code is requires Java 7
-
-dist: trusty
-
-# No need for preliminary install step.
-install: true
-#
-# Run all integration tests.
-script:
- - "mvn --show-version --errors --batch-mode clean verify"
-#
-cache:
- directories:
- - $HOME/.m2
-branches:
- except:
- - gh-pages
-notifications:
- email:
- - khmarbaise@apache.org
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 00000000..261eeb9e
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
index 2c93a80b..bd2877bf 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,10 @@
Plexus-Utils
============
-[](https://travis-ci.org/codehaus-plexus/plexus-utils)
-[](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.codehaus.plexus%22%20a%3A%plexus-utils%22)
+[](https://github.com/codehaus-plexus/plexus-utils/actions)
+[](https://search.maven.org/artifact/org.codehaus.plexus/plexus-utils)
+
+This library is historically used by the Apache Maven project so it's developed and maintained by the same [`bad guys`](http://maven.apache.org/team.html)
The current master is now at https://github.com/codehaus-plexus/plexus-utils
@@ -11,3 +13,4 @@ For publishing [the site](https://codehaus-plexus.github.io/plexus-utils/) do th
```
mvn -Preporting verify site site:stage scm-publish:publish-scm
```
+
diff --git a/pom.xml b/pom.xml
index 0fcea215..6ae634e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,11 +22,11 @@ limitations under the License.
org.codehaus.plexusplexus
- 5.1
+ 10plexus-utils
- 3.3.0
+ 3.5.0Plexus Common UtilitiesA collection of various utility classes to ease working with strings, files, command lines, XML and
@@ -37,7 +37,7 @@ limitations under the License.
scm:git:git@github.com:codehaus-plexus/plexus-utils.gitscm:git:git@github.com:codehaus-plexus/plexus-utils.githttp://github.com/codehaus-plexus/plexus-utils
- plexus-utils-3.3.0
+ plexus-utils-3.5.0github
@@ -50,23 +50,27 @@ limitations under the License.
+
+ 2022-10-23T08:37:59Z
+
+
-
- org.apache.maven.shared
- maven-plugin-testing-harness
- 1.1
- test
- org.openjdk.jmhjmh-core
- 1.21
+ 1.35testorg.openjdk.jmhjmh-generator-annprocess
- 1.21
+ 1.35
+ test
+
+
+ junit
+ junit
+ 4.13.2test
@@ -76,12 +80,32 @@ limitations under the License.
org.apache.maven.plugins
- maven-javadoc-plugin
- 3.0.0
+ maven-resources-plugin
+
+ 2.7
+
+ maven-compiler-plugin
+
+
+ default-compile
+
+ compile
+
+
+ 1.8
+ 1.8
+
+
+
+ org.apache.maven.pluginsmaven-scm-publish-plugin
@@ -121,40 +145,103 @@ limitations under the License.
- org.apache.maven.plugins
- maven-enforcer-plugin
-
-
- enforce-java
-
- enforce
-
-
-
-
- 1.7.0
-
-
-
-
-
+ maven-jar-plugin
+
+
+
+ true
+
+
+
-
-
- eclipse-only-jdk-version
+ jdk9+
-
- m2e.version
-
+ [9,)
-
- 7
-
+
+
+
+
+ maven-compiler-plugin
+
+
+ compile-java-9
+
+ compile
+
+
+ 9
+
+ ${project.basedir}/src/main/java9
+
+ true
+
+
+
+
+
+
+
+
+
+ jdk10+
+
+ [10,)
+
+
+
+
+
+ maven-compiler-plugin
+
+
+ compile-java-10
+
+ compile
+
+
+ 10
+
+ ${project.basedir}/src/main/java10
+
+ true
+
+
+
+
+
+
+
+
+
+ plexus-release
+
+
+
+ maven-enforcer-plugin
+
+
+ enforce-java
+
+ enforce
+
+
+
+
+ 11
+
+
+
+
+
+
+
+
diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
index e3b2ba6e..16d64ef9 100644
--- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java
@@ -42,8 +42,8 @@ public abstract class AbstractScanner
*
Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo,
@@ -90,10 +90,10 @@ public abstract class AbstractScanner
"**/.metadata", "**/.metadata/**",
// Mercurial
- "**/.hg", "**/.hgignore", "**/.hg/**",
+ "**/.hg", "**/.hg/**",
// git
- "**/.git", "**/.gitignore", "**/.gitattributes", "**/.git/**",
+ "**/.git", "**/.git/**",
// BitKeeper
"**/BitKeeper", "**/BitKeeper/**", "**/ChangeSet", "**/ChangeSet/**",
@@ -124,7 +124,7 @@ public abstract class AbstractScanner
* @since 3.3.0
*/
protected Comparator filenameComparator;
-
+
/**
* Sets whether or not the file system should be regarded as case sensitive.
*
@@ -137,7 +137,7 @@ public void setCaseSensitive( boolean isCaseSensitive )
/**
*
Tests whether or not a given path matches the start of a given pattern up to the first "**".
- *
+ *
*
This is not a general purpose test and should only be used if you can live with false positives. For example,
* pattern=**\a and str=b will yield true.
Tests whether or not a given path matches the start of a given pattern up to the first "**".
- *
+ *
*
This is not a general purpose test and should only be used if you can live with false positives. For example,
* pattern=**\a and str=b will yield true.
Sets the list of include patterns to use. All '/' and '\' characters are replaced by
* File.separatorChar, so the separator used need not match File.separatorChar.
- *
+ *
*
When a pattern ends with a '/' or '\', "**" is appended.
*
* @param includes A list of include patterns. May be null, indicating that all files should be
* included. If a non-null list is given, all elements must be non-null.
*/
+ @Override
public void setIncludes( String[] includes )
{
if ( includes == null )
@@ -245,19 +246,20 @@ public void setIncludes( String[] includes )
list.add( normalizePattern( include ) );
}
}
- this.includes = list.toArray( new String[list.size()] );
+ this.includes = list.toArray( new String[0] );
}
}
/**
*
Sets the list of exclude patterns to use. All '/' and '\' characters are replaced by
* File.separatorChar, so the separator used need not match File.separatorChar.
- *
+ *
*
When a pattern ends with a '/' or '\', "**" is appended.
*
* @param excludes A list of exclude patterns. May be null, indicating that no files should be
* excluded. If a non-null list is given, all elements must be non-null.
*/
+ @Override
public void setExcludes( String[] excludes )
{
if ( excludes == null )
@@ -274,7 +276,7 @@ public void setExcludes( String[] excludes )
list.add( normalizePattern( exclude ) );
}
}
- this.excludes = list.toArray( new String[list.size()] );
+ this.excludes = list.toArray( new String[0] );
}
}
@@ -329,6 +331,11 @@ protected boolean isIncluded( String name, String[] tokenizedName )
return includesPatterns.matches( name, tokenizedName, isCaseSensitive );
}
+ protected boolean isIncluded( String name, char[][] tokenizedName )
+ {
+ return includesPatterns.matches( name, tokenizedName, isCaseSensitive );
+ }
+
/**
* Tests whether or not a name matches the start of at least one include pattern.
*
@@ -358,9 +365,15 @@ protected boolean isExcluded( String name, String[] tokenizedName )
return excludesPatterns.matches( name, tokenizedName, isCaseSensitive );
}
+ protected boolean isExcluded( String name, char[][] tokenizedName )
+ {
+ return excludesPatterns.matches( name, tokenizedName, isCaseSensitive );
+ }
+
/**
* Adds default exclusions to the current exclusions set.
*/
+ @Override
public void addDefaultExcludes()
{
int excludesLength = excludes == null ? 0 : excludes.length;
diff --git a/src/main/java/org/codehaus/plexus/util/Base64.java b/src/main/java/org/codehaus/plexus/util/Base64.java
index dd504552..120feb8f 100644
--- a/src/main/java/org/codehaus/plexus/util/Base64.java
+++ b/src/main/java/org/codehaus/plexus/util/Base64.java
@@ -26,7 +26,7 @@
* @see RFC 2045
* @author Apache Software Foundation
* @since 1.0-dev
- * @version $Id$
+ *
*/
public class Base64
{
diff --git a/src/main/java/org/codehaus/plexus/util/BaseIOUtil.java b/src/main/java/org/codehaus/plexus/util/BaseIOUtil.java
new file mode 100644
index 00000000..ac2ade02
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/BaseIOUtil.java
@@ -0,0 +1,27 @@
+package org.codehaus.plexus.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Implementation specific to Java SE 8 version.
+ */
+abstract class BaseIOUtil
+{
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 16;
+
+ static void copy( final InputStream input, final OutputStream output )
+ throws IOException
+ {
+ IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE );
+ }
+
+ static void copy( final Reader input, final Writer output )
+ throws IOException
+ {
+ IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE );
+ }
+}
diff --git a/src/main/java/org/codehaus/plexus/util/CachedMap.java b/src/main/java/org/codehaus/plexus/util/CachedMap.java
index 3c5b40e8..c77d2180 100644
--- a/src/main/java/org/codehaus/plexus/util/CachedMap.java
+++ b/src/main/java/org/codehaus/plexus/util/CachedMap.java
@@ -191,6 +191,7 @@ public void flush()
* @throws ClassCastException if the key is of an inappropriate type for the backing map (optional).
* @throws NullPointerException if the key is null.
*/
+ @Override
public Object get( Object key )
{
int index = key.hashCode() & _mask;
@@ -243,6 +244,7 @@ private Object getCacheMissed( Object key, int index )
* @throws IllegalArgumentException if some aspect of this key or value prevents it from being stored in this map.
* @throws NullPointerException if the key is null.
*/
+ @Override
public Object put( Object key, Object value )
{
// Updates the cache.
@@ -269,6 +271,7 @@ else if ( _keysMap != null )
* @throws NullPointerException if the key is null.
* @throws UnsupportedOperationException if the remove method is not supported by the backing map.
*/
+ @Override
public Object remove( Object key )
{
// Removes from cache.
@@ -292,6 +295,7 @@ public Object remove( Object key )
* @param key the key whose presence in this map is to be tested.
* @return true if this map contains a mapping for the specified key; false otherwise.
*/
+ @Override
public boolean containsKey( Object key )
{
// Checks the cache.
@@ -312,6 +316,7 @@ public boolean containsKey( Object key )
*
* @return the number of key-value mappings in this map.
*/
+ @Override
public int size()
{
return _backingMap.size();
@@ -322,6 +327,7 @@ public int size()
*
* @return true if this map contains no key-value mappings.
*/
+ @Override
public boolean isEmpty()
{
return _backingMap.isEmpty();
@@ -336,6 +342,7 @@ public boolean isEmpty()
* @throws NullPointerException if the value is null and the backing map does not not permit
* null values.
*/
+ @Override
public boolean containsValue( Object value )
{
return _backingMap.containsValue( value );
@@ -354,6 +361,7 @@ public boolean containsValue( Object value )
* @throws NullPointerException the specified map is null, or if the backing map does not permit
* null keys or values, and the specified map contains null keys or values.
*/
+ @Override
public void putAll( Map map )
{
_backingMap.putAll( map );
@@ -365,6 +373,7 @@ public void putAll( Map map )
*
* @throws UnsupportedOperationException if clear is not supported by the backing map.
*/
+ @Override
public void clear()
{
_backingMap.clear();
@@ -376,6 +385,7 @@ public void clear()
*
* @return an unmodifiable view of the keys contained in this map.
*/
+ @Override
public Set keySet()
{
return Collections.unmodifiableSet( _backingMap.keySet() );
@@ -386,6 +396,7 @@ public Set keySet()
*
* @return an unmodifiable view of the values contained in this map.
*/
+ @Override
public Collection values()
{
return Collections.unmodifiableCollection( _backingMap.values() );
@@ -397,18 +408,20 @@ public Collection values()
*
* @return an unmodifiable view of the mappings contained in this map.
*/
+ @Override
public Set entrySet()
{
return Collections.unmodifiableSet( _backingMap.entrySet() );
}
/**
- * Compares the specified object with this map for equality. Returns true if the given object is also a map
+ * Compares the specified object with this map for equality. Returns true if the given object is also a map
* and the two Maps represent the same mappings.
*
* @param o object to be compared for equality with this map.
* @return true if the specified object is equal to this map.
*/
+ @Override
public boolean equals( Object o )
{
return _backingMap.equals( o );
@@ -419,8 +432,9 @@ public boolean equals( Object o )
*
* @return the hash code value for this map.
*/
+ @Override
public int hashCode()
{
return _backingMap.hashCode();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/codehaus/plexus/util/CollectionUtils.java b/src/main/java/org/codehaus/plexus/util/CollectionUtils.java
index d7e745b4..b16200fd 100644
--- a/src/main/java/org/codehaus/plexus/util/CollectionUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/CollectionUtils.java
@@ -28,7 +28,7 @@
/**
* @author olamy
- * @version $Id$
+ *
*/
public class CollectionUtils
{
@@ -44,6 +44,8 @@ public class CollectionUtils
*
* @param dominantMap Dominant Map.
* @param recessiveMap Recessive Map.
+ * @param type
+ * @param type
* @return The result map with combined dominant and recessive values.
*/
public static Map mergeMaps( Map dominantMap, Map recessiveMap )
@@ -64,7 +66,7 @@ public static Map mergeMaps( Map dominantMap, Map reces
return recessiveMap;
}
- Map result = new HashMap();
+ Map result = new HashMap<>();
// Grab the keys from the dominant and recessive maps.
Set dominantMapKeys = dominantMap.keySet();
@@ -94,6 +96,8 @@ public static Map mergeMaps( Map dominantMap, Map reces
* order.
*
* @param maps An array of Maps to merge.
+ * @param type
+ * @param type
* @return Map The result Map produced after the merging process.
*/
public static Map mergeMaps( Map[] maps )
@@ -122,22 +126,24 @@ else if ( maps.length == 1 )
}
/**
- * Returns a {@link Collection} containing the intersection of the given {@link Collection}s.
*
+ * Returns a {@link Collection} containing the intersection of the given {@link Collection}s.
+ *
* The cardinality of each element in the returned {@link Collection} will be equal to the minimum of the
* cardinality of that element in the two given {@link Collection}s.
*
* @param a The first collection
* @param b The second collection
+ * @param the type
* @see Collection#retainAll
* @return The intersection of a and b, never null
*/
public static Collection intersection( final Collection a, final Collection b )
{
- ArrayList list = new ArrayList();
+ ArrayList list = new ArrayList<>();
Map mapa = getCardinalityMap( a );
Map mapb = getCardinalityMap( b );
- Set elts = new HashSet( a );
+ Set elts = new HashSet<>( a );
elts.addAll( b );
for ( E obj : elts )
{
@@ -150,18 +156,19 @@ public static Collection intersection( final Collection a, final Colle
}
/**
- * Returns a {@link Collection} containing a - b. The cardinality of each element e in
+ * Returns a {@link Collection} containing a - b. The cardinality of each element e in
* the returned {@link Collection} will be the cardinality of e in a minus the cardinality of e
* in b, or zero, whichever is greater.
*
* @param a The start collection
* @param b The collection that will be subtracted
+ * @param the type
* @see Collection#removeAll
* @return The result of the subtraction
*/
public static Collection subtract( final Collection a, final Collection b )
{
- ArrayList list = new ArrayList( a );
+ ArrayList list = new ArrayList<>( a );
for ( T aB : b )
{
list.remove( aB );
@@ -172,14 +179,15 @@ public static Collection subtract( final Collection a, final Collectio
/**
* Returns a {@link Map} mapping each unique element in the given {@link Collection} to an {@link Integer}
* representing the number of occurrences of that element in the {@link Collection}. An entry that maps to
- * null indicates that the element does not appear in the given {@link Collection}.
+ * null indicates that the element does not appear in the given {@link Collection}.
*
* @param col The collection to count cardinalities for
+ * @param the type
* @return A map of counts, indexed on each element in the collection
*/
public static Map getCardinalityMap( final Collection col )
{
- HashMap count = new HashMap();
+ HashMap count = new HashMap<>();
for ( E obj : col )
{
Integer c = count.get( obj );
@@ -226,10 +234,7 @@ private static int getFreq( final E obj, final Map freqMap )
return o;
}
}
- catch ( NullPointerException ignore )
- {
- }
- catch ( NoSuchElementException ignore )
+ catch ( NullPointerException | NoSuchElementException ignore )
{
}
return 0;
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
index af118472..5db6a903 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java
@@ -58,7 +58,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Vector;
/**
*
Class for scanning a directory for files/directories which match certain criteria.
@@ -136,6 +135,8 @@ public class DirectoryScanner
extends AbstractScanner
{
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
/**
* The base directory to be scanned.
*/
@@ -144,42 +145,42 @@ public class DirectoryScanner
/**
* The files which matched at least one include and no excludes and were selected.
*/
- protected Vector filesIncluded;
+ protected ArrayList filesIncluded;
/**
* The files which did not match any includes or selectors.
*/
- protected Vector filesNotIncluded;
+ protected ArrayList filesNotIncluded;
/**
* The files which matched at least one include and at least one exclude.
*/
- protected Vector filesExcluded;
+ protected ArrayList filesExcluded;
/**
* The directories which matched at least one include and no excludes and were selected.
*/
- protected Vector dirsIncluded;
+ protected ArrayList dirsIncluded;
/**
* The directories which were found and did not match any includes.
*/
- protected Vector dirsNotIncluded;
+ protected ArrayList dirsNotIncluded;
/**
* The directories which matched at least one include and at least one exclude.
*/
- protected Vector dirsExcluded;
+ protected ArrayList dirsExcluded;
/**
* The files which matched at least one include and no excludes and which a selector discarded.
*/
- protected Vector filesDeselected;
+ protected ArrayList filesDeselected;
/**
* The directories which matched at least one include and no excludes but which a selector discarded.
*/
- protected Vector dirsDeselected;
+ protected ArrayList dirsDeselected;
/**
* Whether or not our results were built by a slow scan.
@@ -198,7 +199,7 @@ public class DirectoryScanner
*/
protected boolean everythingIncluded = true;
- private final String[] tokenizedEmpty = MatchPattern.tokenizePathToString( "", File.separator );
+ private final char[][] tokenizedEmpty = MatchPattern.tokenizePathToCharArray( "", File.separator );
/**
* Sole constructor.
@@ -234,6 +235,7 @@ public void setBasedir( File basedir )
*
* @return the base directory to be scanned
*/
+ @Override
public File getBasedir()
{
return basedir;
@@ -266,6 +268,7 @@ public boolean isEverythingIncluded()
* @throws IllegalStateException if the base directory was set incorrectly (i.e. if it is null, doesn't
* exist, or isn't a directory).
*/
+ @Override
public void scan()
throws IllegalStateException
{
@@ -285,14 +288,14 @@ public void scan()
setupDefaultFilters();
setupMatchPatterns();
- filesIncluded = new Vector();
- filesNotIncluded = new Vector();
- filesExcluded = new Vector();
- filesDeselected = new Vector();
- dirsIncluded = new Vector();
- dirsNotIncluded = new Vector();
- dirsExcluded = new Vector();
- dirsDeselected = new Vector();
+ filesIncluded = new ArrayList();
+ filesNotIncluded = new ArrayList();
+ filesExcluded = new ArrayList();
+ filesDeselected = new ArrayList();
+ dirsIncluded = new ArrayList();
+ dirsNotIncluded = new ArrayList();
+ dirsExcluded = new ArrayList();
+ dirsDeselected = new ArrayList();
if ( isIncluded( "", tokenizedEmpty ) )
{
@@ -301,21 +304,21 @@ public void scan()
{
if ( isSelected( "", basedir ) )
{
- dirsIncluded.addElement( "" );
+ dirsIncluded.add( "" );
}
else
{
- dirsDeselected.addElement( "" );
+ dirsDeselected.add( "" );
}
}
else
{
- dirsExcluded.addElement( "" );
+ dirsExcluded.add( "" );
}
}
else
{
- dirsNotIncluded.addElement( "" );
+ dirsNotIncluded.add( "" );
}
scandir( basedir, "", true );
}
@@ -334,11 +337,8 @@ protected void slowScan()
return;
}
- String[] excl = new String[dirsExcluded.size()];
- dirsExcluded.copyInto( excl );
-
- String[] notIncl = new String[dirsNotIncluded.size()];
- dirsNotIncluded.copyInto( notIncl );
+ String[] excl = dirsExcluded.toArray( EMPTY_STRING_ARRAY );
+ String[] notIncl = dirsNotIncluded.toArray( EMPTY_STRING_ARRAY );
for ( String anExcl : excl )
{
@@ -396,45 +396,39 @@ protected void scandir( File dir, String vpath, boolean fast )
* [bentmann] A null array will also be returned from list() on NTFS when dir refers to a soft link or
* junction point whose target is not existent.
*/
- newfiles = new String[0];
+ newfiles = EMPTY_STRING_ARRAY;
// throw new IOException( "IO error scanning directory " + dir.getAbsolutePath() );
}
if ( !followSymlinks )
{
- ArrayList noLinks = new ArrayList();
- for ( String newfile : newfiles )
+ try
{
- try
+ if ( isParentSymbolicLink( dir, null ) )
{
- if ( isParentSymbolicLink( dir, newfile ) )
+ for ( String newfile : newfiles )
{
String name = vpath + newfile;
File file = new File( dir, newfile );
if ( file.isDirectory() )
{
- dirsExcluded.addElement( name );
+ dirsExcluded.add( name );
}
else
{
- filesExcluded.addElement( name );
+ filesExcluded.add( name );
}
}
- else
- {
- noLinks.add( newfile );
- }
- }
- catch ( IOException ioe )
- {
- String msg = "IOException caught while checking " + "for links, couldn't get canonical path!";
- // will be caught and redirected to Ant's logging system
- System.err.println( msg );
- noLinks.add( newfile );
+ return;
}
}
- newfiles = noLinks.toArray( new String[noLinks.size()] );
+ catch ( IOException ioe )
+ {
+ String msg = "IOException caught while checking for links!";
+ // will be caught and redirected to Ant's logging system
+ System.err.println( msg );
+ }
}
if ( filenameComparator != null )
@@ -445,7 +439,7 @@ protected void scandir( File dir, String vpath, boolean fast )
for ( String newfile : newfiles )
{
String name = vpath + newfile;
- String[] tokenizedName = MatchPattern.tokenizePathToString( name, File.separator );
+ char[][] tokenizedName = MatchPattern.tokenizePathToCharArray( name, File.separator );
File file = new File( dir, newfile );
if ( file.isDirectory() )
{
@@ -456,7 +450,7 @@ protected void scandir( File dir, String vpath, boolean fast )
{
if ( isSelected( name, file ) )
{
- dirsIncluded.addElement( name );
+ dirsIncluded.add( name );
if ( fast )
{
scandir( file, name + File.separator, fast );
@@ -465,7 +459,7 @@ protected void scandir( File dir, String vpath, boolean fast )
else
{
everythingIncluded = false;
- dirsDeselected.addElement( name );
+ dirsDeselected.add( name );
if ( fast && couldHoldIncluded( name ) )
{
scandir( file, name + File.separator, fast );
@@ -476,7 +470,7 @@ protected void scandir( File dir, String vpath, boolean fast )
else
{
everythingIncluded = false;
- dirsExcluded.addElement( name );
+ dirsExcluded.add( name );
if ( fast && couldHoldIncluded( name ) )
{
scandir( file, name + File.separator, fast );
@@ -486,7 +480,7 @@ protected void scandir( File dir, String vpath, boolean fast )
else
{
everythingIncluded = false;
- dirsNotIncluded.addElement( name );
+ dirsNotIncluded.add( name );
if ( fast && couldHoldIncluded( name ) )
{
scandir( file, name + File.separator, fast );
@@ -505,24 +499,24 @@ else if ( file.isFile() )
{
if ( isSelected( name, file ) )
{
- filesIncluded.addElement( name );
+ filesIncluded.add( name );
}
else
{
everythingIncluded = false;
- filesDeselected.addElement( name );
+ filesDeselected.add( name );
}
}
else
{
everythingIncluded = false;
- filesExcluded.addElement( name );
+ filesExcluded.add( name );
}
}
else
{
everythingIncluded = false;
- filesNotIncluded.addElement( name );
+ filesNotIncluded.add( name );
}
}
}
@@ -548,11 +542,10 @@ protected boolean isSelected( String name, File file )
* @return the names of the files which matched at least one of the include patterns and none of the exclude
* patterns.
*/
+ @Override
public String[] getIncludedFiles()
{
- String[] files = new String[filesIncluded.size()];
- filesIncluded.copyInto( files );
- return files;
+ return filesIncluded.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -565,9 +558,7 @@ public String[] getIncludedFiles()
public String[] getNotIncludedFiles()
{
slowScan();
- String[] files = new String[filesNotIncluded.size()];
- filesNotIncluded.copyInto( files );
- return files;
+ return filesNotIncluded.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -582,9 +573,7 @@ public String[] getNotIncludedFiles()
public String[] getExcludedFiles()
{
slowScan();
- String[] files = new String[filesExcluded.size()];
- filesExcluded.copyInto( files );
- return files;
+ return filesExcluded.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -599,9 +588,7 @@ public String[] getExcludedFiles()
public String[] getDeselectedFiles()
{
slowScan();
- String[] files = new String[filesDeselected.size()];
- filesDeselected.copyInto( files );
- return files;
+ return filesDeselected.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -611,11 +598,10 @@ public String[] getDeselectedFiles()
* @return the names of the directories which matched at least one of the include patterns and none of the exclude
* patterns.
*/
+ @Override
public String[] getIncludedDirectories()
{
- String[] directories = new String[dirsIncluded.size()];
- dirsIncluded.copyInto( directories );
- return directories;
+ return dirsIncluded.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -628,9 +614,7 @@ public String[] getIncludedDirectories()
public String[] getNotIncludedDirectories()
{
slowScan();
- String[] directories = new String[dirsNotIncluded.size()];
- dirsNotIncluded.copyInto( directories );
- return directories;
+ return dirsNotIncluded.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -645,9 +629,7 @@ public String[] getNotIncludedDirectories()
public String[] getExcludedDirectories()
{
slowScan();
- String[] directories = new String[dirsExcluded.size()];
- dirsExcluded.copyInto( directories );
- return directories;
+ return dirsExcluded.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -662,9 +644,7 @@ public String[] getExcludedDirectories()
public String[] getDeselectedDirectories()
{
slowScan();
- String[] directories = new String[dirsDeselected.size()];
- dirsDeselected.copyInto( directories );
- return directories;
+ return dirsDeselected.toArray( EMPTY_STRING_ARRAY );
}
/**
@@ -683,13 +663,7 @@ public String[] getDeselectedDirectories()
public boolean isSymbolicLink( File parent, String name )
throws IOException
{
- if ( Java7Detector.isJava7() )
- {
- return NioFiles.isSymbolicLink( new File( parent, name ) );
- }
- File resolvedParent = new File( parent.getCanonicalPath() );
- File toTest = new File( resolvedParent, name );
- return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
+ return NioFiles.isSymbolicLink( new File( parent, name ) );
}
/**
@@ -707,12 +681,6 @@ public boolean isSymbolicLink( File parent, String name )
public boolean isParentSymbolicLink( File parent, String name )
throws IOException
{
- if ( Java7Detector.isJava7() )
- {
- return NioFiles.isSymbolicLink( parent );
- }
- File resolvedParent = new File( parent.getCanonicalPath() );
- File toTest = new File( resolvedParent, name );
- return !toTest.getAbsolutePath().equals( toTest.getCanonicalPath() );
+ return NioFiles.isSymbolicLink( parent );
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java b/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java
index 74bdf957..8e1fda24 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryWalkListener.java
@@ -21,7 +21,7 @@
/**
* Observes the actions of a {@link DirectoryWalker}.
*
- * @version $Id$
+ *
* @see DirectoryWalker
*/
public interface DirectoryWalkListener
diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java b/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java
index 2fd90077..2ffa4b0a 100644
--- a/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java
+++ b/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java
@@ -25,7 +25,7 @@
/**
* DirectoryWalker
*
- * @version $Id$
+ *
*/
public class DirectoryWalker
{
@@ -102,6 +102,7 @@ public int getPercentage()
return (int) Math.floor( percentageOffset + ( percentageWithinDir * percentageSize ) );
}
+ @Override
public String toString()
{
return "DirStackEntry[" + "dir=" + dir.getAbsolutePath() + ",count=" + count + ",index=" + index
@@ -154,7 +155,7 @@ public void addInclude( String include )
*/
public void addSCMExcludes()
{
- String scmexcludes[] = DirectoryScanner.DEFAULTEXCLUDES;
+ String scmexcludes[] = AbstractScanner.DEFAULTEXCLUDES;
for ( String scmexclude : scmexcludes )
{
addExclude( scmexclude );
@@ -330,7 +331,7 @@ public void scan()
}
fireWalkStarting();
- dirStack = new Stack();
+ dirStack = new Stack();
scanDir( baseDir );
fireWalkFinished();
}
@@ -352,7 +353,7 @@ private void scanDir( File dir )
}
else
{
- DirectoryWalker.DirStackEntry previousStackEntry = (DirectoryWalker.DirStackEntry) dirStack.peek();
+ DirectoryWalker.DirStackEntry previousStackEntry = dirStack.peek();
curStackEntry.percentageOffset = previousStackEntry.getNextPercentageOffset();
curStackEntry.percentageSize = previousStackEntry.getNextPercentageSize();
}
diff --git a/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java b/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java
index 6f8d1424..540dbe98 100644
--- a/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java
@@ -76,7 +76,7 @@
* @author Dmitri Plotnikov
* @author Stephen Colebourne
* @since 1.0
- * @version $Id$
+ *
*/
public class ExceptionUtils
{
@@ -112,7 +112,7 @@ public static void addCauseMethodName( String methodName )
{
List list = new ArrayList( Arrays.asList( CAUSE_METHOD_NAMES ) );
list.add( methodName );
- CAUSE_METHOD_NAMES = list.toArray( new String[list.size()] );
+ CAUSE_METHOD_NAMES = list.toArray( new String[0] );
}
}
@@ -158,6 +158,7 @@ public static Throwable getCause( Throwable throwable )
*
*
* @param throwable The exception to introspect for a cause.
+ * @param methodNames the methods names to match
* @return The cause of the Throwable.
* @throws NullPointerException if the method names array is null or contains null
* @throws NullPointerException if the throwable is null
@@ -343,13 +344,13 @@ public static int getThrowableCount( Throwable throwable )
*/
public static Throwable[] getThrowables( Throwable throwable )
{
- List list = new ArrayList();
+ List list = new ArrayList<>();
while ( throwable != null )
{
list.add( throwable );
throwable = getCause( throwable );
}
- return list.toArray( new Throwable[list.size()] );
+ return list.toArray( new Throwable[0] );
}
/**
@@ -357,7 +358,9 @@ public static Throwable[] getThrowables( Throwable throwable )
* Delegates to {@link #indexOfThrowable(Throwable, Class, int)}, starting the search at the beginning of the
* exception chain.
*
- *
+ * @param throwable the exception to inspect
+ * @param type Class to look for
+ * @return index of the stack matching the type
* @see #indexOfThrowable(Throwable, Class, int)
*/
public static int indexOfThrowable( Throwable throwable, Class type )
@@ -406,6 +409,8 @@ public static int indexOfThrowable( Throwable throwable, Class type, int fromInd
* exception and continues with stack frames until the wrapper exception is caught and wrapped again, etc.
*
* The method is equivalent to t.printStackTrace() for throwables that don't have nested causes.
+ * @param t the exception
+ * @param stream the stream
*/
public static void printRootCauseStackTrace( Throwable t, PrintStream stream )
{
@@ -419,6 +424,7 @@ public static void printRootCauseStackTrace( Throwable t, PrintStream stream )
/**
* Equivalent to printRootCauseStackTrace(t, System.err)
+ * @param t the exception
*/
public static void printRootCauseStackTrace( Throwable t )
{
@@ -427,6 +433,8 @@ public static void printRootCauseStackTrace( Throwable t )
/**
* Same as printRootCauseStackTrace(t, stream), except it takes a PrintWriter as an argument.
+ * @param t the cause
+ * @param writer the writer
*/
public static void printRootCauseStackTrace( Throwable t, PrintWriter writer )
{
@@ -441,12 +449,14 @@ public static void printRootCauseStackTrace( Throwable t, PrintWriter writer )
/**
* Creates a compact stack trace for the root cause of the supplied throwable. See
* printRootCauseStackTrace(Throwable t, PrintStream s)
+ * @param t the cause
+ * @return the Stack
*/
public static String[] getRootCauseStackTrace( Throwable t )
{
Throwable[] throwables = getThrowables( t );
int count = throwables.length;
- ArrayList frames = new ArrayList();
+ ArrayList frames = new ArrayList<>();
List nextTrace = getStackFrameList( throwables[count - 1] );
for ( int i = count; --i >= 0; )
{
@@ -469,7 +479,7 @@ public static String[] getRootCauseStackTrace( Throwable t )
frames.add( aTrace );
}
}
- return frames.toArray( new String[frames.size()] );
+ return frames.toArray( new String[0] );
}
/**
@@ -615,7 +625,7 @@ static String[] getStackFrames( String stackTrace )
{
list.add( frames.nextToken() );
}
- return list.toArray( new String[list.size()] );
+ return list.toArray( new String[0] );
}
/**
diff --git a/src/main/java/org/codehaus/plexus/util/Expand.java b/src/main/java/org/codehaus/plexus/util/Expand.java
index 3d3e98aa..5b195811 100644
--- a/src/main/java/org/codehaus/plexus/util/Expand.java
+++ b/src/main/java/org/codehaus/plexus/util/Expand.java
@@ -55,11 +55,11 @@
*/
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
import java.util.Date;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -71,7 +71,7 @@
* @author Stefan Bodewig
* @author Magesh Umasankar
* @since Ant 1.1 @ant.task category="packaging" name="unzip" name="unjar" name="unwar"
- * @version $Id$
+ *
*/
public class Expand
{
@@ -93,43 +93,23 @@ public void execute()
expandFile( source, dest );
}
- /*
- * This method is to be overridden by extending unarchival tasks.
- */
- /**
- * Description of the Method
- */
protected void expandFile( final File srcF, final File dir )
throws Exception
{
- ZipInputStream zis = null;
- try
+ // code from WarExpand
+ try ( ZipInputStream zis = new ZipInputStream( Files.newInputStream( srcF.toPath() ) ) )
{
- // code from WarExpand
- zis = new ZipInputStream( new FileInputStream( srcF ) );
-
for ( ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry() )
{
extractFile( srcF, dir, zis, ze.getName(), new Date( ze.getTime() ), ze.isDirectory() );
}
-
- // log("expand complete", Project.MSG_VERBOSE);
- zis.close();
- zis = null;
}
catch ( IOException ioe )
{
throw new Exception( "Error while expanding " + srcF.getPath(), ioe );
}
- finally
- {
- IOUtil.close( zis );
- }
}
- /**
- * Description of the Method
- */
protected void extractFile( File srcF, File dir, InputStream compressedInputStream, String entryName,
Date entryDate, boolean isDirectory )
throws Exception
@@ -159,22 +139,13 @@ protected void extractFile( File srcF, File dir, InputStream compressedInputStre
else
{
byte[] buffer = new byte[65536];
- FileOutputStream fos = null;
- try
+
+ try ( OutputStream fos = Files.newOutputStream( f.toPath() ) )
{
- fos = new FileOutputStream( f );
-
- for ( int length =
- compressedInputStream.read( buffer ); length >= 0; fos.write( buffer, 0, length ), length =
- compressedInputStream.read( buffer ) )
+ for ( int length = compressedInputStream.read( buffer );
+ length >= 0;
+ fos.write( buffer, 0, length ), length = compressedInputStream.read( buffer ) )
;
-
- fos.close();
- fos = null;
- }
- finally
- {
- IOUtil.close( fos );
}
}
@@ -208,7 +179,7 @@ public void setSrc( File s )
}
/**
- * Should we overwrite files in dest, even if they are newer than the corresponding entries in the archive?
+ * @param b Should we overwrite files in dest, even if they are newer than the corresponding entries in the archive?
*/
public void setOverwrite( boolean b )
{
diff --git a/src/main/java/org/codehaus/plexus/util/FastMap.java b/src/main/java/org/codehaus/plexus/util/FastMap.java
index ca433b7a..9bb9e82f 100644
--- a/src/main/java/org/codehaus/plexus/util/FastMap.java
+++ b/src/main/java/org/codehaus/plexus/util/FastMap.java
@@ -136,6 +136,7 @@ public FastMap( int capacity )
*
* @return this map's size.
*/
+ @Override
public int size()
{
return _size;
@@ -157,6 +158,7 @@ public int capacity()
*
* @return true if this map contains no key-value mappings; false otherwise.
*/
+ @Override
public boolean isEmpty()
{
return _size == 0;
@@ -169,6 +171,7 @@ public boolean isEmpty()
* @return true if this map contains a mapping for the specified key; false otherwise.
* @throws NullPointerException if the key is null.
*/
+ @Override
public boolean containsKey( Object key )
{
EntryImpl entry = _entries[keyHash( key ) & _mask];
@@ -190,6 +193,7 @@ public boolean containsKey( Object key )
* @return true if this map maps one or more keys to the specified value.
* @throws NullPointerException if the key is null.
*/
+ @Override
public boolean containsValue( Object value )
{
EntryImpl entry = _mapFirst;
@@ -212,6 +216,7 @@ public boolean containsValue( Object value )
* key.
* @throws NullPointerException if key is null.
*/
+ @Override
public V get( Object key )
{
EntryImpl entry = _entries[keyHash( key ) & _mask];
@@ -257,6 +262,7 @@ public Map.Entry getEntry( Object key )
* specified key.
* @throws NullPointerException if the key is null.
*/
+ @Override
public Object put( Object key, Object value )
{
EntryImpl entry = _entries[keyHash( key ) & _mask];
@@ -282,6 +288,7 @@ public Object put( Object key, Object value )
* @throws NullPointerException the specified map is null, or the specified map contains
* null keys.
*/
+ @Override
public void putAll( Map extends K, ? extends V> map )
{
for ( Entry extends K, ? extends V> entry : map.entrySet() )
@@ -299,6 +306,7 @@ public void putAll( Map extends K, ? extends V> map )
* specified key.
* @throws NullPointerException if the key is null.
*/
+ @Override
public V remove( Object key )
{
EntryImpl entry = _entries[keyHash( key ) & _mask];
@@ -318,6 +326,7 @@ public V remove( Object key )
/**
* Removes all mappings from this {@link FastMap}.
*/
+ @Override
public void clear()
{
// Clears all keys, values and buckets linked lists.
@@ -417,6 +426,7 @@ else if ( newCapacity < _capacity )
*
* @return a shallow copy of this map.
*/
+ @Override
public Object clone()
{
try
@@ -440,6 +450,7 @@ public Object clone()
* @param obj the object to be compared for equality with this map.
* @return true if the specified object is equal to this map; false otherwise.
*/
+ @Override
public boolean equals( Object obj )
{
if ( obj == this )
@@ -478,6 +489,7 @@ else if ( obj instanceof Map )
*
* @return the hash code value for this map.
*/
+ @Override
public int hashCode()
{
int code = 0;
@@ -495,6 +507,7 @@ public int hashCode()
*
* @return this.entrySet().toString();
*/
+ @Override
public String toString()
{
return entrySet().toString();
@@ -509,6 +522,7 @@ public String toString()
*
* @return a collection view of the values contained in this map.
*/
+ @Override
public Collection values()
{
return _values;
@@ -519,6 +533,7 @@ public Collection values()
private class Values
extends AbstractCollection
{
+ @Override
public Iterator iterator()
{
return new Iterator()
@@ -527,16 +542,19 @@ public Iterator iterator()
EntryImpl before;
+ @Override
public void remove()
{
removeEntry( before );
}
+ @Override
public boolean hasNext()
{
return after != null;
}
+ @Override
public Object next()
{
before = after;
@@ -546,16 +564,19 @@ public Object next()
};
}
+ @Override
public int size()
{
return _size;
}
+ @Override
public boolean contains( Object o )
{
return containsValue( o );
}
+ @Override
public void clear()
{
FastMap.this.clear();
@@ -572,6 +593,7 @@ public void clear()
*
* @return a collection view of the mappings contained in this map.
*/
+ @Override
public Set entrySet()
{
return _entrySet;
@@ -582,6 +604,7 @@ public Set entrySet()
private class EntrySet
extends AbstractSet
{
+ @Override
public Iterator iterator()
{
return new Iterator()
@@ -590,16 +613,19 @@ public Iterator iterator()
EntryImpl before;
+ @Override
public void remove()
{
removeEntry( before );
}
+ @Override
public boolean hasNext()
{
return after != null;
}
+ @Override
public Object next()
{
before = after;
@@ -609,11 +635,13 @@ public Object next()
};
}
+ @Override
public int size()
{
return _size;
}
+ @Override
public boolean contains( Object obj )
{ // Optimization.
if ( obj instanceof Map.Entry )
@@ -628,6 +656,7 @@ public boolean contains( Object obj )
}
}
+ @Override
public boolean remove( Object obj )
{ // Optimization.
if ( obj instanceof Map.Entry )
@@ -653,6 +682,7 @@ public boolean remove( Object obj )
*
* @return a set view of the keys contained in this map.
*/
+ @Override
public Set keySet()
{
return _keySet;
@@ -663,6 +693,7 @@ public Set keySet()
private class KeySet
extends AbstractSet
{
+ @Override
public Iterator iterator()
{
return new Iterator()
@@ -671,16 +702,19 @@ public Iterator iterator()
EntryImpl before;
+ @Override
public void remove()
{
removeEntry( before );
}
+ @Override
public boolean hasNext()
{
return after != null;
}
+ @Override
public Object next()
{
before = after;
@@ -690,21 +724,25 @@ public Object next()
};
}
+ @Override
public int size()
{
return _size;
}
+ @Override
public boolean contains( Object obj )
{ // Optimization.
return FastMap.this.containsKey( obj );
}
+ @Override
public boolean remove( Object obj )
{ // Optimization.
return FastMap.this.remove( obj ) != null;
}
+ @Override
public void clear()
{ // Optimization.
FastMap.this.clear();
@@ -995,6 +1033,7 @@ private static final class EntryImpl
*
* @return the entry's key.
*/
+ @Override
public K getKey()
{
return _key;
@@ -1005,6 +1044,7 @@ public K getKey()
*
* @return the entry's value.
*/
+ @Override
public V getValue()
{
return _value;
@@ -1016,6 +1056,7 @@ public V getValue()
* @param value the new value.
* @return the previous value.
*/
+ @Override
public V setValue( V value )
{
V old = _value;
@@ -1029,6 +1070,7 @@ public V setValue( V value )
* @param that the object to test for equality.
* @return true if both entry are considered equal; false otherwise.
*/
+ @Override
public boolean equals( Object that )
{
if ( that instanceof Map.Entry )
@@ -1048,6 +1090,7 @@ public boolean equals( Object that )
*
* @return this entry's hash code.
*/
+ @Override
public int hashCode()
{
return _key.hashCode() ^ ( ( _value != null ) ? _value.hashCode() : 0 );
@@ -1058,6 +1101,7 @@ public int hashCode()
*
* @return this entry's textual representation.
*/
+ @Override
public String toString()
{
return _key + "=" + _value;
diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java
index a784bf54..4dca8b3c 100644
--- a/src/main/java/org/codehaus/plexus/util/FileUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java
@@ -60,10 +60,6 @@
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -72,7 +68,10 @@
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
-import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
import java.security.SecureRandom;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -83,7 +82,7 @@
/**
*
This class provides basic facilities for manipulating files and file paths.
*
- *
Path-related methods
+ * Path-related methods
*
*
Methods exist to retrieve the components of a typical file path. For example
* /www/hosted/mysite/index.html, can be broken into:
@@ -96,7 +95,7 @@
*
There are also methods to {@link #catPath concatenate two paths}, {@link #resolveFile resolve a path relative to a
* File} and {@link #normalize} a path.
- *
File-related methods
+ * File-related methods
*
*
There are methods to create a {@link #toFile File from a URL}, copy a {@link #copyFileToDirectory File to a
* directory}, copy a {@link #copyFile File to another File}, copy a {@link #copyURLToFile URL's contents to a File}, as
@@ -113,7 +112,7 @@
* @author Christoph.Reck
* @author Peter Donald
* @author Jeff Turner
- * @version $Id$
+ *
*/
public class FileUtils
{
@@ -132,15 +131,10 @@ public class FileUtils
*/
public static final int ONE_GB = ONE_KB * ONE_MB;
- /**
- * The file copy buffer size (30 MB)
- */
- private static final long FILE_COPY_BUFFER_SIZE = ONE_MB * 30;
-
/**
* The vm file separator
*/
- public static String FS = System.getProperty( "file.separator" );
+ public static String FS = File.separator;
/**
* Non-valid Characters for naming files, folders under Windows: ":", "*", "?", "\"", "<", ">", "|"
@@ -363,35 +357,31 @@ public static String fileRead( File file, String encoding )
{
StringBuilder buf = new StringBuilder();
- Reader reader = null;
-
- try
+ try ( Reader reader = getInputStreamReader( file, encoding ) )
{
- if ( encoding != null )
- {
- reader = new InputStreamReader( new FileInputStream( file ), encoding );
- }
- else
- {
- reader = new InputStreamReader( new FileInputStream( file ) );
- }
int count;
char[] b = new char[512];
while ( ( count = reader.read( b ) ) >= 0 ) // blocking read
{
buf.append( b, 0, count );
}
- reader.close();
- reader = null;
- }
- finally
- {
- IOUtil.close( reader );
}
return buf.toString();
}
+ private static InputStreamReader getInputStreamReader( File file, String encoding ) throws IOException
+ {
+ if ( encoding != null )
+ {
+ return new InputStreamReader( Files.newInputStream( file.toPath() ), encoding );
+ }
+ else
+ {
+ return new InputStreamReader( Files.newInputStream( file.toPath() ) );
+ }
+ }
+
/**
* Appends data to a file. The file will be created if it does not exist. Note: the data is written with platform
* encoding
@@ -399,6 +389,8 @@ public static String fileRead( File file, String encoding )
* @param fileName The path of the file to write.
* @param data The content to write to the file.
* @throws IOException if any
+ * @deprecated use {@code java.nio.files.Files.write(filename, data.getBytes(encoding),
+ * StandardOpenOption.APPEND, StandardOpenOption.CREATE)}
*/
public static void fileAppend( String fileName, String data )
throws IOException
@@ -413,14 +405,15 @@ public static void fileAppend( String fileName, String data )
* @param encoding The encoding of the file.
* @param data The content to write to the file.
* @throws IOException if any
+ * @deprecated use {@code java.nio.files.Files.write(filename, data.getBytes(encoding),
+ * StandardOpenOption.APPEND, StandardOpenOption.CREATE)}
*/
public static void fileAppend( String fileName, String encoding, String data )
throws IOException
{
- FileOutputStream out = null;
- try
+ try ( OutputStream out = Files.newOutputStream( Paths.get(fileName),
+ StandardOpenOption.APPEND, StandardOpenOption.CREATE ) )
{
- out = new FileOutputStream( fileName, true );
if ( encoding != null )
{
out.write( data.getBytes( encoding ) );
@@ -429,12 +422,6 @@ public static void fileAppend( String fileName, String encoding, String data )
{
out.write( data.getBytes() );
}
- out.close();
- out = null;
- }
- finally
- {
- IOUtil.close( out );
}
}
@@ -494,25 +481,22 @@ public static void fileWrite( File file, String data )
public static void fileWrite( File file, String encoding, String data )
throws IOException
{
- Writer writer = null;
- try
+ try ( Writer writer = getOutputStreamWriter( file, encoding ) )
{
- OutputStream out = new FileOutputStream( file );
- if ( encoding != null )
- {
- writer = new OutputStreamWriter( out, encoding );
- }
- else
- {
- writer = new OutputStreamWriter( out );
- }
writer.write( data );
- writer.close();
- writer = null;
}
- finally
+ }
+
+ private static OutputStreamWriter getOutputStreamWriter( File file, String encoding ) throws IOException
+ {
+ OutputStream out = Files.newOutputStream( file.toPath() );
+ if ( encoding != null )
+ {
+ return new OutputStreamWriter( out, encoding );
+ }
+ else
{
- IOUtil.close( writer );
+ return new OutputStreamWriter( out );
}
}
@@ -524,20 +508,13 @@ public static void fileWrite( File file, String encoding, String data )
public static void fileDelete( String fileName )
{
File file = new File( fileName );
- if ( Java7Detector.isJava7() )
+ try
{
- try
- {
- NioFiles.deleteIfExists( file );
- }
- catch ( IOException e )
- {
- throw new RuntimeException( e );
- }
+ NioFiles.deleteIfExists( file );
}
- else
+ catch ( IOException e )
{
- file.delete();
+ throw new RuntimeException( e );
}
}
@@ -653,10 +630,7 @@ public static String[] getFilesFromExtension( String directory, String[] extensi
}
// ok... move the Vector into the files list...
- String[] foundFiles = new String[files.size()];
- files.toArray( foundFiles );
-
- return foundFiles;
+ return files.toArray( new String[0] );
}
/**
@@ -751,26 +725,12 @@ public static boolean contentEquals( final File file1, final File file2 )
// don't want to compare directory contents
return false;
}
-
- InputStream input1 = null;
- InputStream input2 = null;
- boolean equals = false;
- try
- {
- input1 = new FileInputStream( file1 );
- input2 = new FileInputStream( file2 );
- equals = IOUtil.contentEquals( input1, input2 );
- input1.close();
- input1 = null;
- input2.close();
- input2 = null;
- }
- finally
+
+ try ( InputStream input1 = Files.newInputStream( file1.toPath() );
+ InputStream input2 = Files.newInputStream( file2.toPath() ) )
{
- IOUtil.close( input1 );
- IOUtil.close( input2 );
+ return IOUtil.contentEquals( input1, input2 );
}
- return equals;
}
/**
@@ -1030,6 +990,7 @@ public static void copyFileToDirectoryIfModified( final File source, final File
* @param sourceBase The basedir used for the directory scan
* @param dirs The getIncludedDirs from the dirscanner
* @param destination The base dir of the output structure
+ * @throws IOException io issue
*/
public static void mkDirs( final File sourceBase, String[] dirs, final File destination )
throws IOException
@@ -1038,7 +999,7 @@ public static void mkDirs( final File sourceBase, String[] dirs, final File dest
{
File src = new File( sourceBase, dir );
File dst = new File( destination, dir );
- if ( Java7Detector.isJava7() && NioFiles.isSymbolicLink( src ) )
+ if ( NioFiles.isSymbolicLink( src ) )
{
File target = NioFiles.readSymbolicLink( src );
NioFiles.createSymbolicLink( dst, target );
@@ -1091,60 +1052,45 @@ public static void copyFile( final File source, final File destination )
private static void doCopyFile( File source, File destination )
throws IOException
{
- // offload to operating system if supported
- if ( Java7Detector.isJava7() )
- {
- doCopyFileUsingNewIO( source, destination );
- }
- else
- {
- doCopyFileUsingLegacyIO( source, destination );
- }
+ doCopyFileUsingNewIO( source, destination );
}
- private static void doCopyFileUsingLegacyIO( File source, File destination )
+ private static void doCopyFileUsingNewIO( File source, File destination )
throws IOException
{
- FileInputStream fis = null;
- FileOutputStream fos = null;
- FileChannel input = null;
- FileChannel output = null;
- try
+ NioFiles.copy( source, destination );
+ }
+
+ /**
+ * Link file from destination to source. The directories up to destination will be created if they
+ * don't already exist. destination will be overwritten if it already exists.
+ *
+ * @param source An existing non-directory File to link to.
+ * @param destination A non-directory File becoming the link (possibly overwriting).
+ * @throws IOException if source does not exist, destination cannot be created, or an
+ * IO error occurs during linking.
+ * @throws java.io.FileNotFoundException if destination is a directory (use
+ * {@link #copyFileToDirectory}).
+ */
+ public static void linkFile( final File source, final File destination )
+ throws IOException
+ {
+ // check source exists
+ if ( !source.exists() )
{
- fis = new FileInputStream( source );
- fos = new FileOutputStream( destination );
- input = fis.getChannel();
- output = fos.getChannel();
- long size = input.size();
- long pos = 0;
- long count = 0;
- while ( pos < size )
- {
- count = size - pos > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : size - pos;
- pos += output.transferFrom( input, pos, count );
- }
- output.close();
- output = null;
- fos.close();
- fos = null;
- input.close();
- input = null;
- fis.close();
- fis = null;
+ final String message = "File " + source + " does not exist";
+ throw new IOException( message );
}
- finally
+
+ // check source != destination, see PLXUTILS-10
+ if ( source.getCanonicalPath().equals( destination.getCanonicalPath() ) )
{
- IOUtil.close( output );
- IOUtil.close( fos );
- IOUtil.close( input );
- IOUtil.close( fis );
+ // if they are equal, we can exit the method without doing any work
+ return;
}
- }
+ mkdirsFor( destination );
- private static void doCopyFileUsingNewIO( File source, File destination )
- throws IOException
- {
- NioFiles.copy( source, destination );
+ NioFiles.createSymbolicLink( destination, source );
}
/**
@@ -1211,22 +1157,10 @@ public static void copyStreamToFile( final InputStreamFacade source, final File
mkdirsFor( destination );
checkCanWrite( destination );
- InputStream input = null;
- FileOutputStream output = null;
- try
+ try ( InputStream input = source.getInputStream();
+ OutputStream output = Files.newOutputStream( destination.toPath() ) )
{
- input = source.getInputStream();
- output = new FileOutputStream( destination );
IOUtil.copy( input, output );
- output.close();
- output = null;
- input.close();
- input = null;
- }
- finally
- {
- IOUtil.close( input );
- IOUtil.close( output );
}
}
@@ -1797,7 +1731,7 @@ public static long sizeOfDirectory( final File directory )
* @param includes the includes pattern, comma separated
* @param excludes the excludes pattern, comma separated
* @return a list of File objects
- * @throws IOException
+ * @throws IOException io issue
* @see #getFileNames(File, String, String, boolean)
*/
public static List getFiles( File directory, String includes, String excludes )
@@ -1814,7 +1748,7 @@ public static List getFiles( File directory, String includes, String exclu
* @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each file
* @return a list of File objects
- * @throws IOException
+ * @throws IOException io issue
* @see #getFileNames(File, String, String, boolean)
*/
public static List getFiles( File directory, String includes, String excludes, boolean includeBasedir )
@@ -1840,7 +1774,7 @@ public static List getFiles( File directory, String includes, String exclu
* @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @return a list of files as String
- * @throws IOException
+ * @throws IOException io issue
*/
public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir )
throws IOException
@@ -1857,7 +1791,7 @@ public static List getFileNames( File directory, String includes, String
* @param includeBasedir true to include the base dir in each String of file
* @param isCaseSensitive true if case sensitive
* @return a list of files as String
- * @throws IOException
+ * @throws IOException io issue
*/
public static List getFileNames( File directory, String includes, String excludes, boolean includeBasedir,
boolean isCaseSensitive )
@@ -1874,7 +1808,7 @@ public static List getFileNames( File directory, String includes, String
* @param excludes the excludes pattern, comma separated
* @param includeBasedir true to include the base dir in each String of file
* @return a list of directories as String
- * @throws IOException
+ * @throws IOException io issue
*/
public static List getDirectoryNames( File directory, String includes, String excludes,
boolean includeBasedir )
@@ -1892,7 +1826,7 @@ public static List getDirectoryNames( File directory, String includes, S
* @param includeBasedir true to include the base dir in each String of file
* @param isCaseSensitive true if case sensitive
* @return a list of directories as String
- * @throws IOException
+ * @throws IOException io issue
*/
public static List getDirectoryNames( File directory, String includes, String excludes,
boolean includeBasedir, boolean isCaseSensitive )
@@ -1912,7 +1846,7 @@ public static List getDirectoryNames( File directory, String includes, S
* @param getFiles true if get files
* @param getDirectories true if get directories
* @return a list of files as String
- * @throws IOException
+ * @throws IOException io issue
*/
public static List getFileAndDirectoryNames( File directory, String includes, String excludes,
boolean includeBasedir, boolean isCaseSensitive,
@@ -2322,16 +2256,14 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[
{
if ( encoding == null || encoding.length() < 1 )
{
- fileReader = new BufferedReader( new FileReader( from ) );
- fileWriter = new FileWriter( to );
+ fileReader = Files.newBufferedReader( from.toPath() );
+ fileWriter = Files.newBufferedWriter( to.toPath() );
}
else
{
- FileInputStream instream = new FileInputStream( from );
+ OutputStream outstream = Files.newOutputStream( to.toPath() );
- FileOutputStream outstream = new FileOutputStream( to );
-
- fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) );
+ fileReader = Files.newBufferedReader( from.toPath(), Charset.forName( encoding ) );
fileWriter = new OutputStreamWriter( outstream, encoding );
}
@@ -2378,13 +2310,11 @@ public static List loadFile( File file )
throws IOException
{
final List lines = new ArrayList();
- BufferedReader reader = null;
- try
+
+ if ( file.exists() )
{
- if ( file.exists() )
+ try ( BufferedReader reader = Files.newBufferedReader( file.toPath() ) )
{
- reader = new BufferedReader( new FileReader( file ) );
-
for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
line = line.trim();
@@ -2394,15 +2324,8 @@ public static List loadFile( File file )
lines.add( line );
}
}
-
- reader.close();
- reader = null;
}
}
- finally
- {
- IOUtil.close( reader );
- }
return lines;
}
diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java
index 5b400f15..b431a8d9 100644
--- a/src/main/java/org/codehaus/plexus/util/IOUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java
@@ -118,7 +118,7 @@
*
* @author Peter Donald
* @author Jeff Turner
- * @version $Id$
+ *
* @since 4.0
*/
@@ -132,7 +132,7 @@
* method variants to specify buffer size and encoding, each row may correspond to up to 4 methods.
*/
-public final class IOUtil
+public final class IOUtil extends BaseIOUtil
{
private static final int DEFAULT_BUFFER_SIZE = 1024 * 16;
@@ -149,17 +149,22 @@ private IOUtil()
/**
* Copy bytes from an InputStream to an OutputStream.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final InputStream input, final OutputStream output )
throws IOException
{
- copy( input, output, DEFAULT_BUFFER_SIZE );
+ BaseIOUtil.copy( input, output );
}
/**
* Copy bytes from an InputStream to an OutputStream.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final InputStream input, final OutputStream output, final int bufferSize )
throws IOException
@@ -174,17 +179,22 @@ public static void copy( final InputStream input, final OutputStream output, fin
/**
* Copy chars from a Reader to a Writer.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final Reader input, final Writer output )
throws IOException
{
- copy( input, output, DEFAULT_BUFFER_SIZE );
+ BaseIOUtil.copy( input, output );
}
/**
* Copy chars from a Reader to a Writer.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final Reader input, final Writer output, final int bufferSize )
throws IOException
@@ -209,6 +219,9 @@ public static void copy( final Reader input, final Writer output, final int buff
/**
* Copy and convert bytes from an InputStream to chars on a Writer. The platform's default
* encoding is used for the byte-to-char conversion.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final InputStream input, final Writer output )
throws IOException
@@ -219,8 +232,10 @@ public static void copy( final InputStream input, final Writer output )
/**
* Copy and convert bytes from an InputStream to chars on a Writer. The platform's default
* encoding is used for the byte-to-char conversion.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final InputStream input, final Writer output, final int bufferSize )
throws IOException
@@ -232,10 +247,12 @@ public static void copy( final InputStream input, final Writer output, final int
/**
* Copy and convert bytes from an InputStream to chars on a Writer, using the specified
* encoding.
- *
+ * @param input to convert
+ * @param output the result
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
+ * @throws IOException io issue
*/
public static void copy( final InputStream input, final Writer output, final String encoding )
throws IOException
@@ -247,11 +264,13 @@ public static void copy( final InputStream input, final Writer output, final Str
/**
* Copy and convert bytes from an InputStream to chars on a Writer, using the specified
* encoding.
- *
+ * @param input to convert
+ * @param output the result
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final InputStream input, final Writer output, final String encoding, final int bufferSize )
throws IOException
@@ -264,8 +283,10 @@ public static void copy( final InputStream input, final Writer output, final Str
// InputStream -> String
/**
- * Get the contents of an InputStream as a String. The platform's default encoding is used for the
+ * @return Get the contents of an InputStream as a String. The platform's default encoding is used for the
* byte-to-char conversion.
+ * @param input to convert
+ * @throws IOException io issue
*/
public static String toString( final InputStream input )
throws IOException
@@ -274,10 +295,11 @@ public static String toString( final InputStream input )
}
/**
- * Get the contents of an InputStream as a String. The platform's default encoding is used for the
+ * @return Get the contents of an InputStream as a String. The platform's default encoding is used for the
* byte-to-char conversion.
- *
+ * @param input to convert
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static String toString( final InputStream input, final int bufferSize )
throws IOException
@@ -288,11 +310,12 @@ public static String toString( final InputStream input, final int bufferSize )
}
/**
- * Get the contents of an InputStream as a String.
- *
+ * @return Get the contents of an InputStream as a String.
+ * @param input to convert
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
+ * @throws IOException io issue
*/
public static String toString( final InputStream input, final String encoding )
throws IOException
@@ -301,12 +324,13 @@ public static String toString( final InputStream input, final String encoding )
}
/**
- * Get the contents of an InputStream as a String.
- *
+ * @return Get the contents of an InputStream as a String.
+ * @param input to convert
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static String toString( final InputStream input, final String encoding, final int bufferSize )
throws IOException
@@ -320,7 +344,9 @@ public static String toString( final InputStream input, final String encoding, f
// InputStream -> byte[]
/**
- * Get the contents of an InputStream as a byte[].
+ * @return Get the contents of an InputStream as a byte[].
+ * @param input to convert
+ * @throws IOException io issue
*/
public static byte[] toByteArray( final InputStream input )
throws IOException
@@ -329,9 +355,10 @@ public static byte[] toByteArray( final InputStream input )
}
/**
- * Get the contents of an InputStream as a byte[].
- *
+ * @return Get the contents of an InputStream as a byte[].
+ * @param input to convert
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static byte[] toByteArray( final InputStream input, final int bufferSize )
throws IOException
@@ -351,6 +378,9 @@ public static byte[] toByteArray( final InputStream input, final int bufferSize
/**
* Serialize chars from a Reader to bytes on an OutputStream, and flush the
* OutputStream.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final Reader input, final OutputStream output )
throws IOException
@@ -361,8 +391,10 @@ public static void copy( final Reader input, final OutputStream output )
/**
* Serialize chars from a Reader to bytes on an OutputStream, and flush the
* OutputStream.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final Reader input, final OutputStream output, final int bufferSize )
throws IOException
@@ -377,7 +409,9 @@ public static void copy( final Reader input, final OutputStream output, final in
///////////////////////////////////////////////////////////////
// Reader -> String
/**
- * Get the contents of a Reader as a String.
+ * @return Get the contents of a Reader as a String.
+ * @param input to convert
+ * @throws IOException io issue
*/
public static String toString( final Reader input )
throws IOException
@@ -386,9 +420,10 @@ public static String toString( final Reader input )
}
/**
- * Get the contents of a Reader as a String.
- *
+ * @return Get the contents of a Reader as a String.
+ * @param input to convert
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static String toString( final Reader input, final int bufferSize )
throws IOException
@@ -401,7 +436,9 @@ public static String toString( final Reader input, final int bufferSize )
///////////////////////////////////////////////////////////////
// Reader -> byte[]
/**
- * Get the contents of a Reader as a byte[].
+ * @return Get the contents of a Reader as a byte[].
+ * @param input to convert
+ * @throws IOException io issue
*/
public static byte[] toByteArray( final Reader input )
throws IOException
@@ -410,9 +447,10 @@ public static byte[] toByteArray( final Reader input )
}
/**
- * Get the contents of a Reader as a byte[].
- *
+ * @return Get the contents of a Reader as a byte[].
+ * @param input to convert
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static byte[] toByteArray( final Reader input, final int bufferSize )
throws IOException
@@ -433,6 +471,9 @@ public static byte[] toByteArray( final Reader input, final int bufferSize )
/**
* Serialize chars from a String to bytes on an OutputStream, and flush the
* OutputStream.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final String input, final OutputStream output )
throws IOException
@@ -443,8 +484,10 @@ public static void copy( final String input, final OutputStream output )
/**
* Serialize chars from a String to bytes on an OutputStream, and flush the
* OutputStream.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final String input, final OutputStream output, final int bufferSize )
throws IOException
@@ -462,6 +505,9 @@ public static void copy( final String input, final OutputStream output, final in
/**
* Copy chars from a String to a Writer.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final String input, final Writer output )
throws IOException
@@ -474,10 +520,13 @@ public static void copy( final String input, final Writer output )
* to passing a {@link java.io.BufferedInputStream} and {@link java.io.BufferedOutputStream} to
* {@link #copy(InputStream, OutputStream)}, and flushing the output stream afterwards. The streams are not closed
* after the copy.
- *
+ * @param input to convert
+ * @param output the result
* @deprecated Buffering streams is actively harmful! See the class description as to why. Use
* {@link #copy(InputStream, OutputStream)} instead.
+ * @throws IOException io issue
*/
+ @Deprecated
public static void bufferedCopy( final InputStream input, final OutputStream output )
throws IOException
{
@@ -490,7 +539,9 @@ public static void bufferedCopy( final InputStream input, final OutputStream out
///////////////////////////////////////////////////////////////
// String -> byte[]
/**
- * Get the contents of a String as a byte[].
+ * @return Get the contents of a String as a byte[].
+ * @param input to convert
+ * @throws IOException io issue
*/
public static byte[] toByteArray( final String input )
throws IOException
@@ -499,9 +550,10 @@ public static byte[] toByteArray( final String input )
}
/**
- * Get the contents of a String as a byte[].
- *
+ * @return Get the contents of a String as a byte[].
+ * @param input to convert
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static byte[] toByteArray( final String input, final int bufferSize )
throws IOException
@@ -522,6 +574,9 @@ public static byte[] toByteArray( final String input, final int bufferSize )
/**
* Copy and convert bytes from a byte[] to chars on a Writer. The platform's default
* encoding is used for the byte-to-char conversion.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final byte[] input, final Writer output )
throws IOException
@@ -532,8 +587,10 @@ public static void copy( final byte[] input, final Writer output )
/**
* Copy and convert bytes from a byte[] to chars on a Writer. The platform's default
* encoding is used for the byte-to-char conversion.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final byte[] input, final Writer output, final int bufferSize )
throws IOException
@@ -545,10 +602,12 @@ public static void copy( final byte[] input, final Writer output, final int buff
/**
* Copy and convert bytes from a byte[] to chars on a Writer, using the specified
* encoding.
- *
+ * @param input to convert
+ * @param output the result
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
+ * @throws IOException io issue
*/
public static void copy( final byte[] input, final Writer output, final String encoding )
throws IOException
@@ -560,11 +619,13 @@ public static void copy( final byte[] input, final Writer output, final String e
/**
* Copy and convert bytes from a byte[] to chars on a Writer, using the specified
* encoding.
- *
+ * @param input to convert
+ * @param output the result
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final byte[] input, final Writer output, final String encoding, final int bufferSize )
throws IOException
@@ -577,8 +638,10 @@ public static void copy( final byte[] input, final Writer output, final String e
// byte[] -> String
/**
- * Get the contents of a byte[] as a String. The platform's default encoding is used for the
+ * @return Get the contents of a byte[] as a String. The platform's default encoding is used for the
* byte-to-char conversion.
+ * @param input to convert
+ * @throws IOException io issue
*/
public static String toString( final byte[] input )
throws IOException
@@ -587,10 +650,11 @@ public static String toString( final byte[] input )
}
/**
- * Get the contents of a byte[] as a String. The platform's default encoding is used for the
+ * @return Get the contents of a byte[] as a String. The platform's default encoding is used for the
* byte-to-char conversion.
- *
+ * @param input to convert
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static String toString( final byte[] input, final int bufferSize )
throws IOException
@@ -601,11 +665,12 @@ public static String toString( final byte[] input, final int bufferSize )
}
/**
- * Get the contents of a byte[] as a String.
- *
+ * @return Get the contents of a byte[] as a String.
+ * @param input to convert
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
+ * @throws IOException io issue
*/
public static String toString( final byte[] input, final String encoding )
throws IOException
@@ -614,12 +679,14 @@ public static String toString( final byte[] input, final String encoding )
}
/**
- * Get the contents of a byte[] as a String.
- *
+ * @return the contents of a byte[] as a String.
+ * @param input to convert
* @param encoding The name of a supported character encoding. See the
* IANA Charset Registry for a list of valid
* encoding types.
* @param bufferSize Size of internal buffer to use.
+ *
+ * @throws IOException io issue
*/
public static String toString( final byte[] input, final String encoding, final int bufferSize )
throws IOException
@@ -634,6 +701,9 @@ public static String toString( final byte[] input, final String encoding, final
/**
* Copy bytes from a byte[] to an OutputStream.
+ * @param input to convert
+ * @param output the result
+ * @throws IOException io issue
*/
public static void copy( final byte[] input, final OutputStream output )
throws IOException
@@ -643,8 +713,10 @@ public static void copy( final byte[] input, final OutputStream output )
/**
* Copy bytes from a byte[] to an OutputStream.
- *
+ * @param input to convert
+ * @param output the result
* @param bufferSize Size of internal buffer to use.
+ * @throws IOException io issue
*/
public static void copy( final byte[] input, final OutputStream output, final int bufferSize )
throws IOException
@@ -658,6 +730,7 @@ public static void copy( final byte[] input, final OutputStream output, final in
* @param input1 the first stream
* @param input2 the second stream
* @return true if the content of the streams are equal or they both don't exist, false otherwise
+ * @throws IOException io issue
*/
public static boolean contentEquals( final InputStream input1, final InputStream input2 )
throws IOException
@@ -695,7 +768,9 @@ public static boolean contentEquals( final InputStream input1, final InputStream
* Closes the input stream. The input stream can be null and any IOException's will be swallowed.
*
* @param inputStream The stream to close.
+ * @deprecated use try-with-resources instead
*/
+ @Deprecated
public static void close( InputStream inputStream )
{
if ( inputStream == null )
@@ -717,7 +792,9 @@ public static void close( InputStream inputStream )
* Closes a channel. Channel can be null and any IOException's will be swallowed.
*
* @param channel The stream to close.
+ * @deprecated use try-with-resources instead
*/
+ @Deprecated
public static void close( Channel channel )
{
if ( channel == null )
@@ -739,7 +816,9 @@ public static void close( Channel channel )
* Closes the output stream. The output stream can be null and any IOException's will be swallowed.
*
* @param outputStream The stream to close.
+ * @deprecated use try-with-resources instead
*/
+ @Deprecated
public static void close( OutputStream outputStream )
{
if ( outputStream == null )
@@ -761,7 +840,9 @@ public static void close( OutputStream outputStream )
* Closes the reader. The reader can be null and any IOException's will be swallowed.
*
* @param reader The reader to close.
+ * @deprecated use try-with-resources instead
*/
+ @Deprecated
public static void close( Reader reader )
{
if ( reader == null )
@@ -783,7 +864,9 @@ public static void close( Reader reader )
* Closes the writer. The writer can be null and any IOException's will be swallowed.
*
* @param writer The writer to close.
+ * @deprecated use try-with-resources instead
*/
+ @Deprecated
public static void close( Writer writer )
{
if ( writer == null )
diff --git a/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java b/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
index 81e5af74..c8515b2e 100644
--- a/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
+++ b/src/main/java/org/codehaus/plexus/util/InterpolationFilterReader.java
@@ -151,6 +151,7 @@ public InterpolationFilterReader( Reader in, Map variables )
* @exception IllegalArgumentException If n is negative.
* @exception IOException If an I/O error occurs
*/
+ @Override
public long skip( long n )
throws IOException
{
@@ -179,6 +180,7 @@ public long skip( long n )
* @return the number of characters read, or -1 if the end of the stream has been reached
* @exception IOException If an I/O error occurs
*/
+ @Override
public int read( char cbuf[], int off, int len )
throws IOException
{
@@ -207,6 +209,7 @@ public int read( char cbuf[], int off, int len )
* @return the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
* @exception IOException if the underlying stream throws an IOException during reading
*/
+ @Override
public int read()
throws IOException
{
diff --git a/src/main/java/org/codehaus/plexus/util/Java7Detector.java b/src/main/java/org/codehaus/plexus/util/Java7Detector.java
deleted file mode 100644
index 7fa7bb5b..00000000
--- a/src/main/java/org/codehaus/plexus/util/Java7Detector.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.codehaus.plexus.util;
-
-/*
- * Copyright 2011 The Codehaus Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Java7 feature detection
- *
- * @author Kristian Rosenvold
- */
-class Java7Detector
-{
-
- private static final boolean isJava7;
-
- static
- {
- boolean isJava7x = true;
- try
- {
- Class.forName( "java.nio.file.Files" );
- }
- catch ( Exception e )
- {
- isJava7x = false;
- }
- isJava7 = isJava7x;
- }
-
- public static boolean isJava7()
- {
- return isJava7;
- }
-}
diff --git a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
index afdc7bcd..8129018f 100644
--- a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
+++ b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java
@@ -90,7 +90,7 @@ public class LineOrientedInterpolatingReader
* @param context keyword/value pairs for interpolation.
* @param startDelim character sequence which (possibly) begins a token.
* @param endDelim character sequence which ends a token.
- * @param escapeSeq
+ * @param escapeSeq escape sequence
*/
public LineOrientedInterpolatingReader( Reader reader, Map context, String startDelim, String endDelim,
String escapeSeq )
@@ -144,6 +144,7 @@ public LineOrientedInterpolatingReader( Reader reader, Map context )
this( reader, context, DEFAULT_START_DELIM, DEFAULT_END_DELIM, DEFAULT_ESCAPE_SEQ );
}
+ @Override
public int read()
throws IOException
{
@@ -162,6 +163,7 @@ public int read()
return next;
}
+ @Override
public int read( char[] cbuf, int off, int len )
throws IOException
{
@@ -190,6 +192,7 @@ public int read( char[] cbuf, int off, int len )
return fillCount;
}
+ @Override
public long skip( long n )
throws IOException
{
@@ -468,4 +471,4 @@ private String findAndReplaceUnlessEscaped( String rawLine, String search, Strin
return lineBuffer.toString();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/codehaus/plexus/util/MatchPattern.java b/src/main/java/org/codehaus/plexus/util/MatchPattern.java
index dade194a..de57de21 100644
--- a/src/main/java/org/codehaus/plexus/util/MatchPattern.java
+++ b/src/main/java/org/codehaus/plexus/util/MatchPattern.java
@@ -124,7 +124,18 @@ static String[] tokenizePathToString( String path, String separator )
{
ret.add( st.nextToken() );
}
- return ret.toArray( new String[ret.size()] );
+ return ret.toArray( new String[0] );
+ }
+
+ static char[][] tokenizePathToCharArray( String path, String separator )
+ {
+ String[] tokenizedName = tokenizePathToString( path, separator );
+ char[][] tokenizedNameChar = new char[tokenizedName.length][];
+ for ( int i = 0; i < tokenizedName.length; i++ )
+ {
+ tokenizedNameChar[i] = tokenizedName[i].toCharArray();
+ }
+ return tokenizedNameChar;
}
public static MatchPattern fromString( String source )
diff --git a/src/main/java/org/codehaus/plexus/util/MatchPatterns.java b/src/main/java/org/codehaus/plexus/util/MatchPatterns.java
index f871f8e1..35f9ea22 100644
--- a/src/main/java/org/codehaus/plexus/util/MatchPatterns.java
+++ b/src/main/java/org/codehaus/plexus/util/MatchPatterns.java
@@ -40,6 +40,11 @@ public boolean matches( String name, String[] tokenizedName, boolean isCaseSensi
{
tokenizedNameChar[i] = tokenizedName[i].toCharArray();
}
+ return matches(name, tokenizedNameChar, isCaseSensitive);
+ }
+
+ public boolean matches(String name, char[][] tokenizedNameChar, boolean isCaseSensitive)
+ {
for ( MatchPattern pattern : patterns )
{
if ( pattern.matchPath( name, tokenizedNameChar, isCaseSensitive ) )
@@ -85,7 +90,7 @@ private static MatchPattern[] getMatchPatterns( Iterable items )
{
result.add( MatchPattern.fromString( string ) );
}
- return result.toArray( new MatchPattern[result.size()] );
+ return result.toArray( new MatchPattern[0] );
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/NioFiles.java b/src/main/java/org/codehaus/plexus/util/NioFiles.java
index 50cdeb72..eb62bac7 100644
--- a/src/main/java/org/codehaus/plexus/util/NioFiles.java
+++ b/src/main/java/org/codehaus/plexus/util/NioFiles.java
@@ -51,7 +51,7 @@ public static void chmod( File file, int mode )
@SuppressWarnings( { "OctalInteger", "MagicNumber" } )
private static Set getPermissions( int mode )
{
- Set perms = new HashSet();
+ Set perms = new HashSet<>();
// add owners permission
if ( ( mode & 0400 ) > 0 )
{
@@ -106,7 +106,7 @@ public static long getLastModified( File file )
*
* @param symlink A file that is a symlink
* @return A file that is the target of the symlink
- * @throws java.io.IOException
+ * @throws java.io.IOException io issue
*/
public static File readSymbolicLink( File symlink )
diff --git a/src/main/java/org/codehaus/plexus/util/Os.java b/src/main/java/org/codehaus/plexus/util/Os.java
index fce9f5d7..b4ed2882 100644
--- a/src/main/java/org/codehaus/plexus/util/Os.java
+++ b/src/main/java/org/codehaus/plexus/util/Os.java
@@ -65,7 +65,7 @@
* @author Magesh Umasankar
* @author Brian Fox
* @since 1.0
- * @version $Revision$
+ *
*/
public class Os
{
@@ -208,9 +208,10 @@ public void setVersion( String version )
}
/**
- * Determines if the current OS matches the type of that set in setFamily.
- *
+ * @return Determines if the current OS matches the type of that set in setFamily.
+ *
* @see Os#setFamily(String)
+ * @throws Exception any errir
*/
public boolean eval()
throws Exception
diff --git a/src/main/java/org/codehaus/plexus/util/PathTool.java b/src/main/java/org/codehaus/plexus/util/PathTool.java
index a64556c7..b8392cdb 100644
--- a/src/main/java/org/codehaus/plexus/util/PathTool.java
+++ b/src/main/java/org/codehaus/plexus/util/PathTool.java
@@ -25,7 +25,7 @@
* @author Pete Kazmier
* @author Vincent Massol
* @author Vincent Siveton
- * @version $Id$
+ *
*/
public class PathTool
{
@@ -34,7 +34,7 @@ public class PathTool
* links within pages of a web site. It provides similar functionality to Anakia's $relativePath
* context variable. The arguments to this method may contain either forward or backward slashes as file separators.
* The relative path returned is formed using forward slashes as it is expected this path is to be used as a link in
- * a web page (again mimicking Anakia's behavior).
+ * a web page (again mimicking Anakia's behavior).
*
*
This method is thread-safe.
*
@@ -169,8 +169,8 @@ public static final String getDirectoryComponent( String filename )
* PathTool.calculateLink( "../index.html", "http://plexus.codehaus.org/plexus-utils" ) = "http://plexus.codehaus.org/plexus-utils/../index.html"
*
*
- * @param link
- * @param relativePath
+ * @param link main link
+ * @param relativePath relative
* @return String
*/
public static final String calculateLink( String link, String relativePath )
@@ -239,8 +239,8 @@ public static final String calculateLink( String link, String relativePath )
* "http://plexus.codehaus.org/" = "../../"
*
*
- * @param oldPath
- * @param newPath
+ * @param oldPath main path
+ * @param newPath second path
* @return a relative web path from oldPath.
*/
public static final String getRelativeWebPath( final String oldPath, final String newPath )
@@ -278,8 +278,8 @@ public static final String getRelativeWebPath( final String oldPath, final Strin
*
* Note: On Windows based system, the / character should be replaced by \ character.
*
- * @param oldPath
- * @param newPath
+ * @param oldPath main path
+ * @param newPath second path
* @return a relative file path from oldPath.
*/
public static final String getRelativeFilePath( final String oldPath, final String newPath )
diff --git a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java
index 44ac5a93..cee5cd25 100644
--- a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java
@@ -1,5 +1,7 @@
package org.codehaus.plexus.util;
+import java.util.Objects;
+
/*
* Copyright The Codehaus Foundation.
*
@@ -18,17 +20,16 @@
import java.util.Properties;
import java.io.File;
-import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
+import java.nio.file.Files;
/**
* Static methods to create Properties loaded from various sources.
*
* @author Jason van Zyl
* @author Michal Maczka
- * @version $Id$
*/
public class PropertyUtils
{
@@ -36,47 +37,30 @@ public class PropertyUtils
public static Properties loadProperties( final URL url )
throws IOException
{
- if ( url == null )
- {
- throw new NullPointerException( "url" );
- }
-
- return loadProperties( url.openStream() );
+ return loadProperties( Objects.requireNonNull( url, "url" ).openStream() );
}
public static Properties loadProperties( final File file )
throws IOException
{
- if ( file == null )
- {
- throw new NullPointerException( "file" );
- }
-
- return loadProperties( new FileInputStream( file ) );
+ return loadProperties( Files.newInputStream( Objects.requireNonNull( file, "file" ).toPath() ) );
}
public static Properties loadProperties( final InputStream is )
throws IOException
{
- InputStream in = is;
- try
+ final Properties properties = new Properties();
+
+ // Make sure the properties stream is valid
+ if ( is != null )
{
- final Properties properties = new Properties();
-
- // Make sure the properties stream is valid
- if ( in != null )
+ try ( InputStream in = is )
{
properties.load( in );
- in.close();
- in = null;
}
-
- return properties;
- }
- finally
- {
- IOUtil.close( in );
}
+
+ return properties;
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
index 70389d68..a469a2c7 100644
--- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java
@@ -17,9 +17,7 @@
*/
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -27,6 +25,7 @@
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.charset.Charset;
+import java.nio.file.Files;
import org.codehaus.plexus.util.xml.XmlStreamReader;
@@ -36,7 +35,7 @@
* @author Herve Boutemy
* @see Charset
* @see Supported encodings
- * @version $Id$
+ *
* @since 1.4.3
*/
public class ReaderFactory
@@ -154,13 +153,13 @@ public static Reader newPlatformReader( InputStream in )
*
* @param file not null file.
* @return a reader instance for the input file using the default platform charset.
- * @throws FileNotFoundException if any.
+ * @throws IOException if any.
* @see Charset#defaultCharset()
*/
public static Reader newPlatformReader( File file )
- throws FileNotFoundException
+ throws IOException
{
- return new FileReader( file );
+ return Files.newBufferedReader( file.toPath() );
}
/**
@@ -199,14 +198,13 @@ public static Reader newReader( InputStream in, String encoding )
* @param file not null file.
* @param encoding not null supported encoding.
* @return a reader instance for the input file using the given encoding.
- * @throws FileNotFoundException if any.
- * @throws UnsupportedEncodingException if any.
+ * @throws IOException if any.
* @see Supported encodings
*/
public static Reader newReader( File file, String encoding )
- throws FileNotFoundException, UnsupportedEncodingException
+ throws IOException
{
- return new InputStreamReader( new FileInputStream( file ), encoding );
+ return new InputStreamReader( Files.newInputStream( file.toPath() ), encoding );
}
/**
diff --git a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
index d43d62a6..3ebf3b2d 100644
--- a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java
@@ -32,7 +32,6 @@
* @author Michal Maczka
* @author Jesse McConnell
* @author Trygve Laugstøl
- * @version $Id$
*/
public final class ReflectionUtils
{
@@ -63,7 +62,7 @@ public static Field getFieldByNameIncludingSuperclasses( String fieldName, Class
public static List getFieldsIncludingSuperclasses( Class> clazz )
{
- List fields = new ArrayList( Arrays.asList( clazz.getDeclaredFields() ) );
+ List fields = new ArrayList<>( Arrays.asList( clazz.getDeclaredFields() ) );
Class> superclass = clazz.getSuperclass();
@@ -104,13 +103,14 @@ public static Method getSetter( String fieldName, Class> clazz )
}
/**
- * Finds all setters in the given class and super classes.
+ * @return all setters in the given class and super classes.
+ * @param clazz the Class
*/
public static List getSetters( Class> clazz )
{
Method[] methods = clazz.getMethods();
- List list = new ArrayList();
+ List list = new ArrayList<>();
for ( Method method : methods )
{
@@ -124,7 +124,8 @@ public static List getSetters( Class> clazz )
}
/**
- * Returns the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter.
+ * @param method the method
+ * @return the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter.
*/
public static Class> getSetterType( Method method )
{
@@ -144,10 +145,10 @@ public static Class> getSetterType( Method method )
/**
* attempts to set the value to the variable in the object passed in
*
- * @param object
- * @param variable
- * @param value
- * @throws IllegalAccessException
+ * @param object see name
+ * @param variable see name
+ * @param value see name
+ * @throws IllegalAccessException if error
*/
public static void setVariableValueInObject( Object object, String variable, Object value )
throws IllegalAccessException
@@ -161,9 +162,11 @@ public static void setVariableValueInObject( Object object, String variable, Obj
/**
* Generates a map of the fields and values on a given object, also pulls from superclasses
- *
+ *
+ * @param variable field name
* @param object the object to generate the list of fields from
* @return map containing the fields and their values
+ * @throws IllegalAccessException cannot access
*/
public static Object getValueIncludingSuperclasses( String variable, Object object )
throws IllegalAccessException
@@ -181,11 +184,12 @@ public static Object getValueIncludingSuperclasses( String variable, Object obje
*
* @param object the object to generate the list of fields from
* @return map containing the fields and their values
+ * @throws IllegalAccessException cannot access
*/
public static Map getVariablesAndValuesIncludingSuperclasses( Object object )
throws IllegalAccessException
{
- Map map = new HashMap();
+ Map map = new HashMap<>();
gatherVariablesAndValuesIncludingSuperclasses( object, map );
@@ -214,6 +218,14 @@ private static void gatherVariablesAndValuesIncludingSuperclasses( Object object
Class> clazz = object.getClass();
+ if ( Float.parseFloat( System.getProperty( "java.specification.version" ) ) >= 11
+ && Class.class.getCanonicalName().equals( clazz.getCanonicalName() ) )
+ {
+ // Updating Class fields accessibility is forbidden on Java 16 (and throws warning from version 11)
+ // No concrete use case to modify accessibility at this level
+ return;
+ }
+
Field[] fields = clazz.getDeclaredFields();
AccessibleObject.setAccessible( fields, true );
diff --git a/src/main/java/org/codehaus/plexus/util/Scanner.java b/src/main/java/org/codehaus/plexus/util/Scanner.java
index 14af3a9d..20bf85fb 100644
--- a/src/main/java/org/codehaus/plexus/util/Scanner.java
+++ b/src/main/java/org/codehaus/plexus/util/Scanner.java
@@ -88,7 +88,7 @@ public interface Scanner
/**
* Use a filename comparator in each directory when scanning.
*
- * @param filenameComparator
+ * @param filenameComparator the Comparator instance to use
* @since 3.3.0
*/
void setFilenameComparator( Comparator filenameComparator );
diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
index 950524ab..234a92c5 100644
--- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java
@@ -69,7 +69,7 @@
* @author Arnout J. Kuiper ajkuiper@wxs.nl
* @author Magesh Umasankar
* @author Bruce Atherton
- * @version $Id$
+ *
* @since 1.5
*/
public final class SelectorUtils
@@ -93,7 +93,7 @@ private SelectorUtils()
}
/**
- * Retrieves the manager of the Singleton.
+ * @return Retrieves the manager of the Singleton.
*/
public static SelectorUtils getInstance()
{
@@ -253,21 +253,32 @@ public static boolean matchPath( String pattern, String str, String separator, b
{
if ( isRegexPrefixedPattern( pattern ) )
{
- pattern =
+ String localPattern =
pattern.substring( REGEX_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
- return str.matches( pattern );
+ return str.matches( localPattern );
}
else
{
- if ( isAntPrefixedPattern( pattern ) )
- {
- pattern = pattern.substring( ANT_HANDLER_PREFIX.length(),
- pattern.length() - PATTERN_HANDLER_SUFFIX.length() );
- }
+ String localPattern = isAntPrefixedPattern( pattern )
+ ? pattern.substring( ANT_HANDLER_PREFIX.length(), pattern.length() - PATTERN_HANDLER_SUFFIX.length() )
+ : pattern;
+ final String osRelatedPath = toOSRelatedPath( str, separator );
+ final String osRelatedPattern = toOSRelatedPath( localPattern, separator );
+ return matchAntPathPattern( osRelatedPattern, osRelatedPath, separator, isCaseSensitive );
+ }
+ }
- return matchAntPathPattern( pattern, str, separator, isCaseSensitive );
+ private static String toOSRelatedPath( String pattern, String separator )
+ {
+ if ( "/".equals( separator ) )
+ {
+ return pattern.replace( "\\", separator );
+ }
+ if ( "\\".equals( separator ) ) {
+ return pattern.replace( "/", separator );
}
+ return pattern;
}
static boolean isRegexPrefixedPattern( String pattern )
@@ -772,7 +783,7 @@ private static String[] tokenizePathToString( String path, String separator )
{
ret.add( st.nextToken() );
}
- return ret.toArray( new String[ret.size()] );
+ return ret.toArray( new String[0] );
}
/**
diff --git a/src/main/java/org/codehaus/plexus/util/StringInputStream.java b/src/main/java/org/codehaus/plexus/util/StringInputStream.java
index 84400070..ea1c46c8 100644
--- a/src/main/java/org/codehaus/plexus/util/StringInputStream.java
+++ b/src/main/java/org/codehaus/plexus/util/StringInputStream.java
@@ -69,6 +69,7 @@
* encoding. Instead, wrap the output from {@link String#getBytes(String)} into a
* {@link java.io.ByteArrayInputStream}.
*/
+@Deprecated
public class StringInputStream
extends InputStream
{
@@ -92,6 +93,7 @@ public StringInputStream( String source )
* @return the value of the next character in the StringReader
* @exception IOException if the original StringReader fails to be read
*/
+ @Override
public int read()
throws IOException
{
@@ -103,6 +105,7 @@ public int read()
*
* @exception IOException if the original StringReader fails to be closed
*/
+ @Override
public void close()
throws IOException
{
@@ -114,6 +117,7 @@ public void close()
*
* @param limit the maximum limit of bytes that can be read before the mark position becomes invalid
*/
+ @Override
public synchronized void mark( final int limit )
{
try
@@ -131,6 +135,7 @@ public synchronized void mark( final int limit )
*
* @exception IOException if the StringReader fails to be reset
*/
+ @Override
public synchronized void reset()
throws IOException
{
@@ -140,6 +145,7 @@ public synchronized void reset()
/**
* @see InputStream#markSupported
*/
+ @Override
public boolean markSupported()
{
return in.markSupported();
diff --git a/src/main/java/org/codehaus/plexus/util/StringOutputStream.java b/src/main/java/org/codehaus/plexus/util/StringOutputStream.java
index a6c9faf8..ef22b575 100644
--- a/src/main/java/org/codehaus/plexus/util/StringOutputStream.java
+++ b/src/main/java/org/codehaus/plexus/util/StringOutputStream.java
@@ -23,27 +23,31 @@
* Wraps a String as an OutputStream.
*
* @author Emmanuel Venisse
- * @version $Id$
+ *
* @deprecated As of version 1.5.2 this class should no longer be used because it does not properly handle character
* encoding. Instead, use {@link java.io.ByteArrayOutputStream#toString(String)}.
*/
+@Deprecated
public class StringOutputStream
extends OutputStream
{
private StringBuffer buf = new StringBuffer();
+ @Override
public void write( byte[] b )
throws IOException
{
buf.append( new String( b ) );
}
+ @Override
public void write( byte[] b, int off, int len )
throws IOException
{
buf.append( new String( b, off, len ) );
}
+ @Override
public void write( int b )
throws IOException
{
@@ -52,6 +56,7 @@ public void write( int b )
buf.append( new String( bytes ) );
}
+ @Override
public String toString()
{
return buf.toString();
diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java
index b52a5a3b..0f8518de 100644
--- a/src/main/java/org/codehaus/plexus/util/StringUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/StringUtils.java
@@ -80,7 +80,7 @@
* @author Alexander Day Chaffee
* @author Vincent Siveton
* @since 1.0
- * @version $Id$
+ *
*/
public class StringUtils
{
@@ -140,7 +140,6 @@ public static String trim( String str )
*
* @param str String target to delete whitespace from
* @return the String without whitespaces
- * @throws NullPointerException
*/
public static String deleteWhitespace( String str )
{
@@ -157,9 +156,7 @@ public static String deleteWhitespace( String str )
}
/**
- *
* Checks if a String is non null and is not empty (length > 0).
- *
*
* @param str the String to check
* @return true if the String is non-null, and not length zero
@@ -170,21 +167,18 @@ public static boolean isNotEmpty( String str )
}
/**
+ * Checks if a String is null or empty.
*
- * Checks if a (trimmed) String is null or empty.
- *
- *
- * Note: In future releases, this method will no longer trim the input string such that it works
- * complementary to {@link #isNotEmpty(String)}. Code that wants to test for whitespace-only strings should be
- * migrated to use {@link #isBlank(String)} instead.
- *
+ * Note: In releases prior 3.5.0, this method trimmed the input string such that it worked
+ * the same as {@link #isBlank(String)}. Since release 3.5.0 it no longer returns {@code true} for strings
+ * containing only whitespace characters.
*
* @param str the String to check
- * @return true if the String is null, or length zero once trimmed
+ * @return true if the String is null, or length zero
*/
public static boolean isEmpty( String str )
{
- return ( ( str == null ) || ( str.trim().isEmpty() ) );
+ return ( ( str == null ) || ( str.isEmpty() ) );
}
/**
@@ -578,7 +572,9 @@ public static String[] split( String str )
}
/**
- * @see #split(String, String, int)
+ * @param text The string to parse.
+ * @param separator Characters used as the delimiters. If null, splits on whitespace.
+ * @return an array of parsed Strings
*/
public static String[] split( String text, String separator )
{
@@ -892,7 +888,7 @@ public static String overlayString( String text, String overlay, int start, int
/**
*
* Center a String in a larger String of size n.
- *
+ *
*
* Uses spaces as the value to buffer the String with. Equivalent to center(str, size, " ").
*
@@ -2141,14 +2137,14 @@ private static void reverseArray( Object[] array )
// --------------------------------------------------------------------------
/**
- * Turn "Now is the time for all good men" into "Now is the time for..."
+ * @return Turn "Now is the time for all good men" into "Now is the time for..."
*
* Specifically:
*
* If str is less than max characters long, return it. Else abbreviate it to (substring(str, 0, max-3) + "..."). If
* maxWidth is less than 3, throw an IllegalArgumentException. In no case will it return a string of length greater
* than maxWidth.
- *
+ * @param s string
* @param maxWidth maximum length of result string
**/
public static String abbreviate( String s, int maxWidth )
@@ -2157,12 +2153,12 @@ public static String abbreviate( String s, int maxWidth )
}
/**
- * Turn "Now is the time for all good men" into "...is the time for..."
- *
+ * @return Turn "Now is the time for all good men" into "...is the time for..."
+ *
* Works like abbreviate(String, int), but allows you to specify a "left edge" offset. Note that this left edge is
* not necessarily going to be the leftmost character in the result, or the first character following the ellipses,
* but it will appear somewhere in the result. In no case will it return a string of length greater than maxWidth.
- *
+ * @param s string
* @param offset left edge of source string
* @param maxWidth maximum length of result string
**/
@@ -2207,7 +2203,8 @@ public static String abbreviate( String s, int offset, int maxWidth )
* second string, starting from where it's different from the first.)
*
* E.g. strdiff("i am a machine", "i am a robot") -> "robot"
- *
+ * @param s1 string
+ * @param s2 string
* @return the portion of s2 where it differs from s1; returns the empty string ("") if they are equal
**/
public static String difference( String s1, String s2 )
@@ -2225,7 +2222,8 @@ public static String difference( String s1, String s2 )
*
* E.g. strdiff("i am a machine", "i am a robot") -> 7
*
- *
+ * @param s1 string
+ * @param s2 string
* @return the index where s2 and s1 begin to differ; -1 if they are equal
**/
public static int differenceAt( String s1, String s2 )
@@ -2340,8 +2338,8 @@ public static String addAndDeHump( String view )
* StringUtils.quoteAndEscape("a\"bc", '\'') = 'a\"bc'
*
*
- * @param source
- * @param quoteChar
+ * @param source the source String
+ * @param quoteChar the char used to quote
* @return the String quoted and escaped
* @since 1.5.1
* @see #quoteAndEscape(String, char, char[], char[], char, boolean)
@@ -2356,9 +2354,9 @@ public static String quoteAndEscape( String source, char quoteChar )
* Quote and escape a String with the given character, handling null.
*
*
- * @param source
- * @param quoteChar
- * @param quotingTriggers
+ * @param source the source String
+ * @param quoteChar the char used to quote
+ * @param quotingTriggers chars generating a quote
* @return the String quoted and escaped
* @since 1.5.1
* @see #quoteAndEscape(String, char, char[], char[], char, boolean)
@@ -2369,11 +2367,11 @@ public static String quoteAndEscape( String source, char quoteChar, char[] quoti
}
/**
- * @param source
- * @param quoteChar
- * @param escapedChars
- * @param escapeChar
- * @param force
+ * @param source the source String
+ * @param quoteChar the char used to quote
+ * @param escapedChars chars to escape
+ * @param escapeChar char used for escaping
+ * @param force force the quoting
* @return the String quoted and escaped
* @since 1.5.1
* @see #quoteAndEscape(String, char, char[], char[], char, boolean)
@@ -2385,12 +2383,12 @@ public static String quoteAndEscape( String source, char quoteChar, final char[]
}
/**
- * @param source
- * @param quoteChar
- * @param escapedChars
- * @param quotingTriggers
- * @param escapeChar
- * @param force
+ * @param source the source String
+ * @param quoteChar the char used to quote
+ * @param escapedChars chars to escape
+ * @param quotingTriggers chars generating a quote
+ * @param escapeChar char used for escaping
+ * @param force force the quoting
* @return the String quoted and escaped
* @since 1.5.1
*/
@@ -2401,12 +2399,12 @@ public static String quoteAndEscape( String source, char quoteChar, final char[]
}
/**
- * @param source
- * @param quoteChar
- * @param escapedChars
- * @param quotingTriggers
- * @param escapePattern
- * @param force
+ * @param source the source String
+ * @param quoteChar the char used to quote
+ * @param escapedChars chars to escape
+ * @param quotingTriggers chars generating a quote
+ * @param escapePattern pattern used for escaping
+ * @param force force the quoting
* @return the String quoted and escaped
* @since 3.0.4
*/
@@ -2456,9 +2454,9 @@ else if ( !escaped.equals( source ) )
}
/**
- * @param source
- * @param escapedChars
- * @param escapeChar
+ * @param source the source String
+ * @param escapedChars chars to escape
+ * @param escapeChar char used for escaping
* @return the String escaped
* @since 1.5.1
*/
@@ -2468,9 +2466,9 @@ public static String escape( String source, final char[] escapedChars, char esca
}
/**
- * @param source
- * @param escapedChars
- * @param escapePattern
+ * @param source the source String
+ * @param escapedChars chars to escape
+ * @param escapePattern pattern used for escaping
* @return the String escaped
* @since 3.0.4
*/
diff --git a/src/main/java/org/codehaus/plexus/util/SweeperPool.java b/src/main/java/org/codehaus/plexus/util/SweeperPool.java
index 0aeca99f..0a2a97a4 100644
--- a/src/main/java/org/codehaus/plexus/util/SweeperPool.java
+++ b/src/main/java/org/codehaus/plexus/util/SweeperPool.java
@@ -23,7 +23,7 @@
* disposed first.
*
* @author Bert van Brakel
- * @version $Id$
+ *
*/
public class SweeperPool
{
@@ -54,17 +54,16 @@ public class SweeperPool
/**
* There are a number of settings to control how the pool operates.
- *
- *
minSize - this is the size the pool is trimmed to
- *
triggerSize - this determines if the pool is trimmed when the sweeper runs. If the pool size is
- * greater or equal than this value then the pool is trimmed to minSize.
- *
maxSize - if the pool has reached this size, any objects added are immediately disposed. If the
- * pool is this size when the sweeper runs, then the pool is also trimmed to minSize irrespective of
- * the triggerSize.
- *
sweepInterval - how often the sweeper runs. Is actually the time since the sweeper last finished
- * a pass. 0 if the sweeper should not run.
- *
-
+ * @param maxSize if the pool has reached this size, any objects added are immediately disposed. If the
+ * pool is this size when the sweeper runs, then the pool is also trimmed to minSize irrespective of
+ * the triggerSize.
+ * @param minSize - this is the size the pool is trimmed to
+ * @param triggerSize - this determines if the pool is trimmed when the sweeper runs. If the pool size is
+ * greater or equal than this value then the pool is trimmed to minSize.
+ *
+ * @param sweepInterval how often the sweeper runs. Is actually the time since the sweeper last finished
+ * a pass. 0 if the sweeper should not run.
+ * @param intialCapacity the intial capacity
*
Any value less than 0 is automatically converted to 0
*/
public SweeperPool( int maxSize, int minSize, int intialCapacity, int sweepInterval, int triggerSize )
@@ -85,18 +84,12 @@ public SweeperPool( int maxSize, int minSize, int intialCapacity, int sweepInter
private int saneConvert( int value )
{
- if ( value < 0 )
- {
- return 0;
- }
- else
- {
- return value;
- }
+ return Math.max( value, 0 );
}
/**
* Return the pooled object
+ * @return first available object from the pool
*/
public synchronized Object get()
{
@@ -225,7 +218,7 @@ public synchronized void trim()
* Override this to be notified of object disposal. Called after the object has been removed. Occurs when the pool
* is trimmed.
*
- * @param obj
+ * @param obj the Object
*/
public void objectDisposed( Object obj )
{
@@ -234,7 +227,7 @@ public void objectDisposed( Object obj )
/**
* Override this to be notified of object addition. Called before object is to be added.
*
- * @param obj
+ * @param obj the Object
*/
public void objectAdded( Object obj )
{
@@ -244,7 +237,7 @@ public void objectAdded( Object obj )
* Override this to be notified of object retrieval. Called after object removed from the pool, but before returned
* to the client.
*
- * @param obj
+ * @param obj the Object
*/
public void objectRetrieved( Object obj )
{
@@ -281,6 +274,7 @@ public Sweeper( SweeperPool pool, int sweepInterval )
*
* @see java.lang.Runnable#run()
*/
+ @Override
public void run()
{
debug( "started" );
diff --git a/src/main/java/org/codehaus/plexus/util/WriterFactory.java b/src/main/java/org/codehaus/plexus/util/WriterFactory.java
index 229f1082..cf8326c4 100644
--- a/src/main/java/org/codehaus/plexus/util/WriterFactory.java
+++ b/src/main/java/org/codehaus/plexus/util/WriterFactory.java
@@ -17,15 +17,13 @@
*/
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.charset.Charset;
+import java.nio.file.Files;
import org.codehaus.plexus.util.xml.XmlStreamWriter;
@@ -35,7 +33,7 @@
* @author Herve Boutemy
* @see Charset
* @see Supported encodings
- * @version $Id$
+ *
* @since 1.4.4
*/
public class WriterFactory
@@ -145,7 +143,7 @@ public static Writer newPlatformWriter( OutputStream out )
public static Writer newPlatformWriter( File file )
throws IOException
{
- return new FileWriter( file );
+ return Files.newBufferedWriter( file.toPath() );
}
/**
@@ -169,13 +167,12 @@ public static Writer newWriter( OutputStream out, String encoding )
* @param file not null file.
* @param encoding not null supported encoding.
* @return a writer instance for the output file using the given encoding.
- * @throws UnsupportedEncodingException if any.
- * @throws FileNotFoundException if any.
+ * @throws IOException if any.
* @see Supported encodings
*/
public static Writer newWriter( File file, String encoding )
- throws UnsupportedEncodingException, FileNotFoundException
+ throws IOException
{
- return newWriter( new FileOutputStream( file ), encoding );
+ return newWriter( Files.newOutputStream( file.toPath() ), encoding );
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java
index 15a0eec2..0a861a75 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java
@@ -26,6 +26,7 @@
public interface CommandLineCallable
extends Callable
{
- public Integer call()
+ @Override
+ Integer call()
throws CommandLineException;
}
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineException.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineException.java
index bf36f527..9d0a439e 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineException.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineException.java
@@ -18,7 +18,7 @@
/**
* @author Trygve Laugstøl
- * @version $Id$
+ *
*/
public class CommandLineException
extends Exception
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineTimeOutException.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineTimeOutException.java
index 20514e8a..9d90c674 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineTimeOutException.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineTimeOutException.java
@@ -22,24 +22,17 @@
/**
* @author olamy
* @since 1.5.9
- * @version $Id$
+ *
*/
public class CommandLineTimeOutException
extends CommandLineException
{
- /**
- * @param message
- */
public CommandLineTimeOutException( String message )
{
super( message );
}
- /**
- * @param message
- * @param cause
- */
public CommandLineTimeOutException( String message, Throwable cause )
{
super( message, cause );
diff --git a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
index 43c5c817..0e168c04 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java
@@ -29,7 +29,7 @@
/**
* @author Trygve Laugstøl
- * @version $Id$
+ *
*/
public abstract class CommandLineUtils
{
@@ -47,6 +47,7 @@ public static class StringStreamConsumer
private String ls = System.getProperty( "line.separator" );
+ @Override
public void consumeLine( String line )
{
string.append( line ).append( ls );
@@ -109,7 +110,7 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Stre
/**
* Immediately forks a process, returns a callable that will block until process is complete.
- *
+ *
* @param cl The command line to execute
* @param systemIn The input to read from, must be thread safe
* @param systemOut A consumer that receives output, must be thread safe
@@ -154,6 +155,7 @@ public void run()
return new CommandLineCallable()
{
+ @Override
public Integer call()
throws CommandLineException
{
@@ -352,12 +354,10 @@ private static void handleException( final StreamFeeder streamFeeder, final Stri
* with case-insensitive environment variables like Windows, all variable names will be normalized to upper case.
*
* @return The shell environment variables, can be empty but never null.
- * @throws IOException If the environment variables could not be queried from the shell.
* @see System#getenv() System.getenv() API, new in JDK 5.0, to get the same result since 2.0.2 System#getenv()
* will be used if available in the current running jvm.
*/
public static Properties getSystemEnvVars()
- throws IOException
{
return getSystemEnvVars( !Os.isFamily( Os.FAMILY_WINDOWS ) );
}
@@ -368,12 +368,10 @@ public static Properties getSystemEnvVars()
*
* @param caseSensitive Whether environment variable keys should be treated case-sensitively.
* @return Properties object of (possibly modified) envar keys mapped to their values.
- * @throws IOException .
* @see System#getenv() System.getenv() API, new in JDK 5.0, to get the same result since 2.0.2 System#getenv()
* will be used if available in the current running jvm.
*/
public static Properties getSystemEnvVars( boolean caseSensitive )
- throws IOException
{
Properties envVars = new Properties();
Map envs = System.getenv();
@@ -498,12 +496,14 @@ else if ( " ".equals( nextTok ) )
* If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single
* quotes - else surround the argument by double quotes.
*
- *
+ * @param argument the argument
+ * @return the transformed command line
* @throws CommandLineException if the argument contains both, single and double quotes.
* @deprecated Use {@link StringUtils#quoteAndEscape(String, char, char[], char[], char, boolean)},
* {@link StringUtils#quoteAndEscape(String, char, char[], char, boolean)}, or
* {@link StringUtils#quoteAndEscape(String, char)} instead.
*/
+ @Deprecated
@SuppressWarnings( { "JavaDoc", "deprecation" } )
public static String quote( String argument )
throws CommandLineException
@@ -519,12 +519,15 @@ public static String quote( String argument )
* If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single
* quotes - else surround the argument by double quotes.
*
- *
+ * @param argument see name
+ * @param wrapExistingQuotes see name
+ * @return the transformed command line
* @throws CommandLineException if the argument contains both, single and double quotes.
* @deprecated Use {@link StringUtils#quoteAndEscape(String, char, char[], char[], char, boolean)},
* {@link StringUtils#quoteAndEscape(String, char, char[], char, boolean)}, or
* {@link StringUtils#quoteAndEscape(String, char)} instead.
*/
+ @Deprecated
@SuppressWarnings( { "JavaDoc", "UnusedDeclaration", "deprecation" } )
public static String quote( String argument, boolean wrapExistingQuotes )
throws CommandLineException
@@ -533,10 +536,17 @@ public static String quote( String argument, boolean wrapExistingQuotes )
}
/**
+ * @param argument the argument
+ * @param escapeSingleQuotes see name
+ * @param escapeDoubleQuotes see name
+ * @param wrapExistingQuotes see name
+ * @return the transformed command line
+ * @throws CommandLineException some trouble
* @deprecated Use {@link StringUtils#quoteAndEscape(String, char, char[], char[], char, boolean)},
* {@link StringUtils#quoteAndEscape(String, char, char[], char, boolean)}, or
* {@link StringUtils#quoteAndEscape(String, char)} instead.
*/
+ @Deprecated
@SuppressWarnings( { "JavaDoc" } )
public static String quote( String argument, boolean escapeSingleQuotes, boolean escapeDoubleQuotes,
boolean wrapExistingQuotes )
diff --git a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
index 20c70c22..c06147a9 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java
@@ -100,14 +100,16 @@ public class Commandline
/**
* @deprecated Use {@link org.codehaus.plexus.util.Os} class instead.
*/
+ @Deprecated
protected static final String OS_NAME = "os.name";
/**
* @deprecated Use {@link org.codehaus.plexus.util.Os} class instead.
*/
+ @Deprecated
protected static final String WINDOWS = "Windows";
- protected Vector arguments = new Vector();
+ protected Vector arguments = new Vector<>();
// protected Vector envVars = new Vector();
// synchronized added to preserve synchronize of Vector class
@@ -120,19 +122,22 @@ public class Commandline
/**
* @deprecated Use {@link Commandline#setExecutable(String)} instead.
*/
+ @Deprecated
protected String executable;
/**
* @deprecated Use {@link Commandline#setWorkingDirectory(File)} or {@link Commandline#setWorkingDirectory(String)}
* instead.
*/
+ @Deprecated
private File workingDir;
/**
* Create a new command line object. Shell is autodetected from operating system Shell usage is only desirable when
* generating code for remote execution.
*
- * @param toProcess
+ * @param toProcess sh to process
+ * @param shell Shell to use
*/
public Commandline( String toProcess, Shell shell )
{
@@ -160,6 +165,7 @@ public Commandline( String toProcess, Shell shell )
/**
* Create a new command line object. Shell is autodetected from operating system Shell usage is only desirable when
* generating code for remote execution.
+ * @param shell the Shell
*/
public Commandline( Shell shell )
{
@@ -169,7 +175,7 @@ public Commandline( Shell shell )
/**
* Create a new command line object, given a command following POSIX sh quoting rules
*
- * @param toProcess
+ * @param toProcess the process
*/
public Commandline( String toProcess )
{
@@ -235,7 +241,7 @@ public class Marker
}
/**
- *
Return the number of arguments that preceded this marker.
+ * @return the number of arguments that preceded this marker.
*
*
The name of the executable - if set - is counted as the very first argument.
*/
@@ -246,7 +252,7 @@ public int getPosition()
realPos = ( getLiteralExecutable() == null ? 0 : 1 );
for ( int i = 0; i < position; i++ )
{
- Arg arg = (Arg) arguments.elementAt( i );
+ Arg arg = arguments.elementAt( i );
realPos += arg.getParts().length;
}
}
@@ -289,6 +295,7 @@ private void setDefaultShell()
* @see #createArgument(boolean)
* @deprecated Use {@link Commandline#createArg()} instead
*/
+ @Deprecated
public Argument createArgument()
{
return this.createArgument( false );
@@ -302,7 +309,9 @@ public Argument createArgument()
* @param insertAtStart if true, the argument is inserted at the beginning of the list of args, otherwise it is
* appended.
* @deprecated Use {@link Commandline#createArg(boolean)} instead
+ * @return Argument the argument Object
*/
+ @Deprecated
public Argument createArgument( boolean insertAtStart )
{
Argument argument = new Argument();
@@ -332,7 +341,7 @@ public Arg createArg()
}
/**
- *
Creates an argument object and adds it to our list of args.
+ * @return Creates an argument object and adds it to our list of args.
*
*
Each commandline object has at most one instance of the argument class.
*
@@ -354,8 +363,7 @@ public Arg createArg( boolean insertAtStart )
}
/**
- * Adds an argument object to our list of args.
- *
+ * @param argument the argument
* @see #addArg(Arg,boolean)
*/
public void addArg( Arg argument )
@@ -365,7 +373,7 @@ public void addArg( Arg argument )
/**
* Adds an argument object to our list of args.
- *
+ * @param argument the argument
* @param insertAtStart if true, the argument is inserted at the beginning of the list of args, otherwise it is
* appended.
*/
@@ -383,6 +391,7 @@ public void addArg( Arg argument, boolean insertAtStart )
/**
* Sets the executable to run.
+ * @param executable the executable
*/
public void setExecutable( String executable )
{
@@ -426,6 +435,8 @@ public void addArguments( String[] line )
/**
* Add an environment variable
+ * @param name name
+ * @param value value
*/
public void addEnvironment( String name, String value )
{
@@ -435,6 +446,7 @@ public void addEnvironment( String name, String value )
/**
* Add system environment variables
+ * @throws Exception if error
*/
public void addSystemEnvironment()
throws Exception
@@ -452,7 +464,8 @@ public void addSystemEnvironment()
}
/**
- * Return the list of environment variables
+ * @return String[] Return the list of environment variables
+ * @throws CommandLineException if error
*/
public String[] getEnvironmentVariables()
throws CommandLineException
@@ -478,8 +491,8 @@ public String[] getEnvironmentVariables()
}
/**
- * Returns the executable and all defined arguments.
- * For Windows Family, {@link Commandline#getShellCommandline()} is returned
+ * @return Returns the executable and all defined arguments.
+ * For Windows Family, {@link Commandline#getShellCommandline()} is returned
*/
public String[] getCommandline()
{
@@ -492,8 +505,8 @@ public String[] getCommandline()
}
/**
- * Returns the executable and all defined arguments.
- *
+ * Returns the executable and all defined arguments.
+ * @return the command line as array not escaped neither quoted
*/
public String[] getRawCommandline()
{
@@ -513,21 +526,22 @@ public String[] getRawCommandline()
/**
* Returns the shell, executable and all defined arguments. Shell usage is only desirable when generating code for
* remote execution.
+ * @return the command line as array
*/
public String[] getShellCommandline()
{
// TODO: Provided only for backward compat. with <= 1.4
verifyShellState();
- return (String[]) getShell().getShellCommandLine( getArguments() ).toArray( new String[0] );
+ return getShell().getShellCommandLine( getArguments() ).toArray( new String[0] );
}
/**
- * Returns all arguments defined by addLine, addValue or the argument object.
+ * @return Returns all arguments defined by addLine, addValue or the argument object.
*/
public String[] getArguments()
{
- Vector result = new Vector( arguments.size() * 2 );
+ Vector result = new Vector<>( arguments.size() * 2 );
for ( int i = 0; i < arguments.size(); i++ )
{
Arg arg = arguments.elementAt( i );
@@ -546,6 +560,7 @@ public String[] getArguments()
return res;
}
+ @Override
public String toString()
{
return StringUtils.join( getShellCommandline(), " " );
@@ -556,6 +571,7 @@ public int size()
return getCommandline().length;
}
+ @Override
public Object clone()
{
Commandline c = new Commandline( (Shell) shell.clone() );
@@ -586,11 +602,11 @@ public void clearArgs()
}
/**
- *
Return a marker.
- *
+ *
*
This marker can be used to locate a position on the commandline - to insert something for example - when all
* parameters have been set.
*
+ * @return Return a marker.
*/
public Marker createMarker()
{
@@ -599,6 +615,7 @@ public Marker createMarker()
/**
* Sets execution directory.
+ * @param path the working directory as String
*/
public void setWorkingDirectory( String path )
{
@@ -608,6 +625,7 @@ public void setWorkingDirectory( String path )
/**
* Sets execution directory.
+ * @param workingDirectory the File used as working directory
*/
public void setWorkingDirectory( File workingDirectory )
{
@@ -629,6 +647,8 @@ public File getWorkingDirectory()
/**
* Executes the command.
+ * @return the Process
+ * @throws CommandLineException if error
*/
public Process execute()
throws CommandLineException
@@ -677,6 +697,7 @@ else if ( !workingDir.isDirectory() )
/**
* @deprecated Remove once backward compat with plexus-utils <= 1.4 is no longer a consideration
*/
+ @Deprecated
private void verifyShellState()
{
if ( shell.getWorkingDirectory() == null )
@@ -700,7 +721,7 @@ public Properties getSystemEnvVars()
* Allows to set the shell to be used in this command line. Shell usage is only desirable when generating code for
* remote execution.
*
- * @param shell
+ * @param shell Shell to use
* @since 1.2
*/
public void setShell( Shell shell )
@@ -713,6 +734,7 @@ public void setShell( Shell shell )
* execution.
*
* @since 1.2
+ * @return the Shell
*/
public Shell getShell()
{
@@ -720,8 +742,12 @@ public Shell getShell()
}
/**
+ * @param toProcess the process
+ * @return the command line arguments
+ * @throws Exception if error happen
* @deprecated Use {@link CommandLineUtils#translateCommandline(String)} instead.
*/
+ @Deprecated
public static String[] translateCommandline( String toProcess )
throws Exception
{
@@ -729,8 +755,12 @@ public static String[] translateCommandline( String toProcess )
}
/**
+ * @param argument the argument
+ * @return the quote arg
+ * @throws CommandLineException if error happen
* @deprecated Use {@link CommandLineUtils#quote(String)} instead.
*/
+ @Deprecated
public static String quoteArgument( String argument )
throws CommandLineException
{
@@ -739,7 +769,10 @@ public static String quoteArgument( String argument )
/**
* @deprecated Use {@link CommandLineUtils#toString(String[])} instead.
+ * @param line the lines
+ * @return lines as single String
*/
+ @Deprecated
public static String toString( String[] line )
{
return CommandLineUtils.toString( line );
@@ -754,6 +787,7 @@ public static class Argument
* (non-Javadoc)
* @see org.codehaus.plexus.util.cli.Argument#setValue(java.lang.String)
*/
+ @Override
public void setValue( String value )
{
if ( value != null )
@@ -766,6 +800,7 @@ public void setValue( String value )
* (non-Javadoc)
* @see org.codehaus.plexus.util.cli.Argument#setLine(java.lang.String)
*/
+ @Override
public void setLine( String line )
{
if ( line == null )
@@ -786,6 +821,7 @@ public void setLine( String line )
* (non-Javadoc)
* @see org.codehaus.plexus.util.cli.Argument#setFile(java.io.File)
*/
+ @Override
public void setFile( File value )
{
parts = new String[] { value.getAbsolutePath() };
@@ -795,6 +831,7 @@ public void setFile( File value )
* (non-Javadoc)
* @see org.codehaus.plexus.util.cli.Argument#getParts()
*/
+ @Override
public String[] getParts()
{
return parts;
diff --git a/src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java b/src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java
index 8def70f4..802dfb02 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java
@@ -20,12 +20,13 @@
/**
* @author Emmanuel Venisse
- * @version $Id$
+ *
*/
public class DefaultConsumer
implements StreamConsumer
{
+ @Override
public void consumeLine( String line )
throws IOException
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizer.java b/src/main/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizer.java
index c260e883..2db89002 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizer.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizer.java
@@ -22,7 +22,7 @@
* The java.util.StringTokenizer is horribly broken. Given the string 1,,,3,,4 (, delim) It will return 1,3,4 Which is
* clearly wrong - 1,EMPTY,EMPTY,3,EMPTY,4 is what it should return
*
- * @version $Id$
+ *
*/
public final class EnhancedStringTokenizer
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamConsumer.java b/src/main/java/org/codehaus/plexus/util/cli/StreamConsumer.java
index 9bc888a3..e01bda2c 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamConsumer.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamConsumer.java
@@ -62,7 +62,7 @@
*
* @author Florin Vancea
* @author Paul Julius
- * @version $Id$
+ *
*/
public interface StreamConsumer
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java b/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
index dd0d7a1c..270d7d8b 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamFeeder.java
@@ -24,7 +24,7 @@
* Read from an InputStream and write the output to an OutputStream.
*
* @author Trygve Laugstøl
- * @version $Id$
+ *
*/
public class StreamFeeder
extends AbstractStreamHandler
@@ -121,6 +121,7 @@ public void close()
/**
* @since 3.1.0
+ * @return the Exception
*/
public Throwable getException()
{
diff --git a/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java b/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
index b5e0a0dc..12126e88 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/StreamPumper.java
@@ -81,7 +81,7 @@
*
* @author Florin Vancea
* @author Paul Julius
- * @version $Id$
+ *
* @since June 11, 2001
*/
public class StreamPumper
diff --git a/src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java b/src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java
index 6898cc09..ed24136e 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java
@@ -21,7 +21,7 @@
/**
* @author Jason van Zyl
- * @version $Id$
+ *
*/
public class WriterStreamConsumer
implements StreamConsumer
@@ -33,6 +33,7 @@ public WriterStreamConsumer( Writer writer )
this.writer = new PrintWriter( writer );
}
+ @Override
public void consumeLine( String line )
{
writer.println( line );
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
index b19eed1e..089bc6fd 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/BourneShell.java
@@ -23,7 +23,7 @@
/**
* @author Jason van Zyl
- * @version $Id$
+ *
*/
public class BourneShell
extends Shell
@@ -52,6 +52,7 @@ public BourneShell( boolean isLoginShell )
}
/** {@inheritDoc} */
+ @Override
public String getExecutable()
{
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
@@ -62,6 +63,7 @@ public String getExecutable()
return quoteOneItem( super.getOriginalExecutable(), true );
}
+ @Override
public List getShellArgsList()
{
List shellArgs = new ArrayList();
@@ -77,6 +79,7 @@ public List getShellArgsList()
return shellArgs;
}
+ @Override
public String[] getShellArgs()
{
String[] shellArgs = super.getShellArgs();
@@ -98,6 +101,7 @@ public String[] getShellArgs()
return shellArgs;
}
+ @Override
protected String getExecutionPreamble()
{
if ( getWorkingDirectoryAsString() == null )
@@ -134,6 +138,7 @@ protected String getExecutionPreamble()
* @param path not null path.
* @return the path unified correctly for the Bourne shell.
*/
+ @Override
protected String quoteOneItem( String path, boolean isExecutable )
{
if ( path == null )
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
index e1054a2d..aa0af43a 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/CmdShell.java
@@ -26,7 +26,7 @@
*
* @author Carlos Sanchez
* @since 1.2
- * @version $Id$
+ *
*/
public class CmdShell
extends Shell
@@ -76,6 +76,7 @@ public CmdShell()
* successfully.
*
*/
+ @Override
public List getCommandLine( String executable, String[] arguments )
{
StringBuilder sb = new StringBuilder();
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/CommandShell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/CommandShell.java
index 5ca7e875..4aa4c2af 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/CommandShell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/CommandShell.java
@@ -23,7 +23,7 @@
*
* @author Carlos Sanchez
* @since 1.2
- * @version $Id$
+ *
*/
public class CommandShell
extends Shell
diff --git a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
index 75b5f80e..c3c911dd 100644
--- a/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
+++ b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java
@@ -32,7 +32,7 @@
*
* @author Carlos Sanchez
* @since 1.2
- * @version $Id$
+ *
*/
public class Shell
implements Cloneable
@@ -70,7 +70,7 @@ public class Shell
/**
* Toggle unconditional quoting
*
- * @param unconditionallyQuote
+ * @param unconditionallyQuote see name
*/
public void setUnconditionalQuoting( boolean unconditionallyQuote )
{
@@ -80,7 +80,7 @@ public void setUnconditionalQuoting( boolean unconditionallyQuote )
/**
* Set the command to execute the shell (eg. COMMAND.COM, /bin/bash,...)
*
- * @param shellCommand
+ * @param shellCommand see name
*/
public void setShellCommand( String shellCommand )
{
@@ -90,7 +90,7 @@ public void setShellCommand( String shellCommand )
/**
* Get the command to execute the shell
*
- * @return
+ * @return the command
*/
public String getShellCommand()
{
@@ -100,7 +100,7 @@ public String getShellCommand()
/**
* Set the shell arguments when calling a command line (not the executable arguments) (eg. /X /C for CMD.EXE)
*
- * @param shellArgs
+ * @param shellArgs see name
*/
public void setShellArgs( String[] shellArgs )
{
@@ -109,9 +109,7 @@ public void setShellArgs( String[] shellArgs )
}
/**
- * Get the shell arguments
- *
- * @return
+ * @return the shell arguments
*/
public String[] getShellArgs()
{
@@ -121,7 +119,7 @@ public String[] getShellArgs()
}
else
{
- return (String[]) shellArgs.toArray( new String[shellArgs.size()] );
+ return shellArgs.toArray( new String[0] );
}
}
@@ -328,7 +326,8 @@ public boolean isQuotedExecutableEnabled()
}
/**
- * Sets the executable to run.
+ *
+ * @param executable Sets the executable to run.
*/
public void setExecutable( String executable )
{
@@ -345,7 +344,7 @@ public String getExecutable()
}
/**
- * Sets execution directory.
+ * @param path Sets execution directory.
*/
public void setWorkingDirectory( String path )
{
@@ -356,7 +355,7 @@ public void setWorkingDirectory( String path )
}
/**
- * Sets execution directory.
+ * @param workingDir Sets execution directory.
*/
public void setWorkingDirectory( File workingDir )
{
@@ -381,6 +380,7 @@ public void clearArguments()
shellArgs.clear();
}
+ @Override
public Object clone()
{
Shell shell = new Shell();
diff --git a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
index 73c846be..e350af9d 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java
@@ -37,9 +37,6 @@ public List getCycle()
return cycle;
}
- /**
- * @return
- */
public String cycleToString()
{
final StringBuilder buffer = new StringBuilder();
@@ -56,6 +53,7 @@ public String cycleToString()
return buffer.toString();
}
+ @Override
public String getMessage()
{
return super.getMessage() + " " + cycleToString();
diff --git a/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java b/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java
index 5b135343..6f810043 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/CycleDetector.java
@@ -24,7 +24,7 @@
/**
* @author Michal Maczka
- * @version $Id$
+ *
*/
public class CycleDetector
{
@@ -39,7 +39,7 @@ public static List hasCycle( final DAG graph )
{
final List vertices = graph.getVertices();
- final Map vertexStateMap = new HashMap();
+ final Map vertexStateMap = new HashMap<>();
List retValue = null;
@@ -63,13 +63,13 @@ public static List hasCycle( final DAG graph )
* This method will be called when an edge leading to given vertex was added and we want to check if introduction of
* this edge has not resulted in apparition of cycle in the graph
*
- * @param vertex
- * @param vertexStateMap
- * @return
+ * @param vertex the vertex
+ * @param vertexStateMap the vertex Map
+ * @return the found cycle
*/
public static List introducesCycle( final Vertex vertex, final Map vertexStateMap )
{
- final LinkedList cycleStack = new LinkedList();
+ final LinkedList cycleStack = new LinkedList<>();
final boolean hasCycle = dfsVisit( vertex, cycleStack, vertexStateMap );
@@ -97,16 +97,11 @@ public static List introducesCycle( final Vertex vertex, final Map introducesCycle( final Vertex vertex )
{
- final Map vertexStateMap = new HashMap();
+ final Map vertexStateMap = new HashMap<>();
return introducesCycle( vertex, vertexStateMap );
}
- /**
- * @param vertex
- * @param vertexStateMap
- * @return
- */
private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
{
final Integer state = vertexStateMap.get( vertex );
@@ -114,11 +109,6 @@ private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
{
final Integer state = vertexStateMap.get( vertex );
@@ -158,4 +148,4 @@ else if ( isVisiting( v, vertexStateMap ) )
return false;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/codehaus/plexus/util/dag/DAG.java b/src/main/java/org/codehaus/plexus/util/dag/DAG.java
index 19fe67c8..4d0f9a45 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/DAG.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/DAG.java
@@ -27,7 +27,7 @@
* DAG = Directed Acyclic Graph
*
* @author Michal Maczka
- * @version $Id$
+ *
* TODO this class should be renamed from DAG to Dag
*/
public class DAG
@@ -42,12 +42,12 @@ public class DAG
/**
* Maps vertex's label to vertex
*/
- private Map vertexMap = new HashMap();
+ private Map vertexMap = new HashMap<>();
/**
* Conatin list of all vertices
*/
- private List vertexList = new ArrayList();
+ private List vertexList = new ArrayList<>();
// ------------------------------------------------------------
// Constructors
@@ -66,7 +66,7 @@ public DAG()
// ------------------------------------------------------------
/**
- * @return
+ * @return the vertices
*/
public List getVertices()
{
@@ -75,6 +75,7 @@ public List getVertices()
/**
* @deprecated instead use {@link #getVertices()}
+ * @return the vertices
*/
@Deprecated
public List getVerticies()
@@ -169,7 +170,7 @@ public void removeEdge( final Vertex from, final Vertex to )
public Vertex getVertex( final String label )
{
- final Vertex retValue = (Vertex) vertexMap.get( label );
+ final Vertex retValue = vertexMap.get( label );
return retValue;
}
@@ -187,8 +188,8 @@ public boolean hasEdge( final String label1, final String label2 )
}
/**
- * @param label
- * @return
+ * @param label see name
+ * @return the childs
*/
public List getChildLabels( final String label )
{
@@ -198,8 +199,8 @@ public List getChildLabels( final String label )
}
/**
- * @param label
- * @return
+ * @param label see name
+ * @return the parents
*/
public List getParentLabels( final String label )
{
@@ -211,6 +212,7 @@ public List getParentLabels( final String label )
/**
* @see java.lang.Object#clone()
*/
+ @Override
public Object clone()
throws CloneNotSupportedException
{
@@ -222,7 +224,7 @@ public Object clone()
/**
* Indicates if there is at least one edge leading to or from vertex of given label
- *
+ * @param label the label
* @return true if this vertex is connected with other vertex,false otherwise
*/
public boolean isConnected( final String label )
@@ -251,7 +253,7 @@ public List getSuccessorLabels( final String label )
// optimization.
if ( vertex.isLeaf() )
{
- retValue = new ArrayList( 1 );
+ retValue = new ArrayList<>( 1 );
retValue.add( label );
}
diff --git a/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java b/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java
index 1552c55f..b2736255 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/TopologicalSorter.java
@@ -23,7 +23,7 @@
/**
* @author Michal Maczka
- * @version $Id$
+ *
*/
public class TopologicalSorter
{
@@ -35,10 +35,9 @@ public class TopologicalSorter
private final static Integer VISITED = 2;
/**
- * @param graph
+ * @param graph the graph
* @return List of String (vertex labels)
*/
-
public static List sort( final DAG graph )
{
return dfs( graph );
@@ -47,7 +46,7 @@ public static List sort( final DAG graph )
public static List sort( final Vertex vertex )
{
// we need to use addFirst method so we will use LinkedList explicitly
- final List retValue = new LinkedList();
+ final List retValue = new LinkedList<>();
dfsVisit( vertex, new HashMap(), retValue );
@@ -57,8 +56,8 @@ public static List sort( final Vertex vertex )
private static List dfs( final DAG graph )
{
// we need to use addFirst method so we will use LinkedList explicitly
- final List retValue = new LinkedList();
- final Map vertexStateMap = new HashMap();
+ final List retValue = new LinkedList<>();
+ final Map vertexStateMap = new HashMap<>();
for ( Vertex vertex : graph.getVertices() )
{
@@ -71,11 +70,6 @@ private static List dfs( final DAG graph )
return retValue;
}
- /**
- * @param vertex
- * @param vertexStateMap
- * @return
- */
private static boolean isNotVisited( final Vertex vertex, final Map vertexStateMap )
{
final Integer state = vertexStateMap.get( vertex );
diff --git a/src/main/java/org/codehaus/plexus/util/dag/Vertex.java b/src/main/java/org/codehaus/plexus/util/dag/Vertex.java
index 9e5260df..489b6185 100644
--- a/src/main/java/org/codehaus/plexus/util/dag/Vertex.java
+++ b/src/main/java/org/codehaus/plexus/util/dag/Vertex.java
@@ -22,7 +22,7 @@
/**
* @author Michal Maczka
- * @version $Id$
+ *
*/
public class Vertex
implements Cloneable, Serializable
@@ -32,17 +32,14 @@ public class Vertex
// ------------------------------------------------------------
private String label = null;
- List children = new ArrayList();
+ List children = new ArrayList<>();
- List parents = new ArrayList();
+ List parents = new ArrayList<>();
// ------------------------------------------------------------
// Constructors
// ------------------------------------------------------------
- /**
- *
- */
public Vertex( final String label )
{
this.label = label;
@@ -52,33 +49,21 @@ public Vertex( final String label )
// Accessors
// ------------------------------------------------------------
- /**
- * @return
- */
public String getLabel()
{
return label;
}
- /**
- * @param vertex
- */
public void addEdgeTo( final Vertex vertex )
{
children.add( vertex );
}
- /**
- * @param vertex
- */
public void removeEdgeTo( final Vertex vertex )
{
children.remove( vertex );
}
- /**
- * @param vertex
- */
public void addEdgeFrom( final Vertex vertex )
{
parents.add( vertex );
@@ -101,7 +86,7 @@ public List getChildren()
*/
public List getChildLabels()
{
- final List retValue = new ArrayList( children.size() );
+ final List retValue = new ArrayList<>( children.size() );
for ( Vertex vertex : children )
{
@@ -127,7 +112,7 @@ public List getParents()
*/
public List getParentLabels()
{
- final List retValue = new ArrayList( parents.size() );
+ final List retValue = new ArrayList<>( parents.size() );
for ( Vertex vertex : parents )
{
@@ -166,6 +151,7 @@ public boolean isConnected()
return isRoot() || isLeaf();
}
+ @Override
public Object clone()
throws CloneNotSupportedException
{
@@ -175,6 +161,7 @@ public Object clone()
return retValue;
}
+ @Override
public String toString()
{
return "Vertex{" + "label='" + label + "'" + "}";
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java b/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
index 387dc68a..6e0c8be2 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/ClassMap.java
@@ -29,7 +29,7 @@
* @author Bob McWhirter
* @author Attila Szegedi
* @author Geir Magnusson Jr.
- * @version $Id$
+ *
*/
public class ClassMap
{
@@ -50,12 +50,13 @@ private static final class CacheMiss
/**
* Cache of Methods, or CACHE_MISS, keyed by method name and actual arguments used to find it.
*/
- private Map methodCache = new Hashtable();
+ private Map methodCache = new Hashtable<>();
private final MethodMap methodMap = new MethodMap();
/**
* Standard constructor
+ * @param clazz the Class
*/
public ClassMap( Class clazz )
{
@@ -78,6 +79,10 @@ Class getCachedClass()
* it'll be a Method, in which case, we return it.
*
*
If nothing is found, then we must actually go and introspect the method from the MethodMap.
+ * @param name method name
+ * @param params method params
+ * @return the find Method or null
+ * @throws org.codehaus.plexus.util.introspection.MethodMap.AmbiguousException if ambiguous name
*/
public Method findMethod( String name, Object[] params )
throws MethodMap.AmbiguousException
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java b/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java
index b6069f95..51420cca 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/MethodMap.java
@@ -30,7 +30,7 @@
* @author Christoph Reck
* @author Geir Magnusson Jr.
* @author Attila Szegedi
- * @version $Id$
+ *
*/
public class MethodMap
{
diff --git a/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java b/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
index e4603f3d..656c8201 100644
--- a/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
+++ b/src/main/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractor.java
@@ -37,7 +37,7 @@
*
* @author Jason van Zyl
* @author Vincent Siveton
- * @version $Id$
+ *
* @see http://struts.apache.org/1.x/struts-taglib/indexedprops.html
*/
@@ -175,6 +175,7 @@ public static Object evaluate( String expression, Object root )
*
* @param expression not null expression
* @param root not null object
+ * @param trimRootToken root start
* @return the object defined by the expression
* @throws Exception if any
*/
diff --git a/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java b/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java
new file mode 100644
index 00000000..744e6f06
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java
@@ -0,0 +1,173 @@
+package org.codehaus.plexus.util.io;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.nio.file.attribute.FileTime;
+import java.time.Instant;
+import java.util.Objects;
+
+/**
+ * Caching OutputStream to avoid overwriting a file with
+ * the same content.
+ */
+public class CachingOutputStream extends OutputStream
+{
+ private final Path path;
+ private FileChannel channel;
+ private ByteBuffer readBuffer;
+ private ByteBuffer writeBuffer;
+ private boolean modified;
+
+ public CachingOutputStream( File path ) throws IOException
+ {
+ this( Objects.requireNonNull( path ).toPath() );
+ }
+
+ public CachingOutputStream( Path path ) throws IOException
+ {
+ this( path, 32 * 1024 );
+ }
+
+ public CachingOutputStream( Path path, int bufferSize ) throws IOException
+ {
+ this.path = Objects.requireNonNull( path );
+ this.channel = FileChannel.open( path,
+ StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE );
+ this.readBuffer = ByteBuffer.allocate( bufferSize );
+ this.writeBuffer = ByteBuffer.allocate( bufferSize );
+ }
+
+ @Override
+ public void write( int b ) throws IOException
+ {
+ if ( writeBuffer.remaining() < 1 )
+ {
+ ( ( Buffer ) writeBuffer ).flip();
+ flushBuffer( writeBuffer );
+ ( ( Buffer ) writeBuffer ).clear();
+ }
+ writeBuffer.put( ( byte ) b );
+ }
+
+ @Override
+ public void write( byte[] b ) throws IOException
+ {
+ write( b, 0, b.length );
+ }
+
+ @Override
+ public void write( byte[] b, int off, int len ) throws IOException
+ {
+ if ( writeBuffer.remaining() < len )
+ {
+ ( ( Buffer ) writeBuffer ).flip();
+ flushBuffer( writeBuffer );
+ ( ( Buffer ) writeBuffer ).clear();
+ }
+ int capacity = writeBuffer.capacity();
+ while ( len >= capacity )
+ {
+ flushBuffer( ByteBuffer.wrap( b, off, capacity ) );
+ off += capacity;
+ len -= capacity;
+ }
+ if ( len > 0 )
+ {
+ writeBuffer.put( b, off, len );
+ }
+ }
+
+ @Override
+ public void flush() throws IOException
+ {
+ ( ( Buffer ) writeBuffer ).flip();
+ flushBuffer( writeBuffer );
+ ( ( Buffer ) writeBuffer ).clear();
+ super.flush();
+ }
+
+ private void flushBuffer( ByteBuffer writeBuffer ) throws IOException
+ {
+ if ( modified )
+ {
+ channel.write( writeBuffer );
+ }
+ else
+ {
+ int len = writeBuffer.remaining();
+ ByteBuffer readBuffer;
+ if ( this.readBuffer.capacity() >= len )
+ {
+ readBuffer = this.readBuffer;
+ ( ( Buffer ) readBuffer ).clear();
+ }
+ else
+ {
+ readBuffer = ByteBuffer.allocate( len );
+ }
+ while ( len > 0 )
+ {
+ int read = channel.read( readBuffer );
+ if ( read <= 0 )
+ {
+ modified = true;
+ channel.position( channel.position() - readBuffer.position() );
+ channel.write( writeBuffer );
+ return;
+ }
+ len -= read;
+ }
+ ( ( Buffer ) readBuffer ).flip();
+ if ( readBuffer.compareTo( writeBuffer ) != 0 )
+ {
+ modified = true;
+ channel.position( channel.position() - readBuffer.remaining() );
+ channel.write( writeBuffer );
+ }
+ }
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ if ( channel.isOpen() )
+ {
+ flush();
+ long position = channel.position();
+ if ( position != channel.size() )
+ {
+ modified = true;
+ channel.truncate( position );
+ }
+ channel.close();
+ }
+ }
+
+ public boolean isModified()
+ {
+ return modified;
+ }
+}
diff --git a/src/main/java/org/codehaus/plexus/util/io/CachingWriter.java b/src/main/java/org/codehaus/plexus/util/io/CachingWriter.java
new file mode 100644
index 00000000..23cc4411
--- /dev/null
+++ b/src/main/java/org/codehaus/plexus/util/io/CachingWriter.java
@@ -0,0 +1,62 @@
+package org.codehaus.plexus.util.io;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Objects;
+
+/**
+ * Caching Writer to avoid overwriting a file with
+ * the same content.
+ */
+public class CachingWriter extends OutputStreamWriter
+{
+ private final CachingOutputStream cos;
+
+ public CachingWriter( File path, Charset charset ) throws IOException
+ {
+ this( Objects.requireNonNull( path ).toPath(), charset );
+ }
+
+ public CachingWriter( Path path, Charset charset ) throws IOException
+ {
+ this( path, charset, 32 * 1024 );
+ }
+
+ public CachingWriter( Path path, Charset charset, int bufferSize ) throws IOException
+ {
+ this( new CachingOutputStream( path, bufferSize ), charset );
+ }
+
+ private CachingWriter( CachingOutputStream outputStream, Charset charset ) throws IOException
+ {
+ super( outputStream, charset );
+ this.cos = outputStream;
+ }
+
+ public boolean isModified()
+ {
+ return cos.isModified();
+ }
+}
diff --git a/src/main/java/org/codehaus/plexus/util/io/InputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/InputStreamFacade.java
index b8207cbe..bfa5c471 100644
--- a/src/main/java/org/codehaus/plexus/util/io/InputStreamFacade.java
+++ b/src/main/java/org/codehaus/plexus/util/io/InputStreamFacade.java
@@ -26,7 +26,9 @@
public interface InputStreamFacade
{
/**
- * Retrieves the actual {@link InputStream}. The caller must assume, that this method may be invoked only once.
+ * The caller must assume, that this method may be invoked only once.
+ * @return Retrieves the actual {@link InputStream}.
+ * @throws IOException if io issue
*/
InputStream getInputStream()
throws IOException;
diff --git a/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java
index acd7163a..e634b95f 100644
--- a/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java
+++ b/src/main/java/org/codehaus/plexus/util/io/RawInputStreamFacade.java
@@ -33,6 +33,7 @@ public RawInputStreamFacade( InputStream stream )
this.stream = stream;
}
+ @Override
public InputStream getInputStream()
throws IOException
{
diff --git a/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java b/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java
index 8267731a..da09b4c1 100644
--- a/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java
+++ b/src/main/java/org/codehaus/plexus/util/io/URLInputStreamFacade.java
@@ -33,6 +33,7 @@ public URLInputStreamFacade( URL url )
this.url = url;
}
+ @Override
public InputStream getInputStream()
throws IOException
{
diff --git a/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java b/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java
index 21523497..4f3a9d84 100644
--- a/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java
+++ b/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java
@@ -50,6 +50,7 @@ public Reflector()
*
* @param theClass The class to instantiate
* @param params The parameters to pass to the constructor
+ * @param the type
* @return The instantiated object
* @throws ReflectorException In case anything goes wrong here...
*/
@@ -94,15 +95,7 @@ public T newInstance( Class theClass, Object[] params )
return con.newInstance( params );
}
- catch ( InstantiationException ex )
- {
- throw new ReflectorException( ex );
- }
- catch ( InvocationTargetException ex )
- {
- throw new ReflectorException( ex );
- }
- catch ( IllegalAccessException ex )
+ catch ( InstantiationException | InvocationTargetException | IllegalAccessException ex )
{
throw new ReflectorException( ex );
}
@@ -114,6 +107,7 @@ public T newInstance( Class theClass, Object[] params )
*
* @param theClass The class to retrieve the singleton of
* @param initParams The parameters to pass to the constructor
+ * @param the type
* @return The singleton object
* @throws ReflectorException In case anything goes wrong here...
*/
@@ -135,11 +129,7 @@ public T getSingleton( Class theClass, Object[] initParams )
// noinspection unchecked
return (T) method.invoke( null, initParams );
}
- catch ( InvocationTargetException ex )
- {
- throw new ReflectorException( ex );
- }
- catch ( IllegalAccessException ex )
+ catch ( InvocationTargetException | IllegalAccessException ex )
{
throw new ReflectorException( ex );
}
@@ -193,11 +183,7 @@ public Object invoke( Object target, String methodName, Object[] params )
return method.invoke( target, params );
}
- catch ( InvocationTargetException ex )
- {
- throw new ReflectorException( ex );
- }
- catch ( IllegalAccessException ex )
+ catch ( InvocationTargetException | IllegalAccessException ex )
{
throw new ReflectorException( ex );
}
@@ -213,19 +199,7 @@ public Object getStaticField( Class targetClass, String fieldName )
return field.get( null );
}
- catch ( SecurityException e )
- {
- throw new ReflectorException( e );
- }
- catch ( NoSuchFieldException e )
- {
- throw new ReflectorException( e );
- }
- catch ( IllegalArgumentException e )
- {
- throw new ReflectorException( e );
- }
- catch ( IllegalAccessException e )
+ catch ( SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e )
{
throw new ReflectorException( e );
}
@@ -331,11 +305,7 @@ public Object invokeStatic( Class targetClass, String methodName, Object[] param
return method.invoke( null, params );
}
- catch ( InvocationTargetException ex )
- {
- throw new ReflectorException( ex );
- }
- catch ( IllegalAccessException ex )
+ catch ( InvocationTargetException | IllegalAccessException ex )
{
throw new ReflectorException( ex );
}
@@ -346,6 +316,7 @@ public Object invokeStatic( Class targetClass, String methodName, Object[] param
*
* @param targetClass The class to get the constructor from
* @param params The classes of the parameters which the constructor should match.
+ * @param the type
* @return the Constructor object that matches.
* @throws ReflectorException In case we can't retrieve the proper constructor.
*/
@@ -496,6 +467,7 @@ public Object getObjectProperty( Object target, String propertyName )
*
* @param targetClass The class to get the method from
* @param params The classes of the parameters which the method should match.
+ * @param methodName the method name
* @return the Method object that matches.
* @throws ReflectorException In case we can't retrieve the proper method.
*/
@@ -536,7 +508,7 @@ private Method _getMethod( Class targetClass, String methodName, Class[] params
synchronized ( paramKey.intern() )
{
- method = (Method) methodMap.get( paramKey );
+ method = methodMap.get( paramKey );
if ( method == null )
{
@@ -615,8 +587,8 @@ private Map> getConstructorMap( Class theClass )
if ( classMethods == null )
{
- classMethods = new HashMap>();
- methodMap = new HashMap();
+ classMethods = new HashMap<>();
+ methodMap = new HashMap<>();
classMethods.put( methodName, methodMap );
classMaps.put( className, classMethods );
}
@@ -630,7 +602,7 @@ private Map> getConstructorMap( Class theClass )
if ( methodMap == null )
{
- methodMap = new HashMap();
+ methodMap = new HashMap<>();
classMethods.put( methodName, methodMap );
}
}
@@ -639,4 +611,4 @@ private Map> getConstructorMap( Class theClass )
return methodMap;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java
index dc4c31f1..85835210 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java
@@ -20,7 +20,7 @@
import java.io.Writer;
/**
- * @version $Id$
+ *
*/
public class CompactXMLWriter
extends PrettyPrintXMLWriter
@@ -36,6 +36,7 @@ public CompactXMLWriter( Writer writer )
super( writer );
}
+ @Override
protected void endOfLine()
{
// override parent: don't write anything at end of line
diff --git a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
index 9710a6f7..c4387317 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java
@@ -27,7 +27,7 @@
/**
* Implementation of XMLWriter which emits nicely formatted documents.
*
- * @version $Id$
+ *
*/
public class PrettyPrintXMLWriter
implements XMLWriter
@@ -158,6 +158,7 @@ public PrettyPrintXMLWriter( PrintWriter writer, String lineIndenter, String lin
}
/** {@inheritDoc} */
+ @Override
public void startElement( String name )
{
tagIsEmpty = false;
@@ -180,12 +181,14 @@ public void startElement( String name )
}
/** {@inheritDoc} */
+ @Override
public void writeText( String text )
{
writeText( text, true );
}
/** {@inheritDoc} */
+ @Override
public void writeMarkup( String text )
{
writeText( text, false );
@@ -272,6 +275,7 @@ private static String escapeXmlAttribute( String text )
}
/** {@inheritDoc} */
+ @Override
public void addAttribute( String key, String value )
{
write( " " );
@@ -286,6 +290,7 @@ public void addAttribute( String key, String value )
}
/** {@inheritDoc} */
+ @Override
public void endElement()
{
setDepth( getDepth() - 1 );
diff --git a/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java
index 0cca0319..488103d4 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java
@@ -28,7 +28,7 @@
* Write to an MXSerializer.
*
* @author Brett Porter
- * @version $Id$
+ *
*/
public class SerializerXMLWriter
implements XMLWriter
@@ -47,6 +47,7 @@ public SerializerXMLWriter( String namespace, XmlSerializer serializer )
this.namespace = namespace;
}
+ @Override
public void startElement( String name )
{
try
@@ -60,6 +61,7 @@ public void startElement( String name )
}
}
+ @Override
public void addAttribute( String key, String value )
{
try
@@ -72,6 +74,7 @@ public void addAttribute( String key, String value )
}
}
+ @Override
public void writeText( String text )
{
try
@@ -84,6 +87,7 @@ public void writeText( String text )
}
}
+ @Override
public void writeMarkup( String text )
{
try
@@ -96,11 +100,12 @@ public void writeMarkup( String text )
}
}
+ @Override
public void endElement()
{
try
{
- serializer.endTag( namespace, (String) elements.pop() );
+ serializer.endTag( namespace, elements.pop() );
}
catch ( IOException e )
{
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java b/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java
index 3f7680be..364849ba 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XMLWriter.java
@@ -17,7 +17,7 @@
*/
/**
- * @version $Id$
+ *
*/
public interface XMLWriter
{
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java
index 2cd639e7..e7c7cc47 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java
@@ -19,7 +19,6 @@
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -27,6 +26,7 @@
import java.io.StringReader;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.file.Files;
import java.net.HttpURLConnection;
import java.util.Locale;
import java.util.regex.Pattern;
@@ -57,6 +57,7 @@
* @deprecated use XmlStreamReader
* @since 1.4.3
*/
+@Deprecated
public class XmlReader
extends Reader
{
@@ -125,7 +126,7 @@ public static String getDefaultEncoding()
public XmlReader( File file )
throws IOException
{
- this( new FileInputStream( file ) );
+ this( Files.newInputStream( file.toPath() ) );
}
/**
@@ -311,6 +312,7 @@ public XmlReader( InputStream is, String httpContentType )
* @param is InputStream to create the reader from.
* @param httpContentType content-type header to use for the resolution of the charset encoding.
* @param lenient indicates if the charset encoding detection should be relaxed.
+ * @param defaultEncoding encoding to use
* @throws IOException thrown if there is a problem reading the file.
* @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs.
*/
@@ -415,6 +417,7 @@ public String getEncoding()
return _encoding;
}
+ @Override
public int read( char[] buf, int offset, int len )
throws IOException
{
@@ -427,6 +430,7 @@ public int read( char[] buf, int offset, int len )
*
* @throws IOException thrown if there was a problem closing the stream.
*/
+ @Override
public void close()
throws IOException
{
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java
index 2c561405..5c26aa98 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamReader.java
@@ -201,6 +201,7 @@ public XmlStreamReader( InputStream is, String httpContentType )
* @param is InputStream to create the reader from.
* @param httpContentType content-type header to use for the resolution of the charset encoding.
* @param lenient indicates if the charset encoding detection should be relaxed.
+ * @param defaultEncoding encoding to use
* @throws IOException thrown if there is a problem reading the file.
* @throws XmlStreamReaderException thrown if the charset encoding could not be determined according to the specs.
*/
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java
index c4afd065..9b5f0a92 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java
@@ -17,13 +17,12 @@
*/
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.file.Files;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -33,7 +32,7 @@
* the XML document written to the stream.
*
* @author Herve Boutemy
- * @version $Id$
+ *
* @since 1.4.4
*/
public class XmlStreamWriter
@@ -55,9 +54,9 @@ public XmlStreamWriter( OutputStream out )
}
public XmlStreamWriter( File file )
- throws FileNotFoundException
+ throws IOException
{
- this( new FileOutputStream( file ) );
+ this( Files.newOutputStream( file.toPath() ) );
}
public String getEncoding()
@@ -65,6 +64,7 @@ public String getEncoding()
return encoding;
}
+ @Override
public void close()
throws IOException
{
@@ -77,6 +77,7 @@ public void close()
writer.close();
}
+ @Override
public void flush()
throws IOException
{
@@ -147,6 +148,7 @@ private void detectEncoding( char[] cbuf, int off, int len )
}
}
+ @Override
public void write( char[] cbuf, int off, int len )
throws IOException
{
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java b/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java
index 376caf44..73464b8e 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java
@@ -24,7 +24,6 @@
import java.io.Reader;
import java.io.Writer;
-import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
@@ -36,7 +35,7 @@
* Common XML utilities methods.
*
* @author Vincent Siveton
- * @version $Id$
+ *
* @since 1.5.7
*/
public class XmlUtil
@@ -65,25 +64,17 @@ public static boolean isXml( File f )
throw new IllegalArgumentException( "The file '" + f.getAbsolutePath() + "' is not a file." );
}
- Reader reader = null;
- try
+ try ( Reader reader = ReaderFactory.newXmlReader( f ) )
{
- reader = ReaderFactory.newXmlReader( f );
XmlPullParser parser = new MXParser();
parser.setInput( reader );
parser.nextToken();
- reader.close();
- reader = null;
return true;
}
catch ( Exception e )
{
return false;
}
- finally
- {
- IOUtil.close( reader );
- }
}
/**
@@ -233,13 +224,9 @@ public static void prettyFormat( InputStream is, OutputStream os, int indentSize
indentSize = 0;
}
- Reader reader = null;
- Writer writer = null;
- try
+ try ( Reader reader = ReaderFactory.newXmlReader( is );
+ Writer writer = new OutputStreamWriter( os ) )
{
- reader = ReaderFactory.newXmlReader( is );
- writer = new OutputStreamWriter( os );
-
final PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );
xmlWriter.setLineIndenter( StringUtils.repeat( " ", indentSize ) );
xmlWriter.setLineSeparator( lineSeparator );
@@ -248,22 +235,11 @@ public static void prettyFormat( InputStream is, OutputStream os, int indentSize
parser.setInput( reader );
prettyFormatInternal( parser, xmlWriter );
-
- writer.close();
- writer = null;
-
- reader.close();
- reader = null;
}
catch ( XmlPullParserException e )
{
throw new IOException( "Unable to parse the XML: " + e.getMessage() );
}
- finally
- {
- IOUtil.close( writer );
- IOUtil.close( reader );
- }
}
/**
diff --git a/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java b/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
index a392b0d0..22527a1b 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/XmlWriterUtil.java
@@ -22,7 +22,7 @@
* Utility class for the XmlWriter class.
*
* @author Vincent Siveton
- * @version $Id$
+ *
*/
public class XmlWriterUtil
{
@@ -63,7 +63,7 @@ public static void writeLineBreak( XMLWriter writer, int repeat )
* Convenience method to repeat CRLF and to indent the writer by 2.
*
* @param writer not null
- * @param repeat
+ * @param repeat space repeat
* @param indent positive number
* @see #DEFAULT_INDENTATION_SIZE
* @see #writeLineBreak(XMLWriter, int, int, int)
@@ -77,7 +77,7 @@ public static void writeLineBreak( XMLWriter writer, int repeat, int indent )
* Convenience method to repeat CRLF and to indent the writer by indentSize.
*
* @param writer not null
- * @param repeat
+ * @param repeat repeat time
* @param indent positive number
* @param indentSize positive number
*/
@@ -131,7 +131,7 @@ public static void writeCommentLineBreak( XMLWriter writer, int columnSize )
* 80.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @see #DEFAULT_INDENTATION_SIZE
* @see #writeComment(XMLWriter, String, int, int)
*/
@@ -145,7 +145,7 @@ public static void writeComment( XMLWriter writer, String comment )
* 80 and is indented by indent using 2 as indentation size.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @param indent positive number
* @see #DEFAULT_INDENTATION_SIZE
* @see #writeComment(XMLWriter, String, int, int)
@@ -160,7 +160,7 @@ public static void writeComment( XMLWriter writer, String comment, int indent )
* 80 and is indented by indent using indentSize.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @param indent positive number
* @param indentSize positive number
* @see #DEFAULT_COLUMN_LINE
@@ -176,7 +176,7 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i
* columnSize and is indented by indent using indentSize.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @param indent positive number
* @param indentSize positive number
* @param columnSize positive number
@@ -266,7 +266,7 @@ public static void writeComment( XMLWriter writer, String comment, int indent, i
* Convenience method to write XML comments between two comments line break. The XML comment block is not indented.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @see #DEFAULT_INDENTATION_SIZE
* @see #writeCommentText(XMLWriter, String, int, int)
*/
@@ -280,7 +280,7 @@ public static void writeCommentText( XMLWriter writer, String comment )
* by indent using 2 as indentation size.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @param indent positive number
* @see #DEFAULT_INDENTATION_SIZE
* @see #writeCommentText(XMLWriter, String, int, int)
@@ -295,7 +295,7 @@ public static void writeCommentText( XMLWriter writer, String comment, int inden
* indent using indentSize.
*
* @param writer not null
- * @param comment
+ * @param comment the comment
* @param indent positive number
* @param indentSize positive number
* @see #DEFAULT_COLUMN_LINE
@@ -311,7 +311,7 @@ public static void writeCommentText( XMLWriter writer, String comment, int inden
* by indent using indentSize. The column size could be also be specified.
*
* @param writer not null
- * @param comment
+ * @param comment comment
* @param indent positive number
* @param indentSize positive number
* @param columnSize positive number
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
index 49b25f89..4f268f9d 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java
@@ -16,13 +16,13 @@
* limitations under the License.
*/
+import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -31,7 +31,7 @@
import java.util.Map;
/**
- * @version $Id$ NOTE: remove all the util code in here when separated, this class should be pure data.
+ * NOTE: remove all the util code in here when separated, this class should be pure data.
*/
public class Xpp3Dom
implements Serializable
@@ -76,6 +76,8 @@ public class Xpp3Dom
public static final String SELF_COMBINATION_MERGE = "merge";
+ public static final String SELF_COMBINATION_REMOVE = "remove";
+
/**
* This default mode for combining a DOM node during merge means that where element names match, the process will
* try to merge the element attributes and values, rather than overriding the recessive element completely with the
@@ -87,11 +89,13 @@ public class Xpp3Dom
public Xpp3Dom( String name )
{
this.name = name;
- childList = new ArrayList();
+ childList = new ArrayList<>();
}
/**
* @since 3.2.0
+ * @param inputLocation The input location.
+ * @param name The name of the Dom.
*/
public Xpp3Dom( String name, Object inputLocation )
{
@@ -101,6 +105,7 @@ public Xpp3Dom( String name, Object inputLocation )
/**
* Copy constructor.
+ * @param src The source Dom.
*/
public Xpp3Dom( Xpp3Dom src )
{
@@ -109,6 +114,8 @@ public Xpp3Dom( Xpp3Dom src )
/**
* Copy constructor with alternative name.
+ * @param src The source Dom.
+ * @param name The name of the Dom.
*/
public Xpp3Dom( Xpp3Dom src, String name )
{
@@ -177,6 +184,17 @@ public String getAttribute( String name )
return ( null != attributes ) ? attributes.get( name ) : null;
}
+ /**
+ *
+ * @param name name of the attribute to be removed
+ * @return true if the attribute has been removed
+ * @since 3.4.0
+ */
+ public boolean removeAttribute( String name )
+ {
+ return StringUtils.isEmpty( name ) ? false: attributes.remove( name ) == null;
+ }
+
/**
* Set the attribute value
*
@@ -301,6 +319,13 @@ public void removeChild( int i )
child.setParent( null );
}
+ public void removeChild( Xpp3Dom child )
+ {
+ childList.remove( child );
+ // In case of any dangling references
+ child.setParent( null );
+ }
+
// ----------------------------------------------------------------------
// Parent handling
// ----------------------------------------------------------------------
@@ -321,6 +346,7 @@ public void setParent( Xpp3Dom parent )
/**
* @since 3.2.0
+ * @return input location
*/
public Object getInputLocation()
{
@@ -329,6 +355,7 @@ public Object getInputLocation()
/**
* @since 3.2.0
+ * @param inputLocation input location to set
*/
public void setInputLocation( Object inputLocation )
{
@@ -418,7 +445,7 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
{
for ( String attr : recessive.attributes.keySet() )
{
- if ( isEmpty( dominant.getAttribute( attr ) ) )
+ if ( isEmpty( dominant.getAttribute( attr ) ) && !SELF_COMBINATION_MODE_ATTRIBUTE.equals( attr ) )
{
dominant.setAttribute( attr, recessive.getAttribute( attr ) );
}
@@ -489,7 +516,17 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
else if ( it.hasNext() )
{
Xpp3Dom dominantChild = it.next();
- mergeIntoXpp3Dom( dominantChild, recessiveChild, childMergeOverride );
+
+ String dominantChildCombinationMode =
+ dominantChild.getAttribute( SELF_COMBINATION_MODE_ATTRIBUTE );
+ if ( SELF_COMBINATION_REMOVE.equals( dominantChildCombinationMode ) )
+ {
+ dominant.removeChild( dominantChild );
+ }
+ else
+ {
+ mergeIntoXpp3Dom( dominantChild, recessiveChild, childMergeOverride );
+ }
}
}
}
@@ -506,6 +543,7 @@ else if ( it.hasNext() )
* @param recessive The recessive DOM, which will be merged into the dominant DOM
* @param childMergeOverride Overrides attribute flags to force merging or appending of child elements into the
* dominant DOM
+ * @return merged DOM
*/
public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
{
@@ -525,6 +563,7 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
* @see #SELF_COMBINATION_MODE_ATTRIBUTE
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
* @param recessive The recessive DOM, which will be merged into the dominant DOM
+ * @return merged DOM
*/
public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
{
@@ -540,6 +579,7 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
// Standard object handling
// ----------------------------------------------------------------------
+ @Override
public boolean equals( Object obj )
{
if ( obj == this )
@@ -576,6 +616,7 @@ else if ( childList == null ? dom.childList != null : !childList.equals( dom.chi
}
}
+ @Override
public int hashCode()
{
int result = 17;
@@ -586,6 +627,7 @@ public int hashCode()
return result;
}
+ @Override
public String toString()
{
// TODO: WARNING! Later versions of plexus-utils psit out an header due to thinking this is a new
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
index ffe108d5..6749dd25 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomBuilder.java
@@ -28,7 +28,7 @@
import java.util.List;
/**
- * @version $Id$
+ *
*/
public class Xpp3DomBuilder
{
@@ -41,7 +41,12 @@ public static Xpp3Dom build( Reader reader )
}
/**
+ * @param reader the reader
+ * @param locationBuilder the builder
* @since 3.2.0
+ * @return DOM
+ * @throws XmlPullParserException xml exception
+ * @throws IOException io
*/
public static Xpp3Dom build( Reader reader, InputLocationBuilder locationBuilder )
throws XmlPullParserException, IOException
@@ -82,7 +87,13 @@ public static Xpp3Dom build( Reader reader, boolean trim )
}
/**
+ * @param reader the reader
+ * @param trim to trim
+ * @param locationBuilder the builder
* @since 3.2.0
+ * @return DOM
+ * @throws XmlPullParserException xml exception
+ * @throws IOException io
*/
public static Xpp3Dom build( Reader reader, boolean trim, InputLocationBuilder locationBuilder )
throws XmlPullParserException, IOException
@@ -118,13 +129,19 @@ public static Xpp3Dom build( XmlPullParser parser, boolean trim )
/**
* @since 3.2.0
+ * @param locationBuilder builder
+ * @param parser the parser
+ * @param trim do trim
+ * @return DOM
+ * @throws XmlPullParserException xml exception
+ * @throws IOException io
*/
public static Xpp3Dom build( XmlPullParser parser, boolean trim, InputLocationBuilder locationBuilder )
throws XmlPullParserException, IOException
{
- List elements = new ArrayList();
+ List elements = new ArrayList<>();
- List values = new ArrayList();
+ List values = new ArrayList<>();
int eventType = parser.getEventType();
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
index 70d00143..555f481e 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
@@ -1,5 +1,9 @@
package org.codehaus.plexus.util.xml;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
/*
* Copyright The Codehaus Foundation.
*
@@ -18,12 +22,6 @@
import org.codehaus.plexus.util.xml.pull.XmlSerializer;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
/** @author Jason van Zyl */
public class Xpp3DomUtils
{
@@ -52,6 +50,14 @@ public class Xpp3DomUtils
* @since 3.0.22
*/
public static final String ID_COMBINATION_MODE_ATTRIBUTE = "combine.id";
+
+ /**
+ * In case of complex XML structures, combining can be done based on keys.
+ * This is a comma separated list of attribute names.
+ *
+ * @since 3.4.0
+ */
+ public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = "combine.keys";
/**
* This default mode for combining a DOM node during merge means that where element names match, the process will
@@ -89,8 +95,6 @@ public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3D
*
*
If mergeSelf == true
*
- *
if the dominant root node's value is empty, set it to the recessive root node's value
- *
For each attribute in the recessive root node which is not set in the dominant root node, set it.
*
Determine whether children from the recessive DOM will be merged or appended to the dominant DOM as
* siblings (flag=mergeChildren).
*
@@ -106,6 +110,8 @@ public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3D
*
*
if 'combine.id' is set and there is a corresponding dominant child (matched by value of 'combine.id'),
* merge the two.
+ *
if 'combine.keys' is set and there is a corresponding dominant child (matched by value of key elements),
+ * merge the two.
*
if mergeChildren == true and there is a corresponding dominant child (matched by element name),
* merge the two.
*
otherwise, add the recessive child as a new child on the dominant root node.
@@ -132,12 +138,6 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
if ( mergeSelf )
{
- if ( isEmpty( dominant.getValue() ) && !isEmpty( recessive.getValue() ) )
- {
- dominant.setValue( recessive.getValue() );
- dominant.setInputLocation( recessive.getInputLocation() );
- }
-
String[] recessiveAttrs = recessive.getAttributeNames();
for ( String attr : recessiveAttrs )
{
@@ -163,6 +163,8 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
}
}
+ final String keysValue = recessive.getAttribute( KEYS_COMBINATION_MODE_ATTRIBUTE );
+
Xpp3Dom[] children = recessive.getChildren();
for ( Xpp3Dom recessiveChild : children )
{
@@ -181,6 +183,32 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
}
}
}
+ else if ( isNotEmpty( keysValue ) )
+ {
+ String[] keys = keysValue.split( "," );
+ Map recessiveKeyValues = new HashMap<>( keys.length );
+ for ( String key : keys )
+ {
+ recessiveKeyValues.put( key, recessiveChild.getAttribute( key ) );
+ }
+
+ for ( Xpp3Dom dominantChild : dominant.getChildren() )
+ {
+ Map dominantKeyValues = new HashMap<>( keys.length );
+ for ( String key : keys )
+ {
+ dominantKeyValues.put( key, dominantChild.getAttribute( key ) );
+ }
+
+ if ( recessiveKeyValues.equals( dominantKeyValues ) )
+ {
+ childDom = dominantChild;
+ // we have a match, so don't append but merge
+ mergeChildren = true;
+ }
+ }
+
+ }
else
{
childDom = dominant.getChild( recessiveChild.getName() );
@@ -207,6 +235,7 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
* @param recessive The recessive DOM, which will be merged into the dominant DOM
* @param childMergeOverride Overrides attribute flags to force merging or appending of child elements into the
* dominant DOM
+ * @return merged DOM
*/
public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride )
{
@@ -226,6 +255,7 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boolean
* @see #SELF_COMBINATION_MODE_ATTRIBUTE
* @param dominant The dominant DOM into which the recessive value/attributes/children will be merged
* @param recessive The recessive DOM, which will be merged into the dominant DOM
+ * @return merged DOM
*/
public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
{
@@ -237,13 +267,21 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive )
return recessive;
}
+ /**
+ * @deprecated Use {@link org.codehaus.plexus.util.StringUtils#isNotEmpty(String)} instead
+ */
+ @Deprecated
public static boolean isNotEmpty( String str )
{
return ( str != null && str.length() > 0 );
}
+ /**
+ * @deprecated Use {@link org.codehaus.plexus.util.StringUtils#isEmpty(String)} instead
+ */
+ @Deprecated
public static boolean isEmpty( String str )
{
- return ( str == null || str.trim().length() == 0 );
+ return ( str == null || str.length() == 0 );
}
}
diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java
index c257a22f..91770cab 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomWriter.java
@@ -20,7 +20,7 @@
import java.io.Writer;
/**
- * @version $Id$
+ *
*/
public class Xpp3DomWriter
{
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
index 38a9ba1a..d44c9a7f 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java
@@ -11,10 +11,12 @@
import java.io.EOFException;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlReader;
//import java.util.Hashtable;
@@ -36,26 +38,26 @@ public class MXParser
implements XmlPullParser
{
// NOTE: no interning of those strings --> by Java leng spec they MUST be already interned
- protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace";
+ private final static String XML_URI = "http://www.w3.org/XML/1998/namespace";
- protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+ private final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
- protected final static String FEATURE_XML_ROUNDTRIP =
+ private final static String FEATURE_XML_ROUNDTRIP =
// "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
"http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
- protected final static String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned";
+ private final static String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned";
- protected final static String PROPERTY_XMLDECL_VERSION =
+ private final static String PROPERTY_XMLDECL_VERSION =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-version";
- protected final static String PROPERTY_XMLDECL_STANDALONE =
+ private final static String PROPERTY_XMLDECL_STANDALONE =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone";
- protected final static String PROPERTY_XMLDECL_CONTENT =
+ private final static String PROPERTY_XMLDECL_CONTENT =
"http://xmlpull.org/v1/doc/properties.html#xmldecl-content";
- protected final static String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location";
+ private final static String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location";
/**
* Implementation notice: the is instance variable that controls if newString() is interning.
@@ -65,19 +67,19 @@ public class MXParser
*
* NOTE: by default in this minimal implementation it is false!
*/
- protected boolean allStringsInterned;
+ private boolean allStringsInterned;
- protected void resetStringCache()
+ private void resetStringCache()
{
// System.out.println("resetStringCache() minimum called");
}
- protected String newString( char[] cbuf, int off, int len )
+ private String newString( char[] cbuf, int off, int len )
{
return new String( cbuf, off, len );
}
- protected String newStringIntern( char[] cbuf, int off, int len )
+ private String newStringIntern( char[] cbuf, int off, int len )
{
return ( new String( cbuf, off, len ) ).intern();
}
@@ -85,48 +87,50 @@ protected String newStringIntern( char[] cbuf, int off, int len )
private static final boolean TRACE_SIZING = false;
// NOTE: features are not resetable and typically defaults to false ...
- protected boolean processNamespaces;
+ private boolean processNamespaces;
- protected boolean roundtripSupported;
+ private boolean roundtripSupported;
// global parser state
- protected String location;
+ private String location;
- protected int lineNumber;
+ private int lineNumber;
- protected int columnNumber;
+ private int columnNumber;
- protected boolean seenRoot;
+ private boolean seenRoot;
- protected boolean reachedEnd;
+ private boolean reachedEnd;
- protected int eventType;
+ private int eventType;
- protected boolean emptyElementTag;
+ private boolean emptyElementTag;
// element stack
- protected int depth;
+ private int depth;
- protected char[] elRawName[];
+ private char[] elRawName[];
- protected int elRawNameEnd[];
+ private int elRawNameEnd[];
- protected int elRawNameLine[];
+ private int elRawNameLine[];
- protected String elName[];
+ private String elName[];
- protected String elPrefix[];
+ private String elPrefix[];
- protected String elUri[];
+ private String elUri[];
- // protected String elValue[];
- protected int elNamespaceCount[];
+ // private String elValue[];
+ private int elNamespaceCount[];
+
+ private String fileEncoding = null;
/**
* Make sure that we have enough space to keep element stack if passed size. It will always create one additional
* slot then current depth
*/
- protected void ensureElementsCapacity()
+ private void ensureElementsCapacity()
{
final int elStackSize = elName != null ? elName.length : 0;
if ( ( depth + 1 ) >= elStackSize )
@@ -204,26 +208,24 @@ protected void ensureElementsCapacity()
}
// attribute stack
- protected int attributeCount;
+ private int attributeCount;
- protected String attributeName[];
+ private String attributeName[];
- protected int attributeNameHash[];
+ private int attributeNameHash[];
- // protected int attributeNameStart[];
- // protected int attributeNameEnd[];
- protected String attributePrefix[];
+ // private int attributeNameStart[];
+ // private int attributeNameEnd[];
+ private String attributePrefix[];
- protected String attributeUri[];
+ private String attributeUri[];
- protected String attributeValue[];
- // protected int attributeValueStart[];
- // protected int attributeValueEnd[];
+ private String attributeValue[];
+ // private int attributeValueStart[];
+ // private int attributeValueEnd[];
- /**
- * Make sure that in attributes temporary array is enough space.
- */
- protected void ensureAttributesCapacity( int size )
+ // Make sure that in attributes temporary array is enough space.
+ private void ensureAttributesCapacity( int size )
{
final int attrPosSize = attributeName != null ? attributeName.length : 0;
if ( size >= attrPosSize )
@@ -270,15 +272,15 @@ protected void ensureAttributesCapacity( int size )
}
// namespace stack
- protected int namespaceEnd;
+ private int namespaceEnd;
- protected String namespacePrefix[];
+ private String namespacePrefix[];
- protected int namespacePrefixHash[];
+ private int namespacePrefixHash[];
- protected String namespaceUri[];
+ private String namespaceUri[];
- protected void ensureNamespacesCapacity( int size )
+ private void ensureNamespacesCapacity( int size )
{
final int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0;
if ( size >= namespaceSize )
@@ -312,11 +314,11 @@ protected void ensureNamespacesCapacity( int size )
}
}
- /**
- * simplistic implementation of hash function that has constant time to compute - so it also means
- * diminishing hash quality for long strings but for XML parsing it should be good enough ...
- */
- protected static final int fastHash( char ch[], int off, int len )
+
+ // simplistic implementation of hash function that has constant time to compute - so it also means
+ // diminishing hash quality for long strings but for XML parsing it should be good enough ...
+
+ private static final int fastHash( char ch[], int off, int len )
{
if ( len == 0 )
return 0;
@@ -339,21 +341,21 @@ protected static final int fastHash( char ch[], int off, int len )
}
// entity replacement stack
- protected int entityEnd;
+ private int entityEnd;
- protected String entityName[];
+ private String entityName[];
- protected char[] entityNameBuf[];
+ private char[] entityNameBuf[];
- protected String entityReplacement[];
+ private String entityReplacement[];
- protected char[] entityReplacementBuf[];
+ private char[] entityReplacementBuf[];
- protected int entityNameHash[];
+ private int entityNameHash[];
private final EntityReplacementMap replacementMapTemplate;
- protected void ensureEntityCapacity()
+ private void ensureEntityCapacity()
{
final int entitySize = entityReplacementBuf != null ? entityReplacementBuf.length : 0;
if ( entityEnd >= entitySize )
@@ -392,75 +394,77 @@ protected void ensureEntityCapacity()
}
// input buffer management
- protected static final int READ_CHUNK_SIZE = 8 * 1024; // max data chars in one read() call
+ private static final int READ_CHUNK_SIZE = 8 * 1024; // max data chars in one read() call
+
+ private Reader reader;
- protected Reader reader;
+ private String inputEncoding;
- protected String inputEncoding;
+ private int bufLoadFactor = 95; // 99%
+ // private int bufHardLimit; // only matters when expanding
- protected int bufLoadFactor = 95; // 99%
- // protected int bufHardLimit; // only matters when expanding
+ private float bufferLoadFactor = bufLoadFactor / 100f;
- protected char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256];
+ private char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256];
- protected int bufSoftLimit = ( bufLoadFactor * buf.length ) / 100; // desirable size of buffer
+ private int bufSoftLimit = (int) ( bufferLoadFactor * buf.length ); // desirable size of buffer
- protected boolean preventBufferCompaction;
+ private boolean preventBufferCompaction;
- protected int bufAbsoluteStart; // this is buf
+ private int bufAbsoluteStart; // this is buf
- protected int bufStart;
+ private int bufStart;
- protected int bufEnd;
+ private int bufEnd;
- protected int pos;
+ private int pos;
- protected int posStart;
+ private int posStart;
- protected int posEnd;
+ private int posEnd;
- protected char pc[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 64];
+ private char pc[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 64];
- protected int pcStart;
+ private int pcStart;
- protected int pcEnd;
+ private int pcEnd;
// parsing state
- // protected boolean needsMore;
- // protected boolean seenMarkup;
- protected boolean usePC;
+ // private boolean needsMore;
+ // private boolean seenMarkup;
+ private boolean usePC;
- protected boolean seenStartTag;
+ private boolean seenStartTag;
- protected boolean seenEndTag;
+ private boolean seenEndTag;
- protected boolean pastEndTag;
+ private boolean pastEndTag;
- protected boolean seenAmpersand;
+ private boolean seenAmpersand;
- protected boolean seenMarkup;
+ private boolean seenMarkup;
- protected boolean seenDocdecl;
+ private boolean seenDocdecl;
// transient variable set during each call to next/Token()
- protected boolean tokenize;
+ private boolean tokenize;
- protected String text;
+ private String text;
- protected String entityRefName;
+ private String entityRefName;
- protected String xmlDeclVersion;
+ private String xmlDeclVersion;
- protected Boolean xmlDeclStandalone;
+ private Boolean xmlDeclStandalone;
- protected String xmlDeclContent;
+ private String xmlDeclContent;
- protected void reset()
+ private void reset()
{
// System.out.println("reset() called");
location = null;
lineNumber = 1;
- columnNumber = 0;
+ columnNumber = 1;
seenRoot = false;
reachedEnd = false;
eventType = START_DOCUMENT;
@@ -534,8 +538,9 @@ public void setupFromTemplate()
*
* @param name a String
* @param state a boolean
- * @throws XmlPullParserException
+ * @throws XmlPullParserException issue
*/
+ @Override
public void setFeature( String name, boolean state )
throws XmlPullParserException
{
@@ -582,9 +587,10 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
}
}
- /**
- * Unknown properties are always returned as false
+ /**
+ * Unknown properties are always returned as false
*/
+ @Override
public boolean getFeature( String name )
{
if ( name == null )
@@ -613,6 +619,7 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
return false;
}
+ @Override
public void setProperty( String name, Object value )
throws XmlPullParserException
{
@@ -626,6 +633,7 @@ public void setProperty( String name, Object value )
}
}
+ @Override
public Object getProperty( String name )
{
if ( name == null )
@@ -649,13 +657,29 @@ else if ( PROPERTY_LOCATION.equals( name ) )
return null;
}
+ @Override
public void setInput( Reader in )
throws XmlPullParserException
{
reset();
reader = in;
+
+ if ( reader instanceof XmlReader ) {
+ // encoding already detected
+ XmlReader xsr = (XmlReader) reader;
+ fileEncoding = xsr.getEncoding();
+ }
+ else if ( reader instanceof InputStreamReader )
+ {
+ InputStreamReader isr = (InputStreamReader) reader;
+ if ( isr.getEncoding() != null )
+ {
+ fileEncoding = isr.getEncoding().toUpperCase();
+ }
+ }
}
+ @Override
public void setInput( java.io.InputStream inputStream, String inputEncoding )
throws XmlPullParserException
{
@@ -689,11 +713,13 @@ public void setInput( java.io.InputStream inputStream, String inputEncoding )
this.inputEncoding = inputEncoding;
}
+ @Override
public String getInputEncoding()
{
return inputEncoding;
}
+ @Override
public void defineEntityReplacementText( String entityName, String replacementText )
throws XmlPullParserException
{
@@ -711,7 +737,7 @@ public void defineEntityReplacementText( String entityName, String replacementTe
}
}
- // protected char[] entityReplacement[];
+ // private char[] entityReplacement[];
ensureEntityCapacity();
// this is to make sure that if interning works we will take advantage of it ...
@@ -730,10 +756,11 @@ public void defineEntityReplacementText( String entityName, String replacementTe
// TOOD keepEntityNormalizedForAttributeValue cached as well ...
}
+ @Override
public int getNamespaceCount( int depth )
throws XmlPullParserException
{
- if ( processNamespaces == false || depth == 0 )
+ if ( !processNamespaces || depth == 0 )
{
return 0;
}
@@ -744,6 +771,7 @@ public int getNamespaceCount( int depth )
return elNamespaceCount[depth];
}
+ @Override
public String getNamespacePrefix( int pos )
throws XmlPullParserException
{
@@ -761,6 +789,7 @@ public String getNamespacePrefix( int pos )
}
}
+ @Override
public String getNamespaceUri( int pos )
throws XmlPullParserException
{
@@ -777,6 +806,7 @@ public String getNamespaceUri( int pos )
}
}
+ @Override
public String getNamespace( String prefix )
// throws XmlPullParserException
{
@@ -813,6 +843,7 @@ else if ( "xmlns".equals( prefix ) )
return null;
}
+ @Override
public int getDepth()
{
return depth;
@@ -848,6 +879,7 @@ private static int findFragment( int bufMinPos, char[] b, int start, int end )
/**
* Return string describing current position of parsers as text 'STATE [seen %s...] @line:column'.
*/
+ @Override
public String getPositionDescription()
{
String fragment = null;
@@ -869,16 +901,19 @@ public String getPositionDescription()
+ ( location != null ? location : "" ) + "@" + getLineNumber() + ":" + getColumnNumber();
}
+ @Override
public int getLineNumber()
{
return lineNumber;
}
+ @Override
public int getColumnNumber()
{
return columnNumber;
}
+ @Override
public boolean isWhitespace()
throws XmlPullParserException
{
@@ -910,6 +945,7 @@ else if ( eventType == IGNORABLE_WHITESPACE )
throw new XmlPullParserException( "no content available to check for whitespaces" );
}
+ @Override
public String getText()
{
if ( eventType == START_DOCUMENT || eventType == END_DOCUMENT )
@@ -939,6 +975,7 @@ else if ( eventType == ENTITY_REF )
return text;
}
+ @Override
public char[] getTextCharacters( int[] holderForStartAndLength )
{
if ( eventType == TEXT )
@@ -986,6 +1023,7 @@ else if ( eventType == START_DOCUMENT || eventType == END_DOCUMENT )
// return cb;
}
+ @Override
public String getNamespace()
{
if ( eventType == START_TAG )
@@ -1016,6 +1054,7 @@ else if ( eventType == END_TAG )
// return "";
}
+ @Override
public String getName()
{
if ( eventType == START_TAG )
@@ -1041,6 +1080,7 @@ else if ( eventType == ENTITY_REF )
}
}
+ @Override
public String getPrefix()
{
if ( eventType == START_TAG )
@@ -1058,6 +1098,7 @@ else if ( eventType == END_TAG )
// return elPrefix[ maxDepth ];
}
+ @Override
public boolean isEmptyElementTag()
throws XmlPullParserException
{
@@ -1066,6 +1107,7 @@ public boolean isEmptyElementTag()
return emptyElementTag;
}
+ @Override
public int getAttributeCount()
{
if ( eventType != START_TAG )
@@ -1073,11 +1115,12 @@ public int getAttributeCount()
return attributeCount;
}
+ @Override
public String getAttributeNamespace( int index )
{
if ( eventType != START_TAG )
throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
- if ( processNamespaces == false )
+ if ( !processNamespaces )
return NO_NAMESPACE;
if ( index < 0 || index >= attributeCount )
throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
@@ -1085,6 +1128,7 @@ public String getAttributeNamespace( int index )
return attributeUri[index];
}
+ @Override
public String getAttributeName( int index )
{
if ( eventType != START_TAG )
@@ -1095,11 +1139,12 @@ public String getAttributeName( int index )
return attributeName[index];
}
+ @Override
public String getAttributePrefix( int index )
{
if ( eventType != START_TAG )
throw new IndexOutOfBoundsException( "only START_TAG can have attributes" );
- if ( processNamespaces == false )
+ if ( !processNamespaces )
return null;
if ( index < 0 || index >= attributeCount )
throw new IndexOutOfBoundsException( "attribute position must be 0.." + ( attributeCount - 1 ) + " and not "
@@ -1107,6 +1152,7 @@ public String getAttributePrefix( int index )
return attributePrefix[index];
}
+ @Override
public String getAttributeType( int index )
{
if ( eventType != START_TAG )
@@ -1117,6 +1163,7 @@ public String getAttributeType( int index )
return "CDATA";
}
+ @Override
public boolean isAttributeDefault( int index )
{
if ( eventType != START_TAG )
@@ -1127,6 +1174,7 @@ public boolean isAttributeDefault( int index )
return false;
}
+ @Override
public String getAttributeValue( int index )
{
if ( eventType != START_TAG )
@@ -1137,6 +1185,7 @@ public String getAttributeValue( int index )
return attributeValue[index];
}
+ @Override
public String getAttributeValue( String namespace, String name )
{
if ( eventType != START_TAG )
@@ -1183,16 +1232,18 @@ public String getAttributeValue( String namespace, String name )
return null;
}
+ @Override
public int getEventType()
throws XmlPullParserException
{
return eventType;
}
+ @Override
public void require( int type, String namespace, String name )
throws XmlPullParserException, IOException
{
- if ( processNamespaces == false && namespace != null )
+ if ( !processNamespaces && namespace != null )
{
throw new XmlPullParserException( "processing namespaces must be enabled on parser (or factory)"
+ " to have possible namespaces declared on elements" + ( " (position:" + getPositionDescription() )
@@ -1217,8 +1268,10 @@ && getNamespace() != null && !namespace.equals( getNamespace() ) ? " and" : "" )
}
/**
- * Skip sub tree that is currently parser positioned on.
+ *
Skip sub tree that is currently parser positioned on.
* NOTE: parser must be on START_TAG and when function returns parser will be positioned on corresponding END_TAG
+ * @throws XmlPullParserException issue
+ * @throws IOException io
*/
public void skipSubTree()
throws XmlPullParserException, IOException
@@ -1247,6 +1300,7 @@ else if ( eventType == START_TAG )
// return result;
// }
+ @Override
public String nextText()
throws XmlPullParserException, IOException
{
@@ -1296,6 +1350,7 @@ else if ( eventType == END_TAG )
}
}
+ @Override
public int nextTag()
throws XmlPullParserException, IOException
{
@@ -1312,6 +1367,7 @@ public int nextTag()
return eventType;
}
+ @Override
public int next()
throws XmlPullParserException, IOException
{
@@ -1319,6 +1375,7 @@ public int next()
return nextImpl();
}
+ @Override
public int nextToken()
throws XmlPullParserException, IOException
{
@@ -1326,7 +1383,7 @@ public int nextToken()
return nextImpl();
}
- protected int nextImpl()
+ private int nextImpl()
throws XmlPullParserException, IOException
{
text = null;
@@ -1539,11 +1596,11 @@ else if ( ch == '&' )
}
final int oldStart = posStart + bufAbsoluteStart;
final int oldEnd = posEnd + bufAbsoluteStart;
- final char[] resolvedEntity = parseEntityRef();
+ parseEntityRef();
if ( tokenize )
return eventType = ENTITY_REF;
// check if replacement text can be resolved !!!
- if ( resolvedEntity == null )
+ if ( resolvedEntityRefCharBuf == BUF_NOT_RESOLVED )
{
if ( entityRefName == null )
{
@@ -1571,7 +1628,7 @@ else if ( ch == '&' )
}
// assert usePC == true;
// write into PC replacement text - do merge for replacement text!!!!
- for ( char aResolvedEntity : resolvedEntity )
+ for ( char aResolvedEntity : resolvedEntityRefCharBuf )
{
if ( pcEnd >= pc.length )
{
@@ -1601,7 +1658,7 @@ else if ( ch == '&' )
hadCharData = true;
boolean normalizedCR = false;
- final boolean normalizeInput = tokenize == false || roundtripSupported == false;
+ final boolean normalizeInput = !tokenize || !roundtripSupported;
// use loop locality here!!!!
boolean seenBracket = false;
boolean seenBracketBracket = false;
@@ -1702,7 +1759,7 @@ else if ( ch == '\n' )
}
}
- protected int parseProlog()
+ private int parseProlog()
throws XmlPullParserException, IOException
{
// [2] prolog: ::= XMLDecl? Misc* (doctypedecl Misc*)? and look for [39] element
@@ -1732,11 +1789,22 @@ protected int parseProlog()
// skipping UNICODE int Order Mark (so called BOM)
ch = more();
}
+ else if ( ch == '\uFFFD' )
+ {
+ // UTF-16 BOM in an UTF-8 encoded file?
+ // This is a hack...not the best way to check for BOM in UTF-16
+ ch = more();
+ if ( ch == '\uFFFD' )
+ {
+ throw new XmlPullParserException( "UTF-16 BOM in a UTF-8 encoded file is incompatible", this,
+ null );
+ }
+ }
}
seenMarkup = false;
boolean gotS = false;
posStart = pos - 1;
- final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
+ final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
boolean normalizedCR = false;
while ( true )
{
@@ -1868,7 +1936,7 @@ else if ( ch == '\n' )
}
}
- protected int parseEpilog()
+ private int parseEpilog()
throws XmlPullParserException, IOException
{
if ( eventType == END_DOCUMENT )
@@ -1880,7 +1948,7 @@ protected int parseEpilog()
return eventType = END_DOCUMENT;
}
boolean gotS = false;
- final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
+ final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
boolean normalizedCR = false;
try
{
@@ -2038,19 +2106,12 @@ else if ( ch == '\n' )
{
reachedEnd = true;
}
- if ( reachedEnd )
+ if ( tokenize && gotS )
{
- if ( tokenize && gotS )
- {
- posEnd = pos; // well - this is LAST available character pos
- return eventType = IGNORABLE_WHITESPACE;
- }
- return eventType = END_DOCUMENT;
- }
- else
- {
- throw new XmlPullParserException( "internal error in parseEpilog" );
+ posEnd = pos; // well - this is LAST available character pos
+ return eventType = IGNORABLE_WHITESPACE;
}
+ return eventType = END_DOCUMENT;
}
public int parseEndTag()
@@ -2219,7 +2280,6 @@ else if ( isNameStartChar( ch ) )
{
ch = parseAttribute();
ch = more();
- continue;
}
else
{
@@ -2331,7 +2391,7 @@ else if ( isNameStartChar( ch ) )
return eventType = START_TAG;
}
- protected char parseAttribute()
+ private char parseAttribute()
throws XmlPullParserException, IOException
{
// parse attribute
@@ -2503,44 +2563,7 @@ else if ( xmlnsPos == 5 )
}
if ( ch == '&' )
{
- // extractEntityRef
- posEnd = pos - 1;
- if ( !usePC )
- {
- final boolean hadCharData = posEnd > posStart;
- if ( hadCharData )
- {
- // posEnd is already set correctly!!!
- joinPC();
- }
- else
- {
- usePC = true;
- pcStart = pcEnd = 0;
- }
- }
- // assert usePC == true;
-
- final char[] resolvedEntity = parseEntityRef();
- // check if replacement text can be resolved !!!
- if ( resolvedEntity == null )
- {
- if ( entityRefName == null )
- {
- entityRefName = newString( buf, posStart, posEnd - posStart );
- }
- throw new XmlPullParserException( "could not resolve entity named '" + printable( entityRefName )
- + "'", this, null );
- }
- // write into PC replacement text - do merge for replacement text!!!!
- for ( char aResolvedEntity : resolvedEntity )
- {
- if ( pcEnd >= pc.length )
- {
- ensurePC( pcEnd );
- }
- pc[pcEnd++] = aResolvedEntity;
- }
+ extractEntityRef();
}
else if ( ch == '\t' || ch == '\n' || ch == '\r' )
{
@@ -2652,9 +2675,28 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' )
return ch;
}
- protected char[] charRefOneCharBuf = new char[1];
+ // state representing that no entity ref have been resolved
+ private static final char[] BUF_NOT_RESOLVED = new char[0];
+
+ // predefined entity refs
+ private static final char[] BUF_LT = new char[] { '<' };
+ private static final char[] BUF_AMP = new char[] { '&' };
+ private static final char[] BUF_GT = new char[] { '>' };
+ private static final char[] BUF_APO = new char[] { '\'' };
+ private static final char[] BUF_QUOT = new char[] { '"' };
+
+ private char[] resolvedEntityRefCharBuf = BUF_NOT_RESOLVED;
- protected char[] parseEntityRef()
+ /**
+ * parse Entity Ref, either a character entity or one of the predefined name entities.
+ *
+ * @return the length of the valid found character reference, which may be one of the predefined character reference
+ * names (resolvedEntityRefCharBuf contains the replaced chars). Returns the length of the not found entity
+ * name, otherwise.
+ * @throws XmlPullParserException if invalid XML is detected.
+ * @throws IOException if an I/O error is found.
+ */
+ private int parseCharOrPredefinedEntityRef()
throws XmlPullParserException, IOException
{
// entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference
@@ -2663,6 +2705,8 @@ protected char[] parseEntityRef()
// ASSUMPTION just after &
entityRefName = null;
posStart = pos;
+ int len = 0;
+ resolvedEntityRefCharBuf = BUF_NOT_RESOLVED;
char ch = more();
if ( ch == '#' )
{
@@ -2727,12 +2771,23 @@ else if ( ch >= 'A' && ch <= 'F' )
ch = more();
}
}
- posEnd = pos - 1;
+
+ boolean isValidCodePoint = true;
try
{
- charRefOneCharBuf = toChars( Integer.parseInt( sb.toString(), isHex ? 16 : 10 ) );
+ int codePoint = Integer.parseInt( sb.toString(), isHex ? 16 : 10 );
+ isValidCodePoint = isValidCodePoint( codePoint );
+ if ( isValidCodePoint )
+ {
+ resolvedEntityRefCharBuf = Character.toChars( codePoint );
+ }
}
catch ( IllegalArgumentException e )
+ {
+ isValidCodePoint = false;
+ }
+
+ if ( !isValidCodePoint )
{
throw new XmlPullParserException( "character reference (with " + ( isHex ? "hex" : "decimal" )
+ " value " + sb.toString() + ") is invalid", this, null );
@@ -2740,14 +2795,14 @@ else if ( ch >= 'A' && ch <= 'F' )
if ( tokenize )
{
- text = newString( charRefOneCharBuf, 0, charRefOneCharBuf.length );
+ text = newString( resolvedEntityRefCharBuf, 0, resolvedEntityRefCharBuf.length );
}
- return charRefOneCharBuf;
+ len = resolvedEntityRefCharBuf.length;
}
else
{
// [68] EntityRef ::= '&' Name ';'
- // scan anem until ;
+ // scan name until ;
if ( !isNameStartChar( ch ) )
{
throw new XmlPullParserException( "entity reference names can not start with character '"
@@ -2766,17 +2821,15 @@ else if ( ch >= 'A' && ch <= 'F' )
+ printable( ch ) + "'", this, null );
}
}
- posEnd = pos - 1;
// determine what name maps to
- final int len = posEnd - posStart;
+ len = ( pos - 1 ) - posStart;
if ( len == 2 && buf[posStart] == 'l' && buf[posStart + 1] == 't' )
{
if ( tokenize )
{
text = "<";
}
- charRefOneCharBuf[0] = '<';
- return charRefOneCharBuf;
+ resolvedEntityRefCharBuf = BUF_LT;
// if(paramPC || isParserTokenizing) {
// if(pcEnd >= pc.length) ensurePC();
// pc[pcEnd++] = '<';
@@ -2788,8 +2841,7 @@ else if ( len == 3 && buf[posStart] == 'a' && buf[posStart + 1] == 'm' && buf[po
{
text = "&";
}
- charRefOneCharBuf[0] = '&';
- return charRefOneCharBuf;
+ resolvedEntityRefCharBuf = BUF_AMP;
}
else if ( len == 2 && buf[posStart] == 'g' && buf[posStart + 1] == 't' )
{
@@ -2797,8 +2849,7 @@ else if ( len == 2 && buf[posStart] == 'g' && buf[posStart + 1] == 't' )
{
text = ">";
}
- charRefOneCharBuf[0] = '>';
- return charRefOneCharBuf;
+ resolvedEntityRefCharBuf = BUF_GT;
}
else if ( len == 4 && buf[posStart] == 'a' && buf[posStart + 1] == 'p' && buf[posStart + 2] == 'o'
&& buf[posStart + 3] == 's' )
@@ -2807,8 +2858,7 @@ else if ( len == 4 && buf[posStart] == 'a' && buf[posStart + 1] == 'p' && buf[po
{
text = "'";
}
- charRefOneCharBuf[0] = '\'';
- return charRefOneCharBuf;
+ resolvedEntityRefCharBuf = BUF_APO;
}
else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[posStart + 2] == 'o'
&& buf[posStart + 3] == 't' )
@@ -2817,26 +2867,77 @@ else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[po
{
text = "\"";
}
- charRefOneCharBuf[0] = '"';
- return charRefOneCharBuf;
- }
- else
- {
- final char[] result = lookuEntityReplacement( len );
- if ( result != null )
- {
- return result;
- }
+ resolvedEntityRefCharBuf = BUF_QUOT;
}
- if ( tokenize )
- text = null;
- return null;
}
+
+ posEnd = pos;
+
+ return len;
+ }
+
+ /**
+ * Parse an entity reference inside the DOCDECL section.
+ *
+ * @throws XmlPullParserException if invalid XML is detected.
+ * @throws IOException if an I/O error is found.
+ */
+ private void parseEntityRefInDocDecl()
+ throws XmlPullParserException, IOException
+ {
+ parseCharOrPredefinedEntityRef();
+ if (usePC) {
+ posStart--; // include in PC the starting '&' of the entity
+ joinPC();
+ }
+
+ if ( resolvedEntityRefCharBuf != BUF_NOT_RESOLVED )
+ return;
+ if ( tokenize )
+ text = null;
}
- protected char[] lookuEntityReplacement( int entityNameLen )
+ /**
+ * Parse an entity reference inside a tag or attribute.
+ *
+ * @throws XmlPullParserException if invalid XML is detected.
+ * @throws IOException if an I/O error is found.
+ */
+ private void parseEntityRef()
throws XmlPullParserException, IOException
+ {
+ final int len = parseCharOrPredefinedEntityRef();
+
+ posEnd--; // don't involve the final ';' from the entity in the search
+
+ if ( resolvedEntityRefCharBuf != BUF_NOT_RESOLVED ) {
+ return;
+ }
+
+ resolvedEntityRefCharBuf = lookuEntityReplacement( len );
+ if ( resolvedEntityRefCharBuf != BUF_NOT_RESOLVED )
+ {
+ return;
+ }
+ if ( tokenize )
+ text = null;
+ }
+
+ /**
+ * Check if the provided parameter is a valid Char. According to
+ * https://www.w3.org/TR/REC-xml/#NT-Char
+ *
+ * @param codePoint the numeric value to check
+ * @return true if it is a valid numeric character reference. False otherwise.
+ */
+ private static boolean isValidCodePoint( int codePoint )
+ {
+ // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
+ return codePoint == 0x9 || codePoint == 0xA || codePoint == 0xD || ( 0x20 <= codePoint && codePoint <= 0xD7FF )
+ || ( 0xE000 <= codePoint && codePoint <= 0xFFFD ) || ( 0x10000 <= codePoint && codePoint <= 0x10FFFF );
+ }
+ private char[] lookuEntityReplacement( int entityNameLen )
{
if ( !allStringsInterned )
{
@@ -2871,10 +2972,10 @@ protected char[] lookuEntityReplacement( int entityNameLen )
}
}
}
- return null;
+ return BUF_NOT_RESOLVED;
}
- protected void parseComment()
+ private void parseComment()
throws XmlPullParserException, IOException
{
// implements XML 1.0 Section 2.5 Comments
@@ -2887,10 +2988,10 @@ protected void parseComment()
posStart = pos;
final int curLine = lineNumber;
- final int curColumn = columnNumber;
+ final int curColumn = columnNumber - 4;
try
{
- final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
+ final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
boolean normalizedCR = false;
boolean seenDash = false;
@@ -2913,7 +3014,6 @@ protected void parseComment()
else
{
seenDashDash = true;
- seenDash = false;
}
}
else if ( ch == '>' )
@@ -2922,16 +3022,16 @@ else if ( ch == '>' )
{
break; // found end sequence!!!!
}
- else
- {
- seenDashDash = false;
- }
seenDash = false;
}
- else
+ else if (isValidCodePoint( ch ))
{
seenDash = false;
}
+ else
+ {
+ throw new XmlPullParserException( "Illegal character 0x" + Integer.toHexString(ch) + " found in comment", this, null );
+ }
if ( normalizeIgnorableWS )
{
if ( ch == '\r' )
@@ -2998,7 +3098,7 @@ else if ( ch == '\n' )
}
}
- protected boolean parsePI()
+ private boolean parsePI()
throws XmlPullParserException, IOException
{
// implements XML 1.0 Section 2.6 Processing Instructions
@@ -3009,15 +3109,16 @@ protected boolean parsePI()
if ( tokenize )
posStart = pos;
final int curLine = lineNumber;
- final int curColumn = columnNumber;
+ final int curColumn = columnNumber - 2;
int piTargetStart = pos;
int piTargetEnd = -1;
- final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
+ final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
boolean normalizedCR = false;
try
{
boolean seenPITarget = false;
+ boolean seenInnerTag = false;
boolean seenQ = false;
char ch = more();
if ( isS( ch ) )
@@ -3051,6 +3152,20 @@ else if ( ch == '>' )
throw new XmlPullParserException( "processing instruction PITarget name not found", this,
null );
}
+ else if ( !seenInnerTag )
+ {
+ // seenPITarget && !seenQ
+ throw new XmlPullParserException( "processing instruction started on line " + curLine
+ + " and column " + curColumn + " was not closed", this, null );
+ }
+ else
+ {
+ seenInnerTag = false;
+ }
+ }
+ else if ( ch == '<' )
+ {
+ seenInnerTag = true;
}
else
{
@@ -3059,7 +3174,7 @@ else if ( ch == '>' )
piTargetEnd = pos - 1;
// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
- if ( ( piTargetEnd - piTargetStart ) == 3 )
+ if ( ( piTargetEnd - piTargetStart ) >= 3 )
{
if ( ( buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X' )
&& ( buf[piTargetStart + 1] == 'm' || buf[piTargetStart + 1] == 'M' )
@@ -3172,17 +3287,17 @@ else if ( ch == '\n' )
// protected final static char[] YES = {'y','e','s'};
// protected final static char[] NO = {'n','o'};
- protected final static char[] VERSION = "version".toCharArray();
+ private final static char[] VERSION = "version".toCharArray();
- protected final static char[] NCODING = "ncoding".toCharArray();
+ private final static char[] NCODING = "ncoding".toCharArray();
- protected final static char[] TANDALONE = "tandalone".toCharArray();
+ private final static char[] TANDALONE = "tandalone".toCharArray();
- protected final static char[] YES = "yes".toCharArray();
+ private final static char[] YES = "yes".toCharArray();
- protected final static char[] NO = "no".toCharArray();
+ private final static char[] NO = "no".toCharArray();
- protected void parseXmlDecl( char ch )
+ private void parseXmlDecl( char ch )
throws XmlPullParserException, IOException
{
// [23] XMLDecl ::= ''
@@ -3230,9 +3345,9 @@ protected void parseXmlDecl( char ch )
parseXmlDeclWithVersion( versionStart, versionEnd );
preventBufferCompaction = false; // allow again buffer compaction - pos MAY change
}
- // protected String xmlDeclVersion;
+ // private String xmlDeclVersion;
- protected void parseXmlDeclWithVersion( int versionStart, int versionEnd )
+ private void parseXmlDeclWithVersion( int versionStart, int versionEnd )
throws XmlPullParserException, IOException
{
// check version is "1.0"
@@ -3244,11 +3359,25 @@ protected void parseXmlDeclWithVersion( int versionStart, int versionEnd )
}
xmlDeclVersion = newString( buf, versionStart, versionEnd - versionStart );
+ String lastParsedAttr = "version";
+
// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName "'" )
char ch = more();
+ char prevCh = ch;
ch = skipS( ch );
+
+ if ( ch != 'e' && ch != 's' && ch != '?' && ch != '>' )
+ {
+ throw new XmlPullParserException( "unexpected character " + printable( ch ), this, null );
+ }
+
if ( ch == 'e' )
{
+ if ( !isS( prevCh ) )
+ {
+ throw new XmlPullParserException( "expected a space after " + lastParsedAttr + " and not "
+ + printable( ch ), this, null );
+ }
ch = more();
ch = requireInput( ch, NCODING );
ch = skipS( ch );
@@ -3288,13 +3417,34 @@ protected void parseXmlDeclWithVersion( int versionStart, int versionEnd )
// TODO reconcile with setInput encodingName
inputEncoding = newString( buf, encodingStart, encodingEnd - encodingStart );
+
+ if ( "UTF8".equals( fileEncoding ) && inputEncoding.toUpperCase().startsWith( "ISO-" ) )
+ {
+ throw new XmlPullParserException( "UTF-8 BOM plus xml decl of " + inputEncoding + " is incompatible",
+ this, null );
+ }
+ else if ("UTF-16".equals( fileEncoding ) && inputEncoding.equalsIgnoreCase( "UTF-8" ))
+ {
+ throw new XmlPullParserException( "UTF-16 BOM plus xml decl of " + inputEncoding + " is incompatible",
+ this, null );
+ }
+
+ lastParsedAttr = "encoding";
+
ch = more();
+ prevCh = ch;
+ ch = skipS( ch );
}
- ch = skipS( ch );
// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
if ( ch == 's' )
{
+ if ( !isS( prevCh ) )
+ {
+ throw new XmlPullParserException( "expected a space after " + lastParsedAttr + " and not "
+ + printable( ch ), this, null );
+ }
+
ch = more();
ch = requireInput( ch, TANDALONE );
ch = skipS( ch );
@@ -3307,11 +3457,10 @@ protected void parseXmlDeclWithVersion( int versionStart, int versionEnd )
ch = skipS( ch );
if ( ch != '\'' && ch != '"' )
{
- throw new XmlPullParserException( "expected apostrophe (') or quotation mark (\") after encoding and not "
+ throw new XmlPullParserException( "expected apostrophe (') or quotation mark (\") after standalone and not "
+ printable( ch ), this, null );
}
char quotChar = ch;
- int standaloneStart = pos;
ch = more();
if ( ch == 'y' )
{
@@ -3336,9 +3485,9 @@ else if ( ch == 'n' )
+ printable( ch ), this, null );
}
ch = more();
+ ch = skipS( ch );
}
- ch = skipS( ch );
if ( ch != '?' )
{
throw new XmlPullParserException( "expected ?> as last part of '
int bracketLevel = 0;
- final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false;
+ final boolean normalizeIgnorableWS = tokenize && !roundtripSupported;
boolean normalizedCR = false;
while ( true )
{
ch = more();
if ( ch == '[' )
++bracketLevel;
- if ( ch == ']' )
+ else if ( ch == ']' )
--bracketLevel;
- if ( ch == '>' && bracketLevel == 0 )
+ else if ( ch == '>' && bracketLevel == 0 )
break;
+ else if ( ch == '&' )
+ {
+ extractEntityRefInDocDecl();
+ continue;
+ }
if ( normalizeIgnorableWS )
{
if ( ch == '\r' )
@@ -3440,9 +3594,65 @@ else if ( ch == '\n' )
}
posEnd = pos - 1;
+ text = null;
}
- protected void parseCDSect( boolean hadCharData )
+ private void extractEntityRefInDocDecl()
+ throws XmlPullParserException, IOException
+ {
+ // extractEntityRef
+ posEnd = pos - 1;
+
+ int prevPosStart = posStart;
+ parseEntityRefInDocDecl();
+
+ posStart = prevPosStart;
+ }
+
+ private void extractEntityRef()
+ throws XmlPullParserException, IOException
+ {
+ // extractEntityRef
+ posEnd = pos - 1;
+ if ( !usePC )
+ {
+ final boolean hadCharData = posEnd > posStart;
+ if ( hadCharData )
+ {
+ // posEnd is already set correctly!!!
+ joinPC();
+ }
+ else
+ {
+ usePC = true;
+ pcStart = pcEnd = 0;
+ }
+ }
+ // assert usePC == true;
+
+ parseEntityRef();
+ // check if replacement text can be resolved !!!
+ if ( resolvedEntityRefCharBuf == BUF_NOT_RESOLVED )
+ {
+ if ( entityRefName == null )
+ {
+ entityRefName = newString( buf, posStart, posEnd - posStart );
+ }
+ throw new XmlPullParserException( "could not resolve entity named '" + printable( entityRefName )
+ + "'", this, null );
+ }
+ // write into PC replacement text - do merge for replacement text!!!!
+ for ( char aResolvedEntity : resolvedEntityRefCharBuf )
+ {
+ if ( pcEnd >= pc.length )
+ {
+ ensurePC( pcEnd );
+ }
+ pc[pcEnd++] = aResolvedEntity;
+ }
+ }
+
+ private void parseCDSect( boolean hadCharData )
throws XmlPullParserException, IOException
{
// implements XML 1.0 Section 2.7 CDATA Sections
@@ -3476,7 +3686,7 @@ protected void parseCDSect( boolean hadCharData )
final int cdStart = pos + bufAbsoluteStart;
final int curLine = lineNumber;
final int curColumn = columnNumber;
- final boolean normalizeInput = tokenize == false || roundtripSupported == false;
+ final boolean normalizeInput = !tokenize || !roundtripSupported;
try
{
if ( normalizeInput )
@@ -3601,7 +3811,7 @@ else if ( ch == '\n' )
posEnd = pos - 3;
}
- protected void fillBuf()
+ private void fillBuf()
throws IOException, XmlPullParserException
{
if ( reader == null )
@@ -3611,28 +3821,9 @@ protected void fillBuf()
if ( bufEnd > bufSoftLimit )
{
- // expand buffer it makes sense!!!!
- boolean compact = bufStart > bufSoftLimit;
- boolean expand = false;
- if ( preventBufferCompaction )
- {
- compact = false;
- expand = true;
- }
- else if ( !compact )
- {
- // freeSpace
- if ( bufStart < buf.length / 2 )
- {
- // less then half buffer available for compacting --> expand instead!!!
- expand = true;
- }
- else
- {
- // at least half of buffer can be reclaimed --> worthwhile effort!!!
- compact = true;
- }
- }
+ // check if we need to compact or expand the buffer
+ boolean compact = !preventBufferCompaction
+ && ( bufStart > bufSoftLimit || bufStart >= buf.length / 2 );
// if buffer almost full then compact it
if ( compact )
@@ -3643,27 +3834,24 @@ else if ( !compact )
if ( TRACE_SIZING )
System.out.println( "TRACE_SIZING fillBuf() compacting " + bufStart + " bufEnd=" + bufEnd + " pos="
+ pos + " posStart=" + posStart + " posEnd=" + posEnd + " buf first 100 chars:"
- + new String( buf, bufStart, bufEnd - bufStart < 100 ? bufEnd - bufStart : 100 ) );
+ + new String( buf, bufStart, Math.min(bufEnd - bufStart, 100)) );
}
- else if ( expand )
+ else
{
final int newSize = 2 * buf.length;
- final char newBuf[] = new char[newSize];
+ final char[] newBuf = new char[newSize];
if ( TRACE_SIZING )
System.out.println( "TRACE_SIZING fillBuf() " + buf.length + " => " + newSize );
System.arraycopy( buf, bufStart, newBuf, 0, bufEnd - bufStart );
buf = newBuf;
if ( bufLoadFactor > 0 )
{
- bufSoftLimit = ( bufLoadFactor * buf.length ) / 100;
+ // Include a fix for https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228
+ bufSoftLimit = (int) ( bufferLoadFactor * buf.length );
}
}
- else
- {
- throw new XmlPullParserException( "internal error in fillBuffer()" );
- }
bufEnd -= bufStart;
pos -= bufStart;
posStart -= bufStart;
@@ -3673,17 +3861,17 @@ else if ( expand )
if ( TRACE_SIZING )
System.out.println( "TRACE_SIZING fillBuf() after bufEnd=" + bufEnd + " pos=" + pos + " posStart="
+ posStart + " posEnd=" + posEnd + " buf first 100 chars:"
- + new String( buf, 0, bufEnd < 100 ? bufEnd : 100 ) );
+ + new String( buf, 0, Math.min(bufEnd, 100)) );
}
// at least one character must be read or error
- final int len = buf.length - bufEnd > READ_CHUNK_SIZE ? READ_CHUNK_SIZE : buf.length - bufEnd;
+ final int len = Math.min(buf.length - bufEnd, READ_CHUNK_SIZE);
final int ret = reader.read( buf, bufEnd, len );
if ( ret > 0 )
{
bufEnd += ret;
if ( TRACE_SIZING )
System.out.println( "TRACE_SIZING fillBuf() after filling in buffer" + " buf first 100 chars:"
- + new String( buf, 0, bufEnd < 100 ? bufEnd : 100 ) );
+ + new String( buf, 0, Math.min(bufEnd, 100)) );
return;
}
@@ -3768,7 +3956,7 @@ else if ( expand )
}
}
- protected char more()
+ private char more()
throws IOException, XmlPullParserException
{
if ( pos >= bufEnd )
@@ -3776,7 +3964,7 @@ protected char more()
fillBuf();
// this return value should be ignored as it is used in epilog parsing ...
if ( reachedEnd )
- return (char) -1;
+ throw new EOFException( "no more data available" + getPositionDescription() );
}
final char ch = buf[pos++];
// line/columnNumber
@@ -3803,7 +3991,7 @@ protected char more()
// return pos + bufAbsoluteStart;
// }
- protected void ensurePC( int end )
+ private void ensurePC( int end )
{
// assert end >= pc.length;
final int newSize = end > READ_CHUNK_SIZE ? 2 * end : 2 * READ_CHUNK_SIZE;
@@ -3815,7 +4003,7 @@ protected void ensurePC( int end )
// assert end < pc.length;
}
- protected void joinPC()
+ private void joinPC()
{
// assert usePC == false;
// assert posEnd > posStart;
@@ -3830,7 +4018,7 @@ protected void joinPC()
}
- protected char requireInput( char ch, char[] input )
+ private char requireInput( char ch, char[] input )
throws XmlPullParserException, IOException
{
for ( char anInput : input )
@@ -3845,18 +4033,7 @@ protected char requireInput( char ch, char[] input )
return ch;
}
- protected char requireNextS()
- throws XmlPullParserException, IOException
- {
- final char ch = more();
- if ( !isS( ch ) )
- {
- throw new XmlPullParserException( "white space is required and not " + printable( ch ), this, null );
- }
- return skipS( ch );
- }
-
- protected char skipS( char ch )
+ private char skipS( char ch )
throws XmlPullParserException, IOException
{
while ( isS( ch ) )
@@ -3867,23 +4044,23 @@ protected char skipS( char ch )
}
// nameStart / name lookup tables based on XML 1.1 http://www.w3.org/TR/2001/WD-xml11-20011213/
- protected static final int LOOKUP_MAX = 0x400;
+ private static final int LOOKUP_MAX = 0x400;
- protected static final char LOOKUP_MAX_CHAR = (char) LOOKUP_MAX;
+ private static final char LOOKUP_MAX_CHAR = (char) LOOKUP_MAX;
- // protected static int lookupNameStartChar[] = new int[ LOOKUP_MAX_CHAR / 32 ];
- // protected static int lookupNameChar[] = new int[ LOOKUP_MAX_CHAR / 32 ];
- protected static boolean lookupNameStartChar[] = new boolean[LOOKUP_MAX];
+ // private static int lookupNameStartChar[] = new int[ LOOKUP_MAX_CHAR / 32 ];
+ // private static int lookupNameChar[] = new int[ LOOKUP_MAX_CHAR / 32 ];
+ private static final boolean[] lookupNameStartChar = new boolean[LOOKUP_MAX];
- protected static boolean lookupNameChar[] = new boolean[LOOKUP_MAX];
+ private static final boolean[] lookupNameChar = new boolean[LOOKUP_MAX];
- private static final void setName( char ch )
+ private static void setName( char ch )
// { lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); }
{
lookupNameChar[ch] = true;
}
- private static final void setNameStart( char ch )
+ private static void setNameStart( char ch )
// { lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); }
{
lookupNameStartChar[ch] = true;
@@ -3914,10 +4091,10 @@ private static final void setNameStart( char ch )
setName( ch );
}
- // private final static boolean isNameStartChar(char ch) {
- protected boolean isNameStartChar( char ch )
+ // protected boolean isNameStartChar( char ch )
+ private static boolean isNameStartChar( char ch )
{
- return ( ch < LOOKUP_MAX_CHAR && lookupNameStartChar[ch] ) || ( ch >= LOOKUP_MAX_CHAR && ch <= '\u2027' )
+ return ch < LOOKUP_MAX_CHAR ? lookupNameStartChar[ch] : ( ch <= '\u2027' )
|| ( ch >= '\u202A' && ch <= '\u218F' ) || ( ch >= '\u2800' && ch <= '\uFFEF' );
// if(ch < LOOKUP_MAX_CHAR) return lookupNameStartChar[ ch ];
@@ -3941,14 +4118,14 @@ protected boolean isNameStartChar( char ch )
// else return (supportXml11 && ( (ch < '\u2027') || (ch > '\u2029' && ch < '\u2200') ...
}
- // private final static boolean isNameChar(char ch) {
- protected boolean isNameChar( char ch )
+ // protected boolean isNameChar( char ch )
+ private static boolean isNameChar( char ch )
{
// return isNameStartChar(ch);
// if(ch < LOOKUP_MAX_CHAR) return (lookupNameChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0;
- return ( ch < LOOKUP_MAX_CHAR && lookupNameChar[ch] ) || ( ch >= LOOKUP_MAX_CHAR && ch <= '\u2027' )
+ return ch < LOOKUP_MAX_CHAR ? lookupNameChar[ch] : ( ch <= '\u2027' )
|| ( ch >= '\u202A' && ch <= '\u218F' ) || ( ch >= '\u2800' && ch <= '\uFFEF' );
// return false;
// return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':'
@@ -3966,7 +4143,7 @@ protected boolean isNameChar( char ch )
// else return false;
}
- protected boolean isS( char ch )
+ private static boolean isS( char ch )
{
return ( ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' );
// || (supportXml11 && (ch == '\u0085' || ch == '\u2028');
@@ -3975,8 +4152,8 @@ protected boolean isS( char ch )
// protected boolean isChar(char ch) { return (ch < '\uD800' || ch > '\uDFFF')
// ch != '\u0000' ch < '\uFFFE'
- // protected char printable(char ch) { return ch; }
- protected String printable( char ch )
+ // private char printable(char ch) { return ch; }
+ private static String printable( char ch )
{
if ( ch == '\n' )
{
@@ -3996,12 +4173,12 @@ else if ( ch == '\'' )
}
if ( ch > 127 || ch < 32 )
{
- return "\\u" + Integer.toHexString( (int) ch );
+ return "\\u" + Integer.toHexString( ch );
}
return "" + ch;
}
- protected String printable( String s )
+ private static String printable( String s )
{
if ( s == null )
return null;
@@ -4015,74 +4192,6 @@ protected String printable( String s )
return s;
}
- //
- // Imported code from ASF Harmony project rev 770909
- // http://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Character.java
- //
-
- private static int toCodePoint( char high, char low )
- {
- // See RFC 2781, Section 2.2
- // http://www.faqs.org/rfcs/rfc2781.html
- int h = ( high & 0x3FF ) << 10;
- int l = low & 0x3FF;
- return ( h | l ) + 0x10000;
- }
-
- private static final char MIN_HIGH_SURROGATE = '\uD800';
-
- private static final char MAX_HIGH_SURROGATE = '\uDBFF';
-
- private static boolean isHighSurrogate( char ch )
- {
- return ( MIN_HIGH_SURROGATE <= ch && MAX_HIGH_SURROGATE >= ch );
- }
-
- private static final int MAX_CODE_POINT = 0x10FFFF;
-
- private static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x10000;
-
- /**
- * Check if the provided parameter is a valid Char, according to: {@link https://www.w3.org/TR/REC-xml/#NT-Char}
- *
- * @param codePoint the numeric value to check
- * @return true if it is a valid numeric character reference. False otherwise.
- */
- private static boolean isValidCodePoint( int codePoint )
- {
- // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
- return codePoint == 0x9 || codePoint == 0xA || codePoint == 0xD || ( 0x20 <= codePoint && codePoint <= 0xD7FF )
- || ( 0xE000 <= codePoint && codePoint <= 0xFFFD ) || ( 0x10000 <= codePoint && codePoint <= 0x10FFFF );
- }
-
- private static boolean isSupplementaryCodePoint( int codePoint )
- {
- return ( MIN_SUPPLEMENTARY_CODE_POINT <= codePoint && MAX_CODE_POINT >= codePoint );
- }
-
- /**
- * TODO add javadoc
- *
- * @param codePoint
- * @return
- */
- public static char[] toChars( int codePoint )
- {
- if ( !isValidCodePoint( codePoint ) )
- {
- throw new IllegalArgumentException();
- }
-
- if ( isSupplementaryCodePoint( codePoint ) )
- {
- int cpPrime = codePoint - 0x10000;
- int high = 0xD800 | ( ( cpPrime >> 10 ) & 0x3FF );
- int low = 0xDC00 | ( cpPrime & 0x3FF );
- return new char[] { (char) high, (char) low };
- }
-
- return new char[] { (char) codePoint };
- }
}
/*
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java
index 71b2abb3..c69db3f4 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/MXSerializer.java
@@ -236,6 +236,7 @@ protected void ensureNamespacesCapacity()
// }
}
+ @Override
public void setFeature( String name, boolean state )
throws IllegalArgumentException, IllegalStateException
{
@@ -257,6 +258,7 @@ else if ( FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE.equals( name ) )
}
}
+ @Override
public boolean getFeature( String name )
throws IllegalArgumentException
{
@@ -347,6 +349,7 @@ protected void writeIndent()
out.write( indentationBuf, start, ( level * indentationJump ) + offsetNewLine );
}
+ @Override
public void setProperty( String name, Object value )
throws IllegalArgumentException, IllegalStateException
{
@@ -380,6 +383,7 @@ else if ( PROPERTY_LOCATION.equals( name ) )
seenTag = false; // for consistency
}
+ @Override
public Object getProperty( String name )
throws IllegalArgumentException
{
@@ -416,12 +420,14 @@ public Writer getWriter()
return out;
}
+ @Override
public void setOutput( Writer writer )
{
reset();
out = writer;
}
+ @Override
public void setOutput( OutputStream os, String encoding )
throws IOException
{
@@ -438,6 +444,7 @@ public void setOutput( OutputStream os, String encoding )
}
}
+ @Override
public void startDocument( String encoding, Boolean standalone )
throws IOException
{
@@ -453,15 +460,15 @@ public void startDocument( String encoding, Boolean standalone )
if ( encoding != null )
{
out.write( " encoding=" );
- out.write( attributeUseApostrophe ? '\'' : '"' );
+ out.write( apos );
out.write( encoding );
- out.write( attributeUseApostrophe ? '\'' : '"' );
+ out.write( apos );
// out.write('\'');
}
if ( standalone != null )
{
out.write( " standalone=" );
- out.write( attributeUseApostrophe ? '\'' : '"' );
+ out.write( apos );
if ( standalone )
{
out.write( "yes" );
@@ -470,7 +477,7 @@ public void startDocument( String encoding, Boolean standalone )
{
out.write( "no" );
}
- out.write( attributeUseApostrophe ? '\'' : '"' );
+ out.write( apos );
// if(standalone.booleanValue()) {
// out.write(" standalone='yes'");
// } else {
@@ -484,6 +491,7 @@ public void startDocument( String encoding, Boolean standalone )
}
}
+ @Override
public void endDocument()
throws IOException
{
@@ -502,6 +510,7 @@ public void endDocument()
out.flush();
}
+ @Override
public void setPrefix( String prefix, String namespace )
throws IOException
{
@@ -563,6 +572,7 @@ protected String lookupOrDeclarePrefix( String namespace )
return getPrefix( namespace, true );
}
+ @Override
public String getPrefix( String namespace, boolean generatePrefix )
{
// assert namespace != null;
@@ -641,21 +651,25 @@ private String generatePrefix( String namespace )
}
}
+ @Override
public int getDepth()
{
return depth;
}
+ @Override
public String getNamespace()
{
return elNamespace[depth];
}
+ @Override
public String getName()
{
return elName[depth];
}
+ @Override
public XmlSerializer startTag( String namespace, String name )
throws IOException
{
@@ -764,6 +778,7 @@ else if ( uri.length() > 0 )
return this;
}
+ @Override
public XmlSerializer attribute( String namespace, String name, String value )
throws IOException
{
@@ -871,6 +886,7 @@ private void writeNamespaceDeclarations()
}
}
+ @Override
public XmlSerializer endTag( String namespace, String name )
throws IOException
{
@@ -947,6 +963,7 @@ else if ( checkNamesInterned )
return this;
}
+ @Override
public XmlSerializer text( String text )
throws IOException
{
@@ -959,6 +976,7 @@ public XmlSerializer text( String text )
return this;
}
+ @Override
public XmlSerializer text( char[] buf, int start, int len )
throws IOException
{
@@ -970,6 +988,7 @@ public XmlSerializer text( char[] buf, int start, int len )
return this;
}
+ @Override
public void cdsect( String text )
throws IOException
{
@@ -982,6 +1001,7 @@ public void cdsect( String text )
out.write( "]]>" );
}
+ @Override
public void entityRef( String text )
throws IOException
{
@@ -994,6 +1014,7 @@ public void entityRef( String text )
out.write( ';' );
}
+ @Override
public void processingInstruction( String text )
throws IOException
{
@@ -1006,6 +1027,7 @@ public void processingInstruction( String text )
out.write( "?>" );
}
+ @Override
public void comment( String text )
throws IOException
{
@@ -1018,6 +1040,7 @@ public void comment( String text )
out.write( "-->" );
}
+ @Override
public void docdecl( String text )
throws IOException
{
@@ -1030,6 +1053,7 @@ public void docdecl( String text )
out.write( ">" );
}
+ @Override
public void ignorableWhitespace( String text )
throws IOException
{
@@ -1045,6 +1069,7 @@ public void ignorableWhitespace( String text )
out.write( text ); // no escape?
}
+ @Override
public void flush()
throws IOException
{
@@ -1317,7 +1342,7 @@ else if ( ch < 32 )
}
}
- /** simple utility method -- good for debugging */
+ // simple utility method -- good for debugging
protected static final String printable( String s )
{
if ( s == null )
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java
index 7c2e139f..a5f06c14 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParser.java
@@ -343,7 +343,8 @@ public interface XmlPullParser
* Example: call setFeature(FEATURE_PROCESS_NAMESPACES, true) in order to switch on namespace processing. The
* initial settings correspond to the properties requested from the XML Pull Parser factory. If none were requested,
* all features are deactivated by default.
- *
+ * @param name feature name
+ * @param state feature state
* @exception XmlPullParserException If the feature is not supported or can not be set
* @exception IllegalArgumentException If string with the feature name is null
*/
@@ -359,14 +360,15 @@ void setFeature( String name, boolean state )
* @return The value of the feature.
* @exception IllegalArgumentException if string the feature name is null
*/
-
boolean getFeature( String name );
/**
* Set the value of a property. The property name is any fully-qualified URI.
- *
+ * @param name property name
+ * @param value property value
* @exception XmlPullParserException If the property is not supported or can not be set
* @exception IllegalArgumentException If string with the property name is null
+ * @throws XmlPullParserException parsing issue
*/
void setProperty( String name, Object value )
throws XmlPullParserException;
@@ -385,6 +387,8 @@ void setProperty( String name, Object value )
* Set the input source for parser to the given reader and resets the parser. The event type is set to the initial
* value START_DOCUMENT. Setting the reader to null will just stop parsing and reset parser state, allowing the
* parser to free internal resources such as parsing buffers.
+ * @param in the Reader
+ * @throws XmlPullParserException parsing issue
*/
void setInput( Reader in )
throws XmlPullParserException;
@@ -401,12 +405,13 @@ void setInput( Reader in )
*
* @param inputStream contains a raw byte input stream of possibly unknown encoding (when inputEncoding is null).
* @param inputEncoding if not null it MUST be used as encoding for inputStream
+ * @throws XmlPullParserException parsing issue
*/
void setInput( InputStream inputStream, String inputEncoding )
throws XmlPullParserException;
/**
- * Returns the input encoding if known, null otherwise. If setInput(InputStream, inputEncoding) was called with an
+ * @return the input encoding if known, null otherwise. If setInput(InputStream, inputEncoding) was called with an
* inputEncoding value other than null, this value must be returned from this method. Otherwise, if inputEncoding is
* null and the parser supports the encoding detection feature
* (http://xmlpull.org/v1/doc/features.html#detect-encoding), it must return the detected encoding. If
@@ -436,16 +441,18 @@ void setInput( InputStream inputStream, String inputEncoding )
* Note: The list of pre-defined entity names will always contain standard XML entities such as amp
* (&), lt (<), gt (>), quot ("), and apos ('). Those cannot be redefined by
* this method!
- *
+ * @param entityName entity name
+ * @param replacementText remplacement
* @see #setInput
* @see #FEATURE_PROCESS_DOCDECL
* @see #FEATURE_VALIDATION
+ * @throws XmlPullParserException parsing issue
*/
void defineEntityReplacementText( String entityName, String replacementText )
throws XmlPullParserException;
/**
- * Returns the numbers of elements in the namespace stack for the given depth. If namespaces are not enabled, 0 is
+ * @return the numbers of elements in the namespace stack for the given depth. If namespaces are not enabled, 0 is
* returned.
*
* NOTE: when parser is on END_TAG then it is allowed to call this function with getDepth()+1 argument to
@@ -468,32 +475,39 @@ void defineEntityReplacementText( String entityName, String replacementText )
* @see #getNamespaceUri
* @see #getNamespace()
* @see #getNamespace(String)
+ * @param depth depth
+ * @throws XmlPullParserException parsing issue
*/
int getNamespaceCount( int depth )
throws XmlPullParserException;
/**
- * Returns the namespace prefix for the given position in the namespace stack. Default namespace declaration
+ * @return Returns the namespace prefix for the given position in the namespace stack. Default namespace declaration
* (xmlns='...') will have null as prefix. If the given index is out of range, an exception is thrown.
- *
+ *
* Please note: when the parser is on an END_TAG, namespace prefixes that were declared in the corresponding
* START_TAG are still accessible although they are no longer in scope.
+ * namespace prefix
+ * @param pos namespace stack position
+ * @throws XmlPullParserException parsing issue
*/
String getNamespacePrefix( int pos )
throws XmlPullParserException;
/**
- * Returns the namespace URI for the given position in the namespace stack If the position is out of range, an
+ * @return Returns the namespace URI for the given position in the namespace stack If the position is out of range, an
* exception is thrown.
- *
+ *
* NOTE: when parser is on END_TAG then namespace prefixes that were declared in corresponding START_TAG are
* still accessible even though they are not in scope
+ * @throws XmlPullParserException parsing issue
+ * @param pos namespace stack position
*/
String getNamespaceUri( int pos )
throws XmlPullParserException;
/**
- * Returns the URI corresponding to the given prefix, depending on current state of the parser.
+ * @return the URI corresponding to the given prefix, depending on current state of the parser.
*
* If the prefix was not declared in the current scope, null is returned. The default namespace is included in the
* namespace table and is available via getNamespace (null).
@@ -515,7 +529,7 @@ String getNamespaceUri( int pos )
* The 'xml' prefix is bound to "http://www.w3.org/XML/1998/namespace", as defined in the
* Namespaces in XML specification. Analogous, the
* 'xmlns' prefix is resolved to http://www.w3.org/2000/xmlns/
- *
+ * @param prefix given prefix
* @see #getNamespaceCount
* @see #getNamespacePrefix
* @see #getNamespaceUri
@@ -526,7 +540,7 @@ String getNamespaceUri( int pos )
// miscellaneous reporting methods
/**
- * Returns the current depth of the element. Outside the root element, the depth is 0. The depth is incremented by 1
+ * @return the current depth of the element. Outside the root element, the depth is 0. The depth is incremented by 1
* when a start tag is reached. The depth is decremented AFTER the end tag event was observed.
*
*
@@ -542,7 +556,7 @@ String getNamespaceUri( int pos )
int getDepth();
/**
- * Returns a short text describing the current parser state, including the position, a description of the current
+ * @return a short text describing the current parser state, including the position, a description of the current
* event and the data source if known. This method is especially useful to provide meaningful error messages and for
* debugging purposes.
*/
@@ -568,19 +582,20 @@ String getNamespaceUri( int pos )
// TEXT related methods
/**
- * Checks whether the current TEXT event contains only whitespace characters. For IGNORABLE_WHITESPACE, this is
+ * @return Checks whether the current TEXT event contains only whitespace characters. For IGNORABLE_WHITESPACE, this is
* always true. For TEXT and CDSECT, false is returned when the current event text contains at least one non-white
* space character. For any other event type an exception is thrown.
*
* Please note: non-validating parsers are not able to distinguish whitespace and ignorable whitespace,
* except from whitespace outside the root element. Ignorable whitespace is reported as separate event, which is
* exposed via nextToken only.
+ * @throws XmlPullParserException parsing issue
*/
boolean isWhitespace()
throws XmlPullParserException;
/**
- * Returns the text content of the current event as String. The value returned depends on current event type, for
+ * @return the text content of the current event as String. The value returned depends on current event type, for
* example for TEXT event it is element content (this is typical case when next() is used). See description of
* nextToken() for detailed description of possible returned values for different types of events.
*
@@ -617,14 +632,14 @@ boolean isWhitespace()
// START_TAG / END_TAG shared methods
/**
- * Returns the namespace URI of the current element. The default namespace is represented as empty string. If
+ * @return the namespace URI of the current element. The default namespace is represented as empty string. If
* namespaces are not enabled, an empty String ("") is always returned. The current event must be START_TAG or
* END_TAG; otherwise, null is returned.
*/
String getNamespace();
/**
- * For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled.
+ * @return For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled.
* When namespace processing is disabled, the raw name is returned. For ENTITY_REF events, the entity name is
* returned. If the current event is not START_TAG, END_TAG, or ENTITY_REF, null is returned.
*
@@ -634,15 +649,16 @@ boolean isWhitespace()
String getName();
/**
- * Returns the prefix of the current element. If the element is in the default namespace (has no prefix), null is
+ * @return the prefix of the current element. If the element is in the default namespace (has no prefix), null is
* returned. If namespaces are not enabled, or the current event is not START_TAG or END_TAG, null is returned.
*/
String getPrefix();
/**
- * Returns true if the current event is START_TAG and the tag is degenerated (e.g. <foobar/>).
+ * @return true if the current event is START_TAG and the tag is degenerated (e.g. <foobar/>).
*
* NOTE: if the parser is not on START_TAG, an exception will be thrown.
+ * @throws XmlPullParserException parsing issue
*/
boolean isEmptyElementTag()
throws XmlPullParserException;
@@ -651,7 +667,7 @@ boolean isEmptyElementTag()
// START_TAG Attributes retrieval methods
/**
- * Returns the number of attributes of the current start tag, or -1 if the current event type is not START_TAG
+ * @return the number of attributes of the current start tag, or -1 if the current event type is not START_TAG
*
* @see #getAttributeNamespace
* @see #getAttributeName
@@ -749,16 +765,17 @@ boolean isEmptyElementTag()
// actual parsing methods
/**
- * Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.)
+ * @return the type of the current event (START_TAG, END_TAG, TEXT, etc.)
*
* @see #next()
* @see #nextToken()
+ * @throws XmlPullParserException parsing issue
*/
int getEventType()
throws XmlPullParserException;
/**
- * Get next parsing event - element content wil be coalesced and only one TEXT event must be returned for whole
+ * @return Get next parsing event - element content wil be coalesced and only one TEXT event must be returned for whole
* element content (comments and processing instructions will be ignored and entity references must be expanded or
* exception mus be thrown if entity reference can not be expanded). If element content is empty (content is "")
* then no TEXT event will be reported.
@@ -771,8 +788,9 @@ int getEventType()
* @see #TEXT
* @see #END_TAG
* @see #END_DOCUMENT
+ * @throws XmlPullParserException parsing issue
+ * @throws IOException io issue
*/
-
int next()
throws XmlPullParserException, IOException;
@@ -788,7 +806,7 @@ int next()
* is enabled exact content of START_TAG, END_TAG, DOCDECL and PROCESSING_INSTRUCTION is available.
*
* Here is the list of tokens that can be returned from nextToken() and what getText() and getTextCharacters()
- * returns:
+ * @return
*
*
START_DOCUMENT
*
null
@@ -854,7 +872,8 @@ int next()
*
* NOTE: XMLDecl (<?xml ...?>) is not reported but its content is available through optional
* properties (see class description above).
- *
+ * @throws XmlPullParserException parsing issue
+ * @throws IOException io issue
* @see #next
* @see #START_TAG
* @see #TEXT
@@ -884,6 +903,11 @@ int nextToken()
* || ( name != null && !name.equals( getName() ) ) )
* throw new XmlPullParserException( "expected " + TYPES[type] + getPositionDescription() );
*
+ * @param type type
+ * @param name name
+ * @param namespace namespace
+ * @throws XmlPullParserException parsing issue
+ * @throws IOException io issue
*/
void require( int type, String namespace, String name )
throws XmlPullParserException, IOException;
@@ -935,6 +959,9 @@ void require( int type, String namespace, String name )
* throw new XmlPullParserException( "parser must be on START_TAG or TEXT to read text", this, null );
* }
*
+ * @return see description
+ * @throws XmlPullParserException parsing issue
+ * @throws IOException io issue
*/
String nextText()
throws XmlPullParserException, IOException;
@@ -957,6 +984,10 @@ String nextText()
* }
* return eventType;
*
+ * @return see description
+ * @throws XmlPullParserException parsing issue
+ * @throws
+ * IOException io issue
*/
int nextTag()
throws XmlPullParserException, IOException;
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java
index 35725125..ff23754f 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlPullParserException.java
@@ -14,6 +14,7 @@ public class XmlPullParserException
/**
* @deprecated use generic getCause() method
*/
+ @Deprecated
protected Throwable detail;
protected int row = -1;
@@ -50,8 +51,9 @@ public XmlPullParserException( String msg, XmlPullParser parser, Throwable chain
/**
* @deprecated Use the generic getCause() method
- * @return
+ * @return the cause
*/
+ @Deprecated
public Throwable getDetail()
{
return getCause();
@@ -74,6 +76,7 @@ public int getColumnNumber()
*/
// NOTE: code that prints this and detail is difficult in J2ME
+ @Override
public void printStackTrace()
{
if ( getCause() == null )
diff --git a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java
index d7668d74..46ef492f 100644
--- a/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java
+++ b/src/main/java/org/codehaus/plexus/util/xml/pull/XmlSerializer.java
@@ -37,7 +37,8 @@ public interface XmlSerializer
* defined in
* http://www.xmlpull.org/v1/doc/features.html. If feature is not recognized or can not be set then
* IllegalStateException MUST be thrown.
- *
+ * @param name feature name
+ * @param state feature state
* @exception IllegalStateException If the feature is not supported or can not be set
*/
void setFeature( String name, boolean state )
@@ -59,7 +60,8 @@ void setFeature( String name, boolean state )
* optional properties are defined in
* http://www.xmlpull.org/v1/doc/properties.html. If property is not recognized or can not be set then
* IllegalStateException MUST be thrown.
- *
+ * @param name property name
+ * @param value property value
* @exception IllegalStateException if the property is not supported or can not be set
*/
void setProperty( String name, Object value )
@@ -77,14 +79,22 @@ void setProperty( String name, Object value )
/**
* Set to use binary output stream with given encoding.
+ * @param os out
+ * @param encoding encoding
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
void setOutput( OutputStream os, String encoding )
throws IOException, IllegalArgumentException, IllegalStateException;
/**
- * Set the output to the given writer.
+ * @param writer Set the output to the given writer.
*
* WARNING no information about encoding is available!
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
void setOutput( Writer writer )
throws IOException, IllegalArgumentException, IllegalStateException;
@@ -92,6 +102,11 @@ void setOutput( Writer writer )
/**
* Write <?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null)
* This method can only be called just after setOutput.
+ * @param encoding document encoding
+ * @param standalone standalone flag value
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
void startDocument( String encoding, Boolean standalone )
throws IOException, IllegalArgumentException, IllegalStateException;
@@ -99,6 +114,9 @@ void startDocument( String encoding, Boolean standalone )
/**
* Finish writing. All unclosed start tags will be closed and output will be flushed. After calling this method no
* more output can be serialized until next call to setOutput()
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
void endDocument()
throws IOException, IllegalArgumentException, IllegalStateException;
@@ -119,12 +137,15 @@ void endDocument()
*
* @param prefix must be not null (or IllegalArgumentException is thrown)
* @param namespace must be not null
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
void setPrefix( String prefix, String namespace )
throws IOException, IllegalArgumentException, IllegalStateException;
/**
- * Return namespace that corresponds to given prefix If there is no prefix bound to this namespace return null but
+ * @return namespace that corresponds to given prefix If there is no prefix bound to this namespace return null but
* if generatePrefix is false then return generated prefix.
*
* NOTE: if the prefix is empty string "" and default namespace is bound to this prefix then empty string
@@ -132,12 +153,15 @@ void setPrefix( String prefix, String namespace )
*
* NOTE: prefixes "xml" and "xmlns" are already bound will have values as defined
* Namespaces in XML specification
+ * @param namespace the namespace
+ * @param generatePrefix to generate the missing prefix
+ * @throws IllegalArgumentException if null
*/
String getPrefix( String namespace, boolean generatePrefix )
throws IllegalArgumentException;
/**
- * Returns the current depth of the element. Outside the root element, the depth is 0. The depth is incremented by 1
+ * @return the current depth of the element. Outside the root element, the depth is 0. The depth is incremented by 1
* when startTag() is called. The depth is decremented after the call to endTag() event was observed.
*
*
@@ -179,6 +203,12 @@ String getPrefix( String namespace, boolean generatePrefix )
* setPrefix() immediately before this method. If namespace is null no namespace prefix is printed but just name. If
* namespace is empty string then serializer will make sure that default empty namespace is declared (in XML 1.0
* xmlns='') or throw IllegalStateException if default namespace is already bound to non-empty string.
+ * @param namespace ns
+ * @param name tag name
+ * @return XmlSerializer
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
XmlSerializer startTag( String namespace, String name )
throws IOException, IllegalArgumentException, IllegalStateException;
@@ -187,16 +217,28 @@ XmlSerializer startTag( String namespace, String name )
* Write an attribute. Calls to attribute() MUST follow a call to startTag() immediately. If there is no prefix
* defined for the given namespace, a prefix will be defined automatically. If namespace is null or empty string no
* namespace prefix is printed but just name.
+ * @param name attribute name
+ * @param value attribute value
+ * @param namespace namespace to use
+ * @return XmlSerializer
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
XmlSerializer attribute( String namespace, String name, String value )
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Write end tag. Repetition of namespace and name is just for avoiding errors.
- *
* Background: in kXML endTag had no arguments, and non matching tags were very difficult to find... If
* namespace is null no namespace prefix is printed but just name. If namespace is empty string then serializer will
* make sure that default empty namespace is declared (in XML 1.0 xmlns='').
+ * @param namespace ns
+ * @param name tag name
+ * @return XmlSerializer
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
XmlSerializer endTag( String namespace, String name )
throws IOException, IllegalArgumentException, IllegalStateException;
@@ -255,13 +297,24 @@ XmlSerializer endTag( String namespace, String name )
// throws IOException, IllegalArgumentException, IllegalStateException;
/**
- * Writes text, where special XML chars are escaped automatically
+ * @param text Writes text, where special XML chars are escaped automatically
+ * @return XmlSerializer
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
XmlSerializer text( String text )
throws IOException, IllegalArgumentException, IllegalStateException;
/**
* Writes text, where special XML chars are escaped automatically
+ * @param buf characters
+ * @param len lenght
+ * @param start start
+ * @return XmlSerializer
+ * @throws IOException io
+ * @throws IllegalArgumentException if null
+ * @throws IllegalStateException illegal use
*/
XmlSerializer text( char[] buf, int start, int len )
throws IOException, IllegalArgumentException, IllegalStateException;
@@ -290,6 +343,7 @@ void ignorableWhitespace( String text )
*
* NOTE: if there is need to close start tag (so no more attribute() calls are allowed) but without flushing
* output call method text() with empty string (text("")).
+ * @throws IOException io
*/
void flush()
throws IOException;
diff --git a/src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java b/src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java
new file mode 100644
index 00000000..fc792be3
--- /dev/null
+++ b/src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java
@@ -0,0 +1,25 @@
+package org.codehaus.plexus.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Implementation specific to Java SE 10 version.
+ */
+abstract class BaseIOUtil
+{
+ static void copy( final InputStream input, final OutputStream output )
+ throws IOException
+ {
+ input.transferTo( output );
+ }
+
+ static void copy( final Reader input, final Writer output )
+ throws IOException
+ {
+ input.transferTo( output );
+ }
+}
diff --git a/src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java b/src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java
new file mode 100644
index 00000000..7e0826c4
--- /dev/null
+++ b/src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java
@@ -0,0 +1,27 @@
+package org.codehaus.plexus.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Implementation specific to Java SE 9 version.
+ */
+abstract class BaseIOUtil
+{
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 16;
+
+ static void copy( final InputStream input, final OutputStream output )
+ throws IOException
+ {
+ input.transferTo( output );
+ }
+
+ static void copy( final Reader input, final Writer output )
+ throws IOException
+ {
+ IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE );
+ }
+}
diff --git a/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java
index 8d556e5e..ca5ba4ed 100644
--- a/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java
+++ b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java
@@ -24,7 +24,8 @@
*
*
* @author Bert van Brakel
- * @version $Revision$
+ * @version $Id: $Id
+ * @since 3.4.0
*/
public abstract class AbstractTestThread
implements Runnable
@@ -32,6 +33,7 @@ public abstract class AbstractTestThread
// ~ Instance fields ----------------------------------------------------------------------------
private String name;
+ /** Constant DEBUG=true */
public static final boolean DEBUG = true;
private boolean isRunning = false;
@@ -68,6 +70,11 @@ public AbstractTestThread()
super();
}
+ /**
+ *
+ *
+ * @return a {@link java.lang.Throwable} object.
*/
public Throwable getError()
{
@@ -129,7 +138,9 @@ public final void start()
}
/**
- * @return
+ *
Getter for the field errorMsg.
+ *
+ * @return a {@link java.lang.String} object.
*/
public String getErrorMsg()
{
@@ -137,7 +148,9 @@ public String getErrorMsg()
}
/**
- * @return
+ *
hasFailed.
+ *
+ * @return a boolean.
*/
public boolean hasFailed()
{
@@ -189,7 +202,7 @@ public final void run()
/**
* Override this to run your custom test
*
- * @throws Throwable
+ * @throws java.lang.Throwable
*/
public abstract void doRun()
throws Throwable;
@@ -197,7 +210,7 @@ public abstract void doRun()
/**
* Set the registry this thread should notify when it has completed running
*
- * @param registry
+ * @param registry a {@link org.codehaus.plexus.util.TestThreadManager} object.
*/
public void setThreadRegistry( TestThreadManager registry )
@@ -208,7 +221,7 @@ public void setThreadRegistry( TestThreadManager registry )
/**
* Test if the test has run
*
- * @return
+ * @return a boolean.
*/
public boolean hasRun()
{
@@ -216,7 +229,9 @@ public boolean hasRun()
}
/**
- * @param throwable
+ *
+ *
+ * @param file a {@link java.io.File} object.
+ * @throws java.lang.Exception if any.
+ */
protected void deleteFile( final File file )
throws Exception
{
@@ -192,10 +258,10 @@ private void assertEqualContent( final File f0, final File f1 )
* + " and " + f1 + " have differing file sizes (" + f0.length() + " vs " + f1.length() + ")", ( f0.length() ==
* f1.length() ) );
*/
- final InputStream is0 = new FileInputStream( f0 );
+ final InputStream is0 = Files.newInputStream( f0.toPath() );
try
{
- final InputStream is1 = new FileInputStream( f1 );
+ final InputStream is1 = Files.newInputStream( f1.toPath() );
try
{
final byte[] buf0 = new byte[1024];
@@ -225,11 +291,17 @@ private void assertEqualContent( final File f0, final File f1 )
}
}
- /** Assert that the content of a file is equal to that in a byte[]. */
+ /**
+ * Assert that the content of a file is equal to that in a byte[].
+ *
+ * @param b0 an array of {@link byte} objects.
+ * @param file a {@link java.io.File} object.
+ * @throws java.io.IOException if any.
+ */
protected void assertEqualContent( final byte[] b0, final File file )
throws IOException
{
- final InputStream is = new FileInputStream( file );
+ final InputStream is = Files.newInputStream( file.toPath() );
try
{
byte[] b1 = new byte[b0.length];
@@ -245,6 +317,11 @@ protected void assertEqualContent( final byte[] b0, final File file )
}
}
+ /**
+ *
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testFilteredWithoutFilterAndOlderFileAndOverwrite()
throws Exception
@@ -1073,6 +1325,11 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite()
}
+ /**
+ *
testFileRead.
+ *
+ * @throws java.io.IOException if any.
+ */
@Test
public void testFileRead()
throws IOException
@@ -1089,7 +1346,7 @@ public void testFileRead()
Writer writer = null;
try
{
- writer = new OutputStreamWriter( new FileOutputStream( testFile ) );
+ writer = new OutputStreamWriter( Files.newOutputStream( testFile.toPath() ) );
writer.write( testString );
writer.flush();
}
@@ -1102,6 +1359,11 @@ public void testFileRead()
testFile.delete();
}
+ /**
+ *
testFileReadWithEncoding.
+ *
+ * @throws java.io.IOException if any.
+ */
@Test
public void testFileReadWithEncoding()
throws IOException
@@ -1114,7 +1376,7 @@ public void testFileReadWithEncoding()
Writer writer = null;
try
{
- writer = new OutputStreamWriter( new FileOutputStream( testFile ), encoding );
+ writer = new OutputStreamWriter( Files.newOutputStream( testFile.toPath() ), encoding );
writer.write( testString );
writer.flush();
}
@@ -1127,6 +1389,11 @@ public void testFileReadWithEncoding()
testFile.delete();
}
+ /**
+ *
testFileAppend.
+ *
+ * @throws java.io.IOException if any.
+ */
@Test
public void testFileAppend()
throws IOException
@@ -1137,7 +1404,7 @@ public void testFileAppend()
Writer writer = null;
try
{
- writer = new OutputStreamWriter( new FileOutputStream( testFile ) );
+ writer = new OutputStreamWriter( Files.newOutputStream( testFile.toPath() ) );
writer.write( baseString );
writer.flush();
}
@@ -1152,6 +1419,11 @@ public void testFileAppend()
testFile.delete();
}
+ /**
+ *
testFileAppendWithEncoding.
+ *
+ * @throws java.io.IOException if any.
+ */
@Test
public void testFileAppendWithEncoding()
throws IOException
@@ -1163,7 +1435,7 @@ public void testFileAppendWithEncoding()
Writer writer = null;
try
{
- writer = new OutputStreamWriter( new FileOutputStream( testFile ), encoding );
+ writer = new OutputStreamWriter( Files.newOutputStream( testFile.toPath() ), encoding );
writer.write( baseString );
writer.flush();
}
@@ -1178,6 +1450,11 @@ public void testFileAppendWithEncoding()
testFile.delete();
}
+ /**
+ *
testFileWrite.
+ *
+ * @throws java.io.IOException if any.
+ */
@Test
public void testFileWrite()
throws IOException
@@ -1191,6 +1468,11 @@ public void testFileWrite()
testFile.delete();
}
+ /**
+ *
testFileWriteWithEncoding.
+ *
+ * @throws java.io.IOException if any.
+ */
@Test
public void testFileWriteWithEncoding()
throws IOException
@@ -1208,7 +1490,7 @@ public void testFileWriteWithEncoding()
/**
* Workaround for the following Sun bugs. They are fixed in JDK 6u1 and JDK 5u11.
*
- * @throws Exception
+ * @throws java.lang.Exception
* @see Sun bug id=4403166
* @see Sun bug id=6182812
* @see Sun bug id=6481955
@@ -1236,7 +1518,7 @@ public void testDeleteLongPathOnWindows()
File f = new File( a1, path.toString() + "test.txt" );
InputStream is = new ByteArrayInputStream( "Blabla".getBytes( "UTF-8" ) );
- OutputStream os = new FileOutputStream( f.getCanonicalFile() );
+ OutputStream os = Files.newOutputStream( f.getCanonicalFile().toPath() );
IOUtil.copy( is, os );
IOUtil.close( is );
IOUtil.close( os );
@@ -1251,6 +1533,11 @@ public void testDeleteLongPathOnWindows()
}
// Test for bug PLXUTILS-10
+ /**
+ *
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testReaderToString()
throws Exception
{
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
String out = IOUtil.toString( fin );
assertNotNull( out );
assertTrue( "Wrong output size: out.length()=" + out.length() + "!=" + FILE_SIZE, out.length() == FILE_SIZE );
fin.close();
}
+ /**
+ *
testStringToOutputStream.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testStringToOutputStream()
throws Exception
{
File destination = newFile( "copy5.txt" );
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
// Create our String. Rely on testReaderToString() to make sure this is valid.
String str = IOUtil.toString( fin );
- FileOutputStream fout = new FileOutputStream( destination );
+ OutputStream fout = Files.newOutputStream( destination.toPath() );
IOUtil.copy( str, fout );
// Note: this method *does* flush. It is equivalent to:
// OutputStreamWriter _out = new OutputStreamWriter(fout);
@@ -280,15 +320,20 @@ public void testStringToOutputStream()
deleteFile( destination );
}
+ /**
+ *
testStringToWriter.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testStringToWriter()
throws Exception
{
File destination = newFile( "copy6.txt" );
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
// Create our String. Rely on testReaderToString() to make sure this is valid.
String str = IOUtil.toString( fin );
- FileWriter fout = new FileWriter( destination );
+ Writer fout = Files.newBufferedWriter( destination.toPath() );
IOUtil.copy( str, fout );
fout.flush();
@@ -300,11 +345,16 @@ public void testStringToWriter()
deleteFile( destination );
}
+ /**
+ *
testInputStreamToByteArray.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testInputStreamToByteArray()
throws Exception
{
- FileInputStream fin = new FileInputStream( testFile );
+ InputStream fin = Files.newInputStream( testFile.toPath() );
byte[] out = IOUtil.toByteArray( fin );
assertNotNull( out );
assertTrue( "Not all bytes were read", fin.available() == 0 );
@@ -313,11 +363,16 @@ public void testInputStreamToByteArray()
fin.close();
}
+ /**
+ *
testStringToByteArray.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testStringToByteArray()
throws Exception
{
- FileReader fin = new FileReader( testFile );
+ Reader fin = Files.newBufferedReader( testFile.toPath() );
// Create our String. Rely on testReaderToString() to make sure this is valid.
String str = IOUtil.toString( fin );
@@ -327,13 +382,18 @@ public void testStringToByteArray()
fin.close();
}
+ /**
+ *
testByteArrayToWriter.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testByteArrayToWriter()
throws Exception
{
File destination = newFile( "copy7.txt" );
- FileWriter fout = new FileWriter( destination );
- FileInputStream fin = new FileInputStream( testFile );
+ Writer fout = Files.newBufferedWriter( destination.toPath() );
+ InputStream fin = Files.newInputStream( testFile.toPath() );
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
byte[] in = IOUtil.toByteArray( fin );
@@ -346,11 +406,16 @@ public void testByteArrayToWriter()
deleteFile( destination );
}
+ /**
+ *
testByteArrayToString.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testByteArrayToString()
throws Exception
{
- FileInputStream fin = new FileInputStream( testFile );
+ InputStream fin = Files.newInputStream( testFile.toPath() );
byte[] in = IOUtil.toByteArray( fin );
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
String str = IOUtil.toString( in );
@@ -358,13 +423,18 @@ public void testByteArrayToString()
fin.close();
}
+ /**
+ *
testByteArrayToOutputStream.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testByteArrayToOutputStream()
throws Exception
{
File destination = newFile( "copy8.txt" );
- FileOutputStream fout = new FileOutputStream( destination );
- FileInputStream fin = new FileInputStream( testFile );
+ OutputStream fout = Files.newOutputStream( destination.toPath() );
+ InputStream fin = Files.newInputStream( testFile.toPath() );
// Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid.
byte[] in = IOUtil.toByteArray( fin );
@@ -384,6 +454,11 @@ public void testByteArrayToOutputStream()
// Test closeXXX()
// ----------------------------------------------------------------------
+ /**
+ *
+ *
+ * @author herve
+ * @version $Id: $Id
+ * @since 3.4.0
+ */
public class InterpolationFilterReaderTest
{
/*
* Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader.
* kenneyw@15-04-2005 fixed the bug.
*/
+ /**
+ *
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter()
throws Exception
diff --git a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java
index 346f1e88..6ff112db 100644
--- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java
+++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java
@@ -31,12 +31,21 @@
/**
* Generated by JUnitDoclet, a tool provided by ObjectFab GmbH under LGPL. Please see www.junitdoclet.org, www.gnu.org
* and www.objectfab.de for informations about the tool, the licence and the authors.
+ *
+ * @author herve
+ * @version $Id: $Id
+ * @since 3.4.0
*/
public class LineOrientedInterpolatingReaderTest
{
/*
* Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader.
*/
+ /**
+ *
+ */
public void runTestThreads()
{
failedThreads.clear();
@@ -83,6 +94,11 @@ public void runTestThreads()
}
}
+ /**
+ *
getFailedTests.
+ *
+ * @return a {@link java.util.Collection} object.
+ */
public Collection getFailedTests()
{
return failedThreads;
@@ -91,13 +107,18 @@ public Collection getFailedTests()
/**
* Return the object which threads can wait on to be notified when all the test threads have completed running
*
- * @return
+ * @return a {@link java.lang.Object} object.
*/
public Object getNotifyObject()
{
return notify;
}
+ /**
+ *
hasFailedThreads.
+ *
+ * @return a boolean.
+ */
public boolean hasFailedThreads()
{
return !failedThreads.isEmpty();
@@ -114,7 +135,9 @@ public boolean isStillRunningThreads()
}
/**
- * @return
+ *
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testEnvironmentWitOverrideSystemEnvironment()
throws Exception
@@ -326,7 +389,7 @@ public void testEnvironmentWitOverrideSystemEnvironment()
/**
* Test an executable with a single apostrophe ' in its path
*
- * @throws Exception
+ * @throws java.lang.Exception
*/
@Test
public void testQuotedPathWithSingleApostrophe()
@@ -342,7 +405,7 @@ public void testQuotedPathWithSingleApostrophe()
/**
* Test an executable with shell-expandable content in its path.
*
- * @throws Exception
+ * @throws java.lang.Exception
*/
@Test
public void testPathWithShellExpansionStrings()
@@ -355,7 +418,7 @@ public void testPathWithShellExpansionStrings()
/**
* Test an executable with a single quotation mark \" in its path only for non Windows box.
*
- * @throws Exception
+ * @throws java.lang.Exception
*/
@Test
public void testQuotedPathWithQuotationMark()
@@ -378,7 +441,7 @@ public void testQuotedPathWithQuotationMark()
* Test an executable with a single quotation mark \" and ' in its path only for non
* Windows box.
*
- * @throws Exception
+ * @throws java.lang.Exception
*/
@Test
public void testQuotedPathWithQuotationMarkAndApostrophe()
@@ -400,7 +463,7 @@ public void testQuotedPathWithQuotationMarkAndApostrophe()
/**
* Test an executable with a quote in its path and no space
*
- * @throws Exception
+ * @throws java.lang.Exception
*/
@Test
public void testOnlyQuotedPath()
@@ -433,6 +496,11 @@ public void testOnlyQuotedPath()
createAndCallScript( dir, javaBinStr + " -version" );
}
+ /**
+ *
+ *
* @author Vincent Siveton
- * @version $Id$
+ * @version $Id: $Id
+ * @since 3.4.0
*/
public class XmlWriterUtilTest
{
@@ -41,6 +44,11 @@ public class XmlWriterUtilTest
private XMLWriter xmlWriter;
+ /**
+ *
setUp.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Before
public void setUp()
throws Exception
@@ -50,6 +58,11 @@ public void setUp()
xmlWriter = new PrettyPrintXMLWriter( writer );
}
+ /**
+ *
tearDown.
+ *
+ * @throws java.lang.Exception if any.
+ */
@After
public void tearDown()
throws Exception
@@ -63,7 +76,7 @@ public void tearDown()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeLineBreak(org.codehaus.plexus.util.xml.XMLWriter)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteLineBreakXMLWriter()
@@ -78,7 +91,7 @@ public void testWriteLineBreakXMLWriter()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeLineBreak(org.codehaus.plexus.util.xml.XMLWriter, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteLineBreakXMLWriterInt()
@@ -93,7 +106,7 @@ public void testWriteLineBreakXMLWriterInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeLineBreak(org.codehaus.plexus.util.xml.XMLWriter, int, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteLineBreakXMLWriterIntInt()
@@ -111,7 +124,7 @@ public void testWriteLineBreakXMLWriterIntInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeLineBreak(org.codehaus.plexus.util.xml.XMLWriter, int, int, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteLineBreakXMLWriterIntIntInt()
@@ -127,7 +140,7 @@ public void testWriteLineBreakXMLWriterIntIntInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeCommentLineBreak(org.codehaus.plexus.util.xml.XMLWriter)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentLineBreakXMLWriter()
@@ -145,7 +158,7 @@ public void testWriteCommentLineBreakXMLWriter()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeCommentLineBreak(org.codehaus.plexus.util.xml.XMLWriter, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentLineBreakXMLWriterInt()
@@ -167,7 +180,7 @@ public void testWriteCommentLineBreakXMLWriterInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentXMLWriterString()
@@ -208,7 +221,7 @@ public void testWriteCommentXMLWriterString()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentXMLWriterStringInt()
@@ -244,7 +257,7 @@ public void testWriteCommentXMLWriterStringInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String, int, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentXMLWriterStringIntInt()
@@ -280,7 +293,7 @@ public void testWriteCommentXMLWriterStringIntInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String, int, int, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentXMLWriterStringIntIntInt()
@@ -312,7 +325,7 @@ public void testWriteCommentXMLWriterStringIntIntInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeCommentText(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentTextXMLWriterStringInt()
@@ -355,7 +368,7 @@ public void testWriteCommentTextXMLWriterStringInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeCommentText(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String, int, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentTextXMLWriterStringIntInt()
@@ -381,7 +394,7 @@ public void testWriteCommentTextXMLWriterStringIntInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeCommentText(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String, int, int, int)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentTextXMLWriterStringIntIntInt()
@@ -407,7 +420,7 @@ public void testWriteCommentTextXMLWriterStringIntIntInt()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentNull()
@@ -424,7 +437,7 @@ public void testWriteCommentNull()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentShort()
@@ -441,7 +454,7 @@ public void testWriteCommentShort()
* Test method for
* {@link org.codehaus.plexus.util.xml.XmlWriterUtil#writeComment(org.codehaus.plexus.util.xml.XMLWriter, java.lang.String)}.
*
- * @throws Exception if any
+ * @throws java.lang.Exception if any
*/
@Test
public void testWriteCommentLong()
diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
index 0c8e5a17..3d3cb5ec 100644
--- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java
@@ -33,12 +33,18 @@
* Test the Xpp3DomBuilder.
*
* @author Brett Porter
- * @version $Id$
+ * @version $Id: $Id
+ * @since 3.4.0
*/
public class Xpp3DomBuilderTest
{
private static final String LS = System.lineSeparator();
+ /**
+ *
testBuildFromReader.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testBuildFromReader()
throws Exception
@@ -52,6 +58,11 @@ public void testBuildFromReader()
assertEquals( "check DOMs match", expectedDom, dom );
}
+ /**
+ *
testBuildTrimming.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testBuildTrimming()
throws Exception
@@ -67,6 +78,11 @@ public void testBuildTrimming()
assertEquals( "test with trimming off", " element1\n ", dom.getChild( "el1" ).getValue() );
}
+ /**
+ *
testBuildFromXpp3Dom.
+ *
+ * @throws java.lang.Exception if any.
+ */
@Test
public void testBuildFromXpp3Dom()
throws Exception
@@ -145,6 +161,12 @@ public void testUnclosedXml()
}
}
+ /**
+ *
+ */
+ @Before
+ public void setUp()
+ {
+ parser = new MXParser();
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n01.xml
+ * Test URI:
not-wf/P24/ibm24n01.xml
+ * Comment:
Tests VersionInfo with a required field missing. The VersionNum is missing in the VersionInfo in the XMLDecl.
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n01xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n01.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with a required field missing. The VersionNum is missing in the VersionInfo in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected apostrophe (') or quotation mark (\") after version and not ?" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n02.xml
+ * Test URI:
not-wf/P24/ibm24n02.xml
+ * Comment:
Tests VersionInfo with a required field missing. The white space is missing between the key word "xml" and the VersionInfo in the XMLDecl.
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n02xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n02.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with a required field missing. The white space is missing between the key word \"xml\" and the VersionInfo in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected v in version and not ?" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n03.xml
+ * Test URI:
not-wf/P24/ibm24n03.xml
+ * Comment:
Tests VersionInfo with a required field missing. The "=" (equal sign) is missing between the key word "version" and the VersionNum.
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n03xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n03.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with a required field missing. The \"=\" (equal sign) is missing between the key word \"version\" and the VersionNum." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected equals sign (=) after version and not \\'" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n04.xml
+ * Test URI:
not-wf/P24/ibm24n04.xml
+ * Comment:
Tests VersionInfo with wrong field ordering. The VersionNum occurs before "=" and "version".
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n04xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n04.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with wrong field ordering. The VersionNum occurs before \"=\" and \"version\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected v in version and not \\'" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n05.xml
+ * Test URI:
not-wf/P24/ibm24n05.xml
+ * Comment:
Tests VersionInfo with wrong field ordering. The "=" occurs after "version" and the VersionNum.
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n05xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n05.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with wrong field ordering. The \"=\" occurs after \"version\" and the VersionNum." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected equals sign (=) after version and not \\'" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n06.xml
+ * Test URI:
not-wf/P24/ibm24n06.xml
+ * Comment:
Tests VersionInfo with the wrong key word "Version".
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n06xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n06.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with the wrong key word \"Version\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected v in version and not V" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n07.xml
+ * Test URI:
not-wf/P24/ibm24n07.xml
+ * Comment:
Tests VersionInfo with the wrong key word "versioN".
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n07xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n07.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with the wrong key word \"versioN\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected n in version and not N" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P24-ibm24n08.xml
+ * Test URI:
not-wf/P24/ibm24n08.xml
+ * Comment:
Tests VersionInfo with mismatched quotes around the VersionNum. version = '1.0" is used as the VersionInfo.
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n08xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n08.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with mismatched quotes around the VersionNum. version = '1.0\" is used as the VersionInfo." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "ibm-not-wf-P24-ibm24n09.xml
+ * Test URI:
not-wf/P24/ibm24n09.xml
+ * Comment:
Tests VersionInfo with mismatched quotes around the VersionNum. The closing bracket for the VersionNum is missing.
+ * Sections:
2.8
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P24_ibm24n09xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P24/ibm24n09.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests VersionInfo with mismatched quotes around the VersionNum. The closing bracket for the VersionNum is missing." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "IBM XML Conformance Test Suite - Production 2
+ * XML test files base folder:
+ */
+ @Before
+ public void setUp() {
+ parser = new MXParser();
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n01.xml
+ * Test URI:
not-wf/P02/ibm02n01.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x00
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n01xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n01.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x00" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x0 found in comment" ) );
+ }
+ }
+
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n02.xml
+ * Test URI:
not-wf/P02/ibm02n02.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x01
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n02xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n02.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x01" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n03.xml
+ * Test URI:
not-wf/P02/ibm02n03.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x02
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n03xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n03.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x02" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x2 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n04.xml
+ * Test URI:
not-wf/P02/ibm02n04.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x03
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n04xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n04.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x03" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x3 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n05.xml
+ * Test URI:
not-wf/P02/ibm02n05.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x04
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n05xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n05.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x04" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x4 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n06.xml
+ * Test URI:
not-wf/P02/ibm02n06.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x05
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n06xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n06.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x05" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x5 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n07.xml
+ * Test URI:
not-wf/P02/ibm02n07.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x06
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n07xml() throws IOException {
+ try(Reader reader = new FileReader(new File(testResourcesDir, "not-wf/P02/ibm02n07.xml"))) {
+ parser.setInput(reader);
+ while (parser.nextToken() != XmlPullParser.END_DOCUMENT);
+ fail("Tests a comment which contains an illegal Char: #x06");
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x6 found in comment" ) );
+ }
+ }
+
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n08.xml
+ * Test URI:
not-wf/P02/ibm02n08.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x07
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n08xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n08.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x07" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x7 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n09.xml
+ * Test URI:
not-wf/P02/ibm02n09.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x08
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n09xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n09.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x08" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x8 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n10.xml
+ * Test URI:
not-wf/P02/ibm02n10.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x0B
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n10xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n10.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x0B" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xb found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n11.xml
+ * Test URI:
not-wf/P02/ibm02n11.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x0C
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n11xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n11.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x0C" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xc found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n12.xml
+ * Test URI:
not-wf/P02/ibm02n12.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x0E
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n12xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n12.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x0E" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xe found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n13.xml
+ * Test URI:
not-wf/P02/ibm02n13.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x0F
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n13xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n13.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x0F" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xf found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n14.xml
+ * Test URI:
not-wf/P02/ibm02n14.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x10
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n14xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n14.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x10" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x10 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n15.xml
+ * Test URI:
not-wf/P02/ibm02n15.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x11
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n15xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n15.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x11" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x11 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n16.xml
+ * Test URI:
not-wf/P02/ibm02n16.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x12
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n16xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n16.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x12" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x12 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n17.xml
+ * Test URI:
not-wf/P02/ibm02n17.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x13
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n17xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n17.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x13" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x13 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n18.xml
+ * Test URI:
not-wf/P02/ibm02n18.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x14
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n18xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n18.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x14" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x14 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n19.xml
+ * Test URI:
not-wf/P02/ibm02n19.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x15
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n19xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n19.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x15" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x15 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n20.xml
+ * Test URI:
not-wf/P02/ibm02n20.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x16
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n20xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n20.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x16" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x16 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n21.xml
+ * Test URI:
not-wf/P02/ibm02n21.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x17
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n21xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n21.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x17" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x17 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n22.xml
+ * Test URI:
not-wf/P02/ibm02n22.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x18
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n22xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n22.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x18" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x18 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n23.xml
+ * Test URI:
not-wf/P02/ibm02n23.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x19
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n23xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n23.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x19" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x19 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n24.xml
+ * Test URI:
not-wf/P02/ibm02n24.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x1A
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n24xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n24.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x1A" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1a found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n25.xml
+ * Test URI:
not-wf/P02/ibm02n25.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x1B
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n25xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n25.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x1B" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1b found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n26.xml
+ * Test URI:
not-wf/P02/ibm02n26.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x1C
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n26xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n26.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x1C" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1c found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n27.xml
+ * Test URI:
not-wf/P02/ibm02n27.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x1D
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n27xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n27.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x1D" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1d found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n28.xml
+ * Test URI:
not-wf/P02/ibm02n28.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x1E
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n28xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n28.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x1E" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1e found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n29.xml
+ * Test URI:
not-wf/P02/ibm02n29.xml
+ * Comment:
Tests a comment which contains an illegal Char: #x1F
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n29xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P02/ibm02n29.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #x1F" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0x1f found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n30.xml
+ * Test URI:
not-wf/P02/ibm02n30.xml
+ * Comment:
Tests a comment which contains an illegal Char: #xD800
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ *
+ * NOTE: This test file is malformed into the original test suite, so I skip it.
+ */
+ //@Test
+ public void testibm_not_wf_P02_ibm02n30xml()
+ throws IOException
+ {
+ try ( BufferedReader reader =
+ Files.newBufferedReader( Paths.get( testResourcesDir.getCanonicalPath(), "not-wf/P02/ibm02n30.xml" ),
+ Charset.forName( "ISO-8859-15" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #xD800" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xd800 found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n31.xml
+ * Test URI:
not-wf/P02/ibm02n31.xml
+ * Comment:
Tests a comment which contains an illegal Char: #xDFFF
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ *
+ * NOTE: This test file is malformed into the original test suite, so I skip it.
+ */
+ //@Test
+ public void testibm_not_wf_P02_ibm02n31xml()
+ throws IOException
+ {
+ try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "not-wf/P02/ibm02n31.xml" ) );
+ InputStreamReader reader = new InputStreamReader( is, "ISO-8859-15" ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #xDFFF" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xdfff found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n32.xml
+ * Test URI:
not-wf/P02/ibm02n32.xml
+ * Comment:
Tests a comment which contains an illegal Char: #xFFFE
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n32xml()
+ throws IOException
+ {
+ try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "not-wf/P02/ibm02n32.xml" ) );
+ InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #xFFFE" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xfffe found in comment" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P02-ibm02n33.xml
+ * Test URI:
not-wf/P02/ibm02n33.xml
+ * Comment:
Tests a comment which contains an illegal Char: #xFFFF
+ * Sections:
2.2
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P02_ibm02n33xml()
+ throws IOException
+ {
+ try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "not-wf/P02/ibm02n33.xml" ) );
+ InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests a comment which contains an illegal Char: #xFFFF" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "Illegal character 0xffff found in comment" ) );
+ }
+ }
+
+}
diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java
new file mode 100644
index 00000000..a6a80030
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java
@@ -0,0 +1,276 @@
+package org.codehaus.plexus.util.xml.pull;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
+ * TESCASES PROFILE:
+ */
+ @Before
+ public void setUp()
+ {
+ parser = new MXParser();
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n01.xml
+ * Test URI:
not-wf/P32/ibm32n01.xml
+ * Comment:
Tests SDDecl with a required field missing. The leading white space is missing with the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n01xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n01.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with a required field missing. The leading white space is missing with the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected a space after version and not s" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n02.xml
+ * Test URI:
not-wf/P32/ibm32n02.xml
+ * Comment:
Tests SDDecl with a required field missing. The "=" sign is missing in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n02xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n02.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with a required field missing. The \"=\" sign is missing in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected equals sign (=) after standalone and not \"" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n03.xml
+ * Test URI:
not-wf/P32/ibm32n03.xml
+ * Comment:
Tests SDDecl with wrong key word. The word "Standalone" occurs in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n03xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n03.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with wrong key word. The word \"Standalone\" occurs in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "unexpected character S" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n04.xml
+ * Test URI:
not-wf/P32/ibm32n04.xml
+ * Comment:
Tests SDDecl with wrong key word. The word "Yes" occurs in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n04xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n04.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with wrong key word. The word \"Yes\" occurs in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not Y" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n05.xml
+ * Test URI:
not-wf/P32/ibm32n05.xml
+ * Comment:
Tests SDDecl with wrong key word. The word "YES" occurs in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n05xml()
+ throws IOException
+ {
+
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n05.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with wrong key word. The word \"YES\" occurs in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not Y" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n06.xml
+ * Test URI:
not-wf/P32/ibm32n06.xml
+ * Comment:
Tests SDDecl with wrong key word. The word "No" occurs in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n06xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n06.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with wrong key word. The word \"No\" occurs in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not N" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n07.xml
+ * Test URI:
not-wf/P32/ibm32n07.xml
+ * Comment:
Tests SDDecl with wrong key word. The word "NO" occurs in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n07xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n07.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with wrong key word. The word \"NO\" occurs in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected 'yes' or 'no' after standalone and not N" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n08.xml
+ * Test URI:
not-wf/P32/ibm32n08.xml
+ * Comment:
Tests SDDecl with wrong field ordering. The "=" sign occurs after the key word "yes" in the SDDecl in the XMLDecl.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P32_ibm32n08xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n08.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests SDDecl with wrong field ordering. The \"=\" sign occurs after the key word \"yes\" in the SDDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected equals sign (=) after standalone and not \"" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P32-ibm32n09.xml
+ * Test URI:
not-wf/P32/ibm32n09.xml
+ * Comment:
This is test violates WFC: Entity Declared in P68. The standalone document declaration has the value yes, BUT there is an external markup declaration of an entity (other than amp, lt, gt, apos, quot), and references to this entity appear in the document.
+ * Sections:
2.9
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ *
+ * NOTE: This test is SKIPPED as MXParser does not support parsing inside DOCTYPEDECL.
+ */
+ // @Test
+ public void testibm_not_wf_P32_ibm32n09xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P32/ibm32n09.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "This is test violates WFC: Entity Declared in P68. The standalone document declaration has the value yes, BUT there is an external markup declaration of an entity (other than amp, lt, gt, apos, quot), and references to this entity appear in the document." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected ?> as last part of IBM XML Conformance Test Suite - Production 66
+ * XML test files base folder:
+ */
+ @Before
+ public void setUp()
+ {
+ parser = new MXParser();
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n01.xml
+ * Test URI:
not-wf/P66/ibm66n01.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#002f" is used as the referred character in the CharRef in the EntityDecl in the DTD.
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n01xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n01.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#002f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain f" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n02.xml
+ * Test URI:
not-wf/P66/ibm66n02.xml
+ * Comment:
Tests CharRef with the semicolon character missing. The semicolon character is missing at the end of the CharRef in the attribute value in the STag of element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n02xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n02.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with the semicolon character missing. The semicolon character is missing at the end of the CharRef in the attribute value in the STag of element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain \"" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n03.xml
+ * Test URI:
not-wf/P66/ibm66n03.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "49" is used as the referred character in the CharRef in the EntityDecl in the DTD.
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n03xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n03.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"49\" is used as the referred character in the CharRef in the EntityDecl in the DTD." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "entity reference names can not start with character '4'" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n04.xml
+ * Test URI:
not-wf/P66/ibm66n04.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#5~0" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n04xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n04.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#5~0\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain ~" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n05.xml
+ * Test URI:
not-wf/P66/ibm66n05.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#x002g" is used as the referred character in the CharRef in the EntityDecl in the DTD.
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ * @throws java.io.FileNotFoundException if any.
+ * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any.
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n05xml()
+ throws FileNotFoundException, IOException, XmlPullParserException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n05.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#x002g\" is used as the referred character in the CharRef in the EntityDecl in the DTD." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain g" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n06.xml
+ * Test URI:
not-wf/P66/ibm66n06.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#x006G" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n06xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n06.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#x006G\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain G" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n07.xml
+ * Test URI:
not-wf/P66/ibm66n07.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#0=2f" is used as the referred character in the CharRef in the EntityDecl in the DTD.
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n07xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n07.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#0=2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain =" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n08.xml
+ * Test URI:
not-wf/P66/ibm66n08.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#56.0" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n08xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n08.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#56.0\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain ." ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n09.xml
+ * Test URI:
not-wf/P66/ibm66n09.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#x00/2f" is used as the referred character in the CharRef in the EntityDecl in the DTD.
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n09xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n09.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#x00/2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain /" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n10.xml
+ * Test URI:
not-wf/P66/ibm66n10.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#51)" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n10xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n10.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#51)\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with decimal value) may not contain )" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n11.xml
+ * Test URI:
not-wf/P66/ibm66n11.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#00 2f" is used as the referred character in the CharRef in the EntityDecl in the DTD.
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n11xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n11.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#00 2f\" is used as the referred character in the CharRef in the EntityDecl in the DTD." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value) may not contain " ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n12.xml
+ * Test URI:
not-wf/P66/ibm66n12.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#x0000" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n12xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n12.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#x0000\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value 0000) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n13.xml
+ * Test URI:
not-wf/P66/ibm66n13.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#x001f" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n13xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n13.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#x001f\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value 001f) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n14.xml
+ * Test URI:
not-wf/P66/ibm66n14.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#xfffe" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n14xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n14.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#xfffe\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value fffe) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P66-ibm66n15.xml
+ * Test URI:
not-wf/P66/ibm66n15.xml
+ * Comment:
Tests CharRef with an illegal character referred to. The "#xffff" is used as the referred character in the attribute value in the EmptyElemTag of the element "root".
+ * Sections:
4.1
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P66_ibm66n15xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P66/ibm66n15.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests CharRef with an illegal character referred to. The \"#xffff\" is used as the referred character in the attribute value in the EmptyElemTag of the element \"root\"." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value ffff) is invalid" ) );
+ }
+ }
+
+}
diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java
new file mode 100644
index 00000000..e5510bb5
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java
@@ -0,0 +1,195 @@
+package org.codehaus.plexus.util.xml.pull;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class that execute a particular set of tests associated to a TESCASES tag from the XML W3C Conformance Tests.
+ * TESCASES PROFILE:
+ */
+ @Before
+ public void setUp()
+ {
+ parser = new MXParser();
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P80-ibm80n01.xml
+ * Test URI:
not-wf/P80/ibm80n01.xml
+ * Comment:
Tests EncodingDecl with a required field missing. The leading white space is missing in the EncodingDecl in the XMLDecl.
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P80_ibm80n01xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n01.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests EncodingDecl with a required field missing. The leading white space is missing in the EncodingDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected a space after version and not e" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P80-ibm80n02.xml
+ * Test URI:
not-wf/P80/ibm80n02.xml
+ * Comment:
Tests EncodingDecl with a required field missing. The "=" sign is missing in the EncodingDecl in the XMLDecl.
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P80_ibm80n02xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n02.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests EncodingDecl with a required field missing. The \"=\" sign is missing in the EncodingDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected equals sign (=) after encoding and not \"" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P80-ibm80n03.xml
+ * Test URI:
not-wf/P80/ibm80n03.xml
+ * Comment:
Tests EncodingDecl with a required field missing. The double quoted EncName are missing in the EncodingDecl in the XMLDecl.
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P80_ibm80n03xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n03.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests EncodingDecl with a required field missing. The double quoted EncName are missing in the EncodingDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "expected apostrophe (') or quotation mark (\") after encoding and not ?" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P80-ibm80n04.xml
+ * Test URI:
not-wf/P80/ibm80n04.xml
+ * Comment:
Tests EncodingDecl with wrong field ordering. The string "encoding=" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl.
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P80_ibm80n04xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n04.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests EncodingDecl with wrong field ordering. The string \"encoding=\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "unexpected character \"" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P80-ibm80n05.xml
+ * Test URI:
not-wf/P80/ibm80n05.xml
+ * Comment:
Tests EncodingDecl with wrong field ordering. The "encoding" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl.
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P80_ibm80n05xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n05.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests EncodingDecl with wrong field ordering. The \"encoding\" occurs after the double quoted EncName in the EncodingDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "unexpected character \"" ) );
+ }
+ }
+
+ /**
+ * Test ID:
ibm-not-wf-P80-ibm80n06.xml
+ * Test URI:
not-wf/P80/ibm80n06.xml
+ * Comment:
Tests EncodingDecl with wrong key word. The string "Encoding" is used as the key word in the EncodingDecl in the XMLDecl.
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testibm_not_wf_P80_ibm80n06xml()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "not-wf/P80/ibm80n06.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "Tests EncodingDecl with wrong key word. The string \"Encoding\" is used as the key word in the EncodingDecl in the XMLDecl." );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "unexpected character E" ) );
+ }
+ }
+
+}
diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java
new file mode 100644
index 00000000..c4d1a74f
--- /dev/null
+++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java
@@ -0,0 +1,100 @@
+package org.codehaus.plexus.util.xml.pull;
+
+/*
+ * Copyright The Codehaus Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.TimeUnit;
+
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.openjdk.jmh.runner.options.TimeValue;
+
+/**
+ *
+ *
+ * @throws java.lang.Exception if any.
+ */
+ @Test
public void testMalformedProcessingInstructionNoClosingQuestionMark()
throws Exception
{
@@ -491,10 +684,16 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark()
}
catch ( XmlPullParserException ex )
{
- assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 2 was not closed" ) );
+ assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 1 was not closed" ) );
}
}
+ /**
+ *
+ *
+ * @throws java.lang.Exception if any.
+ */
+ @Test
public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
throws Exception
{
@@ -518,10 +717,68 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark()
}
catch ( XmlPullParserException ex )
{
- assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 13 was not closed" ) );
+ assertTrue( ex.getMessage().contains( "processing instruction started on line 1 and column 12 was not closed" ) );
+ }
+ }
+
+ /**
+ *
+ */
+ @Before
+ public void setUp()
+ {
+ parser = new MXParser();
+ }
+
+ /**
+ * Test ID:
hst-bh-001
+ * Test URI:
001.xml
+ * Comment:
decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow
+ * Sections:
2.2 [2], 4.1 [66]
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testhst_bh_001()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "001.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value FF000000F6) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
hst-bh-002
+ * Test URI:
002.xml
+ * Comment:
hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow
+ * Sections:
2.2 [2], 4.1 [66]
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testhst_bh_002()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "002.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery from possible overflow" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with decimal value 4294967542) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
hst-bh-003
+ * Test URI:
003.xml
+ * Comment:
decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow
+ * Sections:
2.2 [2], 4.1 [66]
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testhst_bh_003()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "003.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with hex value FFFFFFFF000000F6) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
hst-bh-004
+ * Test URI:
004.xml
+ * Comment:
hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow
+ * Sections:
2.2 [2], 4.1 [66]
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testhst_bh_004()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "004.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery from possible overflow" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "character reference (with decimal value 18446744073709551862) is invalid" ) );
+ }
+ }
+
+ /**
+ * Test ID:
hst-bh-005
+ * Test URI:
005.xml
+ * Comment:
xmlns:xml is an attribute as far as validation is concerned and must be declared
+ * Sections:
3.1 [41]
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ *
+ * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing.
+ */
+ // @Test
+ public void testhst_bh_005()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "005.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "xmlns:xml is an attribute as far as validation is concerned and must be declared" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( true );
+ }
+ }
+
+ /**
+ * Test ID:
hst-bh-006
+ * Test URI:
006.xml
+ * Comment:
xmlns:foo is an attribute as far as validation is concerned and must be declared
+ * Sections:
3.1 [41]
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ *
+ * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing.
+ */
+ // @Test
+ public void testhst_bh_006()
+ throws IOException
+ {
+ try ( Reader reader = new FileReader( new File( testResourcesDir, "006.xml" ) ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "xmlns:foo is an attribute as far as validation is concerned and must be declared" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( true );
+ }
+ }
+
+ /**
+ * Test ID:
hst-lhs-007
+ * Test URI:
007.xml
+ * Comment:
UTF-8 BOM plus xml decl of iso-8859-1 incompatible
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testhst_lhs_007()
+ throws IOException
+ {
+ try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "007.xml" ) );
+ InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "UTF-8 BOM plus xml decl of iso-8859-1 incompatible" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "UTF-8 BOM plus xml decl of iso-8859-1 is incompatible" ) );
+ }
+ }
+
+ /**
+ * Test ID:
hst-lhs-008
+ * Test URI:
008.xml
+ * Comment:
UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible
+ * Sections:
4.3.3
+ * Version:
+ *
+ * @throws java.io.IOException if there is an I/O error
+ */
+ @Test
+ public void testhst_lhs_008()
+ throws IOException
+ {
+ try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "008.xml" ) );
+ InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_16 ) )
+ {
+ parser.setInput( reader );
+ while ( parser.nextToken() != XmlPullParser.END_DOCUMENT )
+ ;
+ fail( "UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible" );
+ }
+ catch ( XmlPullParserException e )
+ {
+ assertTrue( e.getMessage().contains( "UTF-16 BOM plus xml decl of utf-8 is incompatible" ) );
+ }
+ }
+
+ /**
+ * Test ID:
hst-lhs-009
+ * Test URI:
009.xml
+ * Comment:
UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible