From 905a516d151d26627f63ac6af714928c3dfa5095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 10 Oct 2019 19:37:16 +0200 Subject: [PATCH 001/133] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0fcea215..f6602acd 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ limitations under the License. plexus-utils - 3.3.0 + 3.3.1-SNAPSHOT Plexus Common Utilities A 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.git scm:git:git@github.com:codehaus-plexus/plexus-utils.git http://github.com/codehaus-plexus/plexus-utils - plexus-utils-3.3.0 + HEAD github From ecdbeebdbc38f73b8b4cf10fbf13590a81f87463 Mon Sep 17 00:00:00 2001 From: Richard Mealing Date: Mon, 25 Nov 2019 16:48:59 +0000 Subject: [PATCH 002/133] Add fix for overflow error in MXParser buffer sizing closes #72 --- .../plexus/util/xml/pull/MXParser.java | 9 +++++--- .../plexus/util/xml/pull/MXParserTest.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) 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..85a90293 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 @@ -401,9 +401,11 @@ protected void ensureEntityCapacity() protected int bufLoadFactor = 95; // 99% // protected int bufHardLimit; // only matters when expanding - protected char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256]; + protected float bufferLoadFactor = bufLoadFactor / 100f; - protected int bufSoftLimit = ( bufLoadFactor * buf.length ) / 100; // desirable size of buffer + protected char buf[] = new char[Runtime.getRuntime().freeMemory() > 1000000L ? READ_CHUNK_SIZE : 256]; + + protected int bufSoftLimit = (int) ( bufferLoadFactor * buf.length ); // desirable size of buffer protected boolean preventBufferCompaction; @@ -3656,7 +3658,8 @@ else if ( expand ) 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 ); } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 79fb64b1..c0754126 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -391,6 +391,28 @@ public void testSubsequentProcessingInstructionMoreThan8k() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + @Test + public void testLargeText_NoOverflow() + throws Exception + { + StringBuffer sb = new StringBuffer(); + sb.append( "" ); + sb.append( "" ); + // Anything above 33,554,431 would fail without a fix for + // https://web.archive.org/web/20070831191548/http://www.extreme.indiana.edu/bugzilla/show_bug.cgi?id=228 + // with java.io.IOException: error reading input, returned 0 + sb.append( new String( new char[33554432] ) ); + sb.append( "" ); + + MXParser parser = new MXParser(); + parser.setInput( new StringReader( sb.toString() ) ); + + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( XmlPullParser.TEXT, parser.nextToken() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + } + public void testMalformedProcessingInstructionAfterTag() throws Exception { From 89f74c56f4e15b0603c5e8f76cbe4b3c0a1e880a Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sat, 7 Dec 2019 08:41:30 -0300 Subject: [PATCH 003/133] Support combine.self="remove" --- .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 24 +++++++++++++-- .../codehaus/plexus/util/xml/Xpp3DomTest.java | 30 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) 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..a7026384 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -22,7 +22,6 @@ 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; @@ -76,6 +75,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 @@ -301,6 +302,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 // ---------------------------------------------------------------------- @@ -418,7 +426,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 +497,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 ); + } } } } diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java index 04444f31..35fb5590 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -329,6 +329,36 @@ public void testDupeChildren() assertEquals( "y", dom.getChild( "foo" ).getValue() ); } + @Test + public void testShouldRemoveEntireElementWithAttributesAndChildren() + throws Exception + { + String dominantStr = ""; + String recessiveStr = "parameter"; + Xpp3Dom dominantConfig = Xpp3DomBuilder.build( new StringReader( dominantStr ) ); + Xpp3Dom recessiveConfig = Xpp3DomBuilder.build( new StringReader( recessiveStr ) ); + + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( dominantConfig, recessiveConfig ); + + assertEquals( 0, result.getChildCount() ); + assertEquals( "config", result.getName() ); + } + + @Test + public void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() + throws Exception + { + String dominantStr = ""; + String recessiveStr = "parameter"; + Xpp3Dom dominantConfig = Xpp3DomBuilder.build( new StringReader( dominantStr ) ); + Xpp3Dom recessiveConfig = Xpp3DomBuilder.build( new StringReader( recessiveStr ) ); + + // same DOMs as testShouldRemoveEntireElementWithAttributesAndChildren(), swapping dominant <--> recessive + Xpp3Dom result = Xpp3Dom.mergeXpp3Dom( recessiveConfig, dominantConfig ); + + assertEquals( recessiveConfig.toString(), result.toString() ); + } + private static class FixedInputLocationBuilder implements Xpp3DomBuilder.InputLocationBuilder { From 177a0cd86dda0cc07045628b2a5ad47a2559edb9 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sat, 7 Dec 2019 13:26:17 +0100 Subject: [PATCH 004/133] Support combine.keys --- pom.xml | 2 +- .../plexus/util/xml/Xpp3DomUtils.java | 39 ++++++++++++++++++- .../plexus/util/xml/Xpp3DomUtilsTest.java | 35 +++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f6602acd..93014125 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ limitations under the License. plexus-utils - 3.3.1-SNAPSHOT + 3.4.0-SNAPSHOT Plexus Common Utilities A collection of various utility classes to ease working with strings, files, command lines, XML and 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..71efe467 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java @@ -19,9 +19,7 @@ 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 */ @@ -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 @@ -106,6 +112,8 @@ public void writeToSerializer( String namespace, XmlSerializer serializer, Xpp3D *
    *
  1. if 'combine.id' is set and there is a corresponding dominant child (matched by value of 'combine.id'), * merge the two.
  2. + *
  3. if 'combine.keys' is set and there is a corresponding dominant child (matched by value of key elements), + * merge the two.
  4. *
  5. if mergeChildren == true and there is a corresponding dominant child (matched by element name), * merge the two.
  6. *
  7. otherwise, add the recessive child as a new child on the dominant root node.
  8. @@ -167,6 +175,7 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole for ( Xpp3Dom recessiveChild : children ) { String idValue = recessiveChild.getAttribute( ID_COMBINATION_MODE_ATTRIBUTE ); + String keysValue = recessiveChild.getAttribute( KEYS_COMBINATION_MODE_ATTRIBUTE ); Xpp3Dom childDom = null; if ( isNotEmpty( idValue ) ) @@ -181,6 +190,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.getChild( key ).getValue() ); + } + + for ( Xpp3Dom dominantChild : dominant.getChildren() ) + { + Map dominantKeyValues = new HashMap( keys.length ); + for ( String key : keys ) + { + dominantKeyValues.put( key, dominantChild.getChild( key ).getValue() ); + } + + if ( recessiveKeyValues.equals( dominantKeyValues ) ) + { + childDom = dominantChild; + // we have a match, so don't append but merge + mergeChildren = true; + } + } + + } else { childDom = dominant.getChild( recessiveChild.getName() ); diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java index f4d0eb04..e5a68e77 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java @@ -60,6 +60,41 @@ public void testCombineId() assertEquals( "right", p2.getChild( "value" ).getInputLocation() ); } + @Test + public void testCombineKeys() + throws Exception + { + String lhs = "" + "LHS-ONLYLHS" + + "TOOVERWRITELHS" + ""; + + String rhs = "" + "RHS-ONLYRHS" + + "TOOVERWRITERHS" + ""; + + Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) ); + Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ), new FixedInputLocationBuilder( "right" ) ); + + Xpp3Dom mergeResult = Xpp3DomUtils.mergeXpp3Dom( leftDom, rightDom, true ); + assertEquals( 3, mergeResult.getChildren( "property" ).length ); + + Xpp3Dom p0 = mergeResult.getChildren( "property" )[0]; + assertEquals( "LHS-ONLY", p0.getChild( "name" ).getValue() ); + assertEquals( "left", p0.getChild( "name" ).getInputLocation() ); + assertEquals( "LHS", p0.getChild( "value" ).getValue() ); + assertEquals( "left", p0.getChild( "value" ).getInputLocation() ); + + Xpp3Dom p1 = mergeResult.getChildren( "property" )[1]; + assertEquals( "TOOVERWRITE", mergeResult.getChildren( "property" )[1].getChild( "name" ).getValue() ); + assertEquals( "left", p1.getChild( "name" ).getInputLocation() ); + assertEquals( "LHS", mergeResult.getChildren( "property" )[1].getChild( "value" ).getValue() ); + assertEquals( "left", p1.getChild( "value" ).getInputLocation() ); + + Xpp3Dom p2 = mergeResult.getChildren( "property" )[2]; + assertEquals( "RHS-ONLY", mergeResult.getChildren( "property" )[2].getChild( "name" ).getValue() ); + assertEquals( "right", p2.getChild( "name" ).getInputLocation() ); + assertEquals( "RHS", mergeResult.getChildren( "property" )[2].getChild( "value" ).getValue() ); + assertEquals( "right", p2.getChild( "value" ).getInputLocation() ); + } + private static class FixedInputLocationBuilder implements Xpp3DomBuilder.InputLocationBuilder { From b93d9fa862f281292ffb335f92195b1980042f86 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sat, 7 Dec 2019 20:52:00 +0100 Subject: [PATCH 005/133] Clean up code, apply Java 7 features --- pom.xml | 17 +- .../codehaus/plexus/util/AbstractScanner.java | 3 + .../org/codehaus/plexus/util/CachedMap.java | 14 ++ .../plexus/util/DirectoryScanner.java | 20 +- .../codehaus/plexus/util/DirectoryWalker.java | 7 +- .../java/org/codehaus/plexus/util/Expand.java | 34 +-- .../org/codehaus/plexus/util/FastMap.java | 44 ++++ .../org/codehaus/plexus/util/FileUtils.java | 194 ++++-------------- .../java/org/codehaus/plexus/util/IOUtil.java | 11 + .../util/InterpolationFilterReader.java | 3 + .../codehaus/plexus/util/Java7Detector.java | 47 ----- .../util/LineOrientedInterpolatingReader.java | 3 + .../codehaus/plexus/util/PropertyUtils.java | 38 +--- .../plexus/util/StringInputStream.java | 6 + .../plexus/util/StringOutputStream.java | 5 + .../org/codehaus/plexus/util/SweeperPool.java | 1 + .../plexus/util/cli/CommandLineCallable.java | 1 + .../plexus/util/cli/CommandLineUtils.java | 5 + .../codehaus/plexus/util/cli/Commandline.java | 20 +- .../plexus/util/cli/DefaultConsumer.java | 1 + .../plexus/util/cli/WriterStreamConsumer.java | 1 + .../plexus/util/cli/shell/BourneShell.java | 5 + .../plexus/util/cli/shell/CmdShell.java | 1 + .../codehaus/plexus/util/cli/shell/Shell.java | 3 +- .../util/dag/CycleDetectedException.java | 1 + .../org/codehaus/plexus/util/dag/DAG.java | 3 +- .../org/codehaus/plexus/util/dag/Vertex.java | 2 + .../plexus/util/io/RawInputStreamFacade.java | 1 + .../plexus/util/io/URLInputStreamFacade.java | 1 + .../plexus/util/reflection/Reflector.java | 2 +- .../plexus/util/xml/CompactXMLWriter.java | 1 + .../plexus/util/xml/PrettyPrintXMLWriter.java | 5 + .../plexus/util/xml/SerializerXMLWriter.java | 7 +- .../codehaus/plexus/util/xml/XmlReader.java | 3 + .../plexus/util/xml/XmlStreamWriter.java | 3 + .../org/codehaus/plexus/util/xml/XmlUtil.java | 30 +-- .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 3 + .../plexus/util/xml/pull/MXParser.java | 39 +++- .../plexus/util/xml/pull/MXSerializer.java | 25 +++ .../util/xml/pull/XmlPullParserException.java | 3 + 40 files changed, 293 insertions(+), 320 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/util/Java7Detector.java diff --git a/pom.xml b/pom.xml index 93014125..0344cc8f 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.codehaus.plexus plexus - 5.1 + 6.0 plexus-utils @@ -142,19 +142,4 @@ limitations under the License. - - - - - eclipse-only-jdk-version - - - m2e.version - - - - 7 - - - diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java index e3b2ba6e..414b60b8 100644 --- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java +++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java @@ -229,6 +229,7 @@ protected static boolean match( String pattern, String str, boolean isCaseSensit * @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 ) @@ -258,6 +259,7 @@ public void setIncludes( String[] includes ) * @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 ) @@ -361,6 +363,7 @@ protected boolean isExcluded( String name, String[] tokenizedName ) /** * 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/CachedMap.java b/src/main/java/org/codehaus/plexus/util/CachedMap.java index 3c5b40e8..0d399291 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,6 +408,7 @@ public Collection values() * * @return an unmodifiable view of the mappings contained in this map. */ + @Override public Set entrySet() { return Collections.unmodifiableSet( _backingMap.entrySet() ); @@ -409,6 +421,7 @@ public Set entrySet() * @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,6 +432,7 @@ public boolean equals( Object o ) * * @return the hash code value for this map. */ + @Override public int hashCode() { return _backingMap.hashCode(); diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java index af118472..c17a9781 100644 --- a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java +++ b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java @@ -234,6 +234,7 @@ public void setBasedir( File basedir ) * * @return the base directory to be scanned */ + @Override public File getBasedir() { return basedir; @@ -266,6 +267,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 { @@ -548,6 +550,7 @@ 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()]; @@ -611,6 +614,7 @@ 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()]; @@ -683,13 +687,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 +705,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/DirectoryWalker.java b/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java index 2fd90077..40f3c3cc 100644 --- a/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java +++ b/src/main/java/org/codehaus/plexus/util/DirectoryWalker.java @@ -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/Expand.java b/src/main/java/org/codehaus/plexus/util/Expand.java index 3d3e98aa..db81df4a 100644 --- a/src/main/java/org/codehaus/plexus/util/Expand.java +++ b/src/main/java/org/codehaus/plexus/util/Expand.java @@ -102,29 +102,18 @@ public void execute() protected void expandFile( final File srcF, final File dir ) throws Exception { - ZipInputStream zis = null; - try + // code from WarExpand + try ( ZipInputStream zis = new ZipInputStream( new FileInputStream( srcF ) ) ) { - // 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 ); - } } /** @@ -159,22 +148,13 @@ protected void extractFile( File srcF, File dir, InputStream compressedInputStre else { byte[] buffer = new byte[65536]; - FileOutputStream fos = null; - try + + try ( FileOutputStream fos = new FileOutputStream( f ) ) { - 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 ); } } 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 map ) { for ( Entry entry : map.entrySet() ) @@ -299,6 +306,7 @@ public void putAll( Map 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..7cd1ddcf 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -72,7 +72,6 @@ import java.io.Reader; import java.io.Writer; import java.net.URL; -import java.nio.channels.FileChannel; import java.security.SecureRandom; import java.text.DecimalFormat; import java.util.ArrayList; @@ -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( new FileInputStream( file ), encoding ); + } + else + { + return new InputStreamReader( new FileInputStream( file ) ); + } + } + /** * Appends data to a file. The file will be created if it does not exist. Note: the data is written with platform * encoding @@ -417,10 +407,8 @@ public static void fileAppend( String fileName, String data ) public static void fileAppend( String fileName, String encoding, String data ) throws IOException { - FileOutputStream out = null; - try + try ( FileOutputStream out = new FileOutputStream( fileName, true ) ) { - out = new FileOutputStream( fileName, true ); if ( encoding != null ) { out.write( data.getBytes( encoding ) ); @@ -429,12 +417,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 +476,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 = new FileOutputStream( file ); + if ( encoding != null ) { - IOUtil.close( writer ); + return new OutputStreamWriter( out, encoding ); + } + else + { + return new OutputStreamWriter( out ); } } @@ -524,20 +503,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 ); } } @@ -751,26 +723,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 = new FileInputStream( file1 ); + InputStream input2 = new FileInputStream( file2 ) ) { - IOUtil.close( input1 ); - IOUtil.close( input2 ); + return IOUtil.contentEquals( input1, input2 ); } - return equals; } /** @@ -1038,7 +996,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,54 +1049,7 @@ 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 ); - } - } - - private static void doCopyFileUsingLegacyIO( File source, File destination ) - throws IOException - { - FileInputStream fis = null; - FileOutputStream fos = null; - FileChannel input = null; - FileChannel output = null; - try - { - 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; - } - finally - { - IOUtil.close( output ); - IOUtil.close( fos ); - IOUtil.close( input ); - IOUtil.close( fis ); - } + doCopyFileUsingNewIO( source, destination ); } private static void doCopyFileUsingNewIO( File source, File destination ) @@ -1211,22 +1122,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(); + FileOutputStream output = new FileOutputStream( destination ) ) { - 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 ); } } @@ -2378,13 +2277,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 = new BufferedReader( new FileReader( file ) ) ) { - reader = new BufferedReader( new FileReader( file ) ); - for ( String line = reader.readLine(); line != null; line = reader.readLine() ) { line = line.trim(); @@ -2394,15 +2291,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..0bbd1fd2 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -478,6 +478,7 @@ public static void copy( final String input, final Writer output ) * @deprecated Buffering streams is actively harmful! See the class description as to why. Use * {@link #copy(InputStream, OutputStream)} instead. */ + @Deprecated public static void bufferedCopy( final InputStream input, final OutputStream output ) throws IOException { @@ -695,7 +696,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 +720,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 +744,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 +768,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 +792,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..b22ff887 100644 --- a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java +++ b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java @@ -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 { diff --git a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java index 44ac5a93..419fc125 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. * @@ -28,7 +30,6 @@ * * @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( new FileInputStream( Objects.requireNonNull( file, "file" ) ) ); } 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/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..b4051925 100644 --- a/src/main/java/org/codehaus/plexus/util/StringOutputStream.java +++ b/src/main/java/org/codehaus/plexus/util/StringOutputStream.java @@ -27,23 +27,27 @@ * @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/SweeperPool.java b/src/main/java/org/codehaus/plexus/util/SweeperPool.java index 0aeca99f..dcfa0e71 100644 --- a/src/main/java/org/codehaus/plexus/util/SweeperPool.java +++ b/src/main/java/org/codehaus/plexus/util/SweeperPool.java @@ -281,6 +281,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/cli/CommandLineCallable.java b/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java index 15a0eec2..9e8179c3 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 { + @Override public Integer call() throws CommandLineException; } 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..9de3970e 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java +++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineUtils.java @@ -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 ); @@ -154,6 +155,7 @@ public void run() return new CommandLineCallable() { + @Override public Integer call() throws CommandLineException { @@ -504,6 +506,7 @@ else if ( " ".equals( nextTok ) ) * {@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 @@ -525,6 +528,7 @@ public static String quote( String argument ) * {@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 @@ -537,6 +541,7 @@ public static String quote( String argument, boolean wrapExistingQuotes ) * {@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..1d92e2e1 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java +++ b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java @@ -100,11 +100,13 @@ 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(); @@ -120,12 +122,14 @@ 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; /** @@ -246,7 +250,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 +293,7 @@ private void setDefaultShell() * @see #createArgument(boolean) * @deprecated Use {@link Commandline#createArg()} instead */ + @Deprecated public Argument createArgument() { return this.createArgument( false ); @@ -303,6 +308,7 @@ public Argument createArgument() * appended. * @deprecated Use {@link Commandline#createArg(boolean)} instead */ + @Deprecated public Argument createArgument( boolean insertAtStart ) { Argument argument = new Argument(); @@ -519,7 +525,7 @@ 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] ); } /** @@ -546,6 +552,7 @@ public String[] getArguments() return res; } + @Override public String toString() { return StringUtils.join( getShellCommandline(), " " ); @@ -556,6 +563,7 @@ public int size() return getCommandline().length; } + @Override public Object clone() { Commandline c = new Commandline( (Shell) shell.clone() ); @@ -677,6 +685,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 ) @@ -722,6 +731,7 @@ public Shell getShell() /** * @deprecated Use {@link CommandLineUtils#translateCommandline(String)} instead. */ + @Deprecated public static String[] translateCommandline( String toProcess ) throws Exception { @@ -731,6 +741,7 @@ public static String[] translateCommandline( String toProcess ) /** * @deprecated Use {@link CommandLineUtils#quote(String)} instead. */ + @Deprecated public static String quoteArgument( String argument ) throws CommandLineException { @@ -740,6 +751,7 @@ public static String quoteArgument( String argument ) /** * @deprecated Use {@link CommandLineUtils#toString(String[])} instead. */ + @Deprecated public static String toString( String[] line ) { return CommandLineUtils.toString( line ); @@ -754,6 +766,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 +779,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 +800,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 +810,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..c36f64ee 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java +++ b/src/main/java/org/codehaus/plexus/util/cli/DefaultConsumer.java @@ -26,6 +26,7 @@ public class DefaultConsumer implements StreamConsumer { + @Override public void consumeLine( String line ) throws IOException { 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..97b715f0 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java +++ b/src/main/java/org/codehaus/plexus/util/cli/WriterStreamConsumer.java @@ -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..e955eecc 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 @@ -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..50ecbd68 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 @@ -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/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java index 75b5f80e..2150be01 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 @@ -121,7 +121,7 @@ public String[] getShellArgs() } else { - return (String[]) shellArgs.toArray( new String[shellArgs.size()] ); + return shellArgs.toArray( new String[shellArgs.size()] ); } } @@ -381,6 +381,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..53c2c657 100644 --- a/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java +++ b/src/main/java/org/codehaus/plexus/util/dag/CycleDetectedException.java @@ -56,6 +56,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/DAG.java b/src/main/java/org/codehaus/plexus/util/dag/DAG.java index 19fe67c8..2e75e8c7 100644 --- a/src/main/java/org/codehaus/plexus/util/dag/DAG.java +++ b/src/main/java/org/codehaus/plexus/util/dag/DAG.java @@ -169,7 +169,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; } @@ -211,6 +211,7 @@ public List getParentLabels( final String label ) /** * @see java.lang.Object#clone() */ + @Override public Object clone() throws CloneNotSupportedException { 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..b8081b48 100644 --- a/src/main/java/org/codehaus/plexus/util/dag/Vertex.java +++ b/src/main/java/org/codehaus/plexus/util/dag/Vertex.java @@ -166,6 +166,7 @@ public boolean isConnected() return isRoot() || isLeaf(); } + @Override public Object clone() throws CloneNotSupportedException { @@ -175,6 +176,7 @@ public Object clone() return retValue; } + @Override public String toString() { return "Vertex{" + "label='" + label + "'" + "}"; 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..f4adcdf5 100644 --- a/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java +++ b/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java @@ -536,7 +536,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 ) { 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..279e3cef 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/CompactXMLWriter.java @@ -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..df14f8e9 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriter.java @@ -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..d3851035 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/SerializerXMLWriter.java @@ -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/XmlReader.java b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java index 2cd639e7..9864d3df 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java @@ -57,6 +57,7 @@ * @deprecated use XmlStreamReader * @since 1.4.3 */ +@Deprecated public class XmlReader extends Reader { @@ -415,6 +416,7 @@ public String getEncoding() return _encoding; } + @Override public int read( char[] buf, int offset, int len ) throws IOException { @@ -427,6 +429,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/XmlStreamWriter.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java index c4afd065..2dfcc5f0 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java @@ -65,6 +65,7 @@ public String getEncoding() return encoding; } + @Override public void close() throws IOException { @@ -77,6 +78,7 @@ public void close() writer.close(); } + @Override public void flush() throws IOException { @@ -147,6 +149,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..54318004 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; @@ -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/Xpp3Dom.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java index a7026384..1660f9a7 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -558,6 +558,7 @@ public static Xpp3Dom mergeXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive ) // Standard object handling // ---------------------------------------------------------------------- + @Override public boolean equals( Object obj ) { if ( obj == this ) @@ -594,6 +595,7 @@ else if ( childList == null ? dom.childList != null : !childList.equals( dom.chi } } + @Override public int hashCode() { int result = 17; @@ -604,6 +606,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/pull/MXParser.java b/src/main/java/org/codehaus/plexus/util/xml/pull/MXParser.java index 85a90293..475fe7a4 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 @@ -538,6 +538,7 @@ public void setupFromTemplate() * @param state a boolean * @throws XmlPullParserException */ + @Override public void setFeature( String name, boolean state ) throws XmlPullParserException { @@ -587,6 +588,7 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) ) /** * Unknown properties are always returned as false */ + @Override public boolean getFeature( String name ) { if ( name == null ) @@ -615,6 +617,7 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) ) return false; } + @Override public void setProperty( String name, Object value ) throws XmlPullParserException { @@ -628,6 +631,7 @@ public void setProperty( String name, Object value ) } } + @Override public Object getProperty( String name ) { if ( name == null ) @@ -651,6 +655,7 @@ else if ( PROPERTY_LOCATION.equals( name ) ) return null; } + @Override public void setInput( Reader in ) throws XmlPullParserException { @@ -658,6 +663,7 @@ public void setInput( Reader in ) reader = in; } + @Override public void setInput( java.io.InputStream inputStream, String inputEncoding ) throws XmlPullParserException { @@ -691,11 +697,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 { @@ -732,6 +740,7 @@ public void defineEntityReplacementText( String entityName, String replacementTe // TOOD keepEntityNormalizedForAttributeValue cached as well ... } + @Override public int getNamespaceCount( int depth ) throws XmlPullParserException { @@ -746,6 +755,7 @@ public int getNamespaceCount( int depth ) return elNamespaceCount[depth]; } + @Override public String getNamespacePrefix( int pos ) throws XmlPullParserException { @@ -763,6 +773,7 @@ public String getNamespacePrefix( int pos ) } } + @Override public String getNamespaceUri( int pos ) throws XmlPullParserException { @@ -779,6 +790,7 @@ public String getNamespaceUri( int pos ) } } + @Override public String getNamespace( String prefix ) // throws XmlPullParserException { @@ -815,6 +827,7 @@ else if ( "xmlns".equals( prefix ) ) return null; } + @Override public int getDepth() { return depth; @@ -850,6 +863,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; @@ -871,16 +885,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 { @@ -912,6 +929,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 ) @@ -941,6 +959,7 @@ else if ( eventType == ENTITY_REF ) return text; } + @Override public char[] getTextCharacters( int[] holderForStartAndLength ) { if ( eventType == TEXT ) @@ -988,6 +1007,7 @@ else if ( eventType == START_DOCUMENT || eventType == END_DOCUMENT ) // return cb; } + @Override public String getNamespace() { if ( eventType == START_TAG ) @@ -1018,6 +1038,7 @@ else if ( eventType == END_TAG ) // return ""; } + @Override public String getName() { if ( eventType == START_TAG ) @@ -1043,6 +1064,7 @@ else if ( eventType == ENTITY_REF ) } } + @Override public String getPrefix() { if ( eventType == START_TAG ) @@ -1060,6 +1082,7 @@ else if ( eventType == END_TAG ) // return elPrefix[ maxDepth ]; } + @Override public boolean isEmptyElementTag() throws XmlPullParserException { @@ -1068,6 +1091,7 @@ public boolean isEmptyElementTag() return emptyElementTag; } + @Override public int getAttributeCount() { if ( eventType != START_TAG ) @@ -1075,6 +1099,7 @@ public int getAttributeCount() return attributeCount; } + @Override public String getAttributeNamespace( int index ) { if ( eventType != START_TAG ) @@ -1087,6 +1112,7 @@ public String getAttributeNamespace( int index ) return attributeUri[index]; } + @Override public String getAttributeName( int index ) { if ( eventType != START_TAG ) @@ -1097,6 +1123,7 @@ public String getAttributeName( int index ) return attributeName[index]; } + @Override public String getAttributePrefix( int index ) { if ( eventType != START_TAG ) @@ -1109,6 +1136,7 @@ public String getAttributePrefix( int index ) return attributePrefix[index]; } + @Override public String getAttributeType( int index ) { if ( eventType != START_TAG ) @@ -1119,6 +1147,7 @@ public String getAttributeType( int index ) return "CDATA"; } + @Override public boolean isAttributeDefault( int index ) { if ( eventType != START_TAG ) @@ -1129,6 +1158,7 @@ public boolean isAttributeDefault( int index ) return false; } + @Override public String getAttributeValue( int index ) { if ( eventType != START_TAG ) @@ -1139,6 +1169,7 @@ public String getAttributeValue( int index ) return attributeValue[index]; } + @Override public String getAttributeValue( String namespace, String name ) { if ( eventType != START_TAG ) @@ -1185,12 +1216,14 @@ 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 { @@ -1249,6 +1282,7 @@ else if ( eventType == START_TAG ) // return result; // } + @Override public String nextText() throws XmlPullParserException, IOException { @@ -1298,6 +1332,7 @@ else if ( eventType == END_TAG ) } } + @Override public int nextTag() throws XmlPullParserException, IOException { @@ -1314,6 +1349,7 @@ public int nextTag() return eventType; } + @Override public int next() throws XmlPullParserException, IOException { @@ -1321,6 +1357,7 @@ public int next() return nextImpl(); } + @Override public int nextToken() throws XmlPullParserException, IOException { @@ -3999,7 +4036,7 @@ else if ( ch == '\'' ) } if ( ch > 127 || ch < 32 ) { - return "\\u" + Integer.toHexString( (int) ch ); + return "\\u" + Integer.toHexString( ch ); } return "" + ch; } 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..6724be84 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 { @@ -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 { 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..61cf66c3 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; @@ -52,6 +53,7 @@ public XmlPullParserException( String msg, XmlPullParser parser, Throwable chain * @deprecated Use the generic getCause() method * @return */ + @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 ) From e1304ddeb9aef72ac27a1b7f7e58908cc7cee286 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sun, 8 Dec 2019 13:27:08 +0100 Subject: [PATCH 006/133] #26 Support combine.keys (in sync with xml-combiner implementation) --- .../java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java | 7 ++++--- .../org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) 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 71efe467..90213329 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java @@ -171,11 +171,12 @@ 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 ) { String idValue = recessiveChild.getAttribute( ID_COMBINATION_MODE_ATTRIBUTE ); - String keysValue = recessiveChild.getAttribute( KEYS_COMBINATION_MODE_ATTRIBUTE ); Xpp3Dom childDom = null; if ( isNotEmpty( idValue ) ) @@ -196,7 +197,7 @@ else if ( isNotEmpty( keysValue ) ) Map recessiveKeyValues = new HashMap( keys.length ); for ( String key : keys ) { - recessiveKeyValues.put( key, recessiveChild.getChild( key ).getValue() ); + recessiveKeyValues.put( key, recessiveChild.getAttribute( key ) ); } for ( Xpp3Dom dominantChild : dominant.getChildren() ) @@ -204,7 +205,7 @@ else if ( isNotEmpty( keysValue ) ) Map dominantKeyValues = new HashMap( keys.length ); for ( String key : keys ) { - dominantKeyValues.put( key, dominantChild.getChild( key ).getValue() ); + dominantKeyValues.put( key, dominantChild.getAttribute( key ) ); } if ( recessiveKeyValues.equals( dominantKeyValues ) ) diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java index e5a68e77..9a03fa35 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java @@ -64,10 +64,10 @@ public void testCombineId() public void testCombineKeys() throws Exception { - String lhs = "" + "LHS-ONLYLHS" + String lhs = "" + "LHS-ONLYLHS" + "TOOVERWRITELHS" + ""; - String rhs = "" + "RHS-ONLYRHS" + String rhs = "" + "RHS-ONLYRHS" + "TOOVERWRITERHS" + ""; Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) ); From f9e9bef36dbe7a5f19c454c4c7252814b343b5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Tue, 21 Jan 2020 19:44:19 +0100 Subject: [PATCH 007/133] activate Reproducible Builds --- pom.xml | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index 0344cc8f..38255227 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.codehaus.plexus plexus - 6.0 + 6.1 plexus-utils @@ -50,6 +50,10 @@ limitations under the License. + + 2020-01-20T18:52:37Z + + org.apache.maven.shared @@ -120,25 +124,6 @@ limitations under the License. - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-java - - enforce - - - - - 1.7.0 - - - - - - From e230b6f492101808ba1d69e38c02779a4aea6f71 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 29 Jul 2020 15:46:16 +1000 Subject: [PATCH 008/133] add ghactions Signed-off-by: olivier lamy --- .github/release-drafter.yml | 2 ++ .github/workflows/maven.yml | 52 +++++++++++++++++++++++++++ .github/workflows/release-drafter.yml | 12 +++++++ 3 files changed, 66 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/maven.yml create mode 100644 .github/workflows/release-drafter.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 00000000..367327d3 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,2 @@ +_extends: .github +tag-template: jira-plugin-$NEXT_MINOR_VERSION diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000..052712f1 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,52 @@ +# 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: + + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + java: [8, 11, 14] + fail-fast: false + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up cache for ~./m2/repository + uses: actions/cache@v1 + with: + path: ~/.m2/repository + key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} + restore-keys: | + maven-${{ matrix.os }}-java${{ matrix.java }}- + maven-${{ matrix.os }}- + + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Build with Maven + run: mvn verify -e -B -V diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 00000000..84d3cb6f --- /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.11.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From df3ae99df4630b24d6108ab56aadfcddf6991ab4 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 29 Jul 2020 15:48:10 +1000 Subject: [PATCH 009/133] fix bad copy/paste Signed-off-by: olivier lamy --- .github/release-drafter.yml | 59 +++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 367327d3..4416f5a5 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,2 +1,57 @@ -_extends: .github -tag-template: jira-plugin-$NEXT_MINOR_VERSION +# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter +name-template: $NEXT_MINOR_VERSION +tag-template: plexus-compiler-$NEXT_MINOR_VERSION +version-template: $MAJOR.$MINOR.$PATCH + +# Emoji reference: https://gitmoji.carloscuesta.me/ +categories: + - title: ":boom: Breaking changes" + labels: + - breaking + - title: 🚨 Removed + label: removed + - title: ":tada: Major features and improvements" + labels: + - major-enhancement + - major-rfe + - title: 🐛 Major bug fixes + labels: + - major-bug + - title: âš ī¸ Deprecated + label: deprecated + - title: 🚀 New features and improvements + labels: + - enhancement + - feature + - rfe + - title: 🐛 Bug Fixes + labels: + - bug + - fix + - bugfix + - regression + - title: ":construction_worker: Changes for plugin developers" + labels: + - developer + # Default label used by Dependabot + - title: đŸ“Ļ Dependency updates + label: dependencies + - title: 📝 Documentation updates + label: documentation + - title: đŸ‘ģ Maintenance + labels: + - chore + - internal + - title: đŸšĻ Tests + labels: + - test + - tests +exclude-labels: + - reverted + - no-changelog + - skip-changelog + - invalid + +template: | + + $CHANGES From e9d453ac8530c60e04ddec65a6283232475d1021 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Wed, 29 Jul 2020 15:54:55 +1000 Subject: [PATCH 010/133] use template Signed-off-by: olivier lamy --- .github/release-drafter.yml | 59 ++----------------------------------- 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 4416f5a5..c7f59480 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,57 +1,2 @@ -# Configuration for Release Drafter: https://github.com/toolmantim/release-drafter -name-template: $NEXT_MINOR_VERSION -tag-template: plexus-compiler-$NEXT_MINOR_VERSION -version-template: $MAJOR.$MINOR.$PATCH - -# Emoji reference: https://gitmoji.carloscuesta.me/ -categories: - - title: ":boom: Breaking changes" - labels: - - breaking - - title: 🚨 Removed - label: removed - - title: ":tada: Major features and improvements" - labels: - - major-enhancement - - major-rfe - - title: 🐛 Major bug fixes - labels: - - major-bug - - title: âš ī¸ Deprecated - label: deprecated - - title: 🚀 New features and improvements - labels: - - enhancement - - feature - - rfe - - title: 🐛 Bug Fixes - labels: - - bug - - fix - - bugfix - - regression - - title: ":construction_worker: Changes for plugin developers" - labels: - - developer - # Default label used by Dependabot - - title: đŸ“Ļ Dependency updates - label: dependencies - - title: 📝 Documentation updates - label: documentation - - title: đŸ‘ģ Maintenance - labels: - - chore - - internal - - title: đŸšĻ Tests - labels: - - test - - tests -exclude-labels: - - reverted - - no-changelog - - skip-changelog - - invalid - -template: | - - $CHANGES +_extends: .github +tag-template: plexus-utils-$NEXT_MINOR_VERSION From 3f9c4ba68c0767164f2f789f206ec193317c33d2 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 14 Aug 2020 15:39:12 +1000 Subject: [PATCH 011/133] Create dependabot.yml --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml 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" From 2a603fae00b612c5af58626420ae20ad86bae0ff Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 14 Aug 2020 15:39:57 +1000 Subject: [PATCH 012/133] Update maven.yml --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 052712f1..44883b1f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - java: [8, 11, 14] + java: [7, 8, 11, 14, 15-ea] fail-fast: false runs-on: ${{ matrix.os }} From ff298e0c5a15117ca7ea16166bc30584b74b71c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2020 17:09:00 +1000 Subject: [PATCH 013/133] Bump actions/cache from v1 to v2.1.0 (#83) Bumps [actions/cache](https://github.com/actions/cache) from v1 to v2.1.0. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v1...d29c1df198dd38ac88e0ae23a2881b99c2d20e68) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 44883b1f..8101dd9c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2 - name: Set up cache for ~./m2/repository - uses: actions/cache@v1 + uses: actions/cache@v2.1.0 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From f9a5117d22dd8eedc2e1bda6b2e4a628a3ead0da Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2020 17:09:20 +1000 Subject: [PATCH 014/133] Bump jmh-core from 1.21 to 1.25 (#84) Bumps jmh-core from 1.21 to 1.25. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 38255227..28f41060 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.21 + 1.25 test From 787141a69fea504d688213a0526b397abc47e64f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2020 17:09:54 +1000 Subject: [PATCH 015/133] Bump jmh-generator-annprocess from 1.21 to 1.25 (#85) Bumps jmh-generator-annprocess from 1.21 to 1.25. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 28f41060..7e414e57 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.21 + 1.25 test From 01d82ae8d2fbf973b4b908f74688d8cc380182ad Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 15 Aug 2020 21:44:58 +1000 Subject: [PATCH 016/133] Fix Javadoc build with Java 11 (#88) * remove svn id * fix javadoc * remove svn tokens * fix javadoc with jdk14 Signed-off-by: olivier lamy --- .github/workflows/maven.yml | 2 +- pom.xml | 2 +- .../java/org/codehaus/plexus/util/Base64.java | 2 +- .../org/codehaus/plexus/util/CachedMap.java | 4 +- .../codehaus/plexus/util/CollectionUtils.java | 31 ++-- .../plexus/util/DirectoryWalkListener.java | 2 +- .../codehaus/plexus/util/DirectoryWalker.java | 2 +- .../codehaus/plexus/util/ExceptionUtils.java | 18 ++- .../java/org/codehaus/plexus/util/Expand.java | 13 +- .../org/codehaus/plexus/util/FileUtils.java | 21 +-- .../java/org/codehaus/plexus/util/IOUtil.java | 150 +++++++++++++----- .../util/LineOrientedInterpolatingReader.java | 4 +- .../org/codehaus/plexus/util/NioFiles.java | 4 +- .../java/org/codehaus/plexus/util/Os.java | 7 +- .../org/codehaus/plexus/util/PathTool.java | 16 +- .../codehaus/plexus/util/ReaderFactory.java | 2 +- .../codehaus/plexus/util/ReflectionUtils.java | 26 +-- .../org/codehaus/plexus/util/Scanner.java | 2 +- .../codehaus/plexus/util/SelectorUtils.java | 4 +- .../plexus/util/StringOutputStream.java | 2 +- .../org/codehaus/plexus/util/StringUtils.java | 81 +++++----- .../org/codehaus/plexus/util/SweeperPool.java | 39 ++--- .../codehaus/plexus/util/WriterFactory.java | 2 +- .../plexus/util/cli/CommandLineCallable.java | 2 +- .../plexus/util/cli/CommandLineException.java | 2 +- .../util/cli/CommandLineTimeOutException.java | 9 +- .../plexus/util/cli/CommandLineUtils.java | 15 +- .../codehaus/plexus/util/cli/Commandline.java | 57 ++++--- .../plexus/util/cli/DefaultConsumer.java | 2 +- .../util/cli/EnhancedStringTokenizer.java | 2 +- .../plexus/util/cli/StreamConsumer.java | 2 +- .../plexus/util/cli/StreamFeeder.java | 3 +- .../plexus/util/cli/StreamPumper.java | 2 +- .../plexus/util/cli/WriterStreamConsumer.java | 2 +- .../plexus/util/cli/shell/BourneShell.java | 2 +- .../plexus/util/cli/shell/CmdShell.java | 2 +- .../plexus/util/cli/shell/CommandShell.java | 2 +- .../codehaus/plexus/util/cli/shell/Shell.java | 21 ++- .../util/dag/CycleDetectedException.java | 3 - .../plexus/util/dag/CycleDetector.java | 26 +-- .../org/codehaus/plexus/util/dag/DAG.java | 21 +-- .../plexus/util/dag/TopologicalSorter.java | 16 +- .../org/codehaus/plexus/util/dag/Vertex.java | 25 +-- .../plexus/util/introspection/ClassMap.java | 9 +- .../plexus/util/introspection/MethodMap.java | 2 +- .../ReflectionValueExtractor.java | 3 +- .../plexus/util/io/InputStreamFacade.java | 4 +- .../plexus/util/reflection/Reflector.java | 54 ++----- .../plexus/util/xml/CompactXMLWriter.java | 2 +- .../plexus/util/xml/PrettyPrintXMLWriter.java | 2 +- .../plexus/util/xml/SerializerXMLWriter.java | 2 +- .../codehaus/plexus/util/xml/XMLWriter.java | 2 +- .../codehaus/plexus/util/xml/XmlReader.java | 1 + .../plexus/util/xml/XmlStreamReader.java | 1 + .../plexus/util/xml/XmlStreamWriter.java | 2 +- .../org/codehaus/plexus/util/xml/XmlUtil.java | 2 +- .../plexus/util/xml/XmlWriterUtil.java | 22 +-- .../org/codehaus/plexus/util/xml/Xpp3Dom.java | 13 +- .../plexus/util/xml/Xpp3DomBuilder.java | 23 ++- .../plexus/util/xml/Xpp3DomUtils.java | 8 +- .../plexus/util/xml/Xpp3DomWriter.java | 2 +- .../plexus/util/xml/pull/MXParser.java | 25 ++- .../plexus/util/xml/pull/MXSerializer.java | 2 +- .../plexus/util/xml/pull/XmlPullParser.java | 83 +++++++--- .../util/xml/pull/XmlPullParserException.java | 2 +- .../plexus/util/xml/pull/XmlSerializer.java | 68 +++++++- .../plexus/util/AbstractTestThread.java | 2 +- .../codehaus/plexus/util/FileUtilsTest.java | 2 +- .../codehaus/plexus/util/PathToolTest.java | 2 +- .../plexus/util/StringInputStreamTest.java | 2 +- .../codehaus/plexus/util/StringUtilsTest.java | 2 +- .../codehaus/plexus/util/SweeperPoolTest.java | 2 +- .../plexus/util/TestThreadManager.java | 2 +- .../java/org/codehaus/plexus/util/Tracer.java | 2 +- .../util/dag/CycleDetectedExceptionTest.java | 2 +- .../plexus/util/dag/CycleDetectorTest.java | 2 +- .../org/codehaus/plexus/util/dag/DAGTest.java | 2 +- .../util/dag/TopologicalSorterTest.java | 2 +- .../codehaus/plexus/util/dag/VertexTest.java | 2 +- .../ReflectionValueExtractorTest.java | 4 +- .../plexus/util/reflection/ReflectorTest.java | 2 +- .../util/xml/PrettyPrintXMLWriterTest.java | 2 +- .../codehaus/plexus/util/xml/XmlUtilTest.java | 2 +- .../plexus/util/xml/XmlWriterUtilTest.java | 2 +- .../plexus/util/xml/Xpp3DomBuilderTest.java | 2 +- .../plexus/util/xml/pull/MXParserTest.java | 2 +- 86 files changed, 594 insertions(+), 434 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8101dd9c..da347c14 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -49,4 +49,4 @@ jobs: java-version: ${{ matrix.java }} - name: Build with Maven - run: mvn verify -e -B -V + run: mvn verify javadoc:javadoc -e -B -V diff --git a/pom.xml b/pom.xml index 7e414e57..e3f738d9 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ limitations under the License. org.apache.maven.plugins maven-javadoc-plugin - 3.0.0 + 3.2.0 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/CachedMap.java b/src/main/java/org/codehaus/plexus/util/CachedMap.java index 0d399291..c77d2180 100644 --- a/src/main/java/org/codehaus/plexus/util/CachedMap.java +++ b/src/main/java/org/codehaus/plexus/util/CachedMap.java @@ -415,7 +415,7 @@ public Set 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. @@ -437,4 +437,4 @@ 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/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 40f3c3cc..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 { diff --git a/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java b/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java index 6f8d1424..341dc80d 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 { @@ -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,7 +344,7 @@ 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 ); @@ -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; ) { diff --git a/src/main/java/org/codehaus/plexus/util/Expand.java b/src/main/java/org/codehaus/plexus/util/Expand.java index db81df4a..ffc74628 100644 --- a/src/main/java/org/codehaus/plexus/util/Expand.java +++ b/src/main/java/org/codehaus/plexus/util/Expand.java @@ -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,12 +93,6 @@ 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 { @@ -116,9 +110,6 @@ protected void expandFile( final File srcF, final File dir ) } } - /** - * Description of the Method - */ protected void extractFile( File srcF, File dir, InputStream compressedInputStream, String entryName, Date entryDate, boolean isDirectory ) throws Exception @@ -188,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/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index 7cd1ddcf..8d74d775 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -82,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: @@ -95,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 @@ -112,7 +112,7 @@ * @author Christoph.Reck * @author Peter Donald * @author Jeff Turner - * @version $Id$ + * */ public class FileUtils { @@ -988,6 +988,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 @@ -1696,7 +1697,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 ) @@ -1713,7 +1714,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 ) @@ -1739,7 +1740,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 @@ -1756,7 +1757,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 ) @@ -1773,7 +1774,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 ) @@ -1791,7 +1792,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 ) @@ -1811,7 +1812,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, diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index 0bbd1fd2..3fab8411 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 */ @@ -149,6 +149,9 @@ 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 @@ -158,8 +161,10 @@ public static void copy( final InputStream input, final OutputStream 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,6 +179,9 @@ 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 @@ -183,8 +191,10 @@ public static void copy( final Reader input, final Writer 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,9 +520,11 @@ 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 ) @@ -491,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 @@ -500,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 @@ -523,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 @@ -533,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 @@ -546,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 @@ -561,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 @@ -578,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 @@ -588,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 @@ -602,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 @@ -615,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 @@ -635,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 @@ -644,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 @@ -659,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 diff --git a/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java b/src/main/java/org/codehaus/plexus/util/LineOrientedInterpolatingReader.java index b22ff887..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 ) @@ -471,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/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/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java index 70389d68..46041a20 100644 --- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java +++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java @@ -36,7 +36,7 @@ * @author Herve Boutemy * @see Charset * @see Supported encodings - * @version $Id$ + * * @since 1.4.3 */ public class ReaderFactory diff --git a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java index d43d62a6..e83488cc 100644 --- a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java +++ b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java @@ -32,7 +32,7 @@ * @author Michal Maczka * @author Jesse McConnell * @author Trygve Laugstøl - * @version $Id$ + * */ public final class ReflectionUtils { @@ -63,7 +63,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 +104,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 +125,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 +146,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 +163,10 @@ 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 ); 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..2686cfee 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() { diff --git a/src/main/java/org/codehaus/plexus/util/StringOutputStream.java b/src/main/java/org/codehaus/plexus/util/StringOutputStream.java index b4051925..ef22b575 100644 --- a/src/main/java/org/codehaus/plexus/util/StringOutputStream.java +++ b/src/main/java/org/codehaus/plexus/util/StringOutputStream.java @@ -23,7 +23,7 @@ * 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)}. */ diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java index b52a5a3b..2e6a2f3f 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 ) { @@ -578,7 +577,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 +893,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 +2142,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 +2158,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 +2208,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 +2227,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 +2343,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 +2359,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 +2372,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 +2388,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 +2404,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 +2459,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 +2471,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 dcfa0e71..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 ) { diff --git a/src/main/java/org/codehaus/plexus/util/WriterFactory.java b/src/main/java/org/codehaus/plexus/util/WriterFactory.java index 229f1082..87a4283d 100644 --- a/src/main/java/org/codehaus/plexus/util/WriterFactory.java +++ b/src/main/java/org/codehaus/plexus/util/WriterFactory.java @@ -35,7 +35,7 @@ * @author Herve Boutemy * @see Charset * @see Supported encodings - * @version $Id$ + * * @since 1.4.4 */ public class WriterFactory 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 9e8179c3..0a861a75 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java +++ b/src/main/java/org/codehaus/plexus/util/cli/CommandLineCallable.java @@ -27,6 +27,6 @@ public interface CommandLineCallable extends Callable { @Override - public Integer call() + 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 9de3970e..4a556c84 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 { @@ -500,7 +500,8 @@ 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 @@ -522,7 +523,9 @@ 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 @@ -537,6 +540,12 @@ 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. 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 1d92e2e1..c06147a9 100644 --- a/src/main/java/org/codehaus/plexus/util/cli/Commandline.java +++ b/src/main/java/org/codehaus/plexus/util/cli/Commandline.java @@ -109,7 +109,7 @@ public class Commandline @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 @@ -136,7 +136,8 @@ public class Commandline * 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 ) { @@ -164,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 ) { @@ -173,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 ) { @@ -239,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.

    */ @@ -307,6 +309,7 @@ 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 ) @@ -338,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.

    * @@ -360,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 ) @@ -371,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. */ @@ -389,6 +391,7 @@ public void addArg( Arg argument, boolean insertAtStart ) /** * Sets the executable to run. + * @param executable the executable */ public void setExecutable( String executable ) { @@ -432,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 ) { @@ -441,6 +446,7 @@ public void addEnvironment( String name, String value ) /** * Add system environment variables + * @throws Exception if error */ public void addSystemEnvironment() throws Exception @@ -458,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 @@ -484,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() { @@ -498,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() { @@ -519,6 +526,7 @@ 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() { @@ -529,11 +537,11 @@ public String[] getShellCommandline() } /** - * 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 ); @@ -594,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() { @@ -607,6 +615,7 @@ public Marker createMarker() /** * Sets execution directory. + * @param path the working directory as String */ public void setWorkingDirectory( String path ) { @@ -616,6 +625,7 @@ public void setWorkingDirectory( String path ) /** * Sets execution directory. + * @param workingDirectory the File used as working directory */ public void setWorkingDirectory( File workingDirectory ) { @@ -637,6 +647,8 @@ public File getWorkingDirectory() /** * Executes the command. + * @return the Process + * @throws CommandLineException if error */ public Process execute() throws CommandLineException @@ -709,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 ) @@ -722,6 +734,7 @@ public void setShell( Shell shell ) * execution. * * @since 1.2 + * @return the Shell */ public Shell getShell() { @@ -729,6 +742,9 @@ 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 @@ -739,6 +755,9 @@ 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 @@ -750,6 +769,8 @@ 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 ) 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 c36f64ee..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,7 +20,7 @@ /** * @author Emmanuel Venisse - * @version $Id$ + * */ public class DefaultConsumer implements StreamConsumer 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 97b715f0..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 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 e955eecc..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 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 50ecbd68..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 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 2150be01..6082849c 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() { @@ -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 ) { 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 53c2c657..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(); 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 2e75e8c7..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() @@ -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 ) { @@ -223,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 ) @@ -252,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 b8081b48..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 ) { 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/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/reflection/Reflector.java b/src/main/java/org/codehaus/plexus/util/reflection/Reflector.java index f4adcdf5..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. */ @@ -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 279e3cef..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 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 df14f8e9..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 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 d3851035..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 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 9864d3df..2d662f56 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java @@ -312,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. */ 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 2dfcc5f0..cf4e4be7 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java @@ -33,7 +33,7 @@ * the XML document written to the stream. * * @author Herve Boutemy - * @version $Id$ + * * @since 1.4.4 */ public class XmlStreamWriter 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 54318004..73464b8e 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java +++ b/src/main/java/org/codehaus/plexus/util/xml/XmlUtil.java @@ -35,7 +35,7 @@ * Common XML utilities methods. * * @author Vincent Siveton - * @version $Id$ + * * @since 1.5.7 */ public class XmlUtil 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 1660f9a7..db628e41 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3Dom.java @@ -30,7 +30,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 @@ -88,11 +88,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 ) { @@ -102,6 +104,7 @@ public Xpp3Dom( String name, Object inputLocation ) /** * Copy constructor. + * @param src The source Dom. */ public Xpp3Dom( Xpp3Dom src ) { @@ -110,6 +113,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 ) { @@ -329,6 +334,7 @@ public void setParent( Xpp3Dom parent ) /** * @since 3.2.0 + * @return input location */ public Object getInputLocation() { @@ -337,6 +343,7 @@ public Object getInputLocation() /** * @since 3.2.0 + * @param inputLocation input location to set */ public void setInputLocation( Object inputLocation ) { @@ -524,6 +531,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 ) { @@ -543,6 +551,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 ) { 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 90213329..b94cfe84 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java @@ -55,7 +55,7 @@ public class Xpp3DomUtils * 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 + * @since 3.4.0 */ public static final String KEYS_COMBINATION_MODE_ATTRIBUTE = "combine.keys"; @@ -194,7 +194,7 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole else if ( isNotEmpty( keysValue ) ) { String[] keys = keysValue.split( "," ); - Map recessiveKeyValues = new HashMap( keys.length ); + Map recessiveKeyValues = new HashMap<>( keys.length ); for ( String key : keys ) { recessiveKeyValues.put( key, recessiveChild.getAttribute( key ) ); @@ -202,7 +202,7 @@ else if ( isNotEmpty( keysValue ) ) for ( Xpp3Dom dominantChild : dominant.getChildren() ) { - Map dominantKeyValues = new HashMap( keys.length ); + Map dominantKeyValues = new HashMap<>( keys.length ); for ( String key : keys ) { dominantKeyValues.put( key, dominantChild.getAttribute( key ) ); @@ -243,6 +243,7 @@ else if ( isNotEmpty( keysValue ) ) * @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 ) { @@ -262,6 +263,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 ) { 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 475fe7a4..6874eefa 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 @@ -220,9 +220,7 @@ protected void ensureElementsCapacity() // protected int attributeValueStart[]; // protected int attributeValueEnd[]; - /** - * Make sure that in attributes temporary array is enough space. - */ + // Make sure that in attributes temporary array is enough space. protected void ensureAttributesCapacity( int size ) { final int attrPosSize = attributeName != null ? attributeName.length : 0; @@ -312,10 +310,10 @@ 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 ... - */ + + // 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 ) { if ( len == 0 ) @@ -536,7 +534,7 @@ public void setupFromTemplate() * * @param name a String * @param state a boolean - * @throws XmlPullParserException + * @throws XmlPullParserException issue */ @Override public void setFeature( String name, boolean state ) @@ -1252,8 +1250,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 @@ -4100,12 +4100,7 @@ private static boolean isSupplementaryCodePoint( int codePoint ) return ( MIN_SUPPLEMENTARY_CODE_POINT <= codePoint && MAX_CODE_POINT >= codePoint ); } - /** - * TODO add javadoc - * - * @param codePoint - * @return - */ + // TODO add javadoc public static char[] toChars( int codePoint ) { if ( !isValidCodePoint( 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 6724be84..cd1edc59 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 @@ -1342,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 * (&amp;), lt (&lt;), gt (&gt;), quot (&quot;), and apos (&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 61cf66c3..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 @@ -51,7 +51,7 @@ public XmlPullParserException( String msg, XmlPullParser parser, Throwable chain /** * @deprecated Use the generic getCause() method - * @return + * @return the cause */ @Deprecated public Throwable getDetail() 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/test/java/org/codehaus/plexus/util/AbstractTestThread.java b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java index 8d556e5e..45c7329d 100644 --- a/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java +++ b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java @@ -24,7 +24,7 @@ *

    * * @author Bert van Brakel - * @version $Revision$ + * */ public abstract class AbstractTestThread implements Runnable diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index f29dd418..6a326c4b 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -46,7 +46,7 @@ * * @author Peter Donald * @author Matthew Hawthorne - * @version $Id$ + * * @see FileUtils */ public final class FileUtilsTest diff --git a/src/test/java/org/codehaus/plexus/util/PathToolTest.java b/src/test/java/org/codehaus/plexus/util/PathToolTest.java index e7f01ba8..4b9985a9 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -22,7 +22,7 @@ /** * @author Vincent Siveton - * @version $Id$ + * */ public class PathToolTest { diff --git a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java index 5d07271b..cc76544a 100644 --- a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java @@ -20,7 +20,7 @@ /** * @author Ben Walding - * @version $Id$ + * */ public class StringInputStreamTest extends TestCase diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index 42f1a75b..56df66a7 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -29,7 +29,7 @@ * Test string utils. * * @author Brett Porter - * @version $Id$ + * */ public class StringUtilsTest { diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 9dd1a41f..c080d7d0 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -33,7 +33,7 @@ * Created on 21/06/2003 * * @author Bert van Brakel - * @version $Revision$ + * */ public class SweeperPoolTest { diff --git a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java index bfc79229..7c954296 100644 --- a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java +++ b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java @@ -29,7 +29,7 @@ *

    * * @author Bert van Brakel - * @version $Revision$ + * */ public class TestThreadManager { diff --git a/src/test/java/org/codehaus/plexus/util/Tracer.java b/src/test/java/org/codehaus/plexus/util/Tracer.java index df6fd63a..334f85ff 100644 --- a/src/test/java/org/codehaus/plexus/util/Tracer.java +++ b/src/test/java/org/codehaus/plexus/util/Tracer.java @@ -26,7 +26,7 @@ *

    * * @author Bert van Brakel - * @version $Revision$ + * */ public class Tracer { diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java index 4d0c9ad9..8fd33944 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -25,7 +25,7 @@ /** * @author Jason van Zyl - * @version $Id$ + * */ public class CycleDetectedExceptionTest { diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java index df52fe0e..45db6bed 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -28,7 +28,7 @@ /** * @author Michal Maczka - * @version $Id$ + * */ public class CycleDetectorTest { diff --git a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java index 0ff1269c..a4210045 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java @@ -28,7 +28,7 @@ /** * @author Michal Maczka - * @version $Id$ + * */ public class DAGTest { diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java index 67afbbeb..36bdf1f9 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -25,7 +25,7 @@ /** * @author Michal Maczka - * @version $Id$ + * */ public class TopologicalSorterTest { diff --git a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java index 0044795b..d5ab0cd1 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java @@ -22,7 +22,7 @@ /** * @author Michal Maczka - * @version $Id$ + * */ public class VertexTest { diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java index 39b3f9fa..0eb34b6c 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -33,7 +33,7 @@ /** * @author Jason van Zyl - * @version $Id$ + * */ public class ReflectionValueExtractorTest { @@ -552,4 +552,4 @@ public void testRootPropertyRegression() Object evalued = ReflectionValueExtractor.evaluate( "description", project ); assertNotNull( evalued ); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java index c8f1c4aa..ed75fd58 100644 --- a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java @@ -23,7 +23,7 @@ /** * @author Jörg Schaible - * @version $Id$ + * */ public class ReflectorTest { diff --git a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java index 128d004f..1d5b046e 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java @@ -39,7 +39,7 @@ * * @author Vincent Siveton * @author Gabriel Belingueres - * @version $Id$ + * */ public class PrettyPrintXMLWriterTest { diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index 25ee91ae..91b6a7f7 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -39,7 +39,7 @@ * Test the {@link XmlUtil} class. * * @author Vincent Siveton - * @version $Id$ + * */ public class XmlUtilTest { diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java index 6c4fe638..34d99297 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java @@ -31,7 +31,7 @@ /** * @author Vincent Siveton - * @version $Id$ + * */ public class XmlWriterUtilTest { 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..f8ac0489 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java @@ -33,7 +33,7 @@ * Test the Xpp3DomBuilder. * * @author Brett Porter - * @version $Id$ + * */ public class Xpp3DomBuilderTest { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index c0754126..5b685e8e 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -28,7 +28,7 @@ /** * @author Trygve Laugstøl - * @version $Id$ + * */ public class MXParserTest { From d0b612123bbe845d273b81b3289c4395da72d506 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sat, 15 Aug 2020 13:50:24 +0200 Subject: [PATCH 017/133] FileUtils.linkFile(source, destination) (#82) --- .../org/codehaus/plexus/util/FileUtils.java | 32 +++++++++++++ .../codehaus/plexus/util/FileUtilsTest.java | 45 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index 8d74d775..fe80c7d4 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -1059,6 +1059,38 @@ private static void doCopyFileUsingNewIO( File source, File destination ) 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() ) + { + final String message = "File " + source + " does not exist"; + throw new IOException( message ); + } + + // check source != destination, see PLXUTILS-10 + if ( source.getCanonicalPath().equals( destination.getCanonicalPath() ) ) + { + // if they are equal, we can exit the method without doing any work + return; + } + mkdirsFor( destination ); + + NioFiles.createSymbolicLink( destination, source ); + } + /** * Copy file from source to destination only if source timestamp is later than the destination timestamp. The * directories up to destination will be created if they don't already exist. destination diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index 6a326c4b..d4ee85c0 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -34,6 +34,7 @@ import java.io.Reader; import java.io.Writer; import java.net.URL; +import java.nio.file.Files; import java.util.Properties; import org.junit.Before; @@ -428,6 +429,50 @@ public void testCopyFile3() assertTrue( "Check Full copy", destination.length() == testFile2Size ); } + // linkFile + @Test + public void testLinkFile1() + throws Exception + { + final File destination = new File( getTestDirectory(), "link1.txt" ); + FileUtils.linkFile( testFile1, destination ); + assertTrue( "Check Exist", destination.exists() ); + assertTrue( "Check File length", destination.length() == testFile1Size ); + assertTrue( "Check is link", Files.isSymbolicLink(destination.toPath())); + } + + @Test + public void testLinkFile2() + throws Exception + { + final File destination = new File( getTestDirectory(), "link2.txt" ); + FileUtils.linkFile( testFile1, destination ); + assertTrue( "Check Exist", destination.exists() ); + assertTrue( "Check File length", destination.length() == testFile2Size ); + assertTrue( "Check is link", Files.isSymbolicLink(destination.toPath())); + } + + /** + * ensure we create directory tree for destination + * + * @throws Exception + */ + @Test + public void testLinkFile3() + throws Exception + { + File destDirectory = new File( getTestDirectory(), "foo/bar/testlink" ); + if ( destDirectory.exists() ) + { + destDirectory.delete(); + } + final File destination = new File( destDirectory, "link2.txt" ); + FileUtils.linkFile( testFile1, destination ); + assertTrue( "Check Exist", destination.exists() ); + assertTrue( "Check File length", destination.length() == testFile2Size ); + assertTrue( "Check is link", Files.isSymbolicLink(destination.toPath())); + } + // copyFileIfModified @Test From 67c0873587757930973dc9c48e05201baebbd735 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 16 Aug 2020 19:04:16 +1000 Subject: [PATCH 018/133] avoid build issues with symlink (#90) Signed-off-by: olivier lamy --- pom.xml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e3f738d9..e205329a 100644 --- a/pom.xml +++ b/pom.xml @@ -55,12 +55,12 @@ limitations under the License. - - org.apache.maven.shared - maven-plugin-testing-harness - 1.1 - test - + + org.apache.maven.shared + maven-plugin-testing-harness + 1.1 + test + org.openjdk.jmh jmh-core @@ -78,6 +78,16 @@ limitations under the License. + + org.apache.maven.plugins + maven-resources-plugin + + 2.7 + org.apache.maven.plugins maven-javadoc-plugin From cfd4fdf1ff45f2a9a546bed9f25ebfc327940c40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2020 20:06:28 +1000 Subject: [PATCH 019/133] Bump plexus from 6.1 to 6.4 (#89) Bumps [plexus](https://github.com/codehaus-plexus/plexus-pom) from 6.1 to 6.4. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/compare/plexus-6.1...plexus-6.4) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e205329a..1524efc7 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.codehaus.plexus plexus - 6.1 + 6.4 plexus-utils From 57d9e235a049641f0a68b5da665cfd1973918e77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Aug 2020 06:06:03 +0000 Subject: [PATCH 020/133] Bump actions/cache from v2.1.0 to v2.1.1 Bumps [actions/cache](https://github.com/actions/cache) from v2.1.0 to v2.1.1. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.0...5ca27f25cb3a0babe750cad7e4fddd3e55f29e9a) Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index da347c14..bac76113 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2 - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.0 + uses: actions/cache@v2.1.1 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From 7a10026b1dd87d0ae68d8e5251ca47eed4a36100 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 27 Aug 2020 06:52:39 +1000 Subject: [PATCH 021/133] add removeAttribute method to Xpp3Dom (#94) * add removeAttribute method to Xpp3Dom Signed-off-by: olivier lamy * add javadoc Signed-off-by: olivier lamy --- .../java/org/codehaus/plexus/util/xml/Xpp3Dom.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 db628e41..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,6 +16,7 @@ * limitations under the License. */ +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlSerializer; import java.io.IOException; @@ -183,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 * From 02c6d96dccd7b9683b05373ff0a88863f2937a57 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Aug 2020 06:26:49 +0000 Subject: [PATCH 022/133] Bump jmh-generator-annprocess from 1.25 to 1.25.1 Bumps jmh-generator-annprocess from 1.25 to 1.25.1. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1524efc7..06c263dd 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.25 + 1.25.1 test From 870dc96fbe43ce3c2b37dd9e963269d3c8c5bfb4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Aug 2020 06:26:54 +0000 Subject: [PATCH 023/133] Bump jmh-core from 1.25 to 1.25.1 Bumps jmh-core from 1.25 to 1.25.1. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1524efc7..c7838fbc 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.25 + 1.25.1 test From 25787e47b933dad6df061c5c21b1647fbc84e842 Mon Sep 17 00:00:00 2001 From: Eshant Gupta Date: Thu, 27 Aug 2020 14:27:20 +0530 Subject: [PATCH 024/133] Added support for PPC64LE (#97) --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 94a20491..9bcfb349 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,11 @@ +arch: + - amd64 + - ppc64le + +addons: + apt: + packages: maven + language: java jdk: - openjdk7 From 70431739c9df2c54bed411b3b702ac9f0309acac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 06:39:50 +0000 Subject: [PATCH 025/133] Bump actions/cache from v2.1.1 to v2.1.2 Bumps [actions/cache](https://github.com/actions/cache) from v2.1.1 to v2.1.2. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.1...d1255ad9362389eac595a9ae406b8e8cb3331f16) Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bac76113..70731d4c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2 - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.1 + uses: actions/cache@v2.1.2 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From 48ce20249b2780a0e1a0b8240d741316bb56c453 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 06:39:53 +0000 Subject: [PATCH 026/133] Bump jmh-core from 1.25.1 to 1.26 Bumps jmh-core from 1.25.1 to 1.26. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index baa60b8a..46a8421e 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.25.1 + 1.26 test From c4de5513635d05f225bd78cf77658715083b0990 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 06:39:55 +0000 Subject: [PATCH 027/133] Bump jmh-generator-annprocess from 1.25.1 to 1.26 Bumps jmh-generator-annprocess from 1.25.1 to 1.26. Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index baa60b8a..e38bd929 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.25.1 + 1.26 test From dcd9f0a7e43726b3b73d01dc9c7282ffb8111f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 17 Oct 2020 17:03:50 +0200 Subject: [PATCH 028/133] update parent pom to 6.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dc5ef2e4..6aa94399 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.codehaus.plexus plexus - 6.4 + 6.5 plexus-utils From 4117c59641e21898809cb326380a62659ee72f40 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2020 21:07:32 +1000 Subject: [PATCH 029/133] Bump release-drafter/release-drafter from v5.11.0 to v5.12.1 (#104) Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from v5.11.0 to v5.12.1. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5.11.0...3782ccd1a495040818a9e5d0e8bc4ed22d3b1361) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 84d3cb6f..7b35f195 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,6 +7,6 @@ jobs: update_release_draft: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5.11.0 + - uses: release-drafter/release-drafter@v5.12.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From bec2f5370f83da0c6a72d0dc648fdeec2704a7e8 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Thu, 22 Oct 2020 21:19:01 +1000 Subject: [PATCH 030/133] add 16-ea and use 15 final Signed-off-by: olivier lamy --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 70731d4c..98849599 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - java: [7, 8, 11, 14, 15-ea] + java: [7, 8, 11, 14, 15, 16-ea] fail-fast: false runs-on: ${{ matrix.os }} From 94127aee1a09a00fc249be6c267d2079fbb1a2fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Nov 2020 06:58:28 +0000 Subject: [PATCH 031/133] Bump actions/cache from v2.1.2 to v2.1.3 Bumps [actions/cache](https://github.com/actions/cache) from v2.1.2 to v2.1.3. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.2...0781355a23dac32fd3bac414512f4b903437991a) Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 98849599..1de65ef7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2 - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.2 + uses: actions/cache@v2.1.3 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From 797cab4d0fb5ce88ef6863cc504f929f6978ff95 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 18 Nov 2020 18:30:09 +0100 Subject: [PATCH 032/133] Various small speed improvements (#106) * Use non synchronized collections * Use empty arrays when transforming collections to arrays * Avoid tokenizing each file name twice * Save a bunch of file system accesses * Save a few percent on parsing --- .../codehaus/plexus/util/AbstractScanner.java | 14 +- .../plexus/util/DirectoryScanner.java | 134 +++--- .../codehaus/plexus/util/ExceptionUtils.java | 8 +- .../org/codehaus/plexus/util/FileUtils.java | 5 +- .../codehaus/plexus/util/MatchPattern.java | 13 +- .../codehaus/plexus/util/MatchPatterns.java | 7 +- .../codehaus/plexus/util/SelectorUtils.java | 2 +- .../codehaus/plexus/util/cli/shell/Shell.java | 2 +- .../plexus/util/xml/pull/MXParser.java | 417 +++++++----------- .../util/xml/pull/MXParserPerfTest.java | 79 ++++ src/test/resources/xml/pom.xml | 140 ++++++ 11 files changed, 470 insertions(+), 351 deletions(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java create mode 100644 src/test/resources/xml/pom.xml diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java index 414b60b8..af3fbc4a 100644 --- a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java +++ b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java @@ -246,7 +246,7 @@ public void setIncludes( String[] includes ) list.add( normalizePattern( include ) ); } } - this.includes = list.toArray( new String[list.size()] ); + this.includes = list.toArray( new String[0] ); } } @@ -276,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] ); } } @@ -331,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. * @@ -360,6 +365,11 @@ 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. */ diff --git a/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java b/src/main/java/org/codehaus/plexus/util/DirectoryScanner.java index c17a9781..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. @@ -287,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 ) ) { @@ -303,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 ); } @@ -336,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 ) { @@ -398,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 ) @@ -447,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() ) { @@ -458,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 ); @@ -467,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 ); @@ -478,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 ); @@ -488,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 ); @@ -507,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 ); } } } @@ -553,9 +545,7 @@ protected boolean isSelected( String name, File file ) @Override public String[] getIncludedFiles() { - String[] files = new String[filesIncluded.size()]; - filesIncluded.copyInto( files ); - return files; + return filesIncluded.toArray( EMPTY_STRING_ARRAY ); } /** @@ -568,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 ); } /** @@ -585,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 ); } /** @@ -602,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 ); } /** @@ -617,9 +601,7 @@ public String[] getDeselectedFiles() @Override public String[] getIncludedDirectories() { - String[] directories = new String[dirsIncluded.size()]; - dirsIncluded.copyInto( directories ); - return directories; + return dirsIncluded.toArray( EMPTY_STRING_ARRAY ); } /** @@ -632,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 ); } /** @@ -649,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 ); } /** @@ -666,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 ); } /** diff --git a/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java b/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java index 341dc80d..540dbe98 100644 --- a/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java +++ b/src/main/java/org/codehaus/plexus/util/ExceptionUtils.java @@ -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] ); } } @@ -350,7 +350,7 @@ public static Throwable[] getThrowables( Throwable throwable ) list.add( throwable ); throwable = getCause( throwable ); } - return list.toArray( new Throwable[list.size()] ); + return list.toArray( new Throwable[0] ); } /** @@ -479,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] ); } /** @@ -625,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/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index fe80c7d4..31e12a2b 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -625,10 +625,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] ); } /** 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/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java index 2686cfee..de39f4fe 100644 --- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java +++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java @@ -772,7 +772,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/cli/shell/Shell.java b/src/main/java/org/codehaus/plexus/util/cli/shell/Shell.java index 6082849c..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 @@ -119,7 +119,7 @@ public String[] getShellArgs() } else { - return shellArgs.toArray( new String[shellArgs.size()] ); + return shellArgs.toArray( new String[0] ); } } 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 6874eefa..a612e6be 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 @@ -36,26 +36,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 +65,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 +85,48 @@ 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[]; /** * 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,24 +204,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 ) + private void ensureAttributesCapacity( int size ) { final int attrPosSize = attributeName != null ? attributeName.length : 0; if ( size >= attrPosSize ) @@ -268,15 +268,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 ) @@ -314,7 +314,7 @@ 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 ) + private static final int fastHash( char ch[], int off, int len ) { if ( len == 0 ) return 0; @@ -337,21 +337,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 ) @@ -390,72 +390,72 @@ 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 - protected Reader reader; + private Reader reader; - protected String inputEncoding; + private String inputEncoding; - protected int bufLoadFactor = 95; // 99% - // protected int bufHardLimit; // only matters when expanding + private int bufLoadFactor = 95; // 99% + // private int bufHardLimit; // only matters when expanding - protected float bufferLoadFactor = bufLoadFactor / 100f; + 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 = (int) ( bufferLoadFactor * buf.length ); // 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; @@ -719,7 +719,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 ... @@ -742,7 +742,7 @@ public void defineEntityReplacementText( String entityName, String replacementTe public int getNamespaceCount( int depth ) throws XmlPullParserException { - if ( processNamespaces == false || depth == 0 ) + if ( !processNamespaces || depth == 0 ) { return 0; } @@ -1102,7 +1102,7 @@ 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 " @@ -1126,7 +1126,7 @@ 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 " @@ -1225,7 +1225,7 @@ public int getEventType() 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() ) @@ -1365,7 +1365,7 @@ public int nextToken() return nextImpl(); } - protected int nextImpl() + private int nextImpl() throws XmlPullParserException, IOException { text = null; @@ -1640,7 +1640,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; @@ -1741,7 +1741,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 @@ -1775,7 +1775,7 @@ protected int parseProlog() 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 ) { @@ -1907,7 +1907,7 @@ else if ( ch == '\n' ) } } - protected int parseEpilog() + private int parseEpilog() throws XmlPullParserException, IOException { if ( eventType == END_DOCUMENT ) @@ -1919,7 +1919,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 { @@ -2077,19 +2077,12 @@ else if ( ch == '\n' ) { reachedEnd = true; } - if ( reachedEnd ) - { - if ( tokenize && gotS ) - { - posEnd = pos; // well - this is LAST available character pos - return eventType = IGNORABLE_WHITESPACE; - } - return eventType = END_DOCUMENT; - } - else + if ( tokenize && gotS ) { - 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() @@ -2258,7 +2251,6 @@ else if ( isNameStartChar( ch ) ) { ch = parseAttribute(); ch = more(); - continue; } else { @@ -2370,7 +2362,7 @@ else if ( isNameStartChar( ch ) ) return eventType = START_TAG; } - protected char parseAttribute() + private char parseAttribute() throws XmlPullParserException, IOException { // parse attribute @@ -2691,9 +2683,9 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' ) return ch; } - protected char[] charRefOneCharBuf = new char[1]; + private char[] charRefOneCharBuf = new char[1]; - protected char[] parseEntityRef() + private char[] parseEntityRef() throws XmlPullParserException, IOException { // entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference @@ -2769,7 +2761,7 @@ else if ( ch >= 'A' && ch <= 'F' ) posEnd = pos - 1; try { - charRefOneCharBuf = toChars( Integer.parseInt( sb.toString(), isHex ? 16 : 10 ) ); + charRefOneCharBuf = Character.toChars( Integer.parseInt( sb.toString(), isHex ? 16 : 10 ) ); } catch ( IllegalArgumentException e ) { @@ -2873,7 +2865,7 @@ else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[po } } - protected char[] lookuEntityReplacement( int entityNameLen ) + private char[] lookuEntityReplacement( int entityNameLen ) throws XmlPullParserException, IOException { @@ -2913,7 +2905,7 @@ protected char[] lookuEntityReplacement( int entityNameLen ) return null; } - protected void parseComment() + private void parseComment() throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.5 Comments @@ -2929,7 +2921,7 @@ protected void parseComment() final int curColumn = columnNumber; try { - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; + final boolean normalizeIgnorableWS = tokenize && !roundtripSupported; boolean normalizedCR = false; boolean seenDash = false; @@ -2952,7 +2944,6 @@ protected void parseComment() else { seenDashDash = true; - seenDash = false; } } else if ( ch == '>' ) @@ -2961,10 +2952,6 @@ else if ( ch == '>' ) { break; // found end sequence!!!! } - else - { - seenDashDash = false; - } seenDash = false; } else @@ -3037,7 +3024,7 @@ else if ( ch == '\n' ) } } - protected boolean parsePI() + private boolean parsePI() throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.6 Processing Instructions @@ -3051,7 +3038,7 @@ protected boolean parsePI() final int curColumn = columnNumber; int piTargetStart = pos; int piTargetEnd = -1; - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; + final boolean normalizeIgnorableWS = tokenize && !roundtripSupported; boolean normalizedCR = false; try @@ -3211,17 +3198,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 ::= '' @@ -3269,9 +3256,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" @@ -3390,7 +3377,7 @@ else if ( ch == 'n' ) } - protected void parseDocdecl() + private void parseDocdecl() throws XmlPullParserException, IOException { // ASSUMPTION: seen ' int bracketLevel = 0; - final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; + final boolean normalizeIgnorableWS = tokenize && !roundtripSupported; boolean normalizedCR = false; while ( true ) { @@ -3481,7 +3468,7 @@ else if ( ch == '\n' ) posEnd = pos - 1; } - protected void parseCDSect( boolean hadCharData ) + private void parseCDSect( boolean hadCharData ) throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.7 CDATA Sections @@ -3515,7 +3502,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 ) @@ -3640,7 +3627,7 @@ else if ( ch == '\n' ) posEnd = pos - 3; } - protected void fillBuf() + private void fillBuf() throws IOException, XmlPullParserException { if ( reader == null ) @@ -3650,28 +3637,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 ) @@ -3682,13 +3650,13 @@ 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 ); @@ -3700,10 +3668,6 @@ else if ( expand ) } } - else - { - throw new XmlPullParserException( "internal error in fillBuffer()" ); - } bufEnd -= bufStart; pos -= bufStart; posStart -= bufStart; @@ -3713,17 +3677,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; } @@ -3808,7 +3772,7 @@ else if ( expand ) } } - protected char more() + private char more() throws IOException, XmlPullParserException { if ( pos >= bufEnd ) @@ -3843,7 +3807,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; @@ -3855,7 +3819,7 @@ protected void ensurePC( int end ) // assert end < pc.length; } - protected void joinPC() + private void joinPC() { // assert usePC == false; // assert posEnd > posStart; @@ -3870,7 +3834,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 ) @@ -3885,7 +3849,7 @@ protected char requireInput( char ch, char[] input ) return ch; } - protected char requireNextS() + private char requireNextS() throws XmlPullParserException, IOException { final char ch = more(); @@ -3896,7 +3860,7 @@ protected char requireNextS() return skipS( ch ); } - protected char skipS( char ch ) + private char skipS( char ch ) throws XmlPullParserException, IOException { while ( isS( ch ) ) @@ -3907,23 +3871,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; @@ -3954,10 +3918,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 ]; @@ -3981,14 +3945,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 == ':' @@ -4006,7 +3970,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'); @@ -4015,8 +3979,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' ) { @@ -4041,7 +4005,7 @@ else if ( ch == '\'' ) return "" + ch; } - protected String printable( String s ) + private static String printable( String s ) { if ( s == null ) return null; @@ -4055,69 +4019,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 - 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/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..934f8083 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java @@ -0,0 +1,79 @@ +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; + +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) +public class MXParserPerfTest { + + @State(Scope.Benchmark) + static public class AdditionState { + + byte[] data; + + @Setup(Level.Iteration) + public void setUp() throws IOException, XmlPullParserException { + try (InputStream buf = getClass().getResourceAsStream( "/xml/pom.xml" ) ) + { + data = new byte[ buf.available() ]; + buf.read( data, 0, data.length ); + } + } + } + + + @Benchmark + public Xpp3Dom benchmarkBuild( AdditionState state ) throws IOException, XmlPullParserException + { + return Xpp3DomBuilder.build( new ByteArrayInputStream( state.data ), null ); + } + + public static void main( String... args ) + throws RunnerException + { + Options opts = new OptionsBuilder() + .measurementIterations( 3 ) + .measurementTime( TimeValue.milliseconds( 3000 ) ) + .forks( 1 ) + .include( "org.codehaus.plexus.util.xml.pull.MXParserPerfTest" ) + .build(); + new Runner( opts ).run(); + } +} diff --git a/src/test/resources/xml/pom.xml b/src/test/resources/xml/pom.xml new file mode 100644 index 00000000..6aa94399 --- /dev/null +++ b/src/test/resources/xml/pom.xml @@ -0,0 +1,140 @@ + + + + + + 4.0.0 + + + org.codehaus.plexus + plexus + 6.5 + + + plexus-utils + 3.4.0-SNAPSHOT + + Plexus Common Utilities + A collection of various utility classes to ease working with strings, files, command lines, XML and + more. + + + + scm:git:git@github.com:codehaus-plexus/plexus-utils.git + scm:git:git@github.com:codehaus-plexus/plexus-utils.git + http://github.com/codehaus-plexus/plexus-utils + HEAD + + + github + http://github.com/codehaus-plexus/plexus-utils/issues + + + + github:gh-pages + ${project.scm.developerConnection} + + + + + 2020-01-20T18:52:37Z + + + + + org.apache.maven.shared + maven-plugin-testing-harness + 1.1 + test + + + org.openjdk.jmh + jmh-core + 1.26 + test + + + org.openjdk.jmh + jmh-generator-annprocess + 1.26 + test + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + 2.7 + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + + ${project.reporting.outputDirectory} + + + + scm-publish + site-deploy + + publish-scm + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + org/codehaus/plexus/util/FileBasedTestCase.java + **/Test*.java + + + + JAVA_HOME + ${JAVA_HOME} + + + M2_HOME + ${M2_HOME} + + + + + + + + From 3dc33d1d95ba8a1c0185abf7c68c2af4b46d5f3b Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Thu, 30 Jul 2020 18:03:48 +0000 Subject: [PATCH 033/133] Java 7: Files.newOutputStream instead of new FilesOutputStream Provides potentially better performance. Signed-off-by: Markus KARG --- src/main/java/org/codehaus/plexus/util/Expand.java | 5 +++-- .../java/org/codehaus/plexus/util/FileUtils.java | 12 +++++++----- .../java/org/codehaus/plexus/util/WriterFactory.java | 9 ++++----- .../codehaus/plexus/util/xml/XmlStreamWriter.java | 7 +++---- .../org/codehaus/plexus/util/FileBasedTestCase.java | 4 ++-- .../java/org/codehaus/plexus/util/FileUtilsTest.java | 11 +++++------ .../java/org/codehaus/plexus/util/IOUtilTest.java | 12 ++++++------ .../plexus/util/xml/PrettyPrintXMLWriterTest.java | 4 ++-- .../org/codehaus/plexus/util/xml/XmlUtilTest.java | 4 ++-- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/Expand.java b/src/main/java/org/codehaus/plexus/util/Expand.java index ffc74628..de9b2791 100644 --- a/src/main/java/org/codehaus/plexus/util/Expand.java +++ b/src/main/java/org/codehaus/plexus/util/Expand.java @@ -57,9 +57,10 @@ 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; @@ -140,7 +141,7 @@ protected void extractFile( File srcF, File dir, InputStream compressedInputStre { byte[] buffer = new byte[65536]; - try ( FileOutputStream fos = new FileOutputStream( f ) ) + try ( OutputStream fos = Files.newOutputStream( f.toPath() ) ) { for ( int length = compressedInputStream.read( buffer ); length >= 0; diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index 31e12a2b..5cfac7b5 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -61,7 +61,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; @@ -72,6 +71,9 @@ import java.io.Reader; import java.io.Writer; import java.net.URL; +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; @@ -407,7 +409,7 @@ public static void fileAppend( String fileName, String data ) public static void fileAppend( String fileName, String encoding, String data ) throws IOException { - try ( FileOutputStream out = new FileOutputStream( fileName, true ) ) + try ( OutputStream out = Files.newOutputStream( Paths.get(fileName), StandardOpenOption.APPEND ) ) { if ( encoding != null ) { @@ -484,7 +486,7 @@ public static void fileWrite( File file, String encoding, String data ) private static OutputStreamWriter getOutputStreamWriter( File file, String encoding ) throws IOException { - OutputStream out = new FileOutputStream( file ); + OutputStream out = Files.newOutputStream( file.toPath() ); if ( encoding != null ) { return new OutputStreamWriter( out, encoding ); @@ -1153,7 +1155,7 @@ public static void copyStreamToFile( final InputStreamFacade source, final File checkCanWrite( destination ); try ( InputStream input = source.getInputStream(); - FileOutputStream output = new FileOutputStream( destination ) ) + OutputStream output = Files.newOutputStream( destination.toPath() ) ) { IOUtil.copy( input, output ); } @@ -2258,7 +2260,7 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[ { FileInputStream instream = new FileInputStream( from ); - FileOutputStream outstream = new FileOutputStream( to ); + OutputStream outstream = Files.newOutputStream( to.toPath() ); fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) ); diff --git a/src/main/java/org/codehaus/plexus/util/WriterFactory.java b/src/main/java/org/codehaus/plexus/util/WriterFactory.java index 87a4283d..fce68943 100644 --- a/src/main/java/org/codehaus/plexus/util/WriterFactory.java +++ b/src/main/java/org/codehaus/plexus/util/WriterFactory.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; @@ -26,6 +25,7 @@ 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; @@ -169,13 +169,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/xml/XmlStreamWriter.java b/src/main/java/org/codehaus/plexus/util/xml/XmlStreamWriter.java index cf4e4be7..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; @@ -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() diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index 1be701d8..7f3f88ec 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -22,13 +22,13 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.Writer; +import java.nio.file.Files; import java.util.Arrays; import junit.framework.AssertionFailedError; @@ -61,7 +61,7 @@ protected byte[] createFile( final File file, final long size ) byte[] data = generateTestData( size ); - final BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream( file ) ); + final BufferedOutputStream output = new BufferedOutputStream( Files.newOutputStream( file.toPath() ) ); try { diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index d4ee85c0..d79760f9 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -26,7 +26,6 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -1134,7 +1133,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(); } @@ -1159,7 +1158,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(); } @@ -1182,7 +1181,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(); } @@ -1208,7 +1207,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(); } @@ -1281,7 +1280,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 ); diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index c99384c1..f9075f02 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -23,7 +23,6 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -33,6 +32,7 @@ import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; +import java.nio.file.Files; import java.util.Arrays; import org.junit.Before; @@ -95,7 +95,7 @@ public void tearDown() private void createFile( File file, long size ) throws IOException { - BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream( file ) ); + BufferedOutputStream output = new BufferedOutputStream( Files.newOutputStream( file.toPath() ) ); for ( int i = 0; i < size; i++ ) { @@ -161,7 +161,7 @@ public void testInputStreamToOutputStream() { File destination = newFile( "copy1.txt" ); FileInputStream fin = new FileInputStream( testFile ); - FileOutputStream fout = new FileOutputStream( destination ); + OutputStream fout = Files.newOutputStream( destination.toPath() ); IOUtil.copy( fin, fout ); assertTrue( "Not all bytes were read", fin.available() == 0 ); @@ -212,7 +212,7 @@ public void testReaderToOutputStream() { File destination = newFile( "copy3.txt" ); FileReader fin = new FileReader( testFile ); - FileOutputStream fout = new FileOutputStream( destination ); + OutputStream fout = Files.newOutputStream( destination.toPath() ); IOUtil.copy( fin, fout ); // Note: this method *does* flush. It is equivalent to: // OutputStreamWriter _out = new OutputStreamWriter(fout); @@ -264,7 +264,7 @@ public void testStringToOutputStream() FileReader fin = new FileReader( testFile ); // 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); @@ -363,7 +363,7 @@ public void testByteArrayToOutputStream() throws Exception { File destination = newFile( "copy8.txt" ); - FileOutputStream fout = new FileOutputStream( destination ); + OutputStream fout = Files.newOutputStream( destination.toPath() ); FileInputStream fin = new FileInputStream( testFile ); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. diff --git a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java index 1d5b046e..d115a6e9 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java @@ -21,10 +21,10 @@ import static org.junit.Assert.fail; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.StringWriter; +import java.nio.file.Files; import java.util.NoSuchElementException; import javax.swing.text.html.HTML.Tag; @@ -171,7 +171,7 @@ public void testIssue51DetectJava7ConcatenationBug() assertTrue( "cannot create directory test-xml", dir.mkdir() ); } File xmlFile = new File( dir, "test-issue-51.xml" ); - OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream( xmlFile ), "UTF-8" ); + OutputStreamWriter osw = new OutputStreamWriter( Files.newOutputStream( xmlFile.toPath() ), "UTF-8" ); writer = new PrettyPrintXMLWriter( osw ); int iterations = 20000; diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index 91b6a7f7..c09e2adc 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -21,13 +21,13 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.StringWriter; import java.io.Writer; +import java.nio.file.Files; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; @@ -78,7 +78,7 @@ public void testPrettyFormatInputStreamOutputStream() try { is = new FileInputStream( testDocument ); - os = new FileOutputStream( getTestOutputFile( "target/test/prettyFormatTestDocumentOutputStream.xml" ) ); + os = Files.newOutputStream( getTestOutputFile( "target/test/prettyFormatTestDocumentOutputStream.xml" ).toPath() ); assertNotNull( is ); assertNotNull( os ); From ad1a668b54c4c77b496d2a80448698d251696aed Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 16 Aug 2020 14:24:42 +0000 Subject: [PATCH 034/133] Java 7: Files.newInputStream instead of new FilesInputStream Provides potentially better performance. Signed-off-by: Markus KARG --- .../java/org/codehaus/plexus/util/Expand.java | 3 +-- .../org/codehaus/plexus/util/FileUtils.java | 11 +++++----- .../codehaus/plexus/util/PropertyUtils.java | 4 ++-- .../codehaus/plexus/util/ReaderFactory.java | 9 ++++---- .../codehaus/plexus/util/xml/XmlReader.java | 4 ++-- .../plexus/util/FileBasedTestCase.java | 7 +++---- .../codehaus/plexus/util/FileUtilsTest.java | 3 +-- .../org/codehaus/plexus/util/IOUtilTest.java | 21 +++++++++---------- .../codehaus/plexus/util/xml/XmlUtilTest.java | 3 +-- 9 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/Expand.java b/src/main/java/org/codehaus/plexus/util/Expand.java index de9b2791..5b195811 100644 --- a/src/main/java/org/codehaus/plexus/util/Expand.java +++ b/src/main/java/org/codehaus/plexus/util/Expand.java @@ -55,7 +55,6 @@ */ import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -98,7 +97,7 @@ protected void expandFile( final File srcF, final File dir ) throws Exception { // code from WarExpand - try ( ZipInputStream zis = new ZipInputStream( new FileInputStream( srcF ) ) ) + try ( ZipInputStream zis = new ZipInputStream( Files.newInputStream( srcF.toPath() ) ) ) { for ( ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry() ) { diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index 5cfac7b5..f18eac34 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -60,7 +60,6 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -376,11 +375,11 @@ private static InputStreamReader getInputStreamReader( File file, String encodin { if ( encoding != null ) { - return new InputStreamReader( new FileInputStream( file ), encoding ); + return new InputStreamReader( Files.newInputStream( file.toPath() ), encoding ); } else { - return new InputStreamReader( new FileInputStream( file ) ); + return new InputStreamReader( Files.newInputStream( file.toPath() ) ); } } @@ -723,8 +722,8 @@ public static boolean contentEquals( final File file1, final File file2 ) return false; } - try ( InputStream input1 = new FileInputStream( file1 ); - InputStream input2 = new FileInputStream( file2 ) ) + try ( InputStream input1 = Files.newInputStream( file1.toPath() ); + InputStream input2 = Files.newInputStream( file2.toPath() ) ) { return IOUtil.contentEquals( input1, input2 ); } @@ -2258,7 +2257,7 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[ } else { - FileInputStream instream = new FileInputStream( from ); + InputStream instream = Files.newInputStream( from.toPath() ); OutputStream outstream = Files.newOutputStream( to.toPath() ); diff --git a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java index 419fc125..cee5cd25 100644 --- a/src/main/java/org/codehaus/plexus/util/PropertyUtils.java +++ b/src/main/java/org/codehaus/plexus/util/PropertyUtils.java @@ -20,10 +20,10 @@ 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. @@ -43,7 +43,7 @@ public static Properties loadProperties( final URL url ) public static Properties loadProperties( final File file ) throws IOException { - return loadProperties( new FileInputStream( Objects.requireNonNull( file, "file" ) ) ); + return loadProperties( Files.newInputStream( Objects.requireNonNull( file, "file" ).toPath() ) ); } public static Properties loadProperties( final InputStream is ) diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java index 46041a20..d593bbf0 100644 --- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java +++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java @@ -17,7 +17,6 @@ */ import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -27,6 +26,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; @@ -199,14 +199,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/xml/XmlReader.java b/src/main/java/org/codehaus/plexus/util/xml/XmlReader.java index 2d662f56..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; @@ -126,7 +126,7 @@ public static String getDefaultEncoding() public XmlReader( File file ) throws IOException { - this( new FileInputStream( file ) ); + this( Files.newInputStream( file.toPath() ) ); } /** diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index 7f3f88ec..33b1654d 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -21,7 +21,6 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -192,10 +191,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]; @@ -229,7 +228,7 @@ private void assertEqualContent( final File f0, final File f1 ) 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]; diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index d79760f9..cb14f724 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -25,7 +25,6 @@ import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -268,7 +267,7 @@ public void testCopyURLToFile() FileUtils.copyURLToFile( getClass().getResource( resourceName ), file ); // Tests that resource was copied correctly - final FileInputStream fis = new FileInputStream( file ); + final InputStream fis = Files.newInputStream( file.toPath() ); try { assertTrue( "Content is not equal.", diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index f9075f02..0bbd7b0e 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -22,7 +22,6 @@ import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -115,8 +114,8 @@ private void assertEqualContent( byte[] b0, byte[] b1 ) private void assertEqualContent( File f0, File f1 ) throws IOException { - FileInputStream is0 = new FileInputStream( f0 ); - FileInputStream is1 = new FileInputStream( f1 ); + InputStream is0 = Files.newInputStream( f0.toPath() ); + InputStream is1 = Files.newInputStream( f1.toPath() ); byte[] buf0 = new byte[FILE_SIZE]; byte[] buf1 = new byte[FILE_SIZE]; int n0 = 0; @@ -145,7 +144,7 @@ private void assertEqualContent( File f0, File f1 ) private void assertEqualContent( byte[] b0, File file ) throws IOException { - FileInputStream is = new FileInputStream( file ); + InputStream is = Files.newInputStream( file.toPath() ); byte[] b1 = new byte[b0.length]; int numRead = is.read( b1 ); assertTrue( "Different number of bytes", numRead == b0.length && is.available() == 0 ); @@ -160,7 +159,7 @@ public void testInputStreamToOutputStream() throws Exception { File destination = newFile( "copy1.txt" ); - FileInputStream fin = new FileInputStream( testFile ); + InputStream fin = Files.newInputStream( testFile.toPath() ); OutputStream fout = Files.newOutputStream( destination.toPath() ); IOUtil.copy( fin, fout ); @@ -179,7 +178,7 @@ public void testInputStreamToWriter() throws Exception { File destination = newFile( "copy2.txt" ); - FileInputStream fin = new FileInputStream( testFile ); + InputStream fin = Files.newInputStream( testFile.toPath() ); FileWriter fout = new FileWriter( destination ); IOUtil.copy( fin, fout ); @@ -198,7 +197,7 @@ public void testInputStreamToWriter() public void testInputStreamToString() throws Exception { - FileInputStream fin = new FileInputStream( testFile ); + InputStream fin = Files.newInputStream( testFile.toPath() ); String out = IOUtil.toString( fin ); assertNotNull( out ); assertTrue( "Not all bytes were read", fin.available() == 0 ); @@ -304,7 +303,7 @@ public void testStringToWriter() 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 ); @@ -333,7 +332,7 @@ public void testByteArrayToWriter() { File destination = newFile( "copy7.txt" ); FileWriter fout = new FileWriter( destination ); - FileInputStream fin = new FileInputStream( testFile ); + InputStream fin = Files.newInputStream( testFile.toPath() ); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. byte[] in = IOUtil.toByteArray( fin ); @@ -350,7 +349,7 @@ public void testByteArrayToWriter() 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 ); @@ -364,7 +363,7 @@ public void testByteArrayToOutputStream() { File destination = newFile( "copy8.txt" ); OutputStream fout = Files.newOutputStream( destination.toPath() ); - FileInputStream fin = new FileInputStream( testFile ); + InputStream fin = Files.newInputStream( testFile.toPath() ); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. byte[] in = IOUtil.toByteArray( fin ); diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index c09e2adc..01fc8c4c 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -77,7 +76,7 @@ public void testPrettyFormatInputStreamOutputStream() OutputStream os = null; try { - is = new FileInputStream( testDocument ); + is = Files.newInputStream( testDocument.toPath() ); os = Files.newOutputStream( getTestOutputFile( "target/test/prettyFormatTestDocumentOutputStream.xml" ).toPath() ); assertNotNull( is ); From cd3da1ef2d7d11988253dd3b07a9bb0f0e0db8a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Dec 2020 09:02:18 +1000 Subject: [PATCH 035/133] Bump jmh-core from 1.26 to 1.27 (#107) Bumps jmh-core from 1.26 to 1.27. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6aa94399..f4f88a73 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.26 + 1.27 test From 900acba8516814eaf7669df0da6fd41f06153dc3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Dec 2020 09:02:29 +1000 Subject: [PATCH 036/133] Bump jmh-generator-annprocess from 1.26 to 1.27 (#108) Bumps jmh-generator-annprocess from 1.26 to 1.27. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f4f88a73..1965e5ab 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.26 + 1.27 test From 2d0fb07fe417101819d3a433fed5ff8d03ed52e2 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Wed, 23 Dec 2020 09:02:00 +0000 Subject: [PATCH 037/133] Not building on JRE 7 anymore, since we pushed minimum to JRE 8 Signed-off-by: Markus KARG --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1de65ef7..13b4c47e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - java: [7, 8, 11, 14, 15, 16-ea] + java: [8, 11, 14, 15, 16-ea] fail-fast: false runs-on: ${{ matrix.os }} From 659aca39328892b204128dcec973ef2ac22bbae0 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Tue, 22 Dec 2020 12:56:43 +0000 Subject: [PATCH 038/133] Requires parent version 7, as it requires JRE 8. Signed-off-by: Markus KARG --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1965e5ab..efad18f9 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.codehaus.plexus plexus - 6.5 + 7 plexus-utils From 99a001f69f8358c90190dcd076cbc8140810f5aa Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 16 Aug 2020 15:05:37 +0000 Subject: [PATCH 039/133] Java 8: Files.newBufferedReader instead of new FileReader Provides potentially better performance. Signed-off-by: Markus KARG --- .../java/org/codehaus/plexus/util/FileUtils.java | 10 ++++------ .../org/codehaus/plexus/util/ReaderFactory.java | 7 +++---- .../java/org/codehaus/plexus/util/IOUtilTest.java | 13 ++++++------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index f18eac34..c8bf68d7 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -60,7 +60,6 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -70,6 +69,7 @@ import java.io.Reader; import java.io.Writer; import java.net.URL; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; @@ -2252,16 +2252,14 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[ { if ( encoding == null || encoding.length() < 1 ) { - fileReader = new BufferedReader( new FileReader( from ) ); + fileReader = Files.newBufferedReader( from.toPath() ); fileWriter = new FileWriter( to ); } else { - InputStream instream = Files.newInputStream( from.toPath() ); - OutputStream outstream = Files.newOutputStream( to.toPath() ); - fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) ); + fileReader = Files.newBufferedReader( from.toPath(), Charset.forName( encoding ) ); fileWriter = new OutputStreamWriter( outstream, encoding ); } @@ -2311,7 +2309,7 @@ public static List loadFile( File file ) if ( file.exists() ) { - try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) ) + try ( BufferedReader reader = Files.newBufferedReader( file.toPath() ) ) { for ( String line = reader.readLine(); line != null; line = reader.readLine() ) { diff --git a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java index d593bbf0..a469a2c7 100644 --- a/src/main/java/org/codehaus/plexus/util/ReaderFactory.java +++ b/src/main/java/org/codehaus/plexus/util/ReaderFactory.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -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() ); } /** diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index 0bbd7b0e..e5e52a1d 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -22,7 +22,6 @@ import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; @@ -210,7 +209,7 @@ public void testReaderToOutputStream() throws Exception { File destination = newFile( "copy3.txt" ); - FileReader fin = new FileReader( testFile ); + Reader fin = Files.newBufferedReader( testFile.toPath() ); OutputStream fout = Files.newOutputStream( destination.toPath() ); IOUtil.copy( fin, fout ); // Note: this method *does* flush. It is equivalent to: @@ -232,7 +231,7 @@ public void testReaderToWriter() throws Exception { File destination = newFile( "copy4.txt" ); - FileReader fin = new FileReader( testFile ); + Reader fin = Files.newBufferedReader( testFile.toPath() ); FileWriter fout = new FileWriter( destination ); IOUtil.copy( fin, fout ); @@ -248,7 +247,7 @@ public void testReaderToWriter() 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 ); @@ -260,7 +259,7 @@ 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 ); OutputStream fout = Files.newOutputStream( destination.toPath() ); @@ -284,7 +283,7 @@ 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 ); @@ -316,7 +315,7 @@ public void testInputStreamToByteArray() 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 ); From 7e2e788e118adde3dea0a98fad430731631b6e21 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 16 Aug 2020 15:12:44 +0000 Subject: [PATCH 040/133] Java 8: Files.newBufferedWriter instead of new FileWriter Provides potentially better performance. Signed-off-by: Markus KARG --- src/main/java/org/codehaus/plexus/util/FileUtils.java | 3 +-- .../java/org/codehaus/plexus/util/WriterFactory.java | 4 +--- src/test/java/org/codehaus/plexus/util/IOUtilTest.java | 9 ++++----- .../org/codehaus/plexus/util/cli/CommandlineTest.java | 9 +++++---- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index c8bf68d7..cac82ba3 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -60,7 +60,6 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -2253,7 +2252,7 @@ public static void copyFile( File from, File to, String encoding, FilterWrapper[ if ( encoding == null || encoding.length() < 1 ) { fileReader = Files.newBufferedReader( from.toPath() ); - fileWriter = new FileWriter( to ); + fileWriter = Files.newBufferedWriter( to.toPath() ); } else { diff --git a/src/main/java/org/codehaus/plexus/util/WriterFactory.java b/src/main/java/org/codehaus/plexus/util/WriterFactory.java index fce68943..cf8326c4 100644 --- a/src/main/java/org/codehaus/plexus/util/WriterFactory.java +++ b/src/main/java/org/codehaus/plexus/util/WriterFactory.java @@ -17,8 +17,6 @@ */ import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -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() ); } /** diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index e5e52a1d..40f2846c 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -22,7 +22,6 @@ import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -178,7 +177,7 @@ public void testInputStreamToWriter() { File destination = newFile( "copy2.txt" ); InputStream fin = Files.newInputStream( testFile.toPath() ); - FileWriter fout = new FileWriter( destination ); + Writer fout = Files.newBufferedWriter( destination.toPath() ); IOUtil.copy( fin, fout ); @@ -232,7 +231,7 @@ public void testReaderToWriter() { File destination = newFile( "copy4.txt" ); Reader fin = Files.newBufferedReader( testFile.toPath() ); - FileWriter fout = new FileWriter( destination ); + Writer fout = Files.newBufferedWriter( destination.toPath() ); IOUtil.copy( fin, fout ); fout.flush(); @@ -286,7 +285,7 @@ public void testStringToWriter() 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(); @@ -330,7 +329,7 @@ public void testByteArrayToWriter() throws Exception { File destination = newFile( "copy7.txt" ); - FileWriter fout = new FileWriter( destination ); + Writer fout = Files.newBufferedWriter( destination.toPath() ); InputStream fin = Files.newInputStream( testFile.toPath() ); // Create our byte[]. Rely on testInputStreamToByteArray() to make sure this is valid. diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java index 28ec8297..97073d60 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -21,9 +21,10 @@ import static org.junit.Assert.fail; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Paths; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.Os; @@ -443,10 +444,10 @@ public void testDollarSignInArgumentPath() assertTrue( "Can't create dir:" + dir.getAbsolutePath(), dir.mkdirs() ); } - FileWriter writer = null; + Writer writer = null; try { - writer = new FileWriter( new File( dir, "test$1.txt" ) ); + writer = Files.newBufferedWriter( dir.toPath().resolve( "test$1.txt" ) ); IOUtil.copy( "Success", writer ); } finally @@ -568,7 +569,7 @@ private static void createAndCallScript( File dir, String content ) bat = new File( dir, "echo" ); } - Writer w = new FileWriter( bat ); + Writer w = Files.newBufferedWriter( bat.toPath() ); try { IOUtil.copy( content, w ); From 60bee8aca6298a3d29fea554d71db586bd1d2578 Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Mon, 28 Dec 2020 23:55:02 -0300 Subject: [PATCH 041/133] Fixed infinite loop in MXParser and reactivate tests in MXParserTest (#118) --- .../org/codehaus/plexus/util/xml/pull/MXParser.java | 11 +++++++++++ .../codehaus/plexus/util/xml/pull/MXParserTest.java | 10 ++++++++++ 2 files changed, 21 insertions(+) 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 a612e6be..40a12a21 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 @@ -3044,6 +3044,7 @@ private boolean parsePI() try { boolean seenPITarget = false; + boolean seenInnerTag = false; boolean seenQ = false; char ch = more(); if ( isS( ch ) ) @@ -3077,6 +3078,16 @@ 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 if ( ch == '<' ) + { + seenInnerTag = true; } else { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 5b685e8e..0cb9c061 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -413,6 +413,7 @@ public void testLargeText_NoOverflow() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + @Test public void testMalformedProcessingInstructionAfterTag() throws Exception { @@ -438,6 +439,7 @@ public void testMalformedProcessingInstructionAfterTag() } } + @Test public void testMalformedProcessingInstructionBeforeTag() throws Exception { @@ -463,6 +465,7 @@ public void testMalformedProcessingInstructionBeforeTag() } } + @Test public void testMalformedProcessingInstructionSpaceBeforeName() throws Exception { @@ -490,6 +493,7 @@ public void testMalformedProcessingInstructionSpaceBeforeName() } } + @Test public void testMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { @@ -517,6 +521,7 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark() } } + @Test public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exception { @@ -544,6 +549,7 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() } } + @Test public void testMalformedXMLRootElement() throws Exception { @@ -564,6 +570,7 @@ public void testMalformedXMLRootElement() } } + @Test public void testMalformedXMLRootElement2() throws Exception { @@ -584,6 +591,7 @@ public void testMalformedXMLRootElement2() } } + @Test public void testMalformedXMLRootElement3() throws Exception { @@ -605,6 +613,7 @@ public void testMalformedXMLRootElement3() } } + @Test public void testMalformedXMLRootElement4() throws Exception { @@ -628,6 +637,7 @@ public void testMalformedXMLRootElement4() } } + @Test public void testMalformedXMLRootElement5() throws Exception { From 761ac423ce668d0681e30b4c2b75cb44a99234a9 Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sun, 24 Jan 2021 19:55:38 -0300 Subject: [PATCH 042/133] Fixed MXParser do not fail when encountering invalid characters in comments (#126) (#127) * Fixed MXParser do not fail when encountering invalid characters in comments (#126) * Force tests testibm_not_wf_P02_ibm02n32xml and testibm_not_wf_P02_ibm02n33xml to open XML file with UTF-8 encoding, since Windows default encoding (cp1252) decodes another char. fix #126 --- .../plexus/util/xml/pull/MXParser.java | 19 +- ...ConformanceTestSuite_Production2_Test.java | 904 ++++++++++++++++++ .../xmlconf/ibm/not-wf/P02/ibm02n01.xml | Bin 0 -> 91 bytes .../xmlconf/ibm/not-wf/P02/ibm02n02.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n03.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n04.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n05.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n06.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n07.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n08.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n09.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n10.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n11.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n12.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n13.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n14.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n15.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n16.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n17.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n18.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n19.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n20.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n21.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n22.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n23.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n24.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n25.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n26.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n27.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n28.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n29.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n30.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n31.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n32.xml | 6 + .../xmlconf/ibm/not-wf/P02/ibm02n33.xml | 6 + 35 files changed, 1114 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n01.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n02.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n03.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n04.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n05.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n06.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n07.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n08.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n09.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n10.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n11.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n12.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n13.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n14.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n15.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n16.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n17.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n18.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n19.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n20.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n21.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n22.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n23.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n24.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n25.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n26.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n27.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n28.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n29.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n30.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n31.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n32.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n33.xml 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 40a12a21..a9f88752 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 @@ -2865,6 +2865,19 @@ else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[po } } + /** + * 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 char[] lookuEntityReplacement( int entityNameLen ) throws XmlPullParserException, IOException @@ -2954,10 +2967,14 @@ else if ( ch == '>' ) } seenDash = false; } - else + else if (isValidCodePoint( ch )) { seenDash = false; } + else + { + throw new XmlPullParserException( "Illegal character 0x" + Integer.toHexString(((int) ch)) + " found in comment", this, null ); + } if ( normalizeIgnorableWS ) { if ( ch == '\r' ) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java new file mode 100644 index 00000000..65ee879f --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java @@ -0,0 +1,904 @@ +package org.codehaus.plexus.util.xml.pull; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; + +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:

    IBM XML Conformance Test Suite - Production 2
    + * XML test files base folder:
    xmlconf/ibm/
    + * + * @author Gabriel Belingueres + */ +public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test { + + final static File testResourcesDir = new File("src/test/resources/", "xmlconf/ibm/"); + + MXParser parser; + + @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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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/resources/xmlconf/ibm/not-wf/P02/ibm02n01.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n01.xml new file mode 100755 index 0000000000000000000000000000000000000000..867386a2554372d074e54c84da733df0c905174d GIT binary patch literal 91 zcmcCfbn$l%i41U6NXpO8R*2^1vQc#ParJfe3xS9@`bFCDa>W9%jiRouf@e-nYIM_Lxr literal 0 HcmV?d00001 diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n02.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n02.xml new file mode 100755 index 00000000..09845356 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n02.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n03.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n03.xml new file mode 100755 index 00000000..8fb98db7 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n03.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n04.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n04.xml new file mode 100755 index 00000000..35ebb812 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n04.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n05.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n05.xml new file mode 100755 index 00000000..4847c52f --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n05.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n06.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n06.xml new file mode 100755 index 00000000..f4b3fea9 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n06.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n07.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n07.xml new file mode 100755 index 00000000..70b39a42 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n07.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n08.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n08.xml new file mode 100755 index 00000000..d6a07f97 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n08.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n09.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n09.xml new file mode 100755 index 00000000..868f4f75 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n09.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n10.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n10.xml new file mode 100755 index 00000000..127b117d --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n10.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n11.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n11.xml new file mode 100755 index 00000000..3e9b2637 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n11.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n12.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n12.xml new file mode 100755 index 00000000..3aa6b223 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n12.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n13.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n13.xml new file mode 100755 index 00000000..b5da2def --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n13.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n14.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n14.xml new file mode 100755 index 00000000..fb475617 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n14.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n15.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n15.xml new file mode 100755 index 00000000..90e4ce29 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n15.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n16.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n16.xml new file mode 100755 index 00000000..ef0bd5b5 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n16.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n17.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n17.xml new file mode 100755 index 00000000..cb6d61f9 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n17.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n18.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n18.xml new file mode 100755 index 00000000..6d6277d6 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n18.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n19.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n19.xml new file mode 100755 index 00000000..96580223 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n19.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n20.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n20.xml new file mode 100755 index 00000000..0257c823 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n20.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n21.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n21.xml new file mode 100755 index 00000000..89a0b1ad --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n21.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n22.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n22.xml new file mode 100755 index 00000000..3bf0e2d1 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n22.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n23.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n23.xml new file mode 100755 index 00000000..7ce8a85f --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n23.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n24.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n24.xml new file mode 100755 index 00000000..5a2ea3ec --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n24.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n25.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n25.xml new file mode 100755 index 00000000..fb6454ea --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n25.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n26.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n26.xml new file mode 100755 index 00000000..004f5e04 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n26.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n27.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n27.xml new file mode 100755 index 00000000..0cab04e7 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n27.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n28.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n28.xml new file mode 100755 index 00000000..34b1e0a2 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n28.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n29.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n29.xml new file mode 100755 index 00000000..70b9f721 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n29.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n30.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n30.xml new file mode 100755 index 00000000..67a849f6 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n30.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n31.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n31.xml new file mode 100755 index 00000000..c39e5008 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n31.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n32.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n32.xml new file mode 100755 index 00000000..37df65c0 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n32.xml @@ -0,0 +1,6 @@ + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n33.xml b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n33.xml new file mode 100755 index 00000000..8ff5faf6 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P02/ibm02n33.xml @@ -0,0 +1,6 @@ + +]> + + From 724c56d0a6fd9f1fc71d7e1c205570c8f4e5f22e Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sun, 24 Jan 2021 19:56:37 -0300 Subject: [PATCH 043/133] Fix MXParser not failing when space is missing in xml declaration (#128) (#129) fix #128 --- .../plexus/util/xml/pull/MXParser.java | 2 +- ...onformanceTestSuite_Production24_Test.java | 271 ++++++++++++++++++ .../xmlconf/ibm/not-wf/P24/ibm24n01.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n02.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n03.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n04.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n05.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n06.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n07.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n08.xml | 6 + .../xmlconf/ibm/not-wf/P24/ibm24n09.xml | 6 + 11 files changed, 326 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n01.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n02.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n03.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n04.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n05.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n06.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n07.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n08.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n09.xml 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 a9f88752..b6934d48 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 @@ -3113,7 +3113,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' ) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java new file mode 100644 index 00000000..587083a5 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java @@ -0,0 +1,271 @@ +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.FileNotFoundException; +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:
    IBM XML Conformance Test Suite - Production 24
    + * XML test files base folder:
    xmlconf/ibm/
    + * + * @author Gabriel Belingueres + */ +public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test +{ + + final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + + MXParser parser; + + @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 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 XmlPullParserException if there is a problem parsing the XML file + * @throws FileNotFoundException if the testing XML file is not found + * @throws 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 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 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 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 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 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 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 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( " + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n02.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n02.xml new file mode 100755 index 00000000..8a3a4004 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n02.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n03.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n03.xml new file mode 100755 index 00000000..903a5c3b --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n03.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n04.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n04.xml new file mode 100755 index 00000000..0c603b93 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n04.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n05.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n05.xml new file mode 100755 index 00000000..09c191be --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n05.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n06.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n06.xml new file mode 100755 index 00000000..f2aeef6a --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n06.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n07.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n07.xml new file mode 100755 index 00000000..7cd34539 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n07.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n08.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n08.xml new file mode 100755 index 00000000..f162261f --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n08.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n09.xml b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n09.xml new file mode 100755 index 00000000..886e084a --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P24/ibm24n09.xml @@ -0,0 +1,6 @@ + + +]> + + \ No newline at end of file From 2bd2a439119474deeba90b70d44a4685cd153aa4 Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sun, 24 Jan 2021 19:57:12 -0300 Subject: [PATCH 044/133] Fix MXParser failing to parse properly 'standalone' declaration (#131) attribute (#130) fix #130 --- .../plexus/util/xml/pull/MXParser.java | 13 +- ...onformanceTestSuite_Production32_Test.java | 269 ++++++++++++++++++ .../xmlconf/ibm/not-wf/P32/ibm32n01.xml | 6 + .../xmlconf/ibm/not-wf/P32/ibm32n02.xml | 6 + .../xmlconf/ibm/not-wf/P32/ibm32n03.xml | 6 + .../xmlconf/ibm/not-wf/P32/ibm32n04.xml | 6 + .../xmlconf/ibm/not-wf/P32/ibm32n05.xml | 6 + .../xmlconf/ibm/not-wf/P32/ibm32n06.dtd | 1 + .../xmlconf/ibm/not-wf/P32/ibm32n06.xml | 4 + .../xmlconf/ibm/not-wf/P32/ibm32n07.xml | 4 + .../xmlconf/ibm/not-wf/P32/ibm32n08.xml | 6 + .../xmlconf/ibm/not-wf/P32/ibm32n09.dtd | 1 + .../xmlconf/ibm/not-wf/P32/ibm32n09.xml | 9 + 13 files changed, 325 insertions(+), 12 deletions(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test.java create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n01.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n02.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n03.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n04.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n05.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.dtd create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n07.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n08.xml create mode 100644 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.dtd create mode 100644 src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.xml 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 b6934d48..76409606 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 @@ -3342,9 +3342,9 @@ private void parseXmlDeclWithVersion( int versionStart, int versionEnd ) // TODO reconcile with setInput encodingName inputEncoding = newString( buf, encodingStart, encodingEnd - encodingStart ); - ch = more(); } + ch = more(); ch = skipS( ch ); // [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) if ( ch == 's' ) @@ -3877,17 +3877,6 @@ private char requireInput( char ch, char[] input ) return ch; } - private 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 ); - } - private char skipS( char ch ) throws XmlPullParserException, IOException { 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..29ba3947 --- /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,269 @@ +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:
    IBM XML Conformance Test Suite - Production 32
    + * XML test files base folder:
    xmlconf/ibm/
    + * + * @author Gabriel Belingueres + */ +public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test +{ + + final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + + MXParser parser; + + @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 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 ?> as last part of 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 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 ?> as last part of 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 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( "expected ?> as last part of 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 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 ?> as last part of 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 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 ?> as last part of 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 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 ?> as last part of 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 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 ?> as last part of 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 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 ?> as last part of 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 IOException if there is an I/O error + */ + @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 + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n02.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n02.xml new file mode 100755 index 00000000..3a3705e1 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n02.xml @@ -0,0 +1,6 @@ + + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n03.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n03.xml new file mode 100755 index 00000000..8d31eaae --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n03.xml @@ -0,0 +1,6 @@ + + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n04.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n04.xml new file mode 100755 index 00000000..6c80d786 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n04.xml @@ -0,0 +1,6 @@ + + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n05.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n05.xml new file mode 100755 index 00000000..fa9cc064 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n05.xml @@ -0,0 +1,6 @@ + + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.dtd b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.dtd new file mode 100755 index 00000000..b3dde2f9 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.dtd @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.xml new file mode 100755 index 00000000..d9522dc0 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n06.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n07.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n07.xml new file mode 100755 index 00000000..1c906db8 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n07.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n08.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n08.xml new file mode 100755 index 00000000..00903ab0 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n08.xml @@ -0,0 +1,6 @@ + + +]> + + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.dtd b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.dtd new file mode 100644 index 00000000..e30d2928 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.dtd @@ -0,0 +1 @@ + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.xml b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.xml new file mode 100644 index 00000000..a62bac37 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P32/ibm32n09.xml @@ -0,0 +1,9 @@ + + +]> + +&animal_content; From b5a006b5771ba483301632d6cd4b790be7dac28b Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sun, 24 Jan 2021 19:57:37 -0300 Subject: [PATCH 045/133] Fix MXParser fails to recognize illegal character references (#132) (#133) fix #132 --- .../plexus/util/xml/pull/MXParser.java | 107 +++-- ...onformanceTestSuite_Production66_Test.java | 426 ++++++++++++++++++ .../xmlconf/ibm/not-wf/P66/ibm66n01.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n02.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n03.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n04.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n05.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n06.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n07.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n08.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n09.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n10.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n11.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n12.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n13.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n14.xml | 7 + .../xmlconf/ibm/not-wf/P66/ibm66n15.xml | 7 + 17 files changed, 595 insertions(+), 43 deletions(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n01.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n02.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n03.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n04.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n05.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n06.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n07.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n08.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n09.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n10.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n11.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n12.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n13.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n14.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n15.xml 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 76409606..4f1955a1 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 @@ -2534,44 +2534,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' ) { @@ -2759,11 +2722,22 @@ else if ( ch >= 'A' && ch <= 'F' ) } } posEnd = pos - 1; - try + + int codePoint = Integer.parseInt( sb.toString(), isHex ? 16 : 10 ); + boolean isValidCodePoint = isValidCodePoint( codePoint ); + if ( isValidCodePoint ) { - charRefOneCharBuf = Character.toChars( Integer.parseInt( sb.toString(), isHex ? 16 : 10 ) ); + try + { + charRefOneCharBuf = Character.toChars( codePoint ); + } + catch ( IllegalArgumentException e ) + { + isValidCodePoint = false; + } } - catch ( IllegalArgumentException e ) + + if ( !isValidCodePoint ) { throw new XmlPullParserException( "character reference (with " + ( isHex ? "hex" : "decimal" ) + " value " + sb.toString() + ") is invalid", this, null ); @@ -3440,10 +3414,14 @@ private void parseDocdecl() ch = more(); if ( ch == '[' ) ++bracketLevel; - if ( ch == ']' ) + else if ( ch == ']' ) --bracketLevel; - if ( ch == '>' && bracketLevel == 0 ) + else if ( ch == '>' && bracketLevel == 0 ) break; + else if ( ch == '&' ) + { + extractEntityRef(); + } if ( normalizeIgnorableWS ) { if ( ch == '\r' ) @@ -3496,6 +3474,49 @@ else if ( ch == '\n' ) posEnd = pos - 1; } + 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; + + 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; + } + } + private void parseCDSect( boolean hadCharData ) throws XmlPullParserException, IOException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java new file mode 100644 index 00000000..c1d0f2e6 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java @@ -0,0 +1,426 @@ + +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.FileNotFoundException; +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:
    IBM XML Conformance Test Suite - Production 66
    + * XML test files base folder:
    xmlconf/ibm/
    + * + * @author Gabriel Belingueres + */ +public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test +{ + + final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + + MXParser parser; + + @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 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 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 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 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 IOException if there is an I/O error + */ + @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 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 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 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 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 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 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 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 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 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 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/resources/xmlconf/ibm/not-wf/P66/ibm66n01.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n01.xml new file mode 100755 index 00000000..b90314e2 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n01.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n02.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n02.xml new file mode 100755 index 00000000..da5d293a --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n02.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n03.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n03.xml new file mode 100755 index 00000000..60eb3c90 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n03.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n04.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n04.xml new file mode 100755 index 00000000..d9cd5aa3 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n04.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n05.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n05.xml new file mode 100755 index 00000000..ef5287b8 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n05.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n06.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n06.xml new file mode 100755 index 00000000..ef2b241b --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n06.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n07.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n07.xml new file mode 100755 index 00000000..dc7db07f --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n07.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n08.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n08.xml new file mode 100755 index 00000000..257a2b15 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n08.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n09.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n09.xml new file mode 100755 index 00000000..d84e557b --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n09.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n10.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n10.xml new file mode 100755 index 00000000..302b4adc --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n10.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n11.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n11.xml new file mode 100755 index 00000000..c1a7735a --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n11.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n12.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n12.xml new file mode 100755 index 00000000..ac45641e --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n12.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n13.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n13.xml new file mode 100755 index 00000000..5fb7e723 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n13.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n14.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n14.xml new file mode 100755 index 00000000..fbac719b --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n14.xml @@ -0,0 +1,7 @@ + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n15.xml b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n15.xml new file mode 100755 index 00000000..612e4ae0 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P66/ibm66n15.xml @@ -0,0 +1,7 @@ + + + +]> + From a16c27b703b35166f167e116cf7c0a3a12fa975e Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Mon, 25 Jan 2021 22:28:03 -0300 Subject: [PATCH 046/133] Fix MXParser do not fail when the leading white space is missing in the (#135) EncodingDecl in the XMLDecl (file not-wf/P80/ibm80n01.xml) (#134) --- .../plexus/util/xml/pull/MXParser.java | 12 ++ ...onformanceTestSuite_Production32_Test.java | 2 +- ...onformanceTestSuite_Production80_Test.java | 190 ++++++++++++++++++ .../xmlconf/ibm/not-wf/P80/ibm80n01.xml | 8 + .../xmlconf/ibm/not-wf/P80/ibm80n02.xml | 8 + .../xmlconf/ibm/not-wf/P80/ibm80n03.xml | 8 + .../xmlconf/ibm/not-wf/P80/ibm80n04.xml | 8 + .../xmlconf/ibm/not-wf/P80/ibm80n05.xml | 8 + .../xmlconf/ibm/not-wf/P80/ibm80n06.xml | 8 + 9 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test.java create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n01.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n02.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n03.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n04.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n05.xml create mode 100755 src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n06.xml 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 4f1955a1..430c2236 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 @@ -3274,9 +3274,21 @@ private void parseXmlDeclWithVersion( int versionStart, int versionEnd ) // [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 version and not " + printable( ch ), this, + null ); + } ch = more(); ch = requireInput( ch, NCODING ); ch = skipS( ch ); 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 index 29ba3947..d3e5f31a 100644 --- 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 @@ -105,7 +105,7 @@ public void testibm_not_wf_P32_ibm32n03xml() } catch ( XmlPullParserException e ) { - assertTrue( e.getMessage().contains( "expected ?> as last part of IBM XML Conformance Test Suite - Production 80 + * XML test files base folder:
    xmlconf/ibm/
    + * + * @author Gabriel Belingueres + */ +public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test +{ + + final static File testResourcesDir = new File( "src/test/resources/", "xmlconf/ibm/" ); + + MXParser parser; + + @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 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 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 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 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 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 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/resources/xmlconf/ibm/not-wf/P80/ibm80n01.xml b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n01.xml new file mode 100755 index 00000000..7cc18ce4 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n01.xml @@ -0,0 +1,8 @@ + + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n02.xml b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n02.xml new file mode 100755 index 00000000..3ee667bc --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n02.xml @@ -0,0 +1,8 @@ + + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n03.xml b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n03.xml new file mode 100755 index 00000000..9cd9b893 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n03.xml @@ -0,0 +1,8 @@ + + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n04.xml b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n04.xml new file mode 100755 index 00000000..48fbfa17 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n04.xml @@ -0,0 +1,8 @@ + + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n05.xml b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n05.xml new file mode 100755 index 00000000..a805fd65 --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n05.xml @@ -0,0 +1,8 @@ + + + + +]> + diff --git a/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n06.xml b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n06.xml new file mode 100755 index 00000000..f0b36cdd --- /dev/null +++ b/src/test/resources/xmlconf/ibm/not-wf/P80/ibm80n06.xml @@ -0,0 +1,8 @@ + + + + +]> + From 84889e112633d0a3ac1517016416f8ed00b63310 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Jan 2021 06:24:57 +1000 Subject: [PATCH 047/133] Bump release-drafter/release-drafter from v5.12.1 to v5.13.0 (#117) Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from v5.12.1 to v5.13.0. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5.12.1...4d1215c66d92eba9557a55da848b2281a1a19235) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 7b35f195..6b8089f3 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,6 +7,6 @@ jobs: update_release_draft: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5.12.1 + - uses: release-drafter/release-drafter@v5.13.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 85a4a3c534752919dd97d757d4ef0fdb6d40eb8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sat, 20 Feb 2021 04:32:48 +0100 Subject: [PATCH 048/133] update link to search.maven.org --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c93a80b..8406ee41 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Plexus-Utils ============ [![Build Status](https://travis-ci.org/codehaus-plexus/plexus-utils.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-utils) -[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.codehaus.plexus%22%20a%3A%plexus-utils%22) +[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](http://search.maven.org/artifact/org.codehaus.plexus/plexus-utils) The current master is now at https://github.com/codehaus-plexus/plexus-utils From 6e7950308e573fa7c35141d69f2847ab5b9e25e9 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 16 Aug 2020 15:22:29 +0000 Subject: [PATCH 049/133] Java 9: InputStream.transferTo(OutputStream) instead of JVM-based byte transferTo Provides potential higher performance. Signed-off-by: Markus KARG --- src/main/java/org/codehaus/plexus/util/IOUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index 3fab8411..0b2ae40b 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -156,7 +156,7 @@ private IOUtil() public static void copy( final InputStream input, final OutputStream output ) throws IOException { - copy( input, output, DEFAULT_BUFFER_SIZE ); + input.transferTo( output ); } /** From 994b554742b7789e2ab6637a59b7099c9337a641 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 16 Aug 2020 15:24:05 +0000 Subject: [PATCH 050/133] Java 10: Reader.transferTo(Writer) instead of JVM-based byte transfer Provides potential higher performance. Signed-off-by: Markus KARG --- src/main/java/org/codehaus/plexus/util/IOUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index 0b2ae40b..fdb64163 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -186,7 +186,7 @@ public static void copy( final InputStream input, final OutputStream output, fin public static void copy( final Reader input, final Writer output ) throws IOException { - copy( input, output, DEFAULT_BUFFER_SIZE ); + input.transferTo( output ); } /** From 53cbf247b5ed33a1938453e8389376ca94a559ac Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Fri, 1 Jan 2021 15:19:11 +0000 Subject: [PATCH 051/133] Multi-Release-Jar Signed-off-by: Markus KARG --- pom.xml | 50 + .../java/org/codehaus/plexus/util/IOUtil.java | 4 +- .../org/codehaus/plexus/util/IOUtil.java | 886 ++++++++++++++++++ .../org/codehaus/plexus/util/IOUtil.java | 886 ++++++++++++++++++ 4 files changed, 1824 insertions(+), 2 deletions(-) create mode 100644 src/main/java10/org/codehaus/plexus/util/IOUtil.java create mode 100644 src/main/java9/org/codehaus/plexus/util/IOUtil.java diff --git a/pom.xml b/pom.xml index efad18f9..f34b6334 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,46 @@ limitations under the License. + + maven-compiler-plugin + + + default-compile + + compile + + + 8 + + + + compile-java-9 + + compile + + + 9 + + ${project.basedir}/src/main/java9 + + true + + + + compile-java-10 + + compile + + + 10 + + ${project.basedir}/src/main/java10 + + true + + + + org.apache.maven.plugins maven-scm-publish-plugin @@ -134,6 +174,16 @@ limitations under the License. + + maven-jar-plugin + + + + true + + + + diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index fdb64163..3fab8411 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -156,7 +156,7 @@ private IOUtil() public static void copy( final InputStream input, final OutputStream output ) throws IOException { - input.transferTo( output ); + copy( input, output, DEFAULT_BUFFER_SIZE ); } /** @@ -186,7 +186,7 @@ public static void copy( final InputStream input, final OutputStream output, fin public static void copy( final Reader input, final Writer output ) throws IOException { - input.transferTo( output ); + copy( input, output, DEFAULT_BUFFER_SIZE ); } /** diff --git a/src/main/java10/org/codehaus/plexus/util/IOUtil.java b/src/main/java10/org/codehaus/plexus/util/IOUtil.java new file mode 100644 index 00000000..fdb64163 --- /dev/null +++ b/src/main/java10/org/codehaus/plexus/util/IOUtil.java @@ -0,0 +1,886 @@ +package org.codehaus.plexus.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.codehaus.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact codehaus@codehaus.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Turbine", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.nio.channels.Channel; + +/** + * General IO Stream manipulation. + *

    + * This class provides static utility methods for input/output operations, particularly buffered copying between sources + * (InputStream, Reader, String and byte[]) and destinations + * (OutputStream, Writer, String and byte[]). + *

    + *

    + * Unless otherwise noted, these copy methods do not flush or close the streams. Often, doing so + * would require making non-portable assumptions about the streams' origin and further use. This means that both + * streams' close() methods must be called after copying. if one omits this step, then the stream resources + * (sockets, file descriptors) are released when the associated Stream is garbage-collected. It is not a good idea to + * rely on this mechanism. For a good overview of the distinction between "memory management" and "resource management", + * see this UnixReview article + *

    + *

    + * For each copy method, a variant is provided that allows the caller to specify the buffer size (the + * default is 4k). As the buffer size can have a fairly large impact on speed, this may be worth tweaking. Often "large + * buffer -> faster" does not hold, even for large data transfers. + *

    + *

    + * For byte-to-char methods, a copy variant allows the encoding to be selected (otherwise the platform + * default is used). + *

    + *

    + * The copy methods use an internal buffer when copying. It is therefore advisable not to + * deliberately wrap the stream arguments to the copy methods in Buffered* streams. For + * example, don't do the following: + *

    + * copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) ); + *

    + * The rationale is as follows: + *

    + *

    + * Imagine that an InputStream's read() is a very expensive operation, which would usually suggest wrapping in a + * BufferedInputStream. The BufferedInputStream works by issuing infrequent + * {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the underlying InputStream, to fill an + * internal buffer, from which further read requests can inexpensively get their data (until the buffer + * runs out). + *

    + *

    + * However, the copy methods do the same thing, keeping an internal buffer, populated by + * {@link InputStream#read(byte[] b, int off, int len)} requests. Having two buffers (or three if the destination stream + * is also buffered) is pointless, and the unnecessary buffer management hurts performance slightly (about 3%, according + * to some simple experiments). + *

    + * + * @author Peter Donald + * @author Jeff Turner + * + * @since 4.0 + */ + +/* + * Behold, intrepid explorers; a map of this class: Method Input Output Dependency ------ ----- ------ ------- 1 copy + * InputStream OutputStream (primitive) 2 copy Reader Writer (primitive) 3 copy InputStream Writer 2 4 toString + * InputStream String 3 5 toByteArray InputStream byte[] 1 6 copy Reader OutputStream 2 7 toString Reader String 2 8 + * toByteArray Reader byte[] 6 9 copy String OutputStream 2 10 copy String Writer (trivial) 11 toByteArray String byte[] + * 9 12 copy byte[] Writer 3 13 toString byte[] String 12 14 copy byte[] OutputStream (trivial) Note that only the first + * two methods shuffle bytes; the rest use these two, or (if possible) copy using native Java copy methods. As there are + * method variants to specify buffer size and encoding, each row may correspond to up to 4 methods. + */ + +public final class IOUtil +{ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; + + /** + * Private constructor to prevent instantiation. + */ + private IOUtil() + { + } + + /////////////////////////////////////////////////////////////// + // Core copy methods + /////////////////////////////////////////////////////////////// + + /** + * 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 + { + input.transferTo( 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 + { + final byte[] buffer = new byte[bufferSize]; + int n = 0; + while ( 0 <= ( n = input.read( buffer ) ) ) + { + output.write( buffer, 0, n ); + } + } + + /** + * 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 + { + input.transferTo( 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 + { + final char[] buffer = new char[bufferSize]; + int n = 0; + while ( 0 <= ( n = input.read( buffer ) ) ) + { + output.write( buffer, 0, n ); + } + output.flush(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // InputStream -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // InputStream -> Writer + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final InputStreamReader in = new InputStreamReader( input ); + copy( in, output, bufferSize ); + } + + /** + * 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 + { + final InputStreamReader in = new InputStreamReader( input, encoding ); + copy( in, output ); + } + + /** + * 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 + { + final InputStreamReader in = new InputStreamReader( input, encoding ); + copy( in, output, bufferSize ); + } + + /////////////////////////////////////////////////////////////// + // InputStream -> String + + /** + * @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 + { + return toString( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, bufferSize ); + return sw.toString(); + } + + /** + * @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 + { + return toString( input, encoding, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, encoding, bufferSize ); + return sw.toString(); + } + + /////////////////////////////////////////////////////////////// + // InputStream -> 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 + { + return toByteArray( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy( input, output, bufferSize ); + return output.toByteArray(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // Reader -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // Reader -> OutputStream + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final OutputStreamWriter out = new OutputStreamWriter( output ); + copy( input, out, bufferSize ); + // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush + // here. + out.flush(); + } + + /////////////////////////////////////////////////////////////// + // Reader -> 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 + { + return toString( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, bufferSize ); + return sw.toString(); + } + + /////////////////////////////////////////////////////////////// + // Reader -> 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 + { + return toByteArray( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy( input, output, bufferSize ); + return output.toByteArray(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // String -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // String -> OutputStream + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final StringReader in = new StringReader( input ); + final OutputStreamWriter out = new OutputStreamWriter( output ); + copy( in, out, bufferSize ); + // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush + // here. + out.flush(); + } + + /////////////////////////////////////////////////////////////// + // String -> Writer + + /** + * 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 + { + output.write( input ); + } + + /** + * Copy bytes from an InputStream to an OutputStream, with buffering. This is equivalent + * 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 + { + final BufferedInputStream in = new BufferedInputStream( input ); + final BufferedOutputStream out = new BufferedOutputStream( output ); + copy( in, out ); + out.flush(); + } + + /////////////////////////////////////////////////////////////// + // String -> 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 + { + return toByteArray( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy( input, output, bufferSize ); + return output.toByteArray(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // byte[] -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // byte[] -> Writer + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final ByteArrayInputStream in = new ByteArrayInputStream( input ); + copy( in, output, bufferSize ); + } + + /** + * 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 + { + final ByteArrayInputStream in = new ByteArrayInputStream( input ); + copy( in, output, encoding ); + } + + /** + * 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 + { + final ByteArrayInputStream in = new ByteArrayInputStream( input ); + copy( in, output, encoding, bufferSize ); + } + + /////////////////////////////////////////////////////////////// + // byte[] -> String + + /** + * @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 + { + return toString( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, bufferSize ); + return sw.toString(); + } + + /** + * @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 + { + return toString( input, encoding, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, encoding, bufferSize ); + return sw.toString(); + } + + /////////////////////////////////////////////////////////////// + // byte[] -> OutputStream + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + output.write( input ); + } + + /** + * Compare the contents of two Streams to determine if they are equal or not. + * + * @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 + { + final InputStream bufferedInput1 = new BufferedInputStream( input1 ); + final InputStream bufferedInput2 = new BufferedInputStream( input2 ); + + int ch = bufferedInput1.read(); + while ( 0 <= ch ) + { + final int ch2 = bufferedInput2.read(); + if ( ch != ch2 ) + { + return false; + } + ch = bufferedInput1.read(); + } + + final int ch2 = bufferedInput2.read(); + if ( 0 <= ch2 ) + { + return false; + } + else + { + return true; + } + } + + // ---------------------------------------------------------------------- + // closeXXX() + // ---------------------------------------------------------------------- + + /** + * 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 ) + { + return; + } + + try + { + inputStream.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + channel.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + outputStream.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + reader.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + writer.close(); + } + catch ( IOException ex ) + { + // ignore + } + } +} diff --git a/src/main/java9/org/codehaus/plexus/util/IOUtil.java b/src/main/java9/org/codehaus/plexus/util/IOUtil.java new file mode 100644 index 00000000..0b2ae40b --- /dev/null +++ b/src/main/java9/org/codehaus/plexus/util/IOUtil.java @@ -0,0 +1,886 @@ +package org.codehaus.plexus.util; + +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.codehaus.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact codehaus@codehaus.org. + * + * 5. Products derived from this software may not be called "Apache", + * "Apache Turbine", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.nio.channels.Channel; + +/** + * General IO Stream manipulation. + *

    + * This class provides static utility methods for input/output operations, particularly buffered copying between sources + * (InputStream, Reader, String and byte[]) and destinations + * (OutputStream, Writer, String and byte[]). + *

    + *

    + * Unless otherwise noted, these copy methods do not flush or close the streams. Often, doing so + * would require making non-portable assumptions about the streams' origin and further use. This means that both + * streams' close() methods must be called after copying. if one omits this step, then the stream resources + * (sockets, file descriptors) are released when the associated Stream is garbage-collected. It is not a good idea to + * rely on this mechanism. For a good overview of the distinction between "memory management" and "resource management", + * see this UnixReview article + *

    + *

    + * For each copy method, a variant is provided that allows the caller to specify the buffer size (the + * default is 4k). As the buffer size can have a fairly large impact on speed, this may be worth tweaking. Often "large + * buffer -> faster" does not hold, even for large data transfers. + *

    + *

    + * For byte-to-char methods, a copy variant allows the encoding to be selected (otherwise the platform + * default is used). + *

    + *

    + * The copy methods use an internal buffer when copying. It is therefore advisable not to + * deliberately wrap the stream arguments to the copy methods in Buffered* streams. For + * example, don't do the following: + *

    + * copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) ); + *

    + * The rationale is as follows: + *

    + *

    + * Imagine that an InputStream's read() is a very expensive operation, which would usually suggest wrapping in a + * BufferedInputStream. The BufferedInputStream works by issuing infrequent + * {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the underlying InputStream, to fill an + * internal buffer, from which further read requests can inexpensively get their data (until the buffer + * runs out). + *

    + *

    + * However, the copy methods do the same thing, keeping an internal buffer, populated by + * {@link InputStream#read(byte[] b, int off, int len)} requests. Having two buffers (or three if the destination stream + * is also buffered) is pointless, and the unnecessary buffer management hurts performance slightly (about 3%, according + * to some simple experiments). + *

    + * + * @author Peter Donald + * @author Jeff Turner + * + * @since 4.0 + */ + +/* + * Behold, intrepid explorers; a map of this class: Method Input Output Dependency ------ ----- ------ ------- 1 copy + * InputStream OutputStream (primitive) 2 copy Reader Writer (primitive) 3 copy InputStream Writer 2 4 toString + * InputStream String 3 5 toByteArray InputStream byte[] 1 6 copy Reader OutputStream 2 7 toString Reader String 2 8 + * toByteArray Reader byte[] 6 9 copy String OutputStream 2 10 copy String Writer (trivial) 11 toByteArray String byte[] + * 9 12 copy byte[] Writer 3 13 toString byte[] String 12 14 copy byte[] OutputStream (trivial) Note that only the first + * two methods shuffle bytes; the rest use these two, or (if possible) copy using native Java copy methods. As there are + * method variants to specify buffer size and encoding, each row may correspond to up to 4 methods. + */ + +public final class IOUtil +{ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; + + /** + * Private constructor to prevent instantiation. + */ + private IOUtil() + { + } + + /////////////////////////////////////////////////////////////// + // Core copy methods + /////////////////////////////////////////////////////////////// + + /** + * 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 + { + input.transferTo( 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 + { + final byte[] buffer = new byte[bufferSize]; + int n = 0; + while ( 0 <= ( n = input.read( buffer ) ) ) + { + output.write( buffer, 0, n ); + } + } + + /** + * 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 ); + } + + /** + * 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 + { + final char[] buffer = new char[bufferSize]; + int n = 0; + while ( 0 <= ( n = input.read( buffer ) ) ) + { + output.write( buffer, 0, n ); + } + output.flush(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // InputStream -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // InputStream -> Writer + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final InputStreamReader in = new InputStreamReader( input ); + copy( in, output, bufferSize ); + } + + /** + * 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 + { + final InputStreamReader in = new InputStreamReader( input, encoding ); + copy( in, output ); + } + + /** + * 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 + { + final InputStreamReader in = new InputStreamReader( input, encoding ); + copy( in, output, bufferSize ); + } + + /////////////////////////////////////////////////////////////// + // InputStream -> String + + /** + * @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 + { + return toString( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, bufferSize ); + return sw.toString(); + } + + /** + * @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 + { + return toString( input, encoding, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, encoding, bufferSize ); + return sw.toString(); + } + + /////////////////////////////////////////////////////////////// + // InputStream -> 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 + { + return toByteArray( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy( input, output, bufferSize ); + return output.toByteArray(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // Reader -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // Reader -> OutputStream + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final OutputStreamWriter out = new OutputStreamWriter( output ); + copy( input, out, bufferSize ); + // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush + // here. + out.flush(); + } + + /////////////////////////////////////////////////////////////// + // Reader -> 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 + { + return toString( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, bufferSize ); + return sw.toString(); + } + + /////////////////////////////////////////////////////////////// + // Reader -> 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 + { + return toByteArray( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy( input, output, bufferSize ); + return output.toByteArray(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // String -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // String -> OutputStream + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final StringReader in = new StringReader( input ); + final OutputStreamWriter out = new OutputStreamWriter( output ); + copy( in, out, bufferSize ); + // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush + // here. + out.flush(); + } + + /////////////////////////////////////////////////////////////// + // String -> Writer + + /** + * 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 + { + output.write( input ); + } + + /** + * Copy bytes from an InputStream to an OutputStream, with buffering. This is equivalent + * 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 + { + final BufferedInputStream in = new BufferedInputStream( input ); + final BufferedOutputStream out = new BufferedOutputStream( output ); + copy( in, out ); + out.flush(); + } + + /////////////////////////////////////////////////////////////// + // String -> 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 + { + return toByteArray( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + copy( input, output, bufferSize ); + return output.toByteArray(); + } + + /////////////////////////////////////////////////////////////// + // Derived copy methods + // byte[] -> * + /////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////// + // byte[] -> Writer + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + final ByteArrayInputStream in = new ByteArrayInputStream( input ); + copy( in, output, bufferSize ); + } + + /** + * 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 + { + final ByteArrayInputStream in = new ByteArrayInputStream( input ); + copy( in, output, encoding ); + } + + /** + * 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 + { + final ByteArrayInputStream in = new ByteArrayInputStream( input ); + copy( in, output, encoding, bufferSize ); + } + + /////////////////////////////////////////////////////////////// + // byte[] -> String + + /** + * @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 + { + return toString( input, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, bufferSize ); + return sw.toString(); + } + + /** + * @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 + { + return toString( input, encoding, DEFAULT_BUFFER_SIZE ); + } + + /** + * @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 + { + final StringWriter sw = new StringWriter(); + copy( input, sw, encoding, bufferSize ); + return sw.toString(); + } + + /////////////////////////////////////////////////////////////// + // byte[] -> OutputStream + + /** + * 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 + { + copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + /** + * 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 + { + output.write( input ); + } + + /** + * Compare the contents of two Streams to determine if they are equal or not. + * + * @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 + { + final InputStream bufferedInput1 = new BufferedInputStream( input1 ); + final InputStream bufferedInput2 = new BufferedInputStream( input2 ); + + int ch = bufferedInput1.read(); + while ( 0 <= ch ) + { + final int ch2 = bufferedInput2.read(); + if ( ch != ch2 ) + { + return false; + } + ch = bufferedInput1.read(); + } + + final int ch2 = bufferedInput2.read(); + if ( 0 <= ch2 ) + { + return false; + } + else + { + return true; + } + } + + // ---------------------------------------------------------------------- + // closeXXX() + // ---------------------------------------------------------------------- + + /** + * 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 ) + { + return; + } + + try + { + inputStream.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + channel.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + outputStream.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + reader.close(); + } + catch ( IOException ex ) + { + // ignore + } + } + + /** + * 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 ) + { + return; + } + + try + { + writer.close(); + } + catch ( IOException ex ) + { + // ignore + } + } +} From 733b2809783dce199f9de089d783d3d8f20726ca Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sat, 2 Jan 2021 23:14:56 +0000 Subject: [PATCH 052/133] Reducing duplicate code in MRJAR using VersionSpecifics class Signed-off-by: Markus KARG --- .../plexus/util/CommonImplementation.java | 29 + .../java/org/codehaus/plexus/util/IOUtil.java | 4 +- .../plexus/util/VersionSpecifics.java | 13 + .../org/codehaus/plexus/util/IOUtil.java | 886 ------------------ .../plexus/util/VersionSpecifics.java | 31 + .../org/codehaus/plexus/util/IOUtil.java | 886 ------------------ .../plexus/util/VersionSpecifics.java | 25 + 7 files changed, 100 insertions(+), 1774 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/util/CommonImplementation.java create mode 100644 src/main/java/org/codehaus/plexus/util/VersionSpecifics.java delete mode 100644 src/main/java10/org/codehaus/plexus/util/IOUtil.java create mode 100644 src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java delete mode 100644 src/main/java9/org/codehaus/plexus/util/IOUtil.java create mode 100644 src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java diff --git a/src/main/java/org/codehaus/plexus/util/CommonImplementation.java b/src/main/java/org/codehaus/plexus/util/CommonImplementation.java new file mode 100644 index 00000000..16923d9c --- /dev/null +++ b/src/main/java/org/codehaus/plexus/util/CommonImplementation.java @@ -0,0 +1,29 @@ +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; + +/** + * Fallback implementation for all Java SE versions not + * overwriting a method version-specifically. + */ +abstract class CommonImplementation +{ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; + + void copy( final InputStream input, final OutputStream output ) + throws IOException + { + IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE ); + } + + 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/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index 3fab8411..5ba3fb73 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -156,7 +156,7 @@ private IOUtil() public static void copy( final InputStream input, final OutputStream output ) throws IOException { - copy( input, output, DEFAULT_BUFFER_SIZE ); + VersionSpecifics.INSTANCE.copy( input, output ); } /** @@ -186,7 +186,7 @@ public static void copy( final InputStream input, final OutputStream output, fin public static void copy( final Reader input, final Writer output ) throws IOException { - copy( input, output, DEFAULT_BUFFER_SIZE ); + VersionSpecifics.INSTANCE.copy( input, output ); } /** diff --git a/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java new file mode 100644 index 00000000..de3e7d8a --- /dev/null +++ b/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java @@ -0,0 +1,13 @@ +package org.codehaus.plexus.util; + +/** + * Implementation specific to Java SE 8 version. + */ +final class VersionSpecifics extends CommonImplementation +{ + static final VersionSpecifics INSTANCE = new VersionSpecifics(); + + private VersionSpecifics() { + // singleton + } +} diff --git a/src/main/java10/org/codehaus/plexus/util/IOUtil.java b/src/main/java10/org/codehaus/plexus/util/IOUtil.java deleted file mode 100644 index fdb64163..00000000 --- a/src/main/java10/org/codehaus/plexus/util/IOUtil.java +++ /dev/null @@ -1,886 +0,0 @@ -package org.codehaus.plexus.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.codehaus.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact codehaus@codehaus.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.nio.channels.Channel; - -/** - * General IO Stream manipulation. - *

    - * This class provides static utility methods for input/output operations, particularly buffered copying between sources - * (InputStream, Reader, String and byte[]) and destinations - * (OutputStream, Writer, String and byte[]). - *

    - *

    - * Unless otherwise noted, these copy methods do not flush or close the streams. Often, doing so - * would require making non-portable assumptions about the streams' origin and further use. This means that both - * streams' close() methods must be called after copying. if one omits this step, then the stream resources - * (sockets, file descriptors) are released when the associated Stream is garbage-collected. It is not a good idea to - * rely on this mechanism. For a good overview of the distinction between "memory management" and "resource management", - * see this UnixReview article - *

    - *

    - * For each copy method, a variant is provided that allows the caller to specify the buffer size (the - * default is 4k). As the buffer size can have a fairly large impact on speed, this may be worth tweaking. Often "large - * buffer -> faster" does not hold, even for large data transfers. - *

    - *

    - * For byte-to-char methods, a copy variant allows the encoding to be selected (otherwise the platform - * default is used). - *

    - *

    - * The copy methods use an internal buffer when copying. It is therefore advisable not to - * deliberately wrap the stream arguments to the copy methods in Buffered* streams. For - * example, don't do the following: - *

    - * copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) ); - *

    - * The rationale is as follows: - *

    - *

    - * Imagine that an InputStream's read() is a very expensive operation, which would usually suggest wrapping in a - * BufferedInputStream. The BufferedInputStream works by issuing infrequent - * {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the underlying InputStream, to fill an - * internal buffer, from which further read requests can inexpensively get their data (until the buffer - * runs out). - *

    - *

    - * However, the copy methods do the same thing, keeping an internal buffer, populated by - * {@link InputStream#read(byte[] b, int off, int len)} requests. Having two buffers (or three if the destination stream - * is also buffered) is pointless, and the unnecessary buffer management hurts performance slightly (about 3%, according - * to some simple experiments). - *

    - * - * @author Peter Donald - * @author Jeff Turner - * - * @since 4.0 - */ - -/* - * Behold, intrepid explorers; a map of this class: Method Input Output Dependency ------ ----- ------ ------- 1 copy - * InputStream OutputStream (primitive) 2 copy Reader Writer (primitive) 3 copy InputStream Writer 2 4 toString - * InputStream String 3 5 toByteArray InputStream byte[] 1 6 copy Reader OutputStream 2 7 toString Reader String 2 8 - * toByteArray Reader byte[] 6 9 copy String OutputStream 2 10 copy String Writer (trivial) 11 toByteArray String byte[] - * 9 12 copy byte[] Writer 3 13 toString byte[] String 12 14 copy byte[] OutputStream (trivial) Note that only the first - * two methods shuffle bytes; the rest use these two, or (if possible) copy using native Java copy methods. As there are - * method variants to specify buffer size and encoding, each row may correspond to up to 4 methods. - */ - -public final class IOUtil -{ - private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; - - /** - * Private constructor to prevent instantiation. - */ - private IOUtil() - { - } - - /////////////////////////////////////////////////////////////// - // Core copy methods - /////////////////////////////////////////////////////////////// - - /** - * 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 - { - input.transferTo( 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 - { - final byte[] buffer = new byte[bufferSize]; - int n = 0; - while ( 0 <= ( n = input.read( buffer ) ) ) - { - output.write( buffer, 0, n ); - } - } - - /** - * 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 - { - input.transferTo( 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 - { - final char[] buffer = new char[bufferSize]; - int n = 0; - while ( 0 <= ( n = input.read( buffer ) ) ) - { - output.write( buffer, 0, n ); - } - output.flush(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // InputStream -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // InputStream -> Writer - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final InputStreamReader in = new InputStreamReader( input ); - copy( in, output, bufferSize ); - } - - /** - * 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 - { - final InputStreamReader in = new InputStreamReader( input, encoding ); - copy( in, output ); - } - - /** - * 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 - { - final InputStreamReader in = new InputStreamReader( input, encoding ); - copy( in, output, bufferSize ); - } - - /////////////////////////////////////////////////////////////// - // InputStream -> String - - /** - * @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 - { - return toString( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, bufferSize ); - return sw.toString(); - } - - /** - * @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 - { - return toString( input, encoding, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, encoding, bufferSize ); - return sw.toString(); - } - - /////////////////////////////////////////////////////////////// - // InputStream -> 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 - { - return toByteArray( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final ByteArrayOutputStream output = new ByteArrayOutputStream(); - copy( input, output, bufferSize ); - return output.toByteArray(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // Reader -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // Reader -> OutputStream - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final OutputStreamWriter out = new OutputStreamWriter( output ); - copy( input, out, bufferSize ); - // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush - // here. - out.flush(); - } - - /////////////////////////////////////////////////////////////// - // Reader -> 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 - { - return toString( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, bufferSize ); - return sw.toString(); - } - - /////////////////////////////////////////////////////////////// - // Reader -> 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 - { - return toByteArray( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - copy( input, output, bufferSize ); - return output.toByteArray(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // String -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // String -> OutputStream - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final StringReader in = new StringReader( input ); - final OutputStreamWriter out = new OutputStreamWriter( output ); - copy( in, out, bufferSize ); - // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush - // here. - out.flush(); - } - - /////////////////////////////////////////////////////////////// - // String -> Writer - - /** - * 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 - { - output.write( input ); - } - - /** - * Copy bytes from an InputStream to an OutputStream, with buffering. This is equivalent - * 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 - { - final BufferedInputStream in = new BufferedInputStream( input ); - final BufferedOutputStream out = new BufferedOutputStream( output ); - copy( in, out ); - out.flush(); - } - - /////////////////////////////////////////////////////////////// - // String -> 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 - { - return toByteArray( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - copy( input, output, bufferSize ); - return output.toByteArray(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // byte[] -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // byte[] -> Writer - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final ByteArrayInputStream in = new ByteArrayInputStream( input ); - copy( in, output, bufferSize ); - } - - /** - * 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 - { - final ByteArrayInputStream in = new ByteArrayInputStream( input ); - copy( in, output, encoding ); - } - - /** - * 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 - { - final ByteArrayInputStream in = new ByteArrayInputStream( input ); - copy( in, output, encoding, bufferSize ); - } - - /////////////////////////////////////////////////////////////// - // byte[] -> String - - /** - * @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 - { - return toString( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, bufferSize ); - return sw.toString(); - } - - /** - * @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 - { - return toString( input, encoding, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, encoding, bufferSize ); - return sw.toString(); - } - - /////////////////////////////////////////////////////////////// - // byte[] -> OutputStream - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - output.write( input ); - } - - /** - * Compare the contents of two Streams to determine if they are equal or not. - * - * @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 - { - final InputStream bufferedInput1 = new BufferedInputStream( input1 ); - final InputStream bufferedInput2 = new BufferedInputStream( input2 ); - - int ch = bufferedInput1.read(); - while ( 0 <= ch ) - { - final int ch2 = bufferedInput2.read(); - if ( ch != ch2 ) - { - return false; - } - ch = bufferedInput1.read(); - } - - final int ch2 = bufferedInput2.read(); - if ( 0 <= ch2 ) - { - return false; - } - else - { - return true; - } - } - - // ---------------------------------------------------------------------- - // closeXXX() - // ---------------------------------------------------------------------- - - /** - * 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 ) - { - return; - } - - try - { - inputStream.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - channel.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - outputStream.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - reader.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - writer.close(); - } - catch ( IOException ex ) - { - // ignore - } - } -} diff --git a/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java new file mode 100644 index 00000000..ae1d050a --- /dev/null +++ b/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java @@ -0,0 +1,31 @@ +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. + */ +final class VersionSpecifics extends CommonImplementation +{ + static final VersionSpecifics INSTANCE = new VersionSpecifics(); + + private VersionSpecifics() { + // singleton + } + + void copy( final InputStream input, final OutputStream output ) + throws IOException + { + input.transferTo( output ); + } + + void copy( final Reader input, final Writer output ) + throws IOException + { + input.transferTo( output ); + } +} diff --git a/src/main/java9/org/codehaus/plexus/util/IOUtil.java b/src/main/java9/org/codehaus/plexus/util/IOUtil.java deleted file mode 100644 index 0b2ae40b..00000000 --- a/src/main/java9/org/codehaus/plexus/util/IOUtil.java +++ /dev/null @@ -1,886 +0,0 @@ -package org.codehaus.plexus.util; - -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2001 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.codehaus.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For - * written permission, please contact codehaus@codehaus.org. - * - * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without - * prior written permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.nio.channels.Channel; - -/** - * General IO Stream manipulation. - *

    - * This class provides static utility methods for input/output operations, particularly buffered copying between sources - * (InputStream, Reader, String and byte[]) and destinations - * (OutputStream, Writer, String and byte[]). - *

    - *

    - * Unless otherwise noted, these copy methods do not flush or close the streams. Often, doing so - * would require making non-portable assumptions about the streams' origin and further use. This means that both - * streams' close() methods must be called after copying. if one omits this step, then the stream resources - * (sockets, file descriptors) are released when the associated Stream is garbage-collected. It is not a good idea to - * rely on this mechanism. For a good overview of the distinction between "memory management" and "resource management", - * see this UnixReview article - *

    - *

    - * For each copy method, a variant is provided that allows the caller to specify the buffer size (the - * default is 4k). As the buffer size can have a fairly large impact on speed, this may be worth tweaking. Often "large - * buffer -> faster" does not hold, even for large data transfers. - *

    - *

    - * For byte-to-char methods, a copy variant allows the encoding to be selected (otherwise the platform - * default is used). - *

    - *

    - * The copy methods use an internal buffer when copying. It is therefore advisable not to - * deliberately wrap the stream arguments to the copy methods in Buffered* streams. For - * example, don't do the following: - *

    - * copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) ); - *

    - * The rationale is as follows: - *

    - *

    - * Imagine that an InputStream's read() is a very expensive operation, which would usually suggest wrapping in a - * BufferedInputStream. The BufferedInputStream works by issuing infrequent - * {@link java.io.InputStream#read(byte[] b, int off, int len)} requests on the underlying InputStream, to fill an - * internal buffer, from which further read requests can inexpensively get their data (until the buffer - * runs out). - *

    - *

    - * However, the copy methods do the same thing, keeping an internal buffer, populated by - * {@link InputStream#read(byte[] b, int off, int len)} requests. Having two buffers (or three if the destination stream - * is also buffered) is pointless, and the unnecessary buffer management hurts performance slightly (about 3%, according - * to some simple experiments). - *

    - * - * @author Peter Donald - * @author Jeff Turner - * - * @since 4.0 - */ - -/* - * Behold, intrepid explorers; a map of this class: Method Input Output Dependency ------ ----- ------ ------- 1 copy - * InputStream OutputStream (primitive) 2 copy Reader Writer (primitive) 3 copy InputStream Writer 2 4 toString - * InputStream String 3 5 toByteArray InputStream byte[] 1 6 copy Reader OutputStream 2 7 toString Reader String 2 8 - * toByteArray Reader byte[] 6 9 copy String OutputStream 2 10 copy String Writer (trivial) 11 toByteArray String byte[] - * 9 12 copy byte[] Writer 3 13 toString byte[] String 12 14 copy byte[] OutputStream (trivial) Note that only the first - * two methods shuffle bytes; the rest use these two, or (if possible) copy using native Java copy methods. As there are - * method variants to specify buffer size and encoding, each row may correspond to up to 4 methods. - */ - -public final class IOUtil -{ - private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; - - /** - * Private constructor to prevent instantiation. - */ - private IOUtil() - { - } - - /////////////////////////////////////////////////////////////// - // Core copy methods - /////////////////////////////////////////////////////////////// - - /** - * 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 - { - input.transferTo( 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 - { - final byte[] buffer = new byte[bufferSize]; - int n = 0; - while ( 0 <= ( n = input.read( buffer ) ) ) - { - output.write( buffer, 0, n ); - } - } - - /** - * 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 ); - } - - /** - * 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 - { - final char[] buffer = new char[bufferSize]; - int n = 0; - while ( 0 <= ( n = input.read( buffer ) ) ) - { - output.write( buffer, 0, n ); - } - output.flush(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // InputStream -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // InputStream -> Writer - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final InputStreamReader in = new InputStreamReader( input ); - copy( in, output, bufferSize ); - } - - /** - * 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 - { - final InputStreamReader in = new InputStreamReader( input, encoding ); - copy( in, output ); - } - - /** - * 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 - { - final InputStreamReader in = new InputStreamReader( input, encoding ); - copy( in, output, bufferSize ); - } - - /////////////////////////////////////////////////////////////// - // InputStream -> String - - /** - * @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 - { - return toString( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, bufferSize ); - return sw.toString(); - } - - /** - * @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 - { - return toString( input, encoding, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, encoding, bufferSize ); - return sw.toString(); - } - - /////////////////////////////////////////////////////////////// - // InputStream -> 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 - { - return toByteArray( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final ByteArrayOutputStream output = new ByteArrayOutputStream(); - copy( input, output, bufferSize ); - return output.toByteArray(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // Reader -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // Reader -> OutputStream - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final OutputStreamWriter out = new OutputStreamWriter( output ); - copy( input, out, bufferSize ); - // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush - // here. - out.flush(); - } - - /////////////////////////////////////////////////////////////// - // Reader -> 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 - { - return toString( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, bufferSize ); - return sw.toString(); - } - - /////////////////////////////////////////////////////////////// - // Reader -> 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 - { - return toByteArray( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - copy( input, output, bufferSize ); - return output.toByteArray(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // String -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // String -> OutputStream - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final StringReader in = new StringReader( input ); - final OutputStreamWriter out = new OutputStreamWriter( output ); - copy( in, out, bufferSize ); - // NOTE: Unless anyone is planning on rewriting OutputStreamWriter, we have to flush - // here. - out.flush(); - } - - /////////////////////////////////////////////////////////////// - // String -> Writer - - /** - * 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 - { - output.write( input ); - } - - /** - * Copy bytes from an InputStream to an OutputStream, with buffering. This is equivalent - * 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 - { - final BufferedInputStream in = new BufferedInputStream( input ); - final BufferedOutputStream out = new BufferedOutputStream( output ); - copy( in, out ); - out.flush(); - } - - /////////////////////////////////////////////////////////////// - // String -> 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 - { - return toByteArray( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - copy( input, output, bufferSize ); - return output.toByteArray(); - } - - /////////////////////////////////////////////////////////////// - // Derived copy methods - // byte[] -> * - /////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////// - // byte[] -> Writer - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - final ByteArrayInputStream in = new ByteArrayInputStream( input ); - copy( in, output, bufferSize ); - } - - /** - * 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 - { - final ByteArrayInputStream in = new ByteArrayInputStream( input ); - copy( in, output, encoding ); - } - - /** - * 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 - { - final ByteArrayInputStream in = new ByteArrayInputStream( input ); - copy( in, output, encoding, bufferSize ); - } - - /////////////////////////////////////////////////////////////// - // byte[] -> String - - /** - * @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 - { - return toString( input, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, bufferSize ); - return sw.toString(); - } - - /** - * @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 - { - return toString( input, encoding, DEFAULT_BUFFER_SIZE ); - } - - /** - * @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 - { - final StringWriter sw = new StringWriter(); - copy( input, sw, encoding, bufferSize ); - return sw.toString(); - } - - /////////////////////////////////////////////////////////////// - // byte[] -> OutputStream - - /** - * 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 - { - copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - /** - * 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 - { - output.write( input ); - } - - /** - * Compare the contents of two Streams to determine if they are equal or not. - * - * @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 - { - final InputStream bufferedInput1 = new BufferedInputStream( input1 ); - final InputStream bufferedInput2 = new BufferedInputStream( input2 ); - - int ch = bufferedInput1.read(); - while ( 0 <= ch ) - { - final int ch2 = bufferedInput2.read(); - if ( ch != ch2 ) - { - return false; - } - ch = bufferedInput1.read(); - } - - final int ch2 = bufferedInput2.read(); - if ( 0 <= ch2 ) - { - return false; - } - else - { - return true; - } - } - - // ---------------------------------------------------------------------- - // closeXXX() - // ---------------------------------------------------------------------- - - /** - * 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 ) - { - return; - } - - try - { - inputStream.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - channel.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - outputStream.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - reader.close(); - } - catch ( IOException ex ) - { - // ignore - } - } - - /** - * 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 ) - { - return; - } - - try - { - writer.close(); - } - catch ( IOException ex ) - { - // ignore - } - } -} diff --git a/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java new file mode 100644 index 00000000..c72cc7a3 --- /dev/null +++ b/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.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 9 version. + */ +final class VersionSpecifics extends CommonImplementation +{ + static final VersionSpecifics INSTANCE = new VersionSpecifics(); + + private VersionSpecifics() { + // singleton + } + + void copy( final InputStream input, final OutputStream output ) + throws IOException + { + input.transferTo( output ); + } +} From 4338b3809bd5865f4b675005db57ae1f02d4803e Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 3 Jan 2021 13:02:23 +0000 Subject: [PATCH 053/133] Reducing number of classes; No singleton but static. Signed-off-by: Markus KARG --- .../plexus/util/CommonImplementation.java | 29 ------------------- .../java/org/codehaus/plexus/util/IOUtil.java | 4 +-- .../plexus/util/VersionSpecifics.java | 22 ++++++++++++-- .../plexus/util/VersionSpecifics.java | 8 ++--- .../plexus/util/VersionSpecifics.java | 12 ++++++-- 5 files changed, 34 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/util/CommonImplementation.java diff --git a/src/main/java/org/codehaus/plexus/util/CommonImplementation.java b/src/main/java/org/codehaus/plexus/util/CommonImplementation.java deleted file mode 100644 index 16923d9c..00000000 --- a/src/main/java/org/codehaus/plexus/util/CommonImplementation.java +++ /dev/null @@ -1,29 +0,0 @@ -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; - -/** - * Fallback implementation for all Java SE versions not - * overwriting a method version-specifically. - */ -abstract class CommonImplementation -{ - private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; - - void copy( final InputStream input, final OutputStream output ) - throws IOException - { - IOUtil.copy( input, output, DEFAULT_BUFFER_SIZE ); - } - - 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/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index 5ba3fb73..ff5002d2 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -156,7 +156,7 @@ private IOUtil() public static void copy( final InputStream input, final OutputStream output ) throws IOException { - VersionSpecifics.INSTANCE.copy( input, output ); + VersionSpecifics.copy( input, output ); } /** @@ -186,7 +186,7 @@ public static void copy( final InputStream input, final OutputStream output, fin public static void copy( final Reader input, final Writer output ) throws IOException { - VersionSpecifics.INSTANCE.copy( input, output ); + VersionSpecifics.copy( input, output ); } /** diff --git a/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java index de3e7d8a..e6be5b08 100644 --- a/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java +++ b/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java @@ -1,13 +1,31 @@ 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. */ -final class VersionSpecifics extends CommonImplementation +final class VersionSpecifics { - static final VersionSpecifics INSTANCE = new VersionSpecifics(); + private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; private VersionSpecifics() { // singleton } + + 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/java10/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java index ae1d050a..06b385e2 100644 --- a/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java +++ b/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java @@ -9,21 +9,19 @@ /** * Implementation specific to Java SE 10 version. */ -final class VersionSpecifics extends CommonImplementation +final class VersionSpecifics { - static final VersionSpecifics INSTANCE = new VersionSpecifics(); - private VersionSpecifics() { // singleton } - void copy( final InputStream input, final OutputStream output ) + static void copy( final InputStream input, final OutputStream output ) throws IOException { input.transferTo( output ); } - void copy( final Reader input, final Writer 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/VersionSpecifics.java b/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java index c72cc7a3..b3c08c64 100644 --- a/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java +++ b/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java @@ -9,17 +9,23 @@ /** * Implementation specific to Java SE 9 version. */ -final class VersionSpecifics extends CommonImplementation +final class VersionSpecifics { - static final VersionSpecifics INSTANCE = new VersionSpecifics(); + private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; private VersionSpecifics() { // singleton } - void copy( final InputStream input, final OutputStream output ) + 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 ); + } } From 31813d7ee5d5019941a57dec7d8aacaa105fec21 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 3 Jan 2021 17:13:09 +0000 Subject: [PATCH 054/133] Github CI: Build with JDK 15, test with matrix Signed-off-by: Markus KARG --- .github/workflows/maven.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 13b4c47e..a44b5ebf 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -43,10 +43,18 @@ jobs: maven-${{ matrix.os }}-java${{ matrix.java }}- maven-${{ matrix.os }}- - - name: Set up JDK + - name: Set up JDK for building uses: actions/setup-java@v1 with: - java-version: ${{ matrix.java }} + java-version: 15 - name: Build with Maven run: mvn verify javadoc:javadoc -e -B -V + + - name: Set up JDK for testing + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + + - name: Test with Maven + run: mvn verify -e -B -V From a51503777ce910ed8cd4e32030a082ab8cde7259 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 10 Jan 2021 13:44:14 +0000 Subject: [PATCH 055/133] Revert "Github CI: Build with JDK 15, test with matrix" This reverts commit cecd035a846940700fbc62c4eb308e3fb2dba19f. --- .github/workflows/maven.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index a44b5ebf..13b4c47e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -43,18 +43,10 @@ jobs: maven-${{ matrix.os }}-java${{ matrix.java }}- maven-${{ matrix.os }}- - - name: Set up JDK for building + - name: Set up JDK uses: actions/setup-java@v1 with: - java-version: 15 + java-version: ${{ matrix.java }} - name: Build with Maven run: mvn verify javadoc:javadoc -e -B -V - - - name: Set up JDK for testing - uses: actions/setup-java@v1 - with: - java-version: ${{ matrix.java }} - - - name: Test with Maven - run: mvn verify -e -B -V From e13989678eb054db978c2c0269ac2d66c7b92ca7 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 10 Jan 2021 14:10:36 +0000 Subject: [PATCH 056/133] Can build on JDKs before SE 10, too --- pom.xml | 91 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index f34b6334..164776b0 100644 --- a/pom.xml +++ b/pom.xml @@ -105,33 +105,8 @@ limitations under the License. compile - 8 - - - - compile-java-9 - - compile - - - 9 - - ${project.basedir}/src/main/java9 - - true - - - - compile-java-10 - - compile - - - 10 - - ${project.basedir}/src/main/java10 - - true + 1.8 + 1.8 @@ -187,4 +162,66 @@ limitations under the License. + + + jdk9+ + + [9,) + + + + + + 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 + + + + + + + + + From d9824e2d8b68f397bec45751d2647d464929cdfa Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sun, 24 Jan 2021 17:34:49 +0000 Subject: [PATCH 057/133] Renamed per @rfsholte's request --- .../plexus/util/{VersionSpecifics.java => BaseIOUtil.java} | 6 +----- src/main/java/org/codehaus/plexus/util/IOUtil.java | 6 +++--- .../plexus/util/{VersionSpecifics.java => BaseIOUtil.java} | 6 +----- .../plexus/util/{VersionSpecifics.java => BaseIOUtil.java} | 6 +----- 4 files changed, 6 insertions(+), 18 deletions(-) rename src/main/java/org/codehaus/plexus/util/{VersionSpecifics.java => BaseIOUtil.java} (87%) rename src/main/java10/org/codehaus/plexus/util/{VersionSpecifics.java => BaseIOUtil.java} (85%) rename src/main/java9/org/codehaus/plexus/util/{VersionSpecifics.java => BaseIOUtil.java} (87%) diff --git a/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java/org/codehaus/plexus/util/BaseIOUtil.java similarity index 87% rename from src/main/java/org/codehaus/plexus/util/VersionSpecifics.java rename to src/main/java/org/codehaus/plexus/util/BaseIOUtil.java index e6be5b08..ac2ade02 100644 --- a/src/main/java/org/codehaus/plexus/util/VersionSpecifics.java +++ b/src/main/java/org/codehaus/plexus/util/BaseIOUtil.java @@ -9,14 +9,10 @@ /** * Implementation specific to Java SE 8 version. */ -final class VersionSpecifics +abstract class BaseIOUtil { private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; - private VersionSpecifics() { - // singleton - } - static void copy( final InputStream input, final OutputStream output ) throws IOException { diff --git a/src/main/java/org/codehaus/plexus/util/IOUtil.java b/src/main/java/org/codehaus/plexus/util/IOUtil.java index ff5002d2..b431a8d9 100644 --- a/src/main/java/org/codehaus/plexus/util/IOUtil.java +++ b/src/main/java/org/codehaus/plexus/util/IOUtil.java @@ -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; @@ -156,7 +156,7 @@ private IOUtil() public static void copy( final InputStream input, final OutputStream output ) throws IOException { - VersionSpecifics.copy( input, output ); + BaseIOUtil.copy( input, output ); } /** @@ -186,7 +186,7 @@ public static void copy( final InputStream input, final OutputStream output, fin public static void copy( final Reader input, final Writer output ) throws IOException { - VersionSpecifics.copy( input, output ); + BaseIOUtil.copy( input, output ); } /** diff --git a/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java similarity index 85% rename from src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java rename to src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java index 06b385e2..fc792be3 100644 --- a/src/main/java10/org/codehaus/plexus/util/VersionSpecifics.java +++ b/src/main/java10/org/codehaus/plexus/util/BaseIOUtil.java @@ -9,12 +9,8 @@ /** * Implementation specific to Java SE 10 version. */ -final class VersionSpecifics +abstract class BaseIOUtil { - private VersionSpecifics() { - // singleton - } - static void copy( final InputStream input, final OutputStream output ) throws IOException { diff --git a/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java b/src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java similarity index 87% rename from src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java rename to src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java index b3c08c64..7e0826c4 100644 --- a/src/main/java9/org/codehaus/plexus/util/VersionSpecifics.java +++ b/src/main/java9/org/codehaus/plexus/util/BaseIOUtil.java @@ -9,14 +9,10 @@ /** * Implementation specific to Java SE 9 version. */ -final class VersionSpecifics +abstract class BaseIOUtil { private static final int DEFAULT_BUFFER_SIZE = 1024 * 16; - private VersionSpecifics() { - // singleton - } - static void copy( final InputStream input, final OutputStream output ) throws IOException { From 8f3c6a0bd003cd3b29b342074f4df3019dac2012 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 4 Apr 2021 10:20:02 +1000 Subject: [PATCH 058/133] Bump actions/cache from v2.1.3 to v2.1.4 (#140) Bumps [actions/cache](https://github.com/actions/cache) from v2.1.3 to v2.1.4. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.3...26968a09c0ea4f3e233fdddbafd1166051a095f6) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 13b4c47e..04bfb604 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2 - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.3 + uses: actions/cache@v2.1.4 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From e02438233beda5e7a1ef243f91c56f303d6f62b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 4 Apr 2021 10:23:29 +1000 Subject: [PATCH 059/133] Bump release-drafter/release-drafter from v5.13.0 to v5.15.0 (#144) Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from v5.13.0 to v5.15.0. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5.13.0...fe52e97d262833ae07d05efaf1a239df3f1b5cd4) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 6b8089f3..4e2af995 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,6 +7,6 @@ jobs: update_release_draft: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5.13.0 + - uses: release-drafter/release-drafter@v5.15.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 96ce1f0c68a7d3f04e2201fa563949faad3d3745 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 4 Apr 2021 10:23:34 +1000 Subject: [PATCH 060/133] Bump jmh-core from 1.27 to 1.29 (#145) Bumps jmh-core from 1.27 to 1.29. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 164776b0..c97ed7bc 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.27 + 1.29 test From 48e444f9d2f692853996ada0f6307cff40179a57 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 4 Apr 2021 10:23:38 +1000 Subject: [PATCH 061/133] Bump jmh-generator-annprocess from 1.27 to 1.29 (#146) Bumps jmh-generator-annprocess from 1.27 to 1.29. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c97ed7bc..6b1ca17e 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.27 + 1.29 test From 1e18ddcc98f318b36449102f3267fd4631cc668b Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sat, 3 Apr 2021 21:25:38 -0300 Subject: [PATCH 062/133] Fix MXParser improve error reporting (#136) (#137) - when parsing large char entities. - when mixing invalid encoding declarations and file encodings. --- .../plexus/util/xml/pull/MXParser.java | 51 +++- ..._BjoernHoehrmannviaHST2013_09_18_Test.java | 278 ++++++++++++++++++ src/test/resources/xmlconf/eduni/misc/001.xml | 4 + src/test/resources/xmlconf/eduni/misc/002.xml | 4 + src/test/resources/xmlconf/eduni/misc/003.xml | 4 + src/test/resources/xmlconf/eduni/misc/004.xml | 4 + src/test/resources/xmlconf/eduni/misc/005.xml | 2 + src/test/resources/xmlconf/eduni/misc/006.xml | 2 + src/test/resources/xmlconf/eduni/misc/007.xml | 1 + src/test/resources/xmlconf/eduni/misc/008.xml | Bin 0 -> 86 bytes src/test/resources/xmlconf/eduni/misc/009.xml | 1 + .../resources/xmlconf/eduni/misc/ht-bh.xml | 37 +++ .../resources/xmlconf/eduni/misc/xmlconf.xml | 19 ++ 13 files changed, 399 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java create mode 100644 src/test/resources/xmlconf/eduni/misc/001.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/002.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/003.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/004.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/005.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/006.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/007.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/008.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/009.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/ht-bh.xml create mode 100644 src/test/resources/xmlconf/eduni/misc/xmlconf.xml 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 430c2236..4ce9bf0c 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,6 +11,7 @@ import java.io.EOFException; import java.io.IOException; +import java.io.InputStreamReader; import java.io.Reader; import java.io.UnsupportedEncodingException; @@ -122,6 +123,8 @@ private String newStringIntern( char[] cbuf, int off, int len ) // private String elValue[]; private int elNamespaceCount[]; + private String fileEncoding = "UTF8"; + /** * Make sure that we have enough space to keep element stack if passed size. It will always create one additional * slot then current depth @@ -659,6 +662,15 @@ public void setInput( Reader in ) { reset(); reader = in; + + if ( reader instanceof InputStreamReader ) + { + InputStreamReader isr = (InputStreamReader) reader; + if ( isr.getEncoding() != null ) + { + fileEncoding = isr.getEncoding().toUpperCase(); + } + } } @Override @@ -1771,6 +1783,17 @@ private 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; @@ -2723,18 +2746,19 @@ else if ( ch >= 'A' && ch <= 'F' ) } posEnd = pos - 1; - int codePoint = Integer.parseInt( sb.toString(), isHex ? 16 : 10 ); - boolean isValidCodePoint = isValidCodePoint( codePoint ); - if ( isValidCodePoint ) + boolean isValidCodePoint = true; + try { - try + int codePoint = Integer.parseInt( sb.toString(), isHex ? 16 : 10 ); + isValidCodePoint = isValidCodePoint( codePoint ); + if ( isValidCodePoint ) { charRefOneCharBuf = Character.toChars( codePoint ); } - catch ( IllegalArgumentException e ) - { - isValidCodePoint = false; - } + } + catch ( IllegalArgumentException e ) + { + isValidCodePoint = false; } if ( !isValidCodePoint ) @@ -3328,6 +3352,17 @@ private 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 ); + } } ch = more(); diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java new file mode 100644 index 00000000..cf1fe16a --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java @@ -0,0 +1,278 @@ +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.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; + +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:
    Bjoern Hoehrmann via HST 2013-09-18
    + * XML test files base folder:
    xmlconf/eduni/misc/
    + * + * @author Gabriel Belingueres + */ +public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test +{ + + final static File testResourcesDir = new File("src/test/resources/", "xmlconf/eduni/misc/"); + + MXParser parser; + + @Before + public void setUp() + { + parser = new MXParser(); + } + + /** + * Test ID:
    hst-bh-001
    + * Test URI:
    001.xml
    + * Comment:
    decimal charref &#62; 10FFFF, indeed &#62; max 32 bit integer, checking for recovery from possible overflow
    + * Sections:
    2.2 [2], 4.1 [66]
    + * Version: + * + * @throws 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 &#62; 10FFFF, indeed &#62; max 32 bit integer, checking for recovery from possible overflow
    + * Sections:
    2.2 [2], 4.1 [66]
    + * Version: + * + * @throws 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 &#62; 10FFFF, indeed &#62; max 64 bit integer, checking for recovery from possible overflow
    + * Sections:
    2.2 [2], 4.1 [66]
    + * Version: + * + * @throws 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 &#62; 10FFFF, indeed &#62; max 64 bit integer, checking for recovery from possible overflow
    + * Sections:
    2.2 [2], 4.1 [66]
    + * Version: + * + * @throws 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 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 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 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 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
    + * Sections:
    4.3.3
    + * Version: + * + * @throws IOException if there is an I/O error + */ + @Test + public void testhst_lhs_009() + throws IOException + { + try ( FileInputStream is = new FileInputStream( new File( testResourcesDir, "009.xml" ) ); + InputStreamReader reader = new InputStreamReader( is, StandardCharsets.UTF_8 ) ) + { + parser.setInput( reader ); + while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + ; + fail( "UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible" ); + } + catch ( XmlPullParserException e ) + { + assertTrue( e.getMessage().contains( "UTF-16 BOM in a UTF-8 encoded file is incompatible" ) ); + } + } + +} \ No newline at end of file diff --git a/src/test/resources/xmlconf/eduni/misc/001.xml b/src/test/resources/xmlconf/eduni/misc/001.xml new file mode 100644 index 00000000..76de9900 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/001.xml @@ -0,0 +1,4 @@ + +]> +

    Fa�il

    diff --git a/src/test/resources/xmlconf/eduni/misc/002.xml b/src/test/resources/xmlconf/eduni/misc/002.xml new file mode 100644 index 00000000..943d284e --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/002.xml @@ -0,0 +1,4 @@ + +]> +

    Fa�il

    diff --git a/src/test/resources/xmlconf/eduni/misc/003.xml b/src/test/resources/xmlconf/eduni/misc/003.xml new file mode 100644 index 00000000..c2fb6990 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/003.xml @@ -0,0 +1,4 @@ + +]> +

    Fa�il

    diff --git a/src/test/resources/xmlconf/eduni/misc/004.xml b/src/test/resources/xmlconf/eduni/misc/004.xml new file mode 100644 index 00000000..1e83a946 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/004.xml @@ -0,0 +1,4 @@ + +]> +

    Fa�il

    diff --git a/src/test/resources/xmlconf/eduni/misc/005.xml b/src/test/resources/xmlconf/eduni/misc/005.xml new file mode 100644 index 00000000..d353623a --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/005.xml @@ -0,0 +1,2 @@ + ]> + diff --git a/src/test/resources/xmlconf/eduni/misc/006.xml b/src/test/resources/xmlconf/eduni/misc/006.xml new file mode 100644 index 00000000..5234f760 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/006.xml @@ -0,0 +1,2 @@ + ]> + diff --git a/src/test/resources/xmlconf/eduni/misc/007.xml b/src/test/resources/xmlconf/eduni/misc/007.xml new file mode 100644 index 00000000..2da5d51b --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/007.xml @@ -0,0 +1 @@ +īģŋ diff --git a/src/test/resources/xmlconf/eduni/misc/008.xml b/src/test/resources/xmlconf/eduni/misc/008.xml new file mode 100644 index 0000000000000000000000000000000000000000..ef5f345f759d0efa78d93c825403d4835ad5c969 GIT binary patch literal 86 zcmW;EI|_h66hqOwlC-`GluLi3?PRR4p5=g8pIBp_42QwQ+M@CIS ZrF0UbS3gLN>DP;sk(@@0fY(=|#DDSe4^998 literal 0 HcmV?d00001 diff --git a/src/test/resources/xmlconf/eduni/misc/009.xml b/src/test/resources/xmlconf/eduni/misc/009.xml new file mode 100644 index 00000000..8c786226 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/009.xml @@ -0,0 +1 @@ +īŋŊīŋŊ diff --git a/src/test/resources/xmlconf/eduni/misc/ht-bh.xml b/src/test/resources/xmlconf/eduni/misc/ht-bh.xml new file mode 100644 index 00000000..bd238312 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/ht-bh.xml @@ -0,0 +1,37 @@ + + + +decimal charref > 10FFFF, indeed > max 32 bit integer, checking for recovery +from possible overflow + + +hex charref > 10FFFF, indeed > max 32 bit integer, checking for recovery +from possible overflow + + +decimal charref > 10FFFF, indeed > max 64 bit integer, checking for recovery +from possible overflow + + +hex charref > 10FFFF, indeed > max 64 bit integer, checking for recovery +from possible overflow + + +xmlns:xml is an attribute as far as validation is concerned and must +be declared + + +xmlns:foo is an attribute as far as validation is concerned and must +be declared + + +UTF-8 BOM plus xml decl of iso-8859-1 incompatible + + +UTF-16 BOM plus xml decl of utf-8 (using UTF-16 coding) incompatible + + +UTF-16 BOM plus xml decl of utf-8 (using UTF-8 coding) incompatible + + + diff --git a/src/test/resources/xmlconf/eduni/misc/xmlconf.xml b/src/test/resources/xmlconf/eduni/misc/xmlconf.xml new file mode 100644 index 00000000..f42f5dc3 --- /dev/null +++ b/src/test/resources/xmlconf/eduni/misc/xmlconf.xml @@ -0,0 +1,19 @@ + + + + +] > + + + &eduni-misc; + + + From b52d0e5839dd75a18d276f30b4ec40632b4aac63 Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Sun, 4 Apr 2021 10:28:38 +1000 Subject: [PATCH 063/133] remove jdk16 build as it is failing Signed-off-by: olivier lamy --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 04bfb604..bb2826dd 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - java: [8, 11, 14, 15, 16-ea] + java: [8, 11, 14, 15] fail-fast: false runs-on: ${{ matrix.os }} From 9d76e46fb9c627b590b0b1356d8f28e31ce801ce Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sun, 4 Apr 2021 21:24:17 -0300 Subject: [PATCH 064/133] Fix MXParser fails to parse xml declaration properly (#138) (#139) - Fix bugs. - Added tests. - Improved error messages. --- .../plexus/util/xml/pull/MXParser.java | 25 ++++++++---- ...onformanceTestSuite_Production32_Test.java | 18 +++++---- .../plexus/util/xml/pull/MXParserTest.java | 40 +++++++++++++++++++ 3 files changed, 68 insertions(+), 15 deletions(-) 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 4ce9bf0c..bc1c3608 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 @@ -3296,6 +3296,8 @@ private 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; @@ -3310,8 +3312,8 @@ private void parseXmlDeclWithVersion( int versionStart, int versionEnd ) { if ( !isS( prevCh ) ) { - throw new XmlPullParserException( "expected a space after version and not " + printable( ch ), this, - null ); + throw new XmlPullParserException( "expected a space after " + lastParsedAttr + " and not " + + printable( ch ), this, null ); } ch = more(); ch = requireInput( ch, NCODING ); @@ -3363,13 +3365,23 @@ else if ("UTF-16".equals( fileEncoding ) && inputEncoding.equalsIgnoreCase( "UTF 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 = more(); - 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 ); @@ -3382,11 +3394,10 @@ else if ("UTF-16".equals( fileEncoding ) && inputEncoding.equalsIgnoreCase( "UTF 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' ) { @@ -3411,9 +3422,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 as last part of as last part of as last part of as last part of as last part of as last part of as last part of "; + + MXParser parser = new MXParser(); + parser.setInput( new StringReader( input ) ); + + try + { + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + } + catch ( Exception e ) + { + fail( "Should not throw Exception" ); + } + } + + @Test + public void testXMLDeclVersionEncodingStandaloneNoSpace() + throws Exception + { + String input = ""; + + MXParser parser = new MXParser(); + parser.setInput( new StringReader( input ) ); + + try + { + parser.nextToken(); + } + catch ( XmlPullParserException e ) + { + assertTrue( e.getMessage().contains( "expected a space after encoding and not s" )); + } + } + } From 6f11ee1256cfe5803d73c45f3f3786535c15d4f5 Mon Sep 17 00:00:00 2001 From: Alix Lourme Date: Mon, 5 Apr 2021 02:25:53 +0200 Subject: [PATCH 065/133] Fix #116 : Java 16 support for ReflectionUtils (and Java 11 no warning) (#123) --- .../org/codehaus/plexus/util/ReflectionUtils.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java b/src/main/java/org/codehaus/plexus/util/ReflectionUtils.java index e83488cc..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 - * */ public final class ReflectionUtils { @@ -126,7 +125,7 @@ public static List getSetters( Class clazz ) /** * @param method the method - * @return the class of the argument to the setter. Will throw an RuntimeException if the method isn't a setter. + * @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 ) { @@ -163,6 +162,7 @@ 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 @@ -218,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 ); From 7aff941b59fd51ba8e98be5c233e4aa709a6ed5c Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sat, 3 Apr 2021 10:48:55 +0200 Subject: [PATCH 066/133] Using JDK 16 GA instead of JDK 16 EA Since JDK 16 is generally available it makes no sense to use an early access build anybody. --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bb2826dd..e804cf58 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - java: [8, 11, 14, 15] + java: [8, 11, 14, 15, 16] fail-fast: false runs-on: ${{ matrix.os }} From 67ca06dc7d772555a99c34f4739f3943107caff4 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Mon, 12 Apr 2021 18:14:03 +0200 Subject: [PATCH 067/133] Remove old JDK versions and add 17-ea --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e804cf58..c1da6c44 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -25,7 +25,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - java: [8, 11, 14, 15, 16] + java: [8, 11, 16, 17-ea] fail-fast: false runs-on: ${{ matrix.os }} From 9ed17bbfa6529bea67a49c342ff98727134a36e8 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 13 Apr 2021 10:45:31 +1000 Subject: [PATCH 068/133] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8406ee41..e79caf97 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Plexus-Utils [![Build Status](https://travis-ci.org/codehaus-plexus/plexus-utils.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-utils) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](http://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` + The current master is now at https://github.com/codehaus-plexus/plexus-utils For publishing [the site](https://codehaus-plexus.github.io/plexus-utils/) do the following: @@ -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 ``` + From d349b5ff851f45a06df01c2be4572e438f197cfa Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 13 Apr 2021 10:46:40 +1000 Subject: [PATCH 069/133] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e79caf97..45d917c6 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Plexus-Utils [![Build Status](https://travis-ci.org/codehaus-plexus/plexus-utils.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-utils) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](http://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` +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 From 2db9aac74a7bba5791bfe337cf4ca5d11bd813c8 Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Mon, 5 Apr 2021 14:45:05 +0000 Subject: [PATCH 070/133] Enforcing JDK 11 on release Enforcing the use of JDK 11 on release guarantees that the published Multi-Release JAR contains ALL code versions: JDK 8 (default fallback), JDK 9 (enhanced NIO) and JDK 10 (even further enhanced NIO). Without this enforcement, there would be a risk of not having some of these versions packed into the MRJAR due to the way the POM checks for the existence of supported JDK levels using JDK-enabled profiles. --- pom.xml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pom.xml b/pom.xml index 6b1ca17e..20a0b0e9 100644 --- a/pom.xml +++ b/pom.xml @@ -223,5 +223,30 @@ limitations under the License. + + plexus-release + + + + maven-enforcer-plugin + + + enforce-java + + enforce + + + + + 11 + + + + + + + + + From a2efde329a88804235e18a97fd0941e3b2e59f36 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 13 Apr 2021 05:40:33 +0000 Subject: [PATCH 071/133] Bump actions/cache from v2.1.4 to v2.1.5 Bumps [actions/cache](https://github.com/actions/cache) from v2.1.4 to v2.1.5. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.4...1a9e2138d905efd099035b49d8b7a3888c653ca8) Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c1da6c44..9015bea7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2 - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.4 + uses: actions/cache@v2.1.5 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From 8210833bbc8d1b1db94aa237d1385a4eb722ccee Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 18 Apr 2021 10:14:57 +0200 Subject: [PATCH 072/133] Update CI config - Travis CI - remove Java 7 - update build badge to GitHub Actions --- .travis.yml | 3 +-- README.md | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9bcfb349..3cafdcfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,9 @@ addons: language: java jdk: - - openjdk7 - openjdk8 - openjdk11 -# - openjdk12 add once code is requires Java 7 + - openjdk16 dist: trusty diff --git a/README.md b/README.md index 45d917c6..ddd8214b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Plexus-Utils ============ -[![Build Status](https://travis-ci.org/codehaus-plexus/plexus-utils.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-utils) +[![Build Status](https://github.com/codehaus-plexus/plexus-utils/actions/workflows/maven.yml/badge.svg)](https://github.com/codehaus-plexus/plexus-utils/actions) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](http://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) From 2849147617705e4662ecfbf8e29718c27300d738 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 18 Apr 2021 10:23:22 +0200 Subject: [PATCH 073/133] Create codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..f6ec7c49 --- /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@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + 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@v1 + + # â„šī¸ 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@v1 From 17ed658995ab01a5439800223bb85881719b641d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 29 Jul 2021 19:55:12 +0200 Subject: [PATCH 074/133] upgrade parent pom from 7 to 8 --- pom.xml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 20a0b0e9..0195563b 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ limitations under the License. org.codehaus.plexus plexus - 7 + 8 plexus-utils @@ -73,6 +73,12 @@ limitations under the License. 1.29 test
    + + junit + junit + 4.13.1 + test + @@ -88,11 +94,6 @@ limitations under the License. --> 2.7 - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 - From 7d26d046d7ec167788aea58635d4333f30519e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 29 Jul 2021 20:02:31 +0200 Subject: [PATCH 075/133] fix javadoc issues --- .../plexus/util/AbstractTestThread.java | 47 ++- .../plexus/util/CollectionUtilsTest.java | 22 ++ .../plexus/util/DirectoryScannerTest.java | 77 ++++- .../plexus/util/DirectoryWalkerTest.java | 10 + .../plexus/util/FileBasedTestCase.java | 85 +++++- .../codehaus/plexus/util/FileUtilsTest.java | 286 +++++++++++++++++- .../org/codehaus/plexus/util/IOUtilTest.java | 93 ++++++ .../util/InterpolationFilterReaderTest.java | 62 ++++ .../LineOrientedInterpolatingReaderTest.java | 41 ++- .../plexus/util/MatchPatternTest.java | 11 + .../plexus/util/MatchPatternsTest.java | 12 + .../java/org/codehaus/plexus/util/OsTest.java | 13 + .../codehaus/plexus/util/PathToolTest.java | 25 +- .../org/codehaus/plexus/util/PerfTest.java | 13 + .../plexus/util/ReflectionUtilsTest.java | 21 ++ .../plexus/util/SelectorUtilsTest.java | 16 + .../plexus/util/StringInputStreamTest.java | 8 +- .../codehaus/plexus/util/StringUtilsTest.java | 70 ++++- .../codehaus/plexus/util/SweeperPoolTest.java | 16 +- .../plexus/util/TestThreadManager.java | 41 ++- .../java/org/codehaus/plexus/util/Tracer.java | 6 +- .../codehaus/plexus/util/WalkCollector.java | 11 +- .../plexus/util/cli/CommandLineUtilsTest.java | 16 + .../plexus/util/cli/CommandlineTest.java | 94 +++++- .../plexus/util/cli/DefaultConsumerTest.java | 14 +- .../util/cli/EnhancedStringTokenizerTest.java | 25 ++ .../plexus/util/cli/StreamPumperTest.java | 19 ++ .../util/cli/shell/BourneShellTest.java | 38 +++ .../util/dag/CycleDetectedExceptionTest.java | 8 +- .../plexus/util/dag/CycleDetectorTest.java | 8 +- .../org/codehaus/plexus/util/dag/DAGTest.java | 15 +- .../util/dag/TopologicalSorterTest.java | 10 +- .../codehaus/plexus/util/dag/VertexTest.java | 8 +- .../ReflectionValueExtractorTest.java | 85 +++++- .../plexus/util/reflection/ReflectorTest.java | 25 +- .../util/xml/PrettyPrintXMLWriterTest.java | 30 +- .../plexus/util/xml/XmlStreamReaderTest.java | 72 +++++ .../plexus/util/xml/XmlStreamWriterTest.java | 67 ++++ .../codehaus/plexus/util/xml/XmlUtilTest.java | 30 +- .../plexus/util/xml/XmlWriterUtilTest.java | 47 +-- .../plexus/util/xml/Xpp3DomBuilderTest.java | 36 ++- .../plexus/util/xml/Xpp3DomPerfTest.java | 24 ++ .../codehaus/plexus/util/xml/Xpp3DomTest.java | 72 +++++ .../plexus/util/xml/Xpp3DomUtilsTest.java | 17 ++ .../plexus/util/xml/Xpp3DomWriterTest.java | 10 + ...onformanceTestSuite_Production24_Test.java | 39 +-- ...ConformanceTestSuite_Production2_Test.java | 71 +++-- ...onformanceTestSuite_Production32_Test.java | 23 +- ...onformanceTestSuite_Production66_Test.java | 37 ++- ...onformanceTestSuite_Production80_Test.java | 17 +- .../util/xml/pull/MXParserPerfTest.java | 21 ++ .../plexus/util/xml/pull/MXParserTest.java | 141 ++++++++- ..._BjoernHoehrmannviaHST2013_09_18_Test.java | 25 +- 53 files changed, 1958 insertions(+), 172 deletions(-) diff --git a/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java b/src/test/java/org/codehaus/plexus/util/AbstractTestThread.java index 45c7329d..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 $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(); } + /** + *

    Constructor for AbstractTestThread.

    + * + * @param registry a {@link org.codehaus.plexus.util.TestThreadManager} object. + */ public AbstractTestThread( TestThreadManager registry ) { super(); @@ -77,7 +84,9 @@ public AbstractTestThread( TestThreadManager registry ) // ~ Methods ------------------------------------------------------------------------------------ /** - * @return + *

    Getter for the field error.

    + * + * @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 + *

    Setter for the field error.

    + * + * @param throwable a {@link java.lang.Throwable} object. */ public void setError( Throwable throwable ) { @@ -224,7 +239,9 @@ public void setError( Throwable throwable ) } /** - * @param string + *

    Setter for the field errorMsg.

    + * + * @param string a {@link java.lang.String} object. */ public void setErrorMsg( String string ) { @@ -232,7 +249,9 @@ public void setErrorMsg( String string ) } /** - * @param b + *

    Setter for the field passed.

    + * + * @param b a boolean. */ public void setPassed( boolean b ) { @@ -240,7 +259,9 @@ public void setPassed( boolean b ) } /** - * @return + *

    Getter for the field name.

    + * + * @return a {@link java.lang.String} object. */ public String getName() { @@ -248,7 +269,9 @@ public String getName() } /** - * @param string + *

    Setter for the field name.

    + * + * @param string a {@link java.lang.String} object. */ public void setName( String string ) { diff --git a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java index 225c1bb0..70add088 100644 --- a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java @@ -28,8 +28,18 @@ import org.junit.Test; +/** + *

    CollectionUtilsTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class CollectionUtilsTest { + /** + *

    testMergeMaps.

    + */ @Test public void testMergeMaps() { @@ -66,6 +76,9 @@ public void testMergeMaps() assertEquals( "z", result.get( "z" ) ); } + /** + *

    testMergeMapArray.

    + */ @SuppressWarnings( "unchecked" ) @Test public void testMergeMapArray() @@ -119,6 +132,9 @@ public void testMergeMapArray() assertEquals( "ccc", result5.get( "c" ) ); } + /** + *

    testMavenPropertiesLoading.

    + */ @Test public void testMavenPropertiesLoading() { @@ -176,6 +192,9 @@ public void testMavenPropertiesLoading() assertEquals( mavenRepoRemote, (String) result.get( "maven.repo.remote" ) ); } + /** + *

    testIteratorToListWithAPopulatedList.

    + */ @Test public void testIteratorToListWithAPopulatedList() { @@ -196,6 +215,9 @@ public void testIteratorToListWithAPopulatedList() assertEquals( "tre", copy.get( 2 ) ); } + /** + *

    testIteratorToListWithAEmptyList.

    + */ @Test public void testIteratorToListWithAEmptyList() { diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java index 90fe70e6..86c6dd20 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -42,8 +42,10 @@ /** * Base class for testcases doing tests with files. - * + * * @author Dan T. Tran + * @version $Id: $Id + * @since 3.4.0 */ public class DirectoryScannerTest extends FileBasedTestCase @@ -53,6 +55,9 @@ public class DirectoryScannerTest private static String testDir = getTestDirectory().getPath(); + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -66,6 +71,12 @@ public void setUp() } } + /** + *

    testCrossPlatformIncludesString.

    + * + * @throws java.io.IOException if any. + * @throws java.net.URISyntaxException if any. + */ @Test public void testCrossPlatformIncludesString() throws IOException, URISyntaxException @@ -91,6 +102,12 @@ public void testCrossPlatformIncludesString() assertEquals( 1, files.length ); } + /** + *

    testCrossPlatformExcludesString.

    + * + * @throws java.io.IOException if any. + * @throws java.net.URISyntaxException if any. + */ @Test public void testCrossPlatformExcludesString() throws IOException, URISyntaxException @@ -184,6 +201,11 @@ private boolean checkTestFilesSymlinks() } } + /** + *

    testGeneral.

    + * + * @throws java.io.IOException if any. + */ @Test public void testGeneral() throws IOException @@ -202,6 +224,11 @@ public void testGeneral() } + /** + *

    testIncludesExcludesWithWhiteSpaces.

    + * + * @throws java.io.IOException if any. + */ @Test public void testIncludesExcludesWithWhiteSpaces() throws IOException @@ -220,6 +247,9 @@ public void testIncludesExcludesWithWhiteSpaces() assertTrue( "5 not found.", fileNames.contains( new File( "scanner5.dat" ) ) ); } + /** + *

    testFollowSymlinksFalse.

    + */ @Test public void testFollowSymlinksFalse() { @@ -254,6 +284,9 @@ private void assertAlwaysIncluded( List included ) assertTrue( included.contains( "symLinkToFileOnTheOutside" ) ); } + /** + *

    testFollowSymlinks.

    + */ @Test public void testFollowSymlinks() { @@ -293,6 +326,11 @@ private void createTestDirectories() + File.separator + "file1.dat" ), 0 ); } + /** + *

    testDirectoriesWithHyphens.

    + * + * @throws java.io.IOException if any. + */ @Test public void testDirectoriesWithHyphens() throws IOException @@ -312,6 +350,11 @@ public void testDirectoriesWithHyphens() assertEquals( "Wrong number of results.", 3, files.length ); } + /** + *

    testAntExcludesOverrideIncludes.

    + * + * @throws java.io.IOException if any. + */ @Test public void testAntExcludesOverrideIncludes() throws IOException @@ -347,6 +390,11 @@ public void testAntExcludesOverrideIncludes() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + /** + *

    testAntExcludesOverrideIncludesWithExplicitAntPrefix.

    + * + * @throws java.io.IOException if any. + */ @Test public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException @@ -383,6 +431,11 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + /** + *

    testRegexIncludeWithExcludedPrefixDirs.

    + * + * @throws java.io.IOException if any. + */ @Test public void testRegexIncludeWithExcludedPrefixDirs() throws IOException @@ -414,6 +467,11 @@ public void testRegexIncludeWithExcludedPrefixDirs() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + /** + *

    testRegexExcludeWithNegativeLookahead.

    + * + * @throws java.io.IOException if any. + */ @Test public void testRegexExcludeWithNegativeLookahead() throws IOException @@ -453,6 +511,11 @@ public void testRegexExcludeWithNegativeLookahead() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + /** + *

    testRegexWithSlashInsideCharacterClass.

    + * + * @throws java.io.IOException if any. + */ @Test public void testRegexWithSlashInsideCharacterClass() throws IOException @@ -497,7 +560,7 @@ public void testRegexWithSlashInsideCharacterClass() * Test that the directory scanning does not enter into not matching directories. * * @see Issue #63 - * @throws IOException if occurs an I/O error. + * @throws java.io.IOException if occurs an I/O error. */ @Test public void testDoNotScanUnnecesaryDirectories() @@ -562,6 +625,11 @@ protected void scandir( File dir, String vpath, boolean fast ) assertEquals( expectedScannedDirSet, scannedDirSet ); } + /** + *

    testIsSymbolicLink.

    + * + * @throws java.io.IOException if any. + */ @Test public void testIsSymbolicLink() throws IOException @@ -576,6 +644,11 @@ public void testIsSymbolicLink() assertFalse( ds.isSymbolicLink( directory, "aRegularDir" ) ); } + /** + *

    testIsParentSymbolicLink.

    + * + * @throws java.io.IOException if any. + */ @Test public void testIsParentSymbolicLink() throws IOException diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java index 5ccdb9bc..757ce718 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java @@ -24,8 +24,18 @@ import org.junit.Test; +/** + *

    DirectoryWalkerTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class DirectoryWalkerTest { + /** + *

    testDirectoryWalk.

    + */ @Test public void testDirectoryWalk() { diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index 33b1654d..3e111b4e 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -36,11 +36,18 @@ * Base class for testcases doing tests with files. * * @author Jeremias Maerki + * @version $Id: $Id + * @since 3.4.0 */ public abstract class FileBasedTestCase { private static File testDir; + /** + *

    getTestDirectory.

    + * + * @return a {@link java.io.File} object. + */ public static File getTestDirectory() { if ( testDir == null ) @@ -50,6 +57,14 @@ public static File getTestDirectory() return testDir; } + /** + *

    createFile.

    + * + * @param file a {@link java.io.File} object. + * @param size a long. + * @return an array of {@link byte} objects. + * @throws java.io.IOException if any. + */ protected byte[] createFile( final File file, final long size ) throws IOException { @@ -74,6 +89,13 @@ protected byte[] createFile( final File file, final long size ) } } + /** + *

    createSymlink.

    + * + * @param link a {@link java.io.File} object. + * @param target a {@link java.io.File} object. + * @return a boolean. + */ protected boolean createSymlink( final File link, final File target ) { try @@ -94,6 +116,12 @@ protected boolean createSymlink( final File link, final File target ) return true; } + /** + *

    generateTestData.

    + * + * @param size a long. + * @return an array of {@link byte} objects. + */ protected byte[] generateTestData( final long size ) { try @@ -108,6 +136,13 @@ protected byte[] generateTestData( final long size ) } } + /** + *

    generateTestData.

    + * + * @param out a {@link java.io.OutputStream} object. + * @param size a long. + * @throws java.io.IOException if any. + */ protected void generateTestData( final OutputStream out, final long size ) throws IOException { @@ -120,6 +155,13 @@ protected void generateTestData( final OutputStream out, final long size ) } } + /** + *

    newFile.

    + * + * @param filename a {@link java.lang.String} object. + * @return a {@link java.io.File} object. + * @throws java.io.IOException if any. + */ protected File newFile( String filename ) throws IOException { @@ -134,6 +176,13 @@ protected File newFile( String filename ) return destination; } + /** + *

    checkFile.

    + * + * @param file a {@link java.io.File} object. + * @param referenceFile a {@link java.io.File} object. + * @throws java.lang.Exception if any. + */ protected void checkFile( final File file, final File referenceFile ) throws Exception { @@ -141,6 +190,12 @@ protected void checkFile( final File file, final File referenceFile ) assertEqualContent( referenceFile, file ); } + /** + *

    checkWrite.

    + * + * @param output a {@link java.io.OutputStream} object. + * @throws java.lang.Exception if any. + */ protected void checkWrite( final OutputStream output ) throws Exception { @@ -155,6 +210,12 @@ protected void checkWrite( final OutputStream output ) } } + /** + *

    checkWrite.

    + * + * @param output a {@link java.io.Writer} object. + * @throws java.lang.Exception if any. + */ protected void checkWrite( final Writer output ) throws Exception { @@ -169,6 +230,12 @@ protected void checkWrite( final Writer output ) } } + /** + *

    deleteFile.

    + * + * @param file a {@link java.io.File} object. + * @throws java.lang.Exception if any. + */ protected void deleteFile( final File file ) throws Exception { @@ -224,7 +291,13 @@ 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 { @@ -244,6 +317,11 @@ protected void assertEqualContent( final byte[] b0, final File file ) } } + /** + *

    assertIsDirectory.

    + * + * @param file a {@link java.io.File} object. + */ protected void assertIsDirectory( File file ) { assertTrue( "The File doesn't exists: " + file.getAbsolutePath(), file.exists() ); @@ -251,6 +329,11 @@ protected void assertIsDirectory( File file ) assertTrue( "The File isn't a directory: " + file.getAbsolutePath(), file.isDirectory() ); } + /** + *

    assertIsFile.

    + * + * @param file a {@link java.io.File} object. + */ protected void assertIsFile( File file ) { assertTrue( "The File doesn't exists: " + file.getAbsolutePath(), file.exists() ); diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index cb14f724..4e9093d0 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -45,8 +45,9 @@ * * @author Peter Donald * @author Matthew Hawthorne - * * @see FileUtils + * @version $Id: $Id + * @since 3.4.0 */ public final class FileUtilsTest extends FileBasedTestCase @@ -69,6 +70,11 @@ public final class FileUtilsTest private static int testFile2Size; + /** + *

    Constructor for FileUtilsTest.

    + * + * @throws java.lang.Exception if any. + */ public FileUtilsTest() throws Exception { @@ -79,6 +85,11 @@ public FileUtilsTest() testFile2Size = (int) testFile2.length(); } + /** + *

    setUp.

    + * + * @throws java.lang.Exception if any. + */ @Before public void setUp() throws Exception @@ -94,6 +105,9 @@ public void setUp() // byteCountToDisplaySize + /** + *

    testByteCountToDisplaySize.

    + */ @Test public void testByteCountToDisplaySize() { @@ -105,6 +119,9 @@ public void testByteCountToDisplaySize() // waitFor + /** + *

    testWaitFor.

    + */ @Test public void testWaitFor() { @@ -113,6 +130,11 @@ public void testWaitFor() FileUtils.waitFor( "", 2 ); } + /** + *

    testToFile.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testToFile() throws Exception @@ -123,6 +145,11 @@ public void testToFile() assertEquals( "name #%20?{}[]<>.txt", file.getName() ); } + /** + *

    testToFileBadProtocol.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testToFileBadProtocol() throws Exception @@ -132,6 +159,11 @@ public void testToFileBadProtocol() assertNull( file ); } + /** + *

    testToFileNull.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testToFileNull() throws Exception @@ -141,6 +173,11 @@ public void testToFileNull() } // Hacked to sanity by Trygve + /** + *

    testToURLs.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testToURLs() throws Exception @@ -158,6 +195,9 @@ public void testToURLs() } } + /** + *

    testGetFilesFromExtension.

    + */ @Test public void testGetFilesFromExtension() { @@ -179,6 +219,9 @@ public void testGetFilesFromExtension() // mkdir + /** + *

    testMkdir.

    + */ @Test public void testMkdir() { @@ -204,6 +247,11 @@ public void testMkdir() // contentEquals + /** + *

    testContentEquals.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testContentEquals() throws Exception @@ -234,6 +282,9 @@ public void testContentEquals() // removePath + /** + *

    testRemovePath.

    + */ @Test public void testRemovePath() { @@ -244,6 +295,9 @@ public void testRemovePath() // getPath + /** + *

    testGetPath.

    + */ @Test public void testGetPath() { @@ -254,6 +308,11 @@ public void testGetPath() // copyURLToFile + /** + *

    testCopyURLToFile.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyURLToFile() throws Exception @@ -281,6 +340,9 @@ public void testCopyURLToFile() // catPath + /** + *

    testCatPath.

    + */ @Test public void testCatPath() { @@ -294,6 +356,11 @@ public void testCatPath() // forceMkdir + /** + *

    testForceMkdir.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testForceMkdir() throws Exception @@ -341,6 +408,11 @@ public void testForceMkdir() // sizeOfDirectory + /** + *

    testSizeOfDirectory.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testSizeOfDirectory() throws Exception @@ -382,11 +454,19 @@ public void testSizeOfDirectory() // TODO Finish test + /** + *

    XtestIsFileNewer.

    + */ public void XtestIsFileNewer() { } // copyFile + /** + *

    testCopyFile1.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyFile1() throws Exception @@ -397,6 +477,11 @@ public void testCopyFile1() assertTrue( "Check Full copy", destination.length() == testFile1Size ); } + /** + *

    testCopyFile2.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyFile2() throws Exception @@ -410,7 +495,7 @@ public void testCopyFile2() /** * ensure we create directory tree for destination * - * @throws Exception + * @throws java.lang.Exception */ @Test public void testCopyFile3() @@ -428,6 +513,11 @@ public void testCopyFile3() } // linkFile + /** + *

    testLinkFile1.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testLinkFile1() throws Exception @@ -439,6 +529,11 @@ public void testLinkFile1() assertTrue( "Check is link", Files.isSymbolicLink(destination.toPath())); } + /** + *

    testLinkFile2.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testLinkFile2() throws Exception @@ -453,7 +548,7 @@ public void testLinkFile2() /** * ensure we create directory tree for destination * - * @throws Exception + * @throws java.lang.Exception */ @Test public void testLinkFile3() @@ -473,6 +568,11 @@ public void testLinkFile3() // copyFileIfModified + /** + *

    testCopyIfModifiedWhenSourceIsNewer.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyIfModifiedWhenSourceIsNewer() throws Exception @@ -496,6 +596,11 @@ public void testCopyIfModifiedWhenSourceIsNewer() FileUtils.copyFileIfModified( source, destination ) ); } + /** + *

    testCopyIfModifiedWhenSourceIsOlder.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyIfModifiedWhenSourceIsOlder() throws Exception @@ -517,6 +622,11 @@ public void testCopyIfModifiedWhenSourceIsOlder() assertFalse( "Source file should not have been copied.", FileUtils.copyFileIfModified( source, destination ) ); } + /** + *

    testCopyIfModifiedWhenSourceHasZeroDate.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception @@ -537,6 +647,11 @@ public void testCopyIfModifiedWhenSourceHasZeroDate() // forceDelete + /** + *

    testForceDeleteAFile1.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testForceDeleteAFile1() throws Exception @@ -548,6 +663,11 @@ public void testForceDeleteAFile1() assertTrue( "Check No Exist", !destination.exists() ); } + /** + *

    testForceDeleteAFile2.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testForceDeleteAFile2() throws Exception @@ -561,6 +681,11 @@ public void testForceDeleteAFile2() // copyFileToDirectory + /** + *

    testCopyFile1ToDir.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyFile1ToDir() throws Exception @@ -576,6 +701,11 @@ public void testCopyFile1ToDir() assertTrue( "Check Full copy", destination.length() == testFile1Size ); } + /** + *

    testCopyFile2ToDir.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyFile2ToDir() throws Exception @@ -593,6 +723,11 @@ public void testCopyFile2ToDir() // copyFileToDirectoryIfModified + /** + *

    testCopyFile1ToDirIfModified.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyFile1ToDirIfModified() throws Exception @@ -619,6 +754,11 @@ public void testCopyFile1ToDirIfModified() assertTrue( "Timestamp was changed", timestamp == target.lastModified() ); } + /** + *

    testCopyFile2ToDirIfModified.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyFile2ToDirIfModified() throws Exception @@ -647,6 +787,11 @@ public void testCopyFile2ToDirIfModified() // forceDelete + /** + *

    testForceDeleteDir.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testForceDeleteDir() throws Exception @@ -657,6 +802,11 @@ public void testForceDeleteDir() // resolveFile + /** + *

    testResolveFileDotDot.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testResolveFileDotDot() throws Exception @@ -665,6 +815,11 @@ public void testResolveFileDotDot() assertEquals( "Check .. operator", file, getTestDirectory().getParentFile() ); } + /** + *

    testResolveFileDot.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testResolveFileDot() throws Exception @@ -675,6 +830,11 @@ public void testResolveFileDot() // normalize + /** + *

    testNormalize.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testNormalize() throws Exception @@ -712,6 +872,8 @@ private String replaceAll( String text, String lookFor, String replaceWith ) /** * Test the FileUtils implementation. + * + * @throws java.lang.Exception if any. */ // Used to exist as IOTestCase class @Test @@ -752,6 +914,9 @@ public void testFileUtils() } + /** + *

    testGetExtension.

    + */ @Test public void testGetExtension() { @@ -766,6 +931,9 @@ public void testGetExtension() } } + /** + *

    testGetExtensionWithPaths.

    + */ @Test public void testGetExtensionWithPaths() { @@ -786,6 +954,9 @@ public void testGetExtensionWithPaths() } } + /** + *

    testRemoveExtension.

    + */ @Test public void testRemoveExtension() { @@ -800,6 +971,9 @@ public void testRemoveExtension() } /* TODO: Reenable this test */ + /** + *

    testRemoveExtensionWithPaths.

    + */ @Test public void testRemoveExtensionWithPaths() { @@ -825,6 +999,11 @@ public void testRemoveExtensionWithPaths() } } + /** + *

    testCopyDirectoryStructureWithAEmptyDirectoryStructure.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception @@ -842,6 +1021,11 @@ public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() FileUtils.copyDirectoryStructure( from, to ); } + /** + *

    testCopyDirectoryStructureWithAPopulatedStructure.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyDirectoryStructureWithAPopulatedStructure() throws Exception @@ -902,6 +1086,11 @@ public void testCopyDirectoryStructureWithAPopulatedStructure() checkFile( f2_1, new File( to, "2/2_1/2_1.txt" ) ); } + /** + *

    testCopyDirectoryStructureIfModified.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyDirectoryStructureIfModified() throws Exception @@ -982,6 +1171,11 @@ public void testCopyDirectoryStructureIfModified() } + /** + *

    testCopyDirectoryStructureToSelf.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCopyDirectoryStructureToSelf() throws Exception @@ -1024,6 +1218,11 @@ public void testCopyDirectoryStructureToSelf() } } + /** + *

    testFilteredFileCopy.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testFilteredFileCopy() throws Exception @@ -1056,6 +1255,11 @@ public Reader getReader( Reader reader ) compareFile.delete(); } + /** + *

    testFilteredWithoutFilterAndOlderFile.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testFilteredWithoutFilterAndOlderFile() throws Exception @@ -1086,6 +1290,11 @@ public void testFilteredWithoutFilterAndOlderFile() } + /** + *

    testFilteredWithoutFilterAndOlderFileAndOverwrite.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception @@ -1116,6 +1325,11 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite() } + /** + *

    testFileRead.

    + * + * @throws java.io.IOException if any. + */ @Test public void testFileRead() throws IOException @@ -1145,6 +1359,11 @@ public void testFileRead() testFile.delete(); } + /** + *

    testFileReadWithEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testFileReadWithEncoding() throws IOException @@ -1170,6 +1389,11 @@ public void testFileReadWithEncoding() testFile.delete(); } + /** + *

    testFileAppend.

    + * + * @throws java.io.IOException if any. + */ @Test public void testFileAppend() throws IOException @@ -1195,6 +1419,11 @@ public void testFileAppend() testFile.delete(); } + /** + *

    testFileAppendWithEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testFileAppendWithEncoding() throws IOException @@ -1221,6 +1450,11 @@ public void testFileAppendWithEncoding() testFile.delete(); } + /** + *

    testFileWrite.

    + * + * @throws java.io.IOException if any. + */ @Test public void testFileWrite() throws IOException @@ -1234,6 +1468,11 @@ public void testFileWrite() testFile.delete(); } + /** + *

    testFileWriteWithEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testFileWriteWithEncoding() throws IOException @@ -1251,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 @@ -1294,6 +1533,11 @@ public void testDeleteLongPathOnWindows() } // Test for bug PLXUTILS-10 + /** + *

    testCopyFileOnSameFile.

    + * + * @throws java.io.IOException if any. + */ @Test public void testCopyFileOnSameFile() throws IOException @@ -1311,6 +1555,11 @@ public void testCopyFileOnSameFile() assertTrue( theFile.length() > 0 ); } + /** + *

    testExtensions.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testExtensions() throws Exception @@ -1331,6 +1580,11 @@ public void testExtensions() } } + /** + *

    testIsValidWindowsFileName.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testIsValidWindowsFileName() throws Exception @@ -1357,6 +1611,11 @@ public void testIsValidWindowsFileName() } } + /** + *

    testDeleteDirectoryWithValidFileSymlink.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDeleteDirectoryWithValidFileSymlink() throws Exception @@ -1379,6 +1638,11 @@ public void testDeleteDirectoryWithValidFileSymlink() assertTrue( "Failed to delete test directory", !getTestDirectory().exists() ); } + /** + *

    testDeleteDirectoryWithValidDirSymlink.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDeleteDirectoryWithValidDirSymlink() throws Exception @@ -1401,6 +1665,11 @@ public void testDeleteDirectoryWithValidDirSymlink() assertTrue( "Failed to delete test directory", !getTestDirectory().exists() ); } + /** + *

    testDeleteDirectoryWithDanglingSymlink.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDeleteDirectoryWithDanglingSymlink() throws Exception @@ -1422,6 +1691,11 @@ public void testDeleteDirectoryWithDanglingSymlink() assertTrue( "Failed to delete test directory", !getTestDirectory().exists() ); } + /** + *

    testcopyDirectoryLayoutWithExcludesIncludes.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception @@ -1460,9 +1734,9 @@ public void testcopyDirectoryLayoutWithExcludesIncludes() } /** - * Be sure that {@link FileUtils#createTempFile(String, String, File)} is always unique. + * Be sure that {@link org.codehaus.plexus.util.FileUtils#createTempFile(String, String, File)} is always unique. * - * @throws Exception if any + * @throws java.lang.Exception if any */ @Test public void testCreateTempFile() diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index 40f2846c..4179a20e 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -47,6 +47,8 @@ * Due to interdependencies in IOUtils and IOUtilsTestlet, one bug may cause multiple tests to fail. * * @author Jeff Turner + * @version $Id: $Id + * @since 3.4.0 */ public final class IOUtilTest { @@ -62,6 +64,9 @@ public final class IOUtilTest private File testFile; + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -83,6 +88,9 @@ public void setUp() } } + /** + *

    tearDown.

    + */ public void tearDown() { testFile.delete(); @@ -152,6 +160,11 @@ private void assertEqualContent( byte[] b0, File file ) is.close(); } + /** + *

    testInputStreamToOutputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInputStreamToOutputStream() throws Exception @@ -171,6 +184,11 @@ public void testInputStreamToOutputStream() deleteFile( destination ); } + /** + *

    testInputStreamToWriter.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInputStreamToWriter() throws Exception @@ -191,6 +209,11 @@ public void testInputStreamToWriter() deleteFile( destination ); } + /** + *

    testInputStreamToString.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInputStreamToString() throws Exception @@ -203,6 +226,11 @@ public void testInputStreamToString() fin.close(); } + /** + *

    testReaderToOutputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testReaderToOutputStream() throws Exception @@ -225,6 +253,11 @@ public void testReaderToOutputStream() deleteFile( destination ); } + /** + *

    testReaderToWriter.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testReaderToWriter() throws Exception @@ -242,6 +275,11 @@ public void testReaderToWriter() deleteFile( destination ); } + /** + *

    testReaderToString.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testReaderToString() throws Exception @@ -253,6 +291,11 @@ public void testReaderToString() fin.close(); } + /** + *

    testStringToOutputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testStringToOutputStream() throws Exception @@ -277,6 +320,11 @@ public void testStringToOutputStream() deleteFile( destination ); } + /** + *

    testStringToWriter.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testStringToWriter() throws Exception @@ -297,6 +345,11 @@ public void testStringToWriter() deleteFile( destination ); } + /** + *

    testInputStreamToByteArray.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInputStreamToByteArray() throws Exception @@ -310,6 +363,11 @@ public void testInputStreamToByteArray() fin.close(); } + /** + *

    testStringToByteArray.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testStringToByteArray() throws Exception @@ -324,6 +382,11 @@ public void testStringToByteArray() fin.close(); } + /** + *

    testByteArrayToWriter.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testByteArrayToWriter() throws Exception @@ -343,6 +406,11 @@ public void testByteArrayToWriter() deleteFile( destination ); } + /** + *

    testByteArrayToString.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testByteArrayToString() throws Exception @@ -355,6 +423,11 @@ public void testByteArrayToString() fin.close(); } + /** + *

    testByteArrayToOutputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testByteArrayToOutputStream() throws Exception @@ -381,6 +454,11 @@ public void testByteArrayToOutputStream() // Test closeXXX() // ---------------------------------------------------------------------- + /** + *

    testCloseInputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCloseInputStream() throws Exception @@ -394,6 +472,11 @@ public void testCloseInputStream() assertTrue( inputStream.closed ); } + /** + *

    testCloseOutputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCloseOutputStream() throws Exception @@ -407,6 +490,11 @@ public void testCloseOutputStream() assertTrue( outputStream.closed ); } + /** + *

    testCloseReader.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCloseReader() throws Exception @@ -420,6 +508,11 @@ public void testCloseReader() assertTrue( reader.closed ); } + /** + *

    testCloseWriter.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCloseWriter() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java index f68eb400..1d190b4d 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -24,12 +24,24 @@ import org.junit.Test; +/** + *

    InterpolationFilterReaderTest class.

    + * + * @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. */ + /** + *

    testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception @@ -45,6 +57,11 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() /* * kenneyw@14-04-2005 Added test to check above fix. */ + /** + *

    testShouldNotInterpolateExpressionWithMissingEndToken.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception @@ -57,6 +74,11 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() assertEquals( "This is a ${test, really", interpolate( testStr, m ) ); } + /** + *

    testShouldNotInterpolateWithMalformedStartToken.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldNotInterpolateWithMalformedStartToken() throws Exception @@ -69,6 +91,11 @@ public void testShouldNotInterpolateWithMalformedStartToken() assertEquals( "This is a $!test} again", interpolate( foo, m ) ); } + /** + *

    testShouldNotInterpolateWithMalformedEndToken.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldNotInterpolateWithMalformedEndToken() throws Exception @@ -81,6 +108,11 @@ public void testShouldNotInterpolateWithMalformedEndToken() assertEquals( "This is a ${test!} again", interpolate( foo, m, "${", "$}" ) ); } + /** + *

    testInterpolationWithMulticharDelimiters.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithMulticharDelimiters() throws Exception @@ -93,6 +125,11 @@ public void testInterpolationWithMulticharDelimiters() assertEquals( "This is a testValue again", interpolate( foo, m, "${", "$}" ) ); } + /** + *

    testDefaultInterpolationWithNonInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception @@ -106,6 +143,11 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) ); } + /** + *

    testDefaultInterpolationWithInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception @@ -119,6 +161,11 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() assertEquals( "jason is an asshole", interpolate( foo, m ) ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokens.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception @@ -132,6 +179,11 @@ public void testInterpolationWithSpecifiedBoundaryTokens() assertEquals( "jason is an asshole. @not.interpolated@ baby @foo@. @bar@", interpolate( foo, m, "@", "@" ) ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception @@ -145,6 +197,11 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue assertEquals( "jason is an @foobarred@", interpolate( foo, m, "@", "@" ) ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception @@ -158,6 +215,11 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtE assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter.

    + * + * @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. */ + /** + *

    testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken.

    + * + * @throws java.io.IOException if any. + */ @Test public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException @@ -52,6 +61,11 @@ public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() assertEquals( "This is a ${test", result ); } + /** + *

    testDefaultInterpolationWithNonInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception @@ -77,6 +91,11 @@ private Map getStandardMap() return m; } + /** + *

    testDefaultInterpolationWithEscapedExpression.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDefaultInterpolationWithEscapedExpression() throws Exception @@ -94,6 +113,11 @@ public void testDefaultInterpolationWithEscapedExpression() assertEquals( "jason is an asshole. ${noun} value", bar ); } + /** + *

    testDefaultInterpolationWithInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception @@ -111,6 +135,11 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() assertEquals( "jason is an asshole", bar ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokens.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception @@ -129,6 +158,11 @@ public void testInterpolationWithSpecifiedBoundaryTokens() assertEquals( "jason is an asshole. @not.interpolated@ baby @foo@. @bar@", bar ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception @@ -147,6 +181,11 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue assertEquals( "jason is an @foobarred@", bar ); } + /** + *

    testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception @@ -164,4 +203,4 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtE String bar = writer.toString(); assertEquals( "jason is an asshole", bar ); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java index b777a2a3..bd523457 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java @@ -22,10 +22,19 @@ import org.junit.Test; /** + *

    MatchPatternTest class.

    + * * @author Kristian Rosenvold + * @version $Id: $Id + * @since 3.4.0 */ public class MatchPatternTest { + /** + *

    testMatchPath.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMatchPath() throws Exception @@ -35,6 +44,8 @@ public void testMatchPath() } /** + *

    testMatchPatternStart.

    + * * @see Issue #63 */ @Test diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java index d4e51566..a10e340e 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java @@ -21,8 +21,20 @@ import org.junit.Test; +/** + *

    MatchPatternsTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class MatchPatternsTest { + /** + *

    testMatches.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMatches() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/OsTest.java b/src/test/java/org/codehaus/plexus/util/OsTest.java index 363df35b..572d4a56 100644 --- a/src/test/java/org/codehaus/plexus/util/OsTest.java +++ b/src/test/java/org/codehaus/plexus/util/OsTest.java @@ -26,15 +26,25 @@ /** * Test Case for Os + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 */ public class OsTest { + /** + *

    testUndefinedFamily.

    + */ @Test public void testUndefinedFamily() { assertFalse( Os.isFamily( "bogus family" ) ); } + /** + *

    testOs.

    + */ @Test public void testOs() { @@ -79,6 +89,9 @@ public void testOs() assertFalse( Os.isOs( currentFamily, Os.OS_NAME, Os.OS_ARCH, "myversion" ) ); } + /** + *

    testValidList.

    + */ @Test public void testValidList() { diff --git a/src/test/java/org/codehaus/plexus/util/PathToolTest.java b/src/test/java/org/codehaus/plexus/util/PathToolTest.java index 4b9985a9..0a6d011e 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -21,13 +21,18 @@ import org.junit.Test; /** - * @author Vincent Siveton + *

    PathToolTest class.

    * + * @author Vincent Siveton + * @version $Id: $Id + * @since 3.4.0 */ public class PathToolTest { /** - * @throws Exception + *

    testGetRelativePath.

    + * + * @throws java.lang.Exception */ @Test public void testGetRelativePath() @@ -42,7 +47,9 @@ public void testGetRelativePath() } /** - * @throws Exception + *

    testGetDirectoryComponent.

    + * + * @throws java.lang.Exception */ @Test public void testGetDirectoryComponent() @@ -55,7 +62,9 @@ public void testGetDirectoryComponent() } /** - * @throws Exception + *

    testCalculateLink.

    + * + * @throws java.lang.Exception */ @Test public void testCalculateLink() @@ -73,7 +82,9 @@ public void testCalculateLink() } /** - * @throws Exception + *

    testGetRelativeWebPath.

    + * + * @throws java.lang.Exception */ @Test public void testGetRelativeWebPath() @@ -91,7 +102,9 @@ public void testGetRelativeWebPath() } /** - * @throws Exception + *

    testGetRelativeFilePath.

    + * + * @throws java.lang.Exception */ @Test public void testGetRelativeFilePath() diff --git a/src/test/java/org/codehaus/plexus/util/PerfTest.java b/src/test/java/org/codehaus/plexus/util/PerfTest.java index a443fd95..595c7272 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -18,12 +18,22 @@ import org.junit.Test; +/** + *

    PerfTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class PerfTest { String src = "012345578901234556789012345678901234456789012345678901234567890"; private final int oops = 100; + /** + *

    testSubString.

    + */ @Test public void testSubString() { @@ -40,6 +50,9 @@ public void testSubString() System.out.println( "i = " + i ); } + /** + *

    testResDir.

    + */ @Test public void testResDir() { diff --git a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java index 767c72e8..32699154 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -30,11 +30,17 @@ * @author Jesse McConnell * @version $Id:$ * @see org.codehaus.plexus.util.ReflectionUtils + * @since 3.4.0 */ public final class ReflectionUtilsTest { public ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); + /** + *

    testSimpleVariableAccess.

    + * + * @throws java.lang.IllegalAccessException if any. + */ @Test public void testSimpleVariableAccess() throws IllegalAccessException @@ -42,6 +48,11 @@ public void testSimpleVariableAccess() assertEquals( "woohoo", (String) ReflectionUtils.getValueIncludingSuperclasses( "myString", testClass ) ); } + /** + *

    testComplexVariableAccess.

    + * + * @throws java.lang.IllegalAccessException if any. + */ @Test public void testComplexVariableAccess() throws IllegalAccessException @@ -55,6 +66,11 @@ public void testComplexVariableAccess() } + /** + *

    testSuperClassVariableAccess.

    + * + * @throws java.lang.IllegalAccessException if any. + */ @Test public void testSuperClassVariableAccess() throws IllegalAccessException @@ -63,6 +79,11 @@ public void testSuperClassVariableAccess() (String) ReflectionUtils.getValueIncludingSuperclasses( "mySuperString", testClass ) ); } + /** + *

    testSettingVariableValue.

    + * + * @throws java.lang.IllegalAccessException if any. + */ @Test public void testSettingVariableValue() throws IllegalAccessException diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index 194c45b4..ebc2dca0 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -23,8 +23,18 @@ import org.junit.Test; +/** + *

    SelectorUtilsTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class SelectorUtilsTest { + /** + *

    testMatchPath_DefaultFileSeparator.

    + */ @Test public void testMatchPath_DefaultFileSeparator() { @@ -41,6 +51,9 @@ public void testMatchPath_DefaultFileSeparator() assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt" ) ); } + /** + *

    testMatchPath_UnixFileSeparator.

    + */ @Test public void testMatchPath_UnixFileSeparator() { @@ -59,6 +72,9 @@ public void testMatchPath_UnixFileSeparator() assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false ) ); } + /** + *

    testMatchPath_WindowsFileSeparator.

    + */ @Test public void testMatchPath_WindowsFileSeparator() { diff --git a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java index cc76544a..0127c741 100644 --- a/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringInputStreamTest.java @@ -19,12 +19,18 @@ import junit.framework.TestCase; /** - * @author Ben Walding + *

    StringInputStreamTest class.

    * + * @author Ben Walding + * @version $Id: $Id + * @since 3.4.0 */ public class StringInputStreamTest extends TestCase { + /** + *

    testFoo.

    + */ public void testFoo() { } diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index 56df66a7..acabdb9b 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -29,11 +29,15 @@ * Test string utils. * * @author Brett Porter - * + * @version $Id: $Id + * @since 3.4.0 */ public class StringUtilsTest { + /** + *

    testIsEmpty.

    + */ @Test public void testIsEmpty() { @@ -44,6 +48,9 @@ public void testIsEmpty() assertEquals( false, StringUtils.isEmpty( " foo " ) ); } + /** + *

    testIsNotEmpty.

    + */ @Test public void testIsNotEmpty() { @@ -54,6 +61,9 @@ public void testIsNotEmpty() assertEquals( true, StringUtils.isNotEmpty( " foo " ) ); } + /** + *

    testIsBlank.

    + */ @Test public void testIsBlank() { @@ -64,6 +74,9 @@ public void testIsBlank() assertEquals( false, StringUtils.isBlank( " foo " ) ); } + /** + *

    testIsNotBlank.

    + */ @Test public void testIsNotBlank() { @@ -74,6 +87,9 @@ public void testIsNotBlank() assertEquals( true, StringUtils.isNotBlank( " foo " ) ); } + /** + *

    testCapitalizeFirstLetter.

    + */ @Test public void testCapitalizeFirstLetter() { @@ -81,6 +97,9 @@ public void testCapitalizeFirstLetter() assertEquals( "Id", StringUtils.capitalizeFirstLetter( "Id" ) ); } + /** + *

    testCapitalizeFirstLetterTurkish.

    + */ @Test public void testCapitalizeFirstLetterTurkish() { @@ -91,6 +110,9 @@ public void testCapitalizeFirstLetterTurkish() Locale.setDefault( l ); } + /** + *

    testLowerCaseFirstLetter.

    + */ @Test public void testLowerCaseFirstLetter() { @@ -98,6 +120,9 @@ public void testLowerCaseFirstLetter() assertEquals( "id", StringUtils.lowercaseFirstLetter( "Id" ) ); } + /** + *

    testLowerCaseFirstLetterTurkish.

    + */ @Test public void testLowerCaseFirstLetterTurkish() { @@ -108,6 +133,9 @@ public void testLowerCaseFirstLetterTurkish() Locale.setDefault( l ); } + /** + *

    testRemoveAndHump.

    + */ @Test public void testRemoveAndHump() { @@ -115,6 +143,9 @@ public void testRemoveAndHump() assertEquals( "SomeId", StringUtils.removeAndHump( "some-id", "-" ) ); } + /** + *

    testRemoveAndHumpTurkish.

    + */ @Test public void testRemoveAndHumpTurkish() { @@ -125,6 +156,9 @@ public void testRemoveAndHumpTurkish() Locale.setDefault( l ); } + /** + *

    testQuote_EscapeEmbeddedSingleQuotes.

    + */ @Test public void testQuote_EscapeEmbeddedSingleQuotes() { @@ -137,6 +171,9 @@ public void testQuote_EscapeEmbeddedSingleQuotes() assertEquals( check, result ); } + /** + *

    testQuote_EscapeEmbeddedSingleQuotesWithPattern.

    + */ @Test public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { @@ -149,6 +186,9 @@ public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() assertEquals( check, result ); } + /** + *

    testQuote_EscapeEmbeddedDoubleQuotesAndSpaces.

    + */ @Test public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { @@ -161,6 +201,9 @@ public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() assertEquals( check, result ); } + /** + *

    testQuote_DontQuoteIfUnneeded.

    + */ @Test public void testQuote_DontQuoteIfUnneeded() { @@ -172,6 +215,9 @@ public void testQuote_DontQuoteIfUnneeded() assertEquals( src, result ); } + /** + *

    testQuote_WrapWithSingleQuotes.

    + */ @Test public void testQuote_WrapWithSingleQuotes() { @@ -184,6 +230,9 @@ public void testQuote_WrapWithSingleQuotes() assertEquals( check, result ); } + /** + *

    testQuote_PreserveExistingQuotes.

    + */ @Test public void testQuote_PreserveExistingQuotes() { @@ -195,6 +244,9 @@ public void testQuote_PreserveExistingQuotes() assertEquals( src, result ); } + /** + *

    testQuote_WrapExistingQuotesWhenForceIsTrue.

    + */ @Test public void testQuote_WrapExistingQuotesWhenForceIsTrue() { @@ -207,6 +259,9 @@ public void testQuote_WrapExistingQuotesWhenForceIsTrue() assertEquals( check, result ); } + /** + *

    testQuote_ShortVersion_SingleQuotesPreserved.

    + */ @Test public void testQuote_ShortVersion_SingleQuotesPreserved() { @@ -217,6 +272,9 @@ public void testQuote_ShortVersion_SingleQuotesPreserved() assertEquals( src, result ); } + /** + *

    testSplit.

    + */ @Test public void testSplit() { @@ -247,6 +305,11 @@ public void testSplit() assertEquals( Arrays.asList( new String[] { "this", "is", "a", "test", "really" } ), Arrays.asList( tokens ) ); } + /** + *

    testRemoveDuplicateWhitespace.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testRemoveDuplicateWhitespace() throws Exception @@ -262,6 +325,11 @@ public void testRemoveDuplicateWhitespace() } + /** + *

    testUnifyLineSeparators.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testUnifyLineSeparators() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index c080d7d0..a642b5a2 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -33,7 +33,8 @@ * Created on 21/06/2003 * * @author Bert van Brakel - * + * @version $Id: $Id + * @since 3.4.0 */ public class SweeperPoolTest { @@ -89,6 +90,9 @@ public void testMaxSize() } + /** + *

    testSweepAndTrim1.

    + */ @Test public void testSweepAndTrim1() { @@ -121,6 +125,11 @@ public void testSweepAndTrim1() } + /** + *

    setUp.

    + * + * @throws java.lang.Exception if any. + */ @Before public void setUp() throws Exception @@ -133,6 +142,11 @@ public void setUp() o6 = new Object(); } + /** + *

    tearDown.

    + * + * @throws java.lang.Exception if any. + */ @After public void tearDown() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java index 7c954296..1ee704b2 100644 --- a/src/test/java/org/codehaus/plexus/util/TestThreadManager.java +++ b/src/test/java/org/codehaus/plexus/util/TestThreadManager.java @@ -29,7 +29,8 @@ *

    * * @author Bert van Brakel - * + * @version $Id: $Id + * @since 3.4.0 */ public class TestThreadManager { @@ -54,6 +55,11 @@ public class TestThreadManager // ~ Constructors ------------------------------------------------------------------------------- + /** + *

    Constructor for TestThreadManager.

    + * + * @param notify a {@link java.lang.Object} object. + */ public TestThreadManager( Object notify ) { super(); @@ -63,13 +69,18 @@ public TestThreadManager( Object notify ) // ~ Methods ------------------------------------------------------------------------------------ /** - * @return + *

    Getter for the field runThreads.

    + * + * @return a {@link java.util.Collection} object. */ public Collection getRunThreads() { return runThreads; } + /** + *

    runTestThreads.

    + */ 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 + *

    Getter for the field toRunThreads.

    + * + * @return a {@link java.util.Collection} object. */ public Collection getToRunThreads() { @@ -135,6 +158,11 @@ public void clear() * (non-Javadoc) * @see java.util.Collection#remove(java.lang.Object) */ + /** + *

    completed.

    + * + * @param thread a {@link org.codehaus.plexus.util.AbstractTestThread} object. + */ public synchronized void completed( AbstractTestThread thread ) { toRunThreads.remove( thread ); @@ -163,6 +191,11 @@ public void doRegisterThread( AbstractTestThread thread ) { } + /** + *

    registerThread.

    + * + * @param thread a {@link org.codehaus.plexus.util.AbstractTestThread} object. + */ public final void registerThread( AbstractTestThread thread ) { thread.setThreadRegistry( this ); diff --git a/src/test/java/org/codehaus/plexus/util/Tracer.java b/src/test/java/org/codehaus/plexus/util/Tracer.java index 334f85ff..5bf4f84d 100644 --- a/src/test/java/org/codehaus/plexus/util/Tracer.java +++ b/src/test/java/org/codehaus/plexus/util/Tracer.java @@ -26,7 +26,8 @@ *

    * * @author Bert van Brakel - * + * @version $Id: $Id + * @since 3.4.0 */ public class Tracer { @@ -41,6 +42,9 @@ private Tracer() /** * Return the throwable stack trace as a string + * + * @param t a {@link java.lang.Throwable} object. + * @return a {@link java.lang.String} object. */ public static String traceToString( Throwable t ) { diff --git a/src/test/java/org/codehaus/plexus/util/WalkCollector.java b/src/test/java/org/codehaus/plexus/util/WalkCollector.java index 2762db8d..c5c4e018 100644 --- a/src/test/java/org/codehaus/plexus/util/WalkCollector.java +++ b/src/test/java/org/codehaus/plexus/util/WalkCollector.java @@ -35,6 +35,9 @@ class WalkCollector public int percentageHigh; + /** + *

    Constructor for WalkCollector.

    + */ public WalkCollector() { steps = new ArrayList(); @@ -44,6 +47,7 @@ public WalkCollector() percentageHigh = 0; } + /** {@inheritDoc} */ public void directoryWalkStarting( File basedir ) { debug( "Walk Starting: " + basedir ); @@ -51,6 +55,7 @@ public void directoryWalkStarting( File basedir ) startingDir = basedir; } + /** {@inheritDoc} */ public void directoryWalkStep( int percentage, File file ) { percentageLow = Math.min( percentageLow, percentage ); @@ -59,14 +64,18 @@ public void directoryWalkStep( int percentage, File file ) steps.add( file ); } + /** + *

    directoryWalkFinished.

    + */ public void directoryWalkFinished() { debug( "Walk Finished." ); finishCount++; } + /** {@inheritDoc} */ public void debug( String message ) { System.out.println( message ); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java index ae4b3e19..92cdaa2d 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -27,10 +27,20 @@ import org.codehaus.plexus.util.Os; import org.junit.Test; +/** + *

    CommandLineUtilsTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ @SuppressWarnings( { "JavaDoc", "deprecation" } ) public class CommandLineUtilsTest { + /** + *

    testQuoteArguments.

    + */ @Test public void testQuoteArguments() { @@ -62,6 +72,8 @@ public void testQuoteArguments() /** * Tests that case-insensitive environment variables are normalized to upper case. + * + * @throws java.lang.Exception if any. */ @Test public void testGetSystemEnvVarsCaseInsensitive() @@ -77,6 +89,8 @@ public void testGetSystemEnvVarsCaseInsensitive() /** * Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms. + * + * @throws java.lang.Exception if any. */ @Test public void testGetSystemEnvVarsWindows() @@ -96,6 +110,8 @@ public void testGetSystemEnvVarsWindows() /** * Tests the splitting of a command line into distinct arguments. + * + * @throws java.lang.Exception if any. */ @Test public void testTranslateCommandline() diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java index 97073d60..15cb9744 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -35,10 +35,22 @@ import org.junit.Before; import org.junit.Test; +/** + *

    CommandlineTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class CommandlineTest { private String baseDir; + /** + *

    setUp.

    + * + * @throws java.lang.Exception if any. + */ @Before public void setUp() throws Exception @@ -51,6 +63,9 @@ public void setUp() } } + /** + *

    testCommandlineWithoutCommandInConstructor.

    + */ @Test public void testCommandlineWithoutCommandInConstructor() { @@ -63,6 +78,9 @@ public void testCommandlineWithoutCommandInConstructor() assertEquals( "cd .", cmd.toString() ); } + /** + *

    testCommandlineWithCommandInConstructor.

    + */ @Test public void testCommandlineWithCommandInConstructor() { @@ -73,6 +91,11 @@ public void testCommandlineWithCommandInConstructor() assertEquals( "cd .", cmd.toString() ); } + /** + *

    testExecuteBinaryOnPath.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testExecuteBinaryOnPath() throws Exception @@ -90,6 +113,11 @@ public void testExecuteBinaryOnPath() assertTrue( out.contains( "Java version:" ) ); } + /** + *

    testExecute.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testExecute() throws Exception @@ -105,6 +133,9 @@ public void testExecute() assertEquals( "Hello", IOUtil.toString( process.getInputStream() ).trim() ); } + /** + *

    testSetLine.

    + */ @Test public void testSetLine() { @@ -118,6 +149,9 @@ public void testSetLine() assertEquals( "echo Hello", cmd.toString() ); } + /** + *

    testCreateCommandInReverseOrder.

    + */ @Test public void testCreateCommandInReverseOrder() { @@ -130,6 +164,9 @@ public void testCreateCommandInReverseOrder() assertEquals( "cd .", cmd.toString() ); } + /** + *

    testSetFile.

    + */ @Test public void testSetFile() { @@ -148,6 +185,11 @@ public void testSetFile() assertEquals( "more " + fileName, cmd.toString() ); } + /** + *

    testGetShellCommandLineWindows.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testGetShellCommandLineWindows() throws Exception @@ -167,6 +209,11 @@ public void testGetShellCommandLineWindows() assertEquals( expectedShellCmd, shellCommandline[3] ); } + /** + *

    testGetShellCommandLineWindowsWithSeveralQuotes.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception @@ -189,8 +236,8 @@ public void testGetShellCommandLineWindowsWithSeveralQuotes() /** * Test the command line generated for the bash shell - * - * @throws Exception + * + * @throws java.lang.Exception */ @Test public void testGetShellCommandLineBash() @@ -216,8 +263,8 @@ public void testGetShellCommandLineBash() /** * Test the command line generated for the bash shell - * - * @throws Exception + * + * @throws java.lang.Exception */ @Test public void testGetShellCommandLineBash_WithWorkingDirectory() @@ -246,8 +293,8 @@ public void testGetShellCommandLineBash_WithWorkingDirectory() /** * Test the command line generated for the bash shell - * - * @throws Exception + * + * @throws java.lang.Exception */ @Test public void testGetShellCommandLineBash_WithSingleQuotedArg() @@ -271,6 +318,11 @@ public void testGetShellCommandLineBash_WithSingleQuotedArg() assertEquals( expectedShellCmd, shellCommandline[2] ); } + /** + *

    testGetShellCommandLineNonWindows.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testGetShellCommandLineNonWindows() throws Exception @@ -295,6 +347,11 @@ public void testGetShellCommandLineNonWindows() } } + /** + *

    testEnvironment.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testEnvironment() throws Exception @@ -304,6 +361,11 @@ public void testEnvironment() assertEquals( "name=value", cmd.getEnvironmentVariables()[0] ); } + /** + *

    testEnvironmentWitOverrideSystemEnvironment.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testEnvironmentWitOverrideSystemEnvironment() throws Exception @@ -327,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() @@ -343,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() @@ -356,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() @@ -379,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() @@ -401,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() @@ -434,6 +496,11 @@ public void testOnlyQuotedPath() createAndCallScript( dir, javaBinStr + " -version" ); } + /** + *

    testDollarSignInArgumentPath.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDollarSignInArgumentPath() throws Exception @@ -469,6 +536,11 @@ public void testDollarSignInArgumentPath() executeCommandLine( cmd ); } + /** + *

    testTimeOutException.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testTimeOutException() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java index 4c8d9931..423d30ed 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java @@ -18,8 +18,20 @@ import org.junit.Test; +/** + *

    DefaultConsumerTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class DefaultConsumerTest { + /** + *

    testConsumeLine.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testConsumeLine() throws Exception @@ -28,4 +40,4 @@ public void testConsumeLine() cons.consumeLine( "Test DefaultConsumer consumeLine" ); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java index c9ce9ebd..05d043f5 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java @@ -21,8 +21,18 @@ import org.junit.Test; +/** + *

    EnhancedStringTokenizerTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class EnhancedStringTokenizerTest { + /** + *

    test1.

    + */ @Test public void test1() { @@ -36,6 +46,9 @@ public void test1() assertEquals( "this is a test string ", sb.toString() ); } + /** + *

    test2.

    + */ @Test public void test2() { @@ -48,6 +61,9 @@ public void test2() assertEquals( "Token 6", "4", est.nextToken() ); } + /** + *

    test3.

    + */ @Test public void test3() { @@ -65,6 +81,9 @@ public void test3() assertEquals( "Token 11", "4", est.nextToken() ); } + /** + *

    testMultipleDelim.

    + */ @Test public void testMultipleDelim() { @@ -79,6 +98,9 @@ public void testMultipleDelim() assertEquals( "est.hasMoreTokens()", false, est.hasMoreTokens() ); } + /** + *

    testEmptyString.

    + */ @Test public void testEmptyString() { @@ -94,6 +116,9 @@ public void testEmptyString() } } + /** + *

    testSimpleString.

    + */ @Test public void testSimpleString() { diff --git a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java index a00e156c..eec5def5 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -67,12 +67,19 @@ import org.junit.Test; /** + *

    StreamPumperTest class.

    + * * @author Paul Julius + * @version $Id: $Id + * @since 3.4.0 */ public class StreamPumperTest { private String lineSeparator = System.lineSeparator(); + /** + *

    testPumping.

    + */ @Test public void testPumping() { @@ -90,6 +97,9 @@ public void testPumping() assertTrue( consumer.wasLineConsumed( line2, 1000 ) ); } + /** + *

    testPumpingWithPrintWriter.

    + */ @Test public void testPumpingWithPrintWriter() { @@ -105,6 +115,9 @@ public void testPumpingWithPrintWriter() pumper.close(); } + /** + *

    testPumperReadsInputStreamUntilEndEvenIfConsumerFails.

    + */ @Test public void testPumperReadsInputStreamUntilEndEvenIfConsumerFails() { @@ -221,6 +234,9 @@ public void consumeLine( String line ) } } + /** + *

    testEnabled.

    + */ @Test public void testEnabled() { @@ -231,6 +247,9 @@ public void testEnabled() assertEquals( 3, streamConsumer.lines.size() ); } + /** + *

    testDisabled.

    + */ @Test public void testDisabled() { diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java index 95b70b5b..1480685f 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java @@ -27,14 +27,29 @@ import org.codehaus.plexus.util.cli.Commandline; import org.junit.Test; +/** + *

    BourneShellTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class BourneShellTest { + /** + *

    newShell.

    + * + * @return a {@link org.codehaus.plexus.util.cli.shell.Shell} object. + */ protected Shell newShell() { return new BourneShell(); } + /** + *

    testQuoteWorkingDirectoryAndExecutable.

    + */ @Test public void testQuoteWorkingDirectoryAndExecutable() { @@ -48,6 +63,9 @@ public void testQuoteWorkingDirectoryAndExecutable() assertEquals( "/bin/sh -c cd '/usr/local/bin' && 'chmod'", executable ); } + /** + *

    testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes.

    + */ @Test public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { @@ -61,6 +79,9 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() assertEquals( "/bin/sh -c cd '/usr/local/'\"'\"'something else'\"'\"'' && 'chmod'", executable ); } + /** + *

    testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep.

    + */ @Test public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() { @@ -74,6 +95,9 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_Backsl assertEquals( "/bin/sh -c cd '\\usr\\local\\\'\"'\"'something else'\"'\"'' && 'chmod'", executable ); } + /** + *

    testPreserveSingleQuotesOnArgument.

    + */ @Test public void testPreserveSingleQuotesOnArgument() { @@ -91,6 +115,9 @@ public void testPreserveSingleQuotesOnArgument() assertTrue( cli.endsWith( "''\"'\"'some arg with spaces'\"'\"''" ) ); } + /** + *

    testAddSingleQuotesOnArgumentWithSpaces.

    + */ @Test public void testAddSingleQuotesOnArgumentWithSpaces() { @@ -108,6 +135,9 @@ public void testAddSingleQuotesOnArgumentWithSpaces() assertTrue( cli.endsWith( "\'" + args[0] + "\'" ) ); } + /** + *

    testEscapeSingleQuotesOnArgument.

    + */ @Test public void testEscapeSingleQuotesOnArgument() { @@ -126,6 +156,9 @@ public void testEscapeSingleQuotesOnArgument() shellCommandLine.get( shellCommandLine.size() - 1 ) ); } + /** + *

    testArgumentsWithsemicolon.

    + */ @Test public void testArgumentsWithsemicolon() { @@ -183,6 +216,11 @@ public void testArgumentsWithsemicolon() assertEquals( "\"--password ;password\"", lines[3] ); } + /** + *

    testBourneShellQuotingCharacters.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testBourneShellQuotingCharacters() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java index 8fd33944..5c67eb3f 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -24,11 +24,17 @@ import org.junit.Test; /** - * @author Jason van Zyl + *

    CycleDetectedExceptionTest class.

    * + * @author Jason van Zyl + * @version $Id: $Id + * @since 3.4.0 */ public class CycleDetectedExceptionTest { + /** + *

    testException.

    + */ @Test public void testException() { diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java index 45db6bed..76a9c1ff 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -27,12 +27,18 @@ import org.junit.Test; /** - * @author Michal Maczka + *

    CycleDetectorTest class.

    * + * @author Michal Maczka + * @version $Id: $Id + * @since 3.4.0 */ public class CycleDetectorTest { + /** + *

    testCycyleDetection.

    + */ @Test public void testCycyleDetection() { diff --git a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java index a4210045..bf0063eb 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java @@ -27,11 +27,19 @@ import org.junit.Test; /** - * @author Michal Maczka + *

    DAGTest class.

    * + * @author Michal Maczka + * @version $Id: $Id + * @since 3.4.0 */ public class DAGTest { + /** + *

    testDAG.

    + * + * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. + */ @Test public void testDAG() throws CycleDetectedException @@ -135,6 +143,11 @@ public void testDAG() assertTrue( d.getParentLabels().contains( "c" ) ); } + /** + *

    testGetPredecessors.

    + * + * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. + */ @Test public void testGetPredecessors() throws CycleDetectedException diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java index 36bdf1f9..25ea5b54 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -24,11 +24,19 @@ import org.junit.Test; /** - * @author Michal Maczka + *

    TopologicalSorterTest class.

    * + * @author Michal Maczka + * @version $Id: $Id + * @since 3.4.0 */ public class TopologicalSorterTest { + /** + *

    testDfs.

    + * + * @throws org.codehaus.plexus.util.dag.CycleDetectedException if any. + */ @Test public void testDfs() throws CycleDetectedException diff --git a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java index d5ab0cd1..db49acd2 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java @@ -21,11 +21,17 @@ import org.junit.Test; /** - * @author Michal Maczka + *

    VertexTest class.

    * + * @author Michal Maczka + * @version $Id: $Id + * @since 3.4.0 */ public class VertexTest { + /** + *

    testVertex.

    + */ @Test public void testVertex() { diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java index 0eb34b6c..c6f23e2a 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -32,13 +32,21 @@ import org.junit.Test; /** - * @author Jason van Zyl + *

    ReflectionValueExtractorTest class.

    * + * @author Jason van Zyl + * @version $Id: $Id + * @since 3.4.0 */ public class ReflectionValueExtractorTest { private Project project; + /** + *

    setUp.

    + * + * @throws java.lang.Exception if any. + */ @Before public void setUp() throws Exception @@ -66,6 +74,11 @@ public void setUp() project.addArtifact( new Artifact( "g2", "a2", "v2", "e2", "c2" ) ); } + /** + *

    testValueExtraction.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testValueExtraction() throws Exception @@ -149,6 +162,11 @@ public void testValueExtraction() assertNotNull( build ); } + /** + *

    testValueExtractorWithAInvalidExpression.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testValueExtractorWithAInvalidExpression() throws Exception @@ -158,6 +176,11 @@ public void testValueExtractorWithAInvalidExpression() assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[0].foo", project ) ); } + /** + *

    testMappedDottedKey.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMappedDottedKey() throws Exception @@ -168,6 +191,11 @@ public void testMappedDottedKey() assertEquals( "a.b-value", ReflectionValueExtractor.evaluate( "h.value(a.b)", new ValueHolder( map ) ) ); } + /** + *

    testIndexedMapped.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testIndexedMapped() throws Exception @@ -180,6 +208,11 @@ public void testIndexedMapped() assertEquals( "a-value", ReflectionValueExtractor.evaluate( "h.value[0](a)", new ValueHolder( list ) ) ); } + /** + *

    testMappedIndexed.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMappedIndexed() throws Exception @@ -191,6 +224,11 @@ public void testMappedIndexed() assertEquals( "a-value", ReflectionValueExtractor.evaluate( "h.value(a)[0]", new ValueHolder( map ) ) ); } + /** + *

    testMappedMissingDot.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMappedMissingDot() throws Exception @@ -200,6 +238,11 @@ public void testMappedMissingDot() assertNull( ReflectionValueExtractor.evaluate( "h.value(a)value", new ValueHolder( map ) ) ); } + /** + *

    testIndexedMissingDot.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testIndexedMissingDot() throws Exception @@ -209,6 +252,11 @@ public void testIndexedMissingDot() assertNull( ReflectionValueExtractor.evaluate( "h.value[0]value", new ValueHolder( list ) ) ); } + /** + *

    testDotDot.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDotDot() throws Exception @@ -216,6 +264,11 @@ public void testDotDot() assertNull( ReflectionValueExtractor.evaluate( "h..value", new ValueHolder( "value" ) ) ); } + /** + *

    testBadIndexedSyntax.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testBadIndexedSyntax() throws Exception @@ -232,6 +285,11 @@ public void testBadIndexedSyntax() assertNull( ReflectionValueExtractor.evaluate( "h.value[-1]", value ) ); } + /** + *

    testBadMappedSyntax.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testBadMappedSyntax() throws Exception @@ -246,6 +304,11 @@ public void testBadMappedSyntax() assertNull( ReflectionValueExtractor.evaluate( "h.value(a]", value ) ); } + /** + *

    testIllegalIndexedType.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testIllegalIndexedType() throws Exception @@ -260,6 +323,11 @@ public void testIllegalIndexedType() } } + /** + *

    testIllegalMappedType.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testIllegalMappedType() throws Exception @@ -274,6 +342,11 @@ public void testIllegalMappedType() } } + /** + *

    testTrimRootToken.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testTrimRootToken() throws Exception @@ -281,6 +354,11 @@ public void testTrimRootToken() assertNull( ReflectionValueExtractor.evaluate( "project", project, true ) ); } + /** + *

    testArtifactMap.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testArtifactMap() throws Exception @@ -543,6 +621,11 @@ public Object getValue() } } + /** + *

    testRootPropertyRegression.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testRootPropertyRegression() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java index ed75fd58..d3c0db8c 100644 --- a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java @@ -22,8 +22,11 @@ import org.junit.Test; /** - * @author Jörg Schaible + *

    ReflectorTest class.

    * + * @author Jörg Schaible + * @version $Id: $Id + * @since 3.4.0 */ public class ReflectorTest { @@ -31,6 +34,11 @@ public class ReflectorTest private Reflector reflector; + /** + *

    setUp.

    + * + * @throws java.lang.Exception if any. + */ @Before public void setUp() throws Exception @@ -42,6 +50,11 @@ public void setUp() reflector = new Reflector(); } + /** + *

    testObjectPropertyFromName.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testObjectPropertyFromName() throws Exception @@ -49,6 +62,11 @@ public void testObjectPropertyFromName() assertEquals( "1.0.0", reflector.getObjectProperty( project, "modelVersion" ) ); } + /** + *

    testObjectPropertyFromBean.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testObjectPropertyFromBean() throws Exception @@ -56,6 +74,11 @@ public void testObjectPropertyFromBean() assertEquals( "Foo", reflector.getObjectProperty( project, "name" ) ); } + /** + *

    testObjectPropertyFromField.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testObjectPropertyFromField() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java index d115a6e9..76125f95 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java @@ -35,11 +35,12 @@ import org.junit.Test; /** - * Test of {@link PrettyPrintXMLWriter} + * Test of {@link org.codehaus.plexus.util.xml.PrettyPrintXMLWriter} * * @author Vincent Siveton * @author Gabriel Belingueres - * + * @version $Id: $Id + * @since 3.4.0 */ public class PrettyPrintXMLWriterTest { @@ -47,12 +48,18 @@ public class PrettyPrintXMLWriterTest PrettyPrintXMLWriter writer; + /** + *

    setUp.

    + */ @Before public void setUp() { initWriter(); } + /** + *

    tearDown.

    + */ @After public void tearDown() { @@ -66,6 +73,9 @@ private void initWriter() writer = new PrettyPrintXMLWriter( w ); } + /** + *

    testDefaultPrettyPrintXMLWriter.

    + */ @Test public void testDefaultPrettyPrintXMLWriter() { @@ -80,6 +90,9 @@ public void testDefaultPrettyPrintXMLWriter() assertEquals( expectedResult( PrettyPrintXMLWriter.LS ), w.toString() ); } + /** + *

    testPrettyPrintXMLWriterWithGivenLineSeparator.

    + */ @Test public void testPrettyPrintXMLWriterWithGivenLineSeparator() { @@ -96,6 +109,9 @@ public void testPrettyPrintXMLWriterWithGivenLineSeparator() assertEquals( expectedResult( "\n" ), w.toString() ); } + /** + *

    testPrettyPrintXMLWriterWithGivenLineIndenter.

    + */ @Test public void testPrettyPrintXMLWriterWithGivenLineIndenter() { @@ -112,6 +128,9 @@ public void testPrettyPrintXMLWriterWithGivenLineIndenter() assertEquals( expectedResult( " ", PrettyPrintXMLWriter.LS ), w.toString() ); } + /** + *

    testEscapeXmlAttribute.

    + */ @Test public void testEscapeXmlAttribute() { @@ -136,6 +155,9 @@ public void testEscapeXmlAttribute() assertEquals( "
    ", w.toString() ); } + /** + *

    testendElementAlreadyClosed.

    + */ @Test public void testendElementAlreadyClosed() { @@ -158,8 +180,8 @@ public void testendElementAlreadyClosed() * optimization bug is present. Target environment: Java 7 (u79 and u80 verified) running on Windows. Detection * strategy: Tries to build a big XML file (~750MB size) and with many nested tags to force the JVM to trigger the * concatenation string optimization bug that throws a NoSuchElementException when calling endElement() method. - * - * @throws IOException if an I/O error occurs + * + * @throws java.io.IOException if an I/O error occurs */ @Test public void testIssue51DetectJava7ConcatenationBug() diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java index 7beafead..7ca8cc48 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamReaderTest.java @@ -26,6 +26,13 @@ import junit.framework.ComparisonFailure; import junit.framework.TestCase; +/** + *

    XmlStreamReaderTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class XmlStreamReaderTest extends TestCase { @@ -115,6 +122,11 @@ private static void checkXmlStreamReader( String text, String encoding, String e checkXmlContent( xml, effectiveEncoding, bom ); } + /** + *

    testNoXmlHeader.

    + * + * @throws java.io.IOException if any. + */ public void testNoXmlHeader() throws IOException { @@ -123,6 +135,11 @@ public void testNoXmlHeader() checkXmlContent( xml, "UTF-8", BOM_UTF8 ); } + /** + *

    testDefaultEncoding.

    + * + * @throws java.io.IOException if any. + */ public void testDefaultEncoding() throws IOException { @@ -130,6 +147,11 @@ public void testDefaultEncoding() checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8", BOM_UTF8 ); } + /** + *

    testUTF8Encoding.

    + * + * @throws java.io.IOException if any. + */ public void testUTF8Encoding() throws IOException { @@ -137,6 +159,11 @@ public void testUTF8Encoding() checkXmlStreamReader( TEXT_UNICODE, "UTF-8", BOM_UTF8 ); } + /** + *

    testUTF16Encoding.

    + * + * @throws java.io.IOException if any. + */ public void testUTF16Encoding() throws IOException { @@ -145,48 +172,88 @@ public void testUTF16Encoding() checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE ); } + /** + *

    testUTF16BEEncoding.

    + * + * @throws java.io.IOException if any. + */ public void testUTF16BEEncoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, "UTF-16BE" ); } + /** + *

    testUTF16LEEncoding.

    + * + * @throws java.io.IOException if any. + */ public void testUTF16LEEncoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, "UTF-16LE" ); } + /** + *

    testLatin1Encoding.

    + * + * @throws java.io.IOException if any. + */ public void testLatin1Encoding() throws IOException { checkXmlStreamReader( TEXT_LATIN1, "ISO-8859-1" ); } + /** + *

    testLatin7Encoding.

    + * + * @throws java.io.IOException if any. + */ public void testLatin7Encoding() throws IOException { checkXmlStreamReader( TEXT_LATIN7, "ISO-8859-7" ); } + /** + *

    testLatin15Encoding.

    + * + * @throws java.io.IOException if any. + */ public void testLatin15Encoding() throws IOException { checkXmlStreamReader( TEXT_LATIN15, "ISO-8859-15" ); } + /** + *

    testEUC_JPEncoding.

    + * + * @throws java.io.IOException if any. + */ public void testEUC_JPEncoding() throws IOException { checkXmlStreamReader( TEXT_EUC_JP, "EUC-JP" ); } + /** + *

    testEBCDICEncoding.

    + * + * @throws java.io.IOException if any. + */ public void testEBCDICEncoding() throws IOException { checkXmlStreamReader( "simple text in EBCDIC", "CP1047" ); } + /** + *

    testInappropriateEncoding.

    + * + * @throws java.io.IOException if any. + */ public void testInappropriateEncoding() throws IOException { @@ -201,6 +268,11 @@ public void testInappropriateEncoding() } } + /** + *

    testEncodingAttribute.

    + * + * @throws java.io.IOException if any. + */ public void testEncodingAttribute() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java index f87ab7d3..fa13aaa0 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java @@ -23,6 +23,13 @@ import org.junit.Test; +/** + *

    XmlStreamWriterTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class XmlStreamWriterTest { /** french */ @@ -72,6 +79,11 @@ private static void checkXmlWriter( String text, String encoding ) checkXmlContent( xml, effectiveEncoding ); } + /** + *

    testNoXmlHeader.

    + * + * @throws java.io.IOException if any. + */ @Test public void testNoXmlHeader() throws IOException @@ -80,6 +92,11 @@ public void testNoXmlHeader() checkXmlContent( xml, "UTF-8" ); } + /** + *

    testEmpty.

    + * + * @throws java.io.IOException if any. + */ @Test public void testEmpty() throws IOException @@ -94,6 +111,11 @@ public void testEmpty() writer.close(); } + /** + *

    testDefaultEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testDefaultEncoding() throws IOException @@ -101,6 +123,11 @@ public void testDefaultEncoding() checkXmlWriter( TEXT_UNICODE, null ); } + /** + *

    testUTF8Encoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testUTF8Encoding() throws IOException @@ -108,6 +135,11 @@ public void testUTF8Encoding() checkXmlWriter( TEXT_UNICODE, "UTF-8" ); } + /** + *

    testUTF16Encoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testUTF16Encoding() throws IOException @@ -115,6 +147,11 @@ public void testUTF16Encoding() checkXmlWriter( TEXT_UNICODE, "UTF-16" ); } + /** + *

    testUTF16BEEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testUTF16BEEncoding() throws IOException @@ -122,6 +159,11 @@ public void testUTF16BEEncoding() checkXmlWriter( TEXT_UNICODE, "UTF-16BE" ); } + /** + *

    testUTF16LEEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testUTF16LEEncoding() throws IOException @@ -129,6 +171,11 @@ public void testUTF16LEEncoding() checkXmlWriter( TEXT_UNICODE, "UTF-16LE" ); } + /** + *

    testLatin1Encoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testLatin1Encoding() throws IOException @@ -136,6 +183,11 @@ public void testLatin1Encoding() checkXmlWriter( TEXT_LATIN1, "ISO-8859-1" ); } + /** + *

    testLatin7Encoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testLatin7Encoding() throws IOException @@ -143,6 +195,11 @@ public void testLatin7Encoding() checkXmlWriter( TEXT_LATIN7, "ISO-8859-7" ); } + /** + *

    testLatin15Encoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testLatin15Encoding() throws IOException @@ -150,6 +207,11 @@ public void testLatin15Encoding() checkXmlWriter( TEXT_LATIN15, "ISO-8859-15" ); } + /** + *

    testEUC_JPEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testEUC_JPEncoding() throws IOException @@ -157,6 +219,11 @@ public void testEUC_JPEncoding() checkXmlWriter( TEXT_EUC_JP, "EUC-JP" ); } + /** + *

    testEBCDICEncoding.

    + * + * @throws java.io.IOException if any. + */ @Test public void testEBCDICEncoding() throws IOException diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index 01fc8c4c..4d4a083f 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -35,15 +35,21 @@ import org.junit.Test; /** - * Test the {@link XmlUtil} class. + * Test the {@link org.codehaus.plexus.util.xml.XmlUtil} class. * * @author Vincent Siveton - * + * @version $Id: $Id + * @since 3.4.0 */ public class XmlUtilTest { private String basedir; + /** + *

    Getter for the field basedir.

    + * + * @return a {@link java.lang.String} object. + */ public final String getBasedir() { if ( null == basedir ) @@ -65,6 +71,11 @@ private File getTestOutputFile( String relPath ) return file; } + /** + *

    testPrettyFormatInputStreamOutputStream.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testPrettyFormatInputStreamOutputStream() throws Exception @@ -91,6 +102,11 @@ public void testPrettyFormatInputStreamOutputStream() } } + /** + *

    testPrettyFormatReaderWriter.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testPrettyFormatReaderWriter() throws Exception @@ -118,6 +134,11 @@ public void testPrettyFormatReaderWriter() } } + /** + *

    testPrettyFormatString.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testPrettyFormatString() throws Exception @@ -149,6 +170,11 @@ public void testPrettyFormatString() assertTrue( countEOL < StringUtils.countMatches( writer.toString(), XmlUtil.DEFAULT_LINE_SEPARATOR ) ); } + /** + *

    testPrettyFormatReaderWriter2.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testPrettyFormatReaderWriter2() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java index 34d99297..4c1f6954 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java @@ -30,8 +30,11 @@ import org.junit.Test; /** - * @author Vincent Siveton + *

    XmlWriterUtilTest class.

    * + * @author Vincent Siveton + * @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 f8ac0489..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: $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() } } + /** + *

    testEscapingInContent.

    + * + * @throws java.io.IOException if any. + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + */ @Test public void testEscapingInContent() throws IOException, XmlPullParserException @@ -160,6 +182,12 @@ public void testEscapingInContent() assertEquals( "Compare stringified DOMs", getExpectedString(), w.toString() ); } + /** + *

    testEscapingInAttributes.

    + * + * @throws java.io.IOException if any. + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + */ @Test public void testEscapingInAttributes() throws IOException, XmlPullParserException @@ -175,6 +203,12 @@ public void testEscapingInAttributes() assertEquals( "Compare stringified DOMs", newString, s ); } + /** + *

    testInputLocationTracking.

    + * + * @throws java.io.IOException if any. + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + */ @Test public void testInputLocationTracking() throws IOException, XmlPullParserException diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java index 6344adb4..22bba428 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomPerfTest.java @@ -36,6 +36,13 @@ import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.TimeValue; +/** + *

    Xpp3DomPerfTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) @@ -55,18 +62,35 @@ public void setUp() throws IOException, XmlPullParserException { } + /** + *

    benchmarkClone.

    + * + * @param state a {@link org.codehaus.plexus.util.xml.Xpp3DomPerfTest.AdditionState} object. + * @return a {@link org.codehaus.plexus.util.xml.Xpp3Dom} object. + */ @Benchmark public Xpp3Dom benchmarkClone(AdditionState state) { return new Xpp3Dom( state.dom1 ); } + /** + *

    benchmarkMerge.

    + * + * @param state a {@link org.codehaus.plexus.util.xml.Xpp3DomPerfTest.AdditionState} object. + */ @Benchmark public void benchmarkMerge(AdditionState state) { Xpp3Dom.mergeXpp3Dom( state.dom1, state.dom2 ); } + /** + *

    main.

    + * + * @param args a {@link java.lang.String} object. + * @throws org.openjdk.jmh.runner.RunnerException if any. + */ public static void main( String... args ) throws RunnerException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java index 35fb5590..6a1b7078 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -31,8 +31,18 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.junit.Test; +/** + *

    Xpp3DomTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class Xpp3DomTest { + /** + *

    testShouldPerformAppendAtFirstSubElementLevel.

    + */ @Test public void testShouldPerformAppendAtFirstSubElementLevel() { @@ -69,6 +79,9 @@ public void testShouldPerformAppendAtFirstSubElementLevel() assertEquals( "t1s1", result.getChildren( "topsub1" )[1].getInputLocation() ); } + /** + *

    testShouldOverrideAppendAndDeepMerge.

    + */ @Test public void testShouldOverrideAppendAndDeepMerge() { @@ -103,6 +116,9 @@ public void testShouldOverrideAppendAndDeepMerge() assertEquals( "t1s1", result.getChildren( "topsub1" )[0].getInputLocation() ); } + /** + *

    testShouldPerformSelfOverrideAtTopLevel.

    + */ @Test public void testShouldPerformSelfOverrideAtTopLevel() { @@ -127,6 +143,9 @@ public void testShouldPerformSelfOverrideAtTopLevel() assertEquals( "t1top", result.getInputLocation() ); } + /** + *

    testShouldMergeValuesAtTopLevelByDefault.

    + */ @Test public void testShouldMergeValuesAtTopLevelByDefault() { @@ -151,6 +170,9 @@ public void testShouldMergeValuesAtTopLevelByDefault() assertEquals( "t2top", result.getInputLocation() ); } + /** + *

    testShouldMergeValuesAtTopLevel.

    + */ @Test public void testShouldMergeValuesAtTopLevel() { @@ -172,6 +194,9 @@ public void testShouldMergeValuesAtTopLevel() assertEquals( result.getValue(), t2.getValue() ); } + /** + *

    testNullAttributeNameOrValue.

    + */ @Test public void testNullAttributeNameOrValue() { @@ -196,6 +221,9 @@ public void testNullAttributeNameOrValue() t1.toString(); } + /** + *

    testEquals.

    + */ @Test public void testEquals() { @@ -206,6 +234,12 @@ public void testEquals() assertFalse( dom.equals( new Xpp3Dom( (String) null ) ) ); } + /** + *

    testEqualsIsNullSafe.

    + * + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + * @throws java.io.IOException if any. + */ @Test public void testEqualsIsNullSafe() throws XmlPullParserException, IOException @@ -233,6 +267,12 @@ public void testEqualsIsNullSafe() } } + /** + *

    testShouldOverwritePluginConfigurationSubItemsByDefault.

    + * + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + * @throws java.io.IOException if any. + */ @Test public void testShouldOverwritePluginConfigurationSubItemsByDefault() throws XmlPullParserException, IOException @@ -255,6 +295,12 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault() assertEquals( "child", item.getInputLocation() ); } + /** + *

    testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet.

    + * + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + * @throws java.io.IOException if any. + */ @Test public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() throws XmlPullParserException, IOException @@ -283,6 +329,11 @@ public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() assertEquals( "child", item[2].getInputLocation() ); } + /** + *

    testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() throws Exception @@ -301,6 +352,11 @@ public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty( assertEquals( null, items.getChild( 2 ).getValue() ); } + /** + *

    testShouldCopyRecessiveChildrenNotPresentInTarget.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldCopyRecessiveChildrenNotPresentInTarget() throws Exception @@ -319,6 +375,12 @@ public void testShouldCopyRecessiveChildrenNotPresentInTarget() assertNotSame( result.getChild( "bar" ), recessiveConfig.getChild( "bar" ) ); } + /** + *

    testDupeChildren.

    + * + * @throws java.io.IOException if any. + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + */ @Test public void testDupeChildren() throws IOException, XmlPullParserException @@ -329,6 +391,11 @@ public void testDupeChildren() assertEquals( "y", dom.getChild( "foo" ).getValue() ); } + /** + *

    testShouldRemoveEntireElementWithAttributesAndChildren.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldRemoveEntireElementWithAttributesAndChildren() throws Exception @@ -344,6 +411,11 @@ public void testShouldRemoveEntireElementWithAttributesAndChildren() assertEquals( "config", result.getName() ); } + /** + *

    testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java index 9a03fa35..548c93e3 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java @@ -23,8 +23,20 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.junit.Test; +/** + *

    Xpp3DomUtilsTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ public class Xpp3DomUtilsTest { + /** + *

    testCombineId.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCombineId() throws Exception @@ -60,6 +72,11 @@ public void testCombineId() assertEquals( "right", p2.getChild( "value" ).getInputLocation() ); } + /** + *

    testCombineKeys.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCombineKeys() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java index c218e4c7..93c00a7d 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java @@ -23,12 +23,19 @@ import org.junit.Test; /** + *

    Xpp3DomWriterTest class.

    + * * @author Edwin Punzalan + * @version $Id: $Id + * @since 3.4.0 */ public class Xpp3DomWriterTest { private static final String LS = System.getProperty( "line.separator" ); + /** + *

    testWriter.

    + */ @Test public void testWriter() { @@ -39,6 +46,9 @@ public void testWriter() assertEquals( "Check if output matches", createExpectedXML( true ), writer.toString() ); } + /** + *

    testWriterNoEscape.

    + */ @Test public void testWriterNoEscape() { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java index 587083a5..4b1f5eb5 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test.java @@ -18,6 +18,8 @@ * XML test files base folder:
    xmlconf/ibm/
    * * @author Gabriel Belingueres + * @version $Id: $Id + * @since 3.4.0 */ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production24_Test { @@ -26,6 +28,9 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX MXParser parser; + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -33,14 +38,14 @@ public void setUp() } /** - * 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 IOException if there is an I/O error - */ + * 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 @@ -65,9 +70,7 @@ public void testibm_not_wf_P24_ibm24n01xml() * Sections:
    2.8
    * Version: * - * @throws XmlPullParserException if there is a problem parsing the XML file - * @throws FileNotFoundException if the testing XML file is not found - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n02xml() @@ -93,7 +96,7 @@ public void testibm_not_wf_P24_ibm24n02xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n03xml() @@ -119,7 +122,7 @@ public void testibm_not_wf_P24_ibm24n03xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n04xml() @@ -145,7 +148,7 @@ public void testibm_not_wf_P24_ibm24n04xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n05xml() @@ -171,7 +174,7 @@ public void testibm_not_wf_P24_ibm24n05xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n06xml() @@ -197,7 +200,7 @@ public void testibm_not_wf_P24_ibm24n06xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n07xml() @@ -223,7 +226,7 @@ public void testibm_not_wf_P24_ibm24n07xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n08xml() @@ -249,7 +252,7 @@ public void testibm_not_wf_P24_ibm24n08xml() * Sections:
    2.8
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P24_ibm24n09xml() diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java index 65ee879f..92998db9 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test.java @@ -24,6 +24,8 @@ * XML test files base folder:
    xmlconf/ibm/
    * * @author Gabriel Belingueres + * @version $Id: $Id + * @since 3.4.0 */ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production2_Test { @@ -31,6 +33,9 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX MXParser parser; + /** + *

    setUp.

    + */ @Before public void setUp() { parser = new MXParser(); @@ -43,7 +48,7 @@ public void setUp() { * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n01xml() @@ -70,7 +75,7 @@ public void testibm_not_wf_P02_ibm02n01xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n02xml() @@ -96,7 +101,7 @@ public void testibm_not_wf_P02_ibm02n02xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n03xml() @@ -122,7 +127,7 @@ public void testibm_not_wf_P02_ibm02n03xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n04xml() @@ -148,7 +153,7 @@ public void testibm_not_wf_P02_ibm02n04xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n05xml() @@ -174,7 +179,7 @@ public void testibm_not_wf_P02_ibm02n05xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n06xml() @@ -200,7 +205,7 @@ public void testibm_not_wf_P02_ibm02n06xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n07xml() throws IOException { @@ -223,7 +228,7 @@ public void testibm_not_wf_P02_ibm02n07xml() throws IOException { * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n08xml() @@ -249,7 +254,7 @@ public void testibm_not_wf_P02_ibm02n08xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n09xml() @@ -275,7 +280,7 @@ public void testibm_not_wf_P02_ibm02n09xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n10xml() @@ -301,7 +306,7 @@ public void testibm_not_wf_P02_ibm02n10xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n11xml() @@ -327,7 +332,7 @@ public void testibm_not_wf_P02_ibm02n11xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n12xml() @@ -353,7 +358,7 @@ public void testibm_not_wf_P02_ibm02n12xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n13xml() @@ -379,7 +384,7 @@ public void testibm_not_wf_P02_ibm02n13xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n14xml() @@ -405,7 +410,7 @@ public void testibm_not_wf_P02_ibm02n14xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n15xml() @@ -431,7 +436,7 @@ public void testibm_not_wf_P02_ibm02n15xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n16xml() @@ -457,7 +462,7 @@ public void testibm_not_wf_P02_ibm02n16xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n17xml() @@ -483,7 +488,7 @@ public void testibm_not_wf_P02_ibm02n17xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n18xml() @@ -509,7 +514,7 @@ public void testibm_not_wf_P02_ibm02n18xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n19xml() @@ -535,7 +540,7 @@ public void testibm_not_wf_P02_ibm02n19xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n20xml() @@ -561,7 +566,7 @@ public void testibm_not_wf_P02_ibm02n20xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n21xml() @@ -587,7 +592,7 @@ public void testibm_not_wf_P02_ibm02n21xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n22xml() @@ -613,7 +618,7 @@ public void testibm_not_wf_P02_ibm02n22xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n23xml() @@ -639,7 +644,7 @@ public void testibm_not_wf_P02_ibm02n23xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n24xml() @@ -665,7 +670,7 @@ public void testibm_not_wf_P02_ibm02n24xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n25xml() @@ -691,7 +696,7 @@ public void testibm_not_wf_P02_ibm02n25xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n26xml() @@ -717,7 +722,7 @@ public void testibm_not_wf_P02_ibm02n26xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n27xml() @@ -743,7 +748,7 @@ public void testibm_not_wf_P02_ibm02n27xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n28xml() @@ -769,7 +774,7 @@ public void testibm_not_wf_P02_ibm02n28xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n29xml() @@ -795,7 +800,7 @@ public void testibm_not_wf_P02_ibm02n29xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @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. */ @@ -825,7 +830,7 @@ public void testibm_not_wf_P02_ibm02n30xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @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. */ @@ -854,7 +859,7 @@ public void testibm_not_wf_P02_ibm02n31xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n32xml() @@ -881,7 +886,7 @@ public void testibm_not_wf_P02_ibm02n32xml() * Sections:
    2.2
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P02_ibm02n33xml() 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 index 446afef2..a6a80030 100644 --- 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 @@ -17,6 +17,8 @@ * XML test files base folder:
    xmlconf/ibm/
    * * @author Gabriel Belingueres + * @version $Id: $Id + * @since 3.4.0 */ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production32_Test { @@ -25,6 +27,9 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX MXParser parser; + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -38,7 +43,7 @@ public void setUp() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n01xml() @@ -64,7 +69,7 @@ public void testibm_not_wf_P32_ibm32n01xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n02xml() @@ -90,7 +95,7 @@ public void testibm_not_wf_P32_ibm32n02xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n03xml() @@ -116,7 +121,7 @@ public void testibm_not_wf_P32_ibm32n03xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n04xml() @@ -142,7 +147,7 @@ public void testibm_not_wf_P32_ibm32n04xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n05xml() @@ -169,7 +174,7 @@ public void testibm_not_wf_P32_ibm32n05xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n06xml() @@ -195,7 +200,7 @@ public void testibm_not_wf_P32_ibm32n06xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n07xml() @@ -221,7 +226,7 @@ public void testibm_not_wf_P32_ibm32n07xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P32_ibm32n08xml() @@ -247,7 +252,7 @@ public void testibm_not_wf_P32_ibm32n08xml() * Sections:
    2.9
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error * * NOTE: This test is SKIPPED as MXParser does not support parsing inside DOCTYPEDECL. */ diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java index c1d0f2e6..639f1589 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test.java @@ -19,6 +19,8 @@ * XML test files base folder:
    xmlconf/ibm/
    * * @author Gabriel Belingueres + * @version $Id: $Id + * @since 3.4.0 */ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production66_Test { @@ -27,6 +29,9 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX MXParser parser; + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -40,7 +45,7 @@ public void setUp() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n01xml() @@ -66,7 +71,7 @@ public void testibm_not_wf_P66_ibm66n01xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n02xml() @@ -92,7 +97,7 @@ public void testibm_not_wf_P66_ibm66n02xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n03xml() @@ -118,7 +123,7 @@ public void testibm_not_wf_P66_ibm66n03xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n04xml() @@ -144,7 +149,9 @@ public void testibm_not_wf_P66_ibm66n04xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @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() @@ -170,7 +177,7 @@ public void testibm_not_wf_P66_ibm66n05xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n06xml() @@ -196,7 +203,7 @@ public void testibm_not_wf_P66_ibm66n06xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n07xml() @@ -222,7 +229,7 @@ public void testibm_not_wf_P66_ibm66n07xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n08xml() @@ -248,7 +255,7 @@ public void testibm_not_wf_P66_ibm66n08xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n09xml() @@ -274,7 +281,7 @@ public void testibm_not_wf_P66_ibm66n09xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n10xml() @@ -300,7 +307,7 @@ public void testibm_not_wf_P66_ibm66n10xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n11xml() @@ -326,7 +333,7 @@ public void testibm_not_wf_P66_ibm66n11xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n12xml() @@ -352,7 +359,7 @@ public void testibm_not_wf_P66_ibm66n12xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n13xml() @@ -378,7 +385,7 @@ public void testibm_not_wf_P66_ibm66n13xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n14xml() @@ -404,7 +411,7 @@ public void testibm_not_wf_P66_ibm66n14xml() * Sections:
    4.1
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P66_ibm66n15xml() 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 index 344bb555..e5510bb5 100644 --- 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 @@ -17,6 +17,8 @@ * XML test files base folder:
    xmlconf/ibm/
    * * @author Gabriel Belingueres + * @version $Id: $Id + * @since 3.4.0 */ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMXMLConformanceTestSuite_Production80_Test { @@ -25,6 +27,9 @@ public class IBMXML10Tests_Test_IBMXMLConformanceTestSuite_not_wftests_Test_IBMX MXParser parser; + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -38,7 +43,7 @@ public void setUp() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P80_ibm80n01xml() @@ -64,7 +69,7 @@ public void testibm_not_wf_P80_ibm80n01xml() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P80_ibm80n02xml() @@ -90,7 +95,7 @@ public void testibm_not_wf_P80_ibm80n02xml() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P80_ibm80n03xml() @@ -116,7 +121,7 @@ public void testibm_not_wf_P80_ibm80n03xml() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P80_ibm80n04xml() @@ -142,7 +147,7 @@ public void testibm_not_wf_P80_ibm80n04xml() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P80_ibm80n05xml() @@ -168,7 +173,7 @@ public void testibm_not_wf_P80_ibm80n05xml() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testibm_not_wf_P80_ibm80n06xml() 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 index 934f8083..c4d1a74f 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserPerfTest.java @@ -38,6 +38,13 @@ import org.openjdk.jmh.runner.options.OptionsBuilder; import org.openjdk.jmh.runner.options.TimeValue; +/** + *

    MXParserPerfTest class.

    + * + * @author herve + * @version $Id: $Id + * @since 3.4.0 + */ @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) @@ -59,12 +66,26 @@ public void setUp() throws IOException, XmlPullParserException { } + /** + *

    benchmarkBuild.

    + * + * @param state a {@link org.codehaus.plexus.util.xml.pull.MXParserPerfTest.AdditionState} object. + * @return a {@link org.codehaus.plexus.util.xml.Xpp3Dom} object. + * @throws java.io.IOException if any. + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + */ @Benchmark public Xpp3Dom benchmarkBuild( AdditionState state ) throws IOException, XmlPullParserException { return Xpp3DomBuilder.build( new ByteArrayInputStream( state.data ), null ); } + /** + *

    main.

    + * + * @param args a {@link java.lang.String} object. + * @throws org.openjdk.jmh.runner.RunnerException if any. + */ public static void main( String... args ) throws RunnerException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 82bdeac9..7b9fe30a 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -27,11 +27,19 @@ import org.junit.Test; /** - * @author Trygve Laugstøl + *

    MXParserTest class.

    * + * @author Trygve Laugstøl + * @version $Id: $Id + * @since 3.4.0 */ public class MXParserTest { + /** + *

    testHexadecimalEntities.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testHexadecimalEntities() throws Exception @@ -53,6 +61,11 @@ public void testHexadecimalEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + /** + *

    testDecimalEntities.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testDecimalEntities() throws Exception @@ -74,6 +87,11 @@ public void testDecimalEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + /** + *

    testPredefinedEntities.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testPredefinedEntities() throws Exception @@ -95,6 +113,12 @@ public void testPredefinedEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + /** + *

    testEntityReplacementMap.

    + * + * @throws org.codehaus.plexus.util.xml.pull.XmlPullParserException if any. + * @throws java.io.IOException if any. + */ @Test public void testEntityReplacementMap() throws XmlPullParserException, IOException @@ -111,6 +135,11 @@ public void testEntityReplacementMap() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + /** + *

    testCustomEntities.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testCustomEntities() throws Exception @@ -136,6 +165,11 @@ public void testCustomEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + /** + *

    testUnicodeEntities.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testUnicodeEntities() throws Exception @@ -159,6 +193,11 @@ public void testUnicodeEntities() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + /** + *

    testInvalidCharacterReferenceHexa.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInvalidCharacterReferenceHexa() throws Exception @@ -179,6 +218,11 @@ public void testInvalidCharacterReferenceHexa() } } + /** + *

    testValidCharacterReferenceHexa.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testValidCharacterReferenceHexa() throws Exception @@ -222,6 +266,11 @@ public void testValidCharacterReferenceHexa() } } + /** + *

    testInvalidCharacterReferenceDecimal.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testInvalidCharacterReferenceDecimal() throws Exception @@ -242,6 +291,11 @@ public void testInvalidCharacterReferenceDecimal() } } + /** + *

    testValidCharacterReferenceDecimal.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testValidCharacterReferenceDecimal() throws Exception @@ -286,6 +340,11 @@ public void testValidCharacterReferenceDecimal() } } + /** + *

    testProcessingInstruction.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testProcessingInstruction() throws Exception @@ -301,6 +360,11 @@ public void testProcessingInstruction() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + /** + *

    testProcessingInstructionsContainingXml.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testProcessingInstructionsContainingXml() throws Exception @@ -326,6 +390,11 @@ public void testProcessingInstructionsContainingXml() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + /** + *

    testSubsequentProcessingInstructionShort.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testSubsequentProcessingInstructionShort() throws Exception @@ -348,6 +417,11 @@ public void testSubsequentProcessingInstructionShort() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + /** + *

    testSubsequentProcessingInstructionMoreThan8k.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testSubsequentProcessingInstructionMoreThan8k() throws Exception @@ -391,6 +465,11 @@ public void testSubsequentProcessingInstructionMoreThan8k() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + /** + *

    testLargeText_NoOverflow.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testLargeText_NoOverflow() throws Exception @@ -413,6 +492,11 @@ public void testLargeText_NoOverflow() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + /** + *

    testMalformedProcessingInstructionAfterTag.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedProcessingInstructionAfterTag() throws Exception @@ -439,6 +523,11 @@ public void testMalformedProcessingInstructionAfterTag() } } + /** + *

    testMalformedProcessingInstructionBeforeTag.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedProcessingInstructionBeforeTag() throws Exception @@ -465,6 +554,11 @@ public void testMalformedProcessingInstructionBeforeTag() } } + /** + *

    testMalformedProcessingInstructionSpaceBeforeName.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedProcessingInstructionSpaceBeforeName() throws Exception @@ -493,6 +587,11 @@ public void testMalformedProcessingInstructionSpaceBeforeName() } } + /** + *

    testMalformedProcessingInstructionNoClosingQuestionMark.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedProcessingInstructionNoClosingQuestionMark() throws Exception @@ -521,6 +620,11 @@ public void testMalformedProcessingInstructionNoClosingQuestionMark() } } + /** + *

    testSubsequentMalformedProcessingInstructionNoClosingQuestionMark.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() throws Exception @@ -549,6 +653,11 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() } } + /** + *

    testMalformedXMLRootElement.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedXMLRootElement() throws Exception @@ -570,6 +679,11 @@ public void testMalformedXMLRootElement() } } + /** + *

    testMalformedXMLRootElement2.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedXMLRootElement2() throws Exception @@ -591,6 +705,11 @@ public void testMalformedXMLRootElement2() } } + /** + *

    testMalformedXMLRootElement3.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedXMLRootElement3() throws Exception @@ -613,6 +732,11 @@ public void testMalformedXMLRootElement3() } } + /** + *

    testMalformedXMLRootElement4.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedXMLRootElement4() throws Exception @@ -637,6 +761,11 @@ public void testMalformedXMLRootElement4() } } + /** + *

    testMalformedXMLRootElement5.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testMalformedXMLRootElement5() throws Exception @@ -661,6 +790,11 @@ public void testMalformedXMLRootElement5() } } + /** + *

    testXMLDeclVersionOnly.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testXMLDeclVersionOnly() throws Exception @@ -682,6 +816,11 @@ public void testXMLDeclVersionOnly() } } + /** + *

    testXMLDeclVersionEncodingStandaloneNoSpace.

    + * + * @throws java.lang.Exception if any. + */ @Test public void testXMLDeclVersionEncodingStandaloneNoSpace() throws Exception diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java index cf1fe16a..854fb494 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test.java @@ -20,6 +20,8 @@ * XML test files base folder:
    xmlconf/eduni/misc/
    * * @author Gabriel Belingueres + * @version $Id: $Id + * @since 3.4.0 */ public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test { @@ -28,6 +30,9 @@ public class eduni_misc_Test_BjoernHoehrmannviaHST2013_09_18_Test MXParser parser; + /** + *

    setUp.

    + */ @Before public void setUp() { @@ -41,7 +46,7 @@ public void setUp() * Sections:
    2.2 [2], 4.1 [66]
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_bh_001() @@ -67,7 +72,7 @@ public void testhst_bh_001() * Sections:
    2.2 [2], 4.1 [66]
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_bh_002() @@ -93,7 +98,7 @@ public void testhst_bh_002() * Sections:
    2.2 [2], 4.1 [66]
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_bh_003() @@ -119,7 +124,7 @@ public void testhst_bh_003() * Sections:
    2.2 [2], 4.1 [66]
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_bh_004() @@ -145,7 +150,7 @@ public void testhst_bh_004() * Sections:
    3.1 [41]
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error * * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. */ @@ -173,7 +178,7 @@ public void testhst_bh_005() * Sections:
    3.1 [41]
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error * * NOTE: This test is SKIPPED as MXParser do not supports DOCDECL parsing. */ @@ -201,7 +206,7 @@ public void testhst_bh_006() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_lhs_007() @@ -228,7 +233,7 @@ public void testhst_lhs_007() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_lhs_008() @@ -255,7 +260,7 @@ public void testhst_lhs_008() * Sections:
    4.3.3
    * Version: * - * @throws IOException if there is an I/O error + * @throws java.io.IOException if there is an I/O error */ @Test public void testhst_lhs_009() @@ -275,4 +280,4 @@ public void testhst_lhs_009() } } -} \ No newline at end of file +} From 6f2b70a826dc4885b2a3206ec374cba75a4f09bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 29 Jul 2021 20:03:29 +0200 Subject: [PATCH 076/133] [maven-release-plugin] prepare release plexus-utils-3.4.0 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0195563b..14a4ea4e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ limitations under the License. plexus-utils - 3.4.0-SNAPSHOT + 3.4.0 Plexus Common Utilities A 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.git scm:git:git@github.com:codehaus-plexus/plexus-utils.git http://github.com/codehaus-plexus/plexus-utils - HEAD + plexus-utils-3.4.0 github @@ -51,7 +51,7 @@ limitations under the License. - 2020-01-20T18:52:37Z + 2021-07-29T18:02:50Z From fe646bf079eeae5a2e188dc1f91c529b0334e470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 29 Jul 2021 20:03:35 +0200 Subject: [PATCH 077/133] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 14a4ea4e..031fa9c5 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ limitations under the License. plexus-utils - 3.4.0 + 3.4.1-SNAPSHOT Plexus Common Utilities A 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.git scm:git:git@github.com:codehaus-plexus/plexus-utils.git http://github.com/codehaus-plexus/plexus-utils - plexus-utils-3.4.0 + HEAD github @@ -51,7 +51,7 @@ limitations under the License. - 2021-07-29T18:02:50Z + 2021-07-29T18:03:35Z From 6aee20db3b1e5ef00ebabbd3b5f62116419691ba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:49:03 +1000 Subject: [PATCH 078/133] Bump actions/checkout from 2 to 2.3.4 (#154) Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 2.3.4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v2.3.4) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/maven.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f6ec7c49..b0dfc833 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9015bea7..027cda56 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v2.3.4 - name: Set up cache for ~./m2/repository uses: actions/cache@v2.1.5 From 0d8c1cbeb9bc4a18c1d3fa570c02f06544d0f310 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:52:33 +1000 Subject: [PATCH 079/133] Bump actions/cache from 2.1.5 to 2.1.6 (#161) Bumps [actions/cache](https://github.com/actions/cache) from 2.1.5 to 2.1.6. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.5...v2.1.6) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 027cda56..bfdedc69 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v2.3.4 - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.5 + uses: actions/cache@v2.1.6 with: path: ~/.m2/repository key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} From d8256eb9df834177e8212644c86a98d3c63a1ecc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:53:12 +1000 Subject: [PATCH 080/133] Bump actions/cache from 2.1.5 to 2.1.6 (#161) Bumps [actions/cache](https://github.com/actions/cache) from 2.1.5 to 2.1.6. - [Release notes](https://github.com/actions/cache/releases) - [Commits](https://github.com/actions/cache/compare/v2.1.5...v2.1.6) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From f270f591528e9742f5f74edcee5995b54db0056c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:53:30 +1000 Subject: [PATCH 081/133] Bump jmh-core from 1.29 to 1.32 (#160) Bumps jmh-core from 1.29 to 1.32. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 031fa9c5..4f5b81bd 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.29 + 1.32 test From 572701fd7740c3ad96b15ce55f03b6ec417778e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:53:39 +1000 Subject: [PATCH 082/133] Bump jmh-generator-annprocess from 1.29 to 1.32 (#159) Bumps jmh-generator-annprocess from 1.29 to 1.32. Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4f5b81bd..5ee9740f 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.29 + 1.32 test From c778cf1f0fd47125b851a6a1ceb6b2191b2d7b8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 11:08:46 +1000 Subject: [PATCH 083/133] Bump actions/setup-java from 1 to 2.1.0 (#157) * Bump actions/setup-java from 1 to 2.1.0 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 1 to 2.1.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v1...v2.1.0) Signed-off-by: dependabot[bot] * fix setup-java action upgrade Signed-off-by: Olivier Lamy Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Olivier Lamy --- .github/workflows/maven.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bfdedc69..873d2a75 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,6 +26,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] java: [8, 11, 16, 17-ea] + jdk: [adopt-hotspot, zulu, adopt-openj9] fail-fast: false runs-on: ${{ matrix.os }} @@ -44,8 +45,9 @@ jobs: maven-${{ matrix.os }}- - name: Set up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@v2.1.0 with: + distribution: ${{ matrix.jdk }} java-version: ${{ matrix.java }} - name: Build with Maven From 85b7e7f271847640d146ddbd409360f3878adae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Fri, 30 Jul 2021 05:21:23 +0200 Subject: [PATCH 084/133] fix link to search.maven.org: HTTPS required --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ddd8214b..bd2877bf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Plexus-Utils ============ [![Build Status](https://github.com/codehaus-plexus/plexus-utils/actions/workflows/maven.yml/badge.svg)](https://github.com/codehaus-plexus/plexus-utils/actions) -[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](http://search.maven.org/artifact/org.codehaus.plexus/plexus-utils) +[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-utils.svg?label=Maven%20Central)](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) From 0a18bb8af8eef7d8d33b1b466a4ad2889128ef02 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 30 Jul 2021 02:02:08 +0000 Subject: [PATCH 085/133] Bump junit from 4.13.1 to 4.13.2 Bumps [junit](https://github.com/junit-team/junit4) from 4.13.1 to 4.13.2. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.13.1.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.13.1...r4.13.2) --- updated-dependencies: - dependency-name: junit:junit dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ee9740f..da9423b5 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ limitations under the License. junit junit - 4.13.1 + 4.13.2 test From 9f8c3ba2b36f5fefa5bb1eb5c25ed825e20bb3d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Aug 2021 02:01:57 +0000 Subject: [PATCH 086/133] Bump actions/setup-java from 2.1.0 to 2.2.0 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.1.0 to 2.2.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.1.0...v2.2.0) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 873d2a75..47af7977 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -45,7 +45,7 @@ jobs: maven-${{ matrix.os }}- - name: Set up JDK - uses: actions/setup-java@v2.1.0 + uses: actions/setup-java@v2.2.0 with: distribution: ${{ matrix.jdk }} java-version: ${{ matrix.java }} From e797c88ad4b450400f938e34133aadcfa7231fb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Aug 2021 02:01:56 +0000 Subject: [PATCH 087/133] Bump jmh-core from 1.32 to 1.33 Bumps jmh-core from 1.32 to 1.33. --- updated-dependencies: - dependency-name: org.openjdk.jmh:jmh-core dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index da9423b5..74260d23 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.32 + 1.33 test From 938e6f860d364ebebdb1e25a60be0d4bf499318c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Aug 2021 02:01:57 +0000 Subject: [PATCH 088/133] Bump jmh-generator-annprocess from 1.32 to 1.33 Bumps jmh-generator-annprocess from 1.32 to 1.33. --- updated-dependencies: - dependency-name: org.openjdk.jmh:jmh-generator-annprocess dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 74260d23..23c0ef09 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.32 + 1.33 test From 5e6d78ec018c3dc4a4c128fc468fdde7726a3983 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 22 Aug 2021 17:33:47 +0200 Subject: [PATCH 089/133] Delete .travis.yml --- .travis.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3cafdcfc..00000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -arch: - - amd64 - - ppc64le - -addons: - apt: - packages: maven - -language: java -jdk: - - openjdk8 - - openjdk11 - - openjdk16 - -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 From bb346ad63efc6f0cbfd5b1f1736df677bad276cf Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Thu, 26 Aug 2021 20:43:05 -0300 Subject: [PATCH 090/133] Fixes #163: Regression: encoding error when parsing a ISO-8859-1 xml (#164) - Fixed code. - Added tests. --- .../plexus/util/xml/pull/MXParser.java | 8 +- .../plexus/util/xml/pull/MXParserTest.java | 58 + .../xml/test-encoding-ISO-8859-1.xml | 1503 +++++++++++++++++ 3 files changed, 1568 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/xml/test-encoding-ISO-8859-1.xml 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 bc1c3608..3874f572 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 @@ -16,6 +16,7 @@ import java.io.UnsupportedEncodingException; import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlReader; //import java.util.Hashtable; @@ -663,7 +664,12 @@ public void setInput( Reader in ) reset(); reader = in; - if ( reader instanceof InputStreamReader ) + 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 ) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 7b9fe30a..e0be666a 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -21,9 +21,15 @@ import static org.junit.Assert.fail; import java.io.EOFException; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; import java.io.StringReader; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.codehaus.plexus.util.ReaderFactory; import org.junit.Test; /** @@ -840,4 +846,56 @@ public void testXMLDeclVersionEncodingStandaloneNoSpace() } } + /** + * Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163 + * + * @throws IOException if IO error. + * + * @since 3.4.1 + */ + @Test + public void testEncodingISO_8859_1setInputReader() + throws IOException + { + try ( Reader reader = + ReaderFactory.newXmlReader( new File( "src/test/resources/xml", "test-encoding-ISO-8859-1.xml" ) ) ) + { + MXParser parser = new MXParser(); + parser.setInput( reader ); + while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + ; + assertTrue( true ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } + + /** + * Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163 + * + * @throws IOException if IO error. + * + * @since 3.4.1 + */ + @Test + public void testEncodingISO_8859_1_setInputStream() + throws IOException + { + try ( InputStream input = + Files.newInputStream( Paths.get( "src/test/resources/xml", "test-encoding-ISO-8859-1.xml" ) ) ) + { + MXParser parser = new MXParser(); + parser.setInput( input, null ); + while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + ; + assertTrue( true ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } + } diff --git a/src/test/resources/xml/test-encoding-ISO-8859-1.xml b/src/test/resources/xml/test-encoding-ISO-8859-1.xml new file mode 100644 index 00000000..ae0aefe7 --- /dev/null +++ b/src/test/resources/xml/test-encoding-ISO-8859-1.xml @@ -0,0 +1,1503 @@ + + + + 4.0.0 + + org.apache + apache + 16 + + org.apache.commons + commons-parent + pom + 39 + Apache Commons Parent + http://commons.apache.org/ + The Apache Commons Parent POM provides common settings for all Apache Commons components. + + + + + + 3.0.1 + + + + continuum + https://continuum-ci.apache.org/ + + + + + + + scm:svn:http://svn.apache.org/repos/asf/commons/proper/commons-parent/tags/commons-parent-39 + scm:svn:https://svn.apache.org/repos/asf/commons/proper/commons-parent/tags/commons-parent-39 + http://svn.apache.org/viewvc/commons/proper/commons-parent/tags/commons-parent-39 + + + + + + + + Commons User List + user-subscribe@commons.apache.org + user-unsubscribe@commons.apache.org + user@commons.apache.org + http://mail-archives.apache.org/mod_mbox/commons-user/ + + http://markmail.org/list/org.apache.commons.users/ + http://old.nabble.com/Commons---User-f319.html + http://www.mail-archive.com/user@commons.apache.org/ + http://news.gmane.org/gmane.comp.jakarta.commons.user + + + + Commons Dev List + dev-subscribe@commons.apache.org + dev-unsubscribe@commons.apache.org + dev@commons.apache.org + http://mail-archives.apache.org/mod_mbox/commons-dev/ + + http://markmail.org/list/org.apache.commons.dev/ + http://old.nabble.com/Commons---Dev-f317.html + http://www.mail-archive.com/dev@commons.apache.org/ + http://news.gmane.org/gmane.comp.jakarta.commons.devel + + + + Commons Issues List + issues-subscribe@commons.apache.org + issues-unsubscribe@commons.apache.org + http://mail-archives.apache.org/mod_mbox/commons-issues/ + + http://markmail.org/list/org.apache.commons.issues/ + http://old.nabble.com/Commons---Issues-f25499.html + http://www.mail-archive.com/issues@commons.apache.org/ + + + + Commons Commits List + commits-subscribe@commons.apache.org + commits-unsubscribe@commons.apache.org + http://mail-archives.apache.org/mod_mbox/commons-commits/ + + http://markmail.org/list/org.apache.commons.commits/ + http://www.mail-archive.com/commits@commons.apache.org/ + + + + Apache Announce List + announce-subscribe@apache.org + announce-unsubscribe@apache.org + http://mail-archives.apache.org/mod_mbox/www-announce/ + + http://markmail.org/list/org.apache.announce/ + http://old.nabble.com/Apache-News-and-Announce-f109.html + http://www.mail-archive.com/announce@apache.org/ + http://news.gmane.org/gmane.comp.apache.announce + + + + + + + + + src/main/resources + + + + ${basedir} + META-INF + + NOTICE.txt + LICENSE.txt + + + + + + + + src/test/resources + + + + ${basedir} + META-INF + + NOTICE.txt + LICENSE.txt + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + org.apache.maven.plugins + maven-assembly-plugin + 2.5.5 + + + org.apache.maven.plugins + maven-clean-plugin + 2.6.1 + + + org.apache.maven.plugins + maven-compiler-plugin + ${commons.compiler.version} + + ${maven.compiler.source} + ${maven.compiler.target} + ${commons.encoding} + + ${commons.compiler.fork} + + ${commons.compiler.compilerVersion} + ${commons.compiler.javac} + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + org.apache.maven.plugins + maven-javadoc-plugin + ${commons.javadoc.version} + + + true + ${commons.encoding} + ${commons.docEncoding} + true + + ${commons.javadoc.java.link} + ${commons.javadoc.javaee.link} + + + + true + true + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.2 + + + + org.apache.maven.plugins + maven-remote-resources-plugin + + 1.5 + + + true + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + + + org.apache.maven.plugins + maven-site-plugin + ${commons.site-plugin.version} + + + true + + + + + org.apache.maven.wagon + wagon-ssh + ${commons.wagon-ssh.version} + + + + + attach-descriptor + + attach-descriptor + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + + true + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${commons.surefire.version} + + + + org.apache.commons + commons-build-plugin + 1.4 + + ${commons.release.name} + + + + org.apache.felix + maven-bundle-plugin + 2.5.3 + true + + + org.apache.rat + apache-rat-plugin + ${commons.rat.version} + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.3 + + + org.codehaus.mojo + clirr-maven-plugin + ${commons.clirr.version} + + ${minSeverity} + + + + + + + + + + maven-assembly-plugin + + + src/assembly/src.xml + + gnu + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + javadoc.resources + generate-sources + + run + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + true + org.apache.maven.plugins + maven-enforcer-plugin + 1.3.1 + + + enforce-maven-3 + + enforce + + + + + 3.0.0 + + + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + ${commons.manifestfile} + + ${project.name} + ${project.version} + ${project.organization.name} + ${project.name} + ${project.version} + ${project.organization.name} + org.apache + ${implementation.build} + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${commons.surefire.java} + + + + + org.apache.commons + commons-build-plugin + + + org.apache.felix + maven-bundle-plugin + + + + true + + ${commons.osgi.excludeDependencies} + ${project.build.directory}/osgi + + + <_nouses>true + + <_removeheaders>JAVA_1_3_HOME,JAVA_1_4_HOME,JAVA_1_5_HOME,JAVA_1_6_HOME,JAVA_1_7_HOME,JAVA_1_8_HOME,JAVA_1_9_HOME + ${commons.osgi.symbolicName} + ${commons.osgi.export} + ${commons.osgi.private} + ${commons.osgi.import} + ${commons.osgi.dynamicImport} + ${project.url} + + + + + bundle-manifest + process-classes + + manifest + + + + + + + org.apache.rat + apache-rat-plugin + ${commons.rat.version} + + + + + site-content/** + .checkstyle + .fbprefs + .pmd + src/site/resources/download_*.cgi + src/site/resources/profile.* + + + + + + org.apache.maven.plugins + maven-scm-publish-plugin + ${commons.scm-publish.version} + + ${project.reporting.outputDirectory} + scm:svn:${commons.scmPubUrl} + ${commons.scmPubCheckoutDirectory} + ${commons.scmPubServer} + true + + + + scm-publish + site-deploy + + publish-scm + + + + + + + + + + + + + + org.apache.maven.plugins + maven-changes-plugin + ${commons.changes.version} + + ${basedir}/src/changes/changes.xml + Fix Version,Key,Component,Summary,Type,Resolution,Status + + Fix Version DESC,Type,Key DESC + Fixed + Resolved,Closed + + Bug,New Feature,Task,Improvement,Wish,Test + + true + ${commons.changes.onlyCurrentVersion} + ${commons.changes.maxEntries} + ${commons.changes.runOnlyAtExecutionRoot} + + + + + changes-report + jira-report + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${commons.javadoc.version} + + + true + ${maven.compiler.source} + ${commons.encoding} + ${commons.docEncoding} + true + true + + true + + ${commons.javadoc.java.link} + ${commons.javadoc.javaee.link} + + + + + + default + + javadoc + + + + + + org.apache.maven.plugins + maven-jxr-plugin + ${commons.jxr.version} + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${commons.project-info.version} + + + + + index + summary + modules + + project-team + scm + issue-tracking + mailing-list + dependency-info + dependency-management + dependencies + dependency-convergence + cim + + + distribution-management + + + + + + org.apache.maven.plugins + maven-site-plugin + ${commons.site-plugin.version} + + + + navigation.xml,changes.xml + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + ${commons.surefire-report.version} + + ${commons.surefire-report.aggregate} + + + + + org.apache.rat + apache-rat-plugin + ${commons.rat.version} + + + + + site-content/** + .checkstyle + .fbprefs + .pmd + src/site/resources/download_*.cgi + src/site/resources/profile.* + + + + + org.codehaus.mojo + clirr-maven-plugin + ${commons.clirr.version} + + ${minSeverity} + + + + org.codehaus.mojo + jdepend-maven-plugin + ${commons.jdepend.version} + + + + + + + + + parse-target-version + + + + user.home + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + parse-version + + + parse-version + + + javaTarget + ${maven.compiler.target} + + + + + + + + + + + + animal-sniffer + + + + src/site/resources/profile.noanimal + + + + + + java${javaTarget.majorVersion}${javaTarget.minorVersion} + + + + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + ${commons.animal-sniffer.version} + + + checkAPIcompatibility + + + + check + + + + + + org.codehaus.mojo.signature + ${animal-sniffer.signature} + ${commons.animal-sniffer.signature.version} + + + + + + + + + + jacoco + + + + src/site/resources/profile.jacoco + + + + + + org.jacoco + jacoco-maven-plugin + ${commons.jacoco.version} + + + + prepare-agent + process-test-classes + + prepare-agent + + + + report + site + + report + + + + check + + check + + + + + BUNDLE + + + CLASS + COVEREDRATIO + ${commons.jacoco.classRatio} + + + INSTRUCTION + COVEREDRATIO + ${commons.jacoco.instructionRatio} + + + METHOD + COVEREDRATIO + ${commons.jacoco.methodRatio} + + + BRANCH + COVEREDRATIO + ${commons.jacoco.branchRatio} + + + LINE + COVEREDRATIO + ${commons.jacoco.lineRatio} + + + COMPLEXITY + COVEREDRATIO + ${commons.jacoco.complexityRatio} + + + + + ${commons.jacoco.haltOnFailure} + + + + + + + + + + org.jacoco + jacoco-maven-plugin + ${commons.jacoco.version} + + + + + + + cobertura + + + src/site/resources/profile.cobertura + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${commons.cobertura.version} + + + + + + + + release + + + + + maven-gpg-plugin + + ${gpg.passphrase} + + + + sign-artifacts + verify + + sign + + + + + + maven-install-plugin + + true + + + + maven-source-plugin + + + create-source-jar + + jar + test-jar + + + + + + maven-jar-plugin + + + + test-jar + + + + true + + + + + + maven-release-plugin + + + -Prelease + + + + maven-javadoc-plugin + + + create-javadoc-jar + + javadoc + jar + + package + + + + ${maven.compiler.source} + + + + maven-assembly-plugin + true + + + + single + + package + + + + + + + + + + apache-release + + + + maven-release-plugin + + apache-release + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-test-sources + + test-jar + + + + + + maven-install-plugin + + true + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + + + + + java-1.3 + + true + 1.3 + ${JAVA_1_3_HOME}/bin/javac + ${JAVA_1_3_HOME}/bin/java + + + + + + java-1.4 + + true + 1.4 + ${JAVA_1_4_HOME}/bin/javac + ${JAVA_1_4_HOME}/bin/java + + 2.11 + + + + + + java-1.5 + + true + 1.5 + ${JAVA_1_5_HOME}/bin/javac + ${JAVA_1_5_HOME}/bin/java + + + + + + java-1.6 + + true + 1.6 + ${JAVA_1_6_HOME}/bin/javac + ${JAVA_1_6_HOME}/bin/java + + + + + + java-1.7 + + true + 1.7 + ${JAVA_1_7_HOME}/bin/javac + ${JAVA_1_7_HOME}/bin/java + + + + + + java-1.8 + + true + 1.8 + ${JAVA_1_8_HOME}/bin/javac + ${JAVA_1_8_HOME}/bin/java + + + + + + java-1.9 + + true + 1.9 + ${JAVA_1_9_HOME}/bin/javac + ${JAVA_1_9_HOME}/bin/java + + + + + + + + test-deploy + + id::default::file:target/deploy + + + + + + release-notes + + + + org.apache.maven.plugins + maven-changes-plugin + ${commons.changes.version} + + + src/changes + true + . + RELEASE-NOTES.txt + + ${commons.release.version} + + + + + create-release-notes + generate-resources + + announcement-generate + + + + + + + + + + + svn-buildnumber + + + !buildNumber.skip + !true + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + + + generate-resources + + create + + + + + + true + + ?????? + false + false + + + + + + + + javasvn + + + + org.codehaus.mojo + buildnumber-maven-plugin + + + javasvn + + + + + + + + + jdk7-plugin-fix-version + + [1.7,) + + + + 3.0.0 + + 1.14 + + + + + + site-basic + + true + true + true + true + true + true + true + true + true + true + + + + + + + + ${project.version} + RC1 + COMMONSSITE + + + + 1.3 + 1.3 + + + false + + + + + + 2.18.1 + 2.18.1 + 2.10.3 + 0.11 + 2.11 + 2.6.1 + 2.5 + 2.8 + 2.8 + 3.4 + 0.7.5.201505241946 + 2.7 + 2.0 + 3.3 + 1.1 + 2.5.5 + + 1.11 + + 1.0 + + + ${project.artifactId}-${commons.release.version} + + -bin + ${project.artifactId}-${commons.release.2.version} + + -bin + ${project.artifactId}-${commons.release.3.version} + + -bin + + + 1.00 + 0.90 + 0.95 + 0.85 + 0.85 + 0.90 + false + + + ${project.artifactId} + + + org.apache.commons.${commons.componentid} + org.apache.commons.*;version=${project.version};-noimport:=true + * + + + true + + + ${project.build.directory}/osgi/MANIFEST.MF + + + scp + + + iso-8859-1 + + ${commons.encoding} + + ${commons.encoding} + + ${commons.encoding} + + + http://docs.oracle.com/javase/7/docs/api/ + http://docs.oracle.com/javaee/6/api/ + + + yyyy-MM-dd HH:mm:ssZ + ${scmBranch}@r${buildNumber}; ${maven.build.timestamp} + + + info + + + 100 + + + false + + + false + + 100 + + false + + + ${user.home}/commons-sites + + ${project.artifactId} + + https://svn.apache.org/repos/infra/websites/production/commons/content/proper/${project.artifactId} + ${commons.site.cache}/${commons.site.path} + commons.site + + https://analysis.apache.org/ + + + + From c01b83e6715835b3e065e60643971e00a41c807f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Aug 2021 09:43:32 +1000 Subject: [PATCH 091/133] Bump actions/setup-java from 2.2.0 to 2.3.0 (#168) * Bump actions/setup-java from 2.2.0 to 2.3.0 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.2.0 to 2.3.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.2.0...v2.3.0) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * setup-java add cache and use temurin Signed-off-by: Olivier Lamy Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Olivier Lamy --- .github/workflows/maven.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 47af7977..10cbc78e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,7 +26,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] java: [8, 11, 16, 17-ea] - jdk: [adopt-hotspot, zulu, adopt-openj9] + jdk: [temurin, zulu, adopt-openj9] fail-fast: false runs-on: ${{ matrix.os }} @@ -45,8 +45,9 @@ jobs: maven-${{ matrix.os }}- - name: Set up JDK - uses: actions/setup-java@v2.2.0 + uses: actions/setup-java@v2.3.0 with: + cache: 'maven' distribution: ${{ matrix.jdk }} java-version: ${{ matrix.java }} From abc5db68410568c4c95c72f948353cbe8cd44d01 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 27 Aug 2021 10:07:15 +1000 Subject: [PATCH 092/133] [maven-release-plugin] prepare release plexus-utils-3.4.1 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 23c0ef09..164b7b15 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ limitations under the License. plexus-utils - 3.4.1-SNAPSHOT + 3.4.1 Plexus Common Utilities A 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.git scm:git:git@github.com:codehaus-plexus/plexus-utils.git http://github.com/codehaus-plexus/plexus-utils - HEAD + plexus-utils-3.4.1 github @@ -51,7 +51,7 @@ limitations under the License. - 2021-07-29T18:03:35Z + 2021-08-27T00:06:38Z From e2a3c0b59b0b8218dbb6ceaf2694d00c83e115c4 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 27 Aug 2021 10:07:22 +1000 Subject: [PATCH 093/133] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 164b7b15..014f729a 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ limitations under the License. plexus-utils - 3.4.1 + 3.4.2-SNAPSHOT Plexus Common Utilities A 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.git scm:git:git@github.com:codehaus-plexus/plexus-utils.git http://github.com/codehaus-plexus/plexus-utils - plexus-utils-3.4.1 + HEAD github @@ -51,7 +51,7 @@ limitations under the License. - 2021-08-27T00:06:38Z + 2021-08-27T00:07:22Z From cbe5a84f604e50c31efce67504c00962b7565841 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 27 Aug 2021 13:57:34 +1000 Subject: [PATCH 094/133] cache action not needed anymore --- .github/workflows/maven.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 10cbc78e..6f98066c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -35,15 +35,6 @@ jobs: - name: Checkout uses: actions/checkout@v2.3.4 - - name: Set up cache for ~./m2/repository - uses: actions/cache@v2.1.6 - with: - path: ~/.m2/repository - key: maven-${{ matrix.os }}-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} - restore-keys: | - maven-${{ matrix.os }}-java${{ matrix.java }}- - maven-${{ matrix.os }}- - - name: Set up JDK uses: actions/setup-java@v2.3.0 with: From 138d57efe3756f2d505f01720747b89af826b851 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Sep 2021 02:02:09 +0000 Subject: [PATCH 095/133] Bump actions/setup-java from 2.3.0 to 2.3.1 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.3.0 to 2.3.1. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.3.0...v2.3.1) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6f98066c..2ea5498e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -36,7 +36,7 @@ jobs: uses: actions/checkout@v2.3.4 - name: Set up JDK - uses: actions/setup-java@v2.3.0 + uses: actions/setup-java@v2.3.1 with: cache: 'maven' distribution: ${{ matrix.jdk }} From dd8e9820e5b1291156a6a013b6b34a26e44c58e2 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 15 Oct 2021 14:27:59 +1000 Subject: [PATCH 096/133] use github shared actions (#171) * use shared actions Signed-off-by: Olivier Lamy * fix reference Signed-off-by: Olivier Lamy --- .github/workflows/maven.yml | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2ea5498e..776d2439 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,26 +21,5 @@ on: [push, pull_request] jobs: build: - - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] - java: [8, 11, 16, 17-ea] - jdk: [temurin, zulu, adopt-openj9] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - name: Checkout - uses: actions/checkout@v2.3.4 - - - name: Set up JDK - uses: actions/setup-java@v2.3.1 - with: - cache: 'maven' - distribution: ${{ matrix.jdk }} - java-version: ${{ matrix.java }} - - - name: Build with Maven - run: mvn verify javadoc:javadoc -e -B -V + name: Build it + uses: codehaus-plexus/.github/.github/workflows/maven.yml@v0.0.1 From e8a8433894eae9e8f82cbba4b903508362e9322a Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Sun, 7 Nov 2021 17:52:50 +0100 Subject: [PATCH 097/133] Don't ignore valid SCM files This closes #174 and fixes #71 --- .../codehaus/plexus/util/AbstractScanner.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/AbstractScanner.java b/src/main/java/org/codehaus/plexus/util/AbstractScanner.java index af3fbc4a..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 *
  9. SurroundSCM: **/.MySCMServerInfo
  10. *
  11. Mac: **/.DS_Store
  12. *
  13. Serena Dimension: **/.metadata, **/.metadata/**
  14. - *
  15. Mercurial: **/.hg, **/.hg/**, **/.hgignore
  16. - *
  17. GIT: **/.git, **/.gitignore, **/.gitattributes, **/.git/**
  18. + *
  19. Mercurial: **/.hg, **/.hg/**
  20. + *
  21. Git: **/.git, **/.git/**
  22. *
  23. Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, * **/ChangeSet/**
  24. *
  25. 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.

    * @@ -152,7 +152,7 @@ protected static boolean matchPatternStart( String pattern, String str ) /** *

    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.

    * @@ -223,7 +223,7 @@ protected static boolean match( String pattern, String str, boolean isCaseSensit /** *

    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 @@ -253,7 +253,7 @@ public void setIncludes( String[] includes ) /** *

    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 From 1f93cc8583f872b7bc01bef1dc32979f0a2335bb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Nov 2021 15:41:08 +1000 Subject: [PATCH 098/133] Bump actions/checkout from 2.3.4 to 2.4.0 (#173) Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.4.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.4.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b0dfc833..3f39b7e2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2.3.4 + uses: actions/checkout@v2.4.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From f3f41548bed5935b69af3caa56373b461f11068b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Feb 2022 02:02:56 +0000 Subject: [PATCH 099/133] Bump release-drafter/release-drafter from 5.15.0 to 5.18.1 Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from 5.15.0 to 5.18.1. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5.15.0...v5.18.1) --- updated-dependencies: - dependency-name: release-drafter/release-drafter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 4e2af995..4ece1c1a 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,6 +7,6 @@ jobs: update_release_draft: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5.15.0 + - uses: release-drafter/release-drafter@v5.18.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9468fd780d9611fb96215f6532da9d62926ebf48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Dec 2021 02:02:56 +0000 Subject: [PATCH 100/133] Bump jmh-core from 1.33 to 1.34 Bumps jmh-core from 1.33 to 1.34. --- updated-dependencies: - dependency-name: org.openjdk.jmh:jmh-core dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 014f729a..8166a9f2 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.33 + 1.34 test From 667ce0ee7ce353a09f38511e91a51c94c2aa7e36 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Dec 2021 02:02:54 +0000 Subject: [PATCH 101/133] Bump jmh-generator-annprocess from 1.33 to 1.34 Bumps jmh-generator-annprocess from 1.33 to 1.34. --- updated-dependencies: - dependency-name: org.openjdk.jmh:jmh-generator-annprocess dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8166a9f2..a758c676 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.33 + 1.34 test From 3896620b4fbf031b1b02b4d46b328c5839a231da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20=C5=BBygie=C5=82o?= Date: Thu, 24 Feb 2022 12:28:56 +0100 Subject: [PATCH 102/133] Use (already) precalculated value --- .../org/codehaus/plexus/util/xml/pull/MXSerializer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 cd1edc59..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 @@ -460,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" ); @@ -477,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 { From b99f7c0e46d8b08d63afa4c2c7d274ebf5ebcc94 Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sat, 2 Apr 2022 12:31:39 -0300 Subject: [PATCH 103/133] Fixed regressions: * #163 - new case: Don't assume UTF8 as default, to allow parsing from String. * #194 - Incorrect getText() after parsing the DOCDECL section. * Added tests exercising other regressions exposed while fixing this issues. --- .../plexus/util/xml/pull/MXParser.java | 157 ++++-- .../plexus/util/xml/pull/MXParserTest.java | 495 ++++++++++++++++++ src/test/resources/xml/test-entities-dos.xml | 6 + .../xml/test-entities-in-attr-dos.xml | 9 + .../resources/xml/test-entities-in-attr.xml | 9 + src/test/resources/xml/test-entities.xml | 6 + 6 files changed, 637 insertions(+), 45 deletions(-) create mode 100644 src/test/resources/xml/test-entities-dos.xml create mode 100644 src/test/resources/xml/test-entities-in-attr-dos.xml create mode 100644 src/test/resources/xml/test-entities-in-attr.xml create mode 100644 src/test/resources/xml/test-entities.xml 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 3874f572..e21b66cb 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 @@ -124,7 +124,7 @@ private String newStringIntern( char[] cbuf, int off, int len ) // private String elValue[]; private int elNamespaceCount[]; - private String fileEncoding = "UTF8"; + private String fileEncoding = null; /** * Make sure that we have enough space to keep element stack if passed size. It will always create one additional @@ -587,8 +587,8 @@ 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 ) @@ -1596,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 ) { @@ -1628,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 ) { @@ -2675,9 +2675,28 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' ) return ch; } - private 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[] parseEntityRef() + private char[] resolvedEntityRefCharBuf = BUF_NOT_RESOLVED; + + /** + * 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 @@ -2686,6 +2705,8 @@ private char[] parseEntityRef() // ASSUMPTION just after & entityRefName = null; posStart = pos; + int len = 0; + resolvedEntityRefCharBuf = BUF_NOT_RESOLVED; char ch = more(); if ( ch == '#' ) { @@ -2750,7 +2771,6 @@ else if ( ch >= 'A' && ch <= 'F' ) ch = more(); } } - posEnd = pos - 1; boolean isValidCodePoint = true; try @@ -2759,7 +2779,7 @@ else if ( ch >= 'A' && ch <= 'F' ) isValidCodePoint = isValidCodePoint( codePoint ); if ( isValidCodePoint ) { - charRefOneCharBuf = Character.toChars( codePoint ); + resolvedEntityRefCharBuf = Character.toChars( codePoint ); } } catch ( IllegalArgumentException e ) @@ -2775,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 '" @@ -2801,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++] = '<'; @@ -2823,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' ) { @@ -2832,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' ) @@ -2842,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' ) @@ -2852,25 +2867,65 @@ 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; + } + + /** + * 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: {@link https://www.w3.org/TR/REC-xml/#NT-Char} + * 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. @@ -2883,8 +2938,6 @@ private static boolean isValidCodePoint( int codePoint ) } private char[] lookuEntityReplacement( int entityNameLen ) - throws XmlPullParserException, IOException - { if ( !allStringsInterned ) { @@ -2919,7 +2972,7 @@ private char[] lookuEntityReplacement( int entityNameLen ) } } } - return null; + return BUF_NOT_RESOLVED; } private void parseComment() @@ -2977,7 +3030,7 @@ else if (isValidCodePoint( ch )) } else { - throw new XmlPullParserException( "Illegal character 0x" + Integer.toHexString(((int) ch)) + " found in comment", this, null ); + throw new XmlPullParserException( "Illegal character 0x" + Integer.toHexString(ch) + " found in comment", this, null ); } if ( normalizeIgnorableWS ) { @@ -3484,7 +3537,8 @@ else if ( ch == '>' && bracketLevel == 0 ) break; else if ( ch == '&' ) { - extractEntityRef(); + extractEntityRefInDocDecl(); + continue; } if ( normalizeIgnorableWS ) { @@ -3536,6 +3590,19 @@ else if ( ch == '\n' ) } posEnd = pos - 1; + text = null; + } + + private void extractEntityRefInDocDecl() + throws XmlPullParserException, IOException + { + // extractEntityRef + posEnd = pos - 1; + + int prevPosStart = posStart; + parseEntityRefInDocDecl(); + + posStart = prevPosStart; } private void extractEntityRef() @@ -3559,9 +3626,9 @@ private void extractEntityRef() } // assert usePC == true; - final char[] resolvedEntity = parseEntityRef(); + parseEntityRef(); // check if replacement text can be resolved !!! - if ( resolvedEntity == null ) + if ( resolvedEntityRefCharBuf == BUF_NOT_RESOLVED ) { if ( entityRefName == null ) { @@ -3571,7 +3638,7 @@ private void extractEntityRef() + "'", this, null ); } // write into PC replacement text - do merge for replacement text!!!! - for ( char aResolvedEntity : resolvedEntity ) + for ( char aResolvedEntity : resolvedEntityRefCharBuf ) { if ( pcEnd >= pc.length ) { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index e0be666a..6fc6e9c6 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -17,6 +17,7 @@ */ import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -29,6 +30,7 @@ import java.nio.file.Files; import java.nio.file.Paths; +import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import org.junit.Test; @@ -898,4 +900,497 @@ public void testEncodingISO_8859_1_setInputStream() } } + /** + * Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163 + * + * Another case of bug #163: File encoding information is lost after the input file is copied to a String. + * + * @throws IOException if IO error. + * + * @since 3.4.2 + */ + @Test + public void testEncodingISO_8859_1setStringReader() + throws IOException + { + try ( Reader reader = + ReaderFactory.newXmlReader( new File( "src/test/resources/xml", "test-encoding-ISO-8859-1.xml" ) ) ) + { + MXParser parser = new MXParser(); + String xmlFileContents = IOUtil.toString( reader ); + parser.setInput( new StringReader( xmlFileContents ) ); + while ( parser.nextToken() != XmlPullParser.END_DOCUMENT ) + ; + assertTrue( true ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } + + /** + *

    + * Test custom Entity not found. + *

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws java.lang.Exception if any. + * + * @since 3.4.2 + */ + @Test + public void testCustomEntityNotFoundInText() + throws Exception + { + MXParser parser = new MXParser(); + + String input = "&otherentity;"; + parser.setInput( new StringReader( input ) ); + parser.defineEntityReplacementText( "myentity", "replacement" ); + + try + { + assertEquals( XmlPullParser.START_TAG, parser.next() ); + assertEquals( XmlPullParser.TEXT, parser.next() ); + fail( "should raise exception" ); + } + catch ( XmlPullParserException e ) + { + assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_TAG seen &otherentity;... @1:19)" ) ); + assertEquals( XmlPullParser.START_TAG, parser.getEventType() ); // not an ENTITY_REF + assertEquals( "otherentity", parser.getText() ); + } + } + + /** + *

    + * Test custom Entity not found, with tokenize. + *

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws java.lang.Exception if any. + * + * @since 3.4.2 + */ + @Test + public void testCustomEntityNotFoundInTextTokenize() + throws Exception + { + MXParser parser = new MXParser(); + + String input = "&otherentity;"; + parser.setInput( new StringReader( input ) ); + parser.defineEntityReplacementText( "myentity", "replacement" ); + + try + { + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertNull( parser.getText() ); + } + catch ( XmlPullParserException e ) + { + fail( "should not throw exception if tokenize" ); + } + } + + /** + *

    + * Test custom Entity not found in attribute. + *

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws java.lang.Exception if any. + * + * @since 3.4.2 + */ + @Test + public void testCustomEntityNotFoundInAttr() + throws Exception + { + MXParser parser = new MXParser(); + + String input = "sometext"; + parser.setInput( new StringReader( input ) ); + parser.defineEntityReplacementText( "myentity", "replacement" ); + + try + { + assertEquals( XmlPullParser.START_TAG, parser.next() ); + fail( "should raise exception" ); + } + catch ( XmlPullParserException e ) + { + assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen + * Test custom Entity not found in attribute, with tokenize. + *

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * @throws XmlPullParserException + * + * @throws Exception if any. + * + * @since 3.4.2 + */ + @Test + public void testCustomEntityNotFoundInAttrTokenize() throws Exception + { + MXParser parser = new MXParser(); + + String input = "sometext"; + + try + { + parser.setInput( new StringReader( input ) ); + parser.defineEntityReplacementText( "myentity", "replacement" ); + + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + fail( "should raise exception" ); + } + catch ( XmlPullParserException e ) + { + assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen Issue #194: Incorrect getText() after parsing the DOCDECL section + * + *

    test DOCDECL text with myCustomEntity that cannot be resolved, Unix line separator.

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testDocdeclTextWithEntitiesUnix() + throws IOException + { + testDocdeclTextWithEntities( "test-entities.xml" ); + } + + /** + *

    Issue #194: Incorrect getText() after parsing the DOCDECL section + * + *

    test DOCDECL text with myCustomEntity that cannot be resolved, DOS line separator.

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testDocdeclTextWithEntitiesDOS() + throws IOException + { + testDocdeclTextWithEntities( "test-entities-dos.xml" ); + } + + private void testDocdeclTextWithEntities( String filename ) + throws IOException + { + try ( Reader reader = ReaderFactory.newXmlReader( new File( "src/test/resources/xml", filename ) ) ) + { + MXParser parser = new MXParser(); + parser.setInput( reader ); + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.DOCDECL, parser.nextToken() ); + assertEquals( " document [\n" + + "\n" + + "\n" + + "]", parser.getText() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "document", parser.getName() ); + assertEquals( XmlPullParser.TEXT, parser.next() ); + + fail( "should fail to resolve 'myCustomEntity' entity"); + } + catch ( XmlPullParserException e ) + { + assertTrue( e.getMessage().contains( "could not resolve entity named 'myCustomEntity'" )); + } + } + + /** + *

    Issue #194: Incorrect getText() after parsing the DOCDECL section + * + *

    test DOCDECL text with entities appearing in attributes, Unix line separator.

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testDocdeclTextWithEntitiesInAttributesUnix() + throws IOException + { + testDocdeclTextWithEntitiesInAttributes( "test-entities-in-attr.xml" ); + } + + /** + *

    Issue #194: Incorrect getText() after parsing the DOCDECL section + * + *

    test DOCDECL text with entities appearing in attributes, DOS line separator.

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testDocdeclTextWithEntitiesInAttributesDOS() + throws IOException + { + testDocdeclTextWithEntitiesInAttributes( "test-entities-in-attr-dos.xml" ); + } + + private void testDocdeclTextWithEntitiesInAttributes( String filename ) + throws IOException + { + try ( Reader reader = ReaderFactory.newXmlReader( new File( "src/test/resources/xml", filename ) ) ) + { + MXParser parser = new MXParser(); + parser.setInput( reader ); + parser.defineEntityReplacementText( "nbsp", " " ); + parser.defineEntityReplacementText( "Alpha", "Α" ); + parser.defineEntityReplacementText( "tritPos", "𝟭" ); + parser.defineEntityReplacementText( "flo", "ř" ); + parser.defineEntityReplacementText( "myCustomEntity", "&flo;" ); + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.DOCDECL, parser.nextToken() ); + assertEquals( " document [\n" + + " \n" + + " \n" + + " \n" + + "\n" + + "\n" + + "]", parser.getText() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "document", parser.getName() ); + assertEquals( 1, parser.getAttributeCount() ); + assertEquals( "name", parser.getAttributeName( 0 ) ); + assertEquals( "section name with entities: '&' 'Α' '<' ' ' '>' '𝟭' ''' 'ř' '\"'", + parser.getAttributeValue( 0 ) ); + + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "myCustomEntity", parser.getName() ); + assertEquals( "ř", parser.getText() ); + + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } + + /** + *

    test entity ref with entities appearing in tags, Unix line separator.

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testEntityRefTextUnix() + throws IOException + { + testEntityRefText( "\n" ); + } + + /** + *

    test entity ref with entities appearing in tags, DOS line separator.

    + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testEntityRefTextDOS() + throws IOException + { + testEntityRefText( "\r\n" ); + } + + private void testEntityRefText( String newLine ) + throws IOException + { + StringBuilder sb = new StringBuilder(); + sb.append( "" ).append( newLine ); + sb.append( "" ).append( newLine ); + sb.append( "" ).append( newLine ); + sb.append( "" ).append( newLine ); + sb.append( "]>" ).append( newLine ); + sb.append( "&foo;&foo1;&foo2;&tritPos;" ); + + try + { + MXParser parser = new MXParser(); + parser.setInput( new StringReader( sb.toString() ) ); + parser.defineEntityReplacementText( "foo", "ř" ); + parser.defineEntityReplacementText( "nbsp", " " ); + parser.defineEntityReplacementText( "foo1", " " ); + parser.defineEntityReplacementText( "foo2", "š" ); + parser.defineEntityReplacementText( "tritPos", "𝟭" ); + + assertEquals( XmlPullParser.DOCDECL, parser.nextToken() ); + assertEquals( " test [\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "]", parser.getText() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "b", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "ř", parser.getText() ); + assertEquals( "foo", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( " ", parser.getText() ); + assertEquals( "foo1", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "š", parser.getText() ); + assertEquals( "foo2", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "𝟭", parser.getText() ); + assertEquals( "tritPos", parser.getName() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( "b", parser.getName() ); + assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } + + /** + * Ensures that entity ref getText() and getName() return the correct value. + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testEntityReplacement() throws IOException { + String input = "

      

    "; + + try + { + MXParser parser = new MXParser(); + parser.setInput( new StringReader( input ) ); + parser.defineEntityReplacementText( "nbsp", " " ); + + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "p", parser.getName() ); + assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); + assertEquals( " a pagebreak: ", parser.getText() ); + assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); + assertEquals( " PB ", parser.getText() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "\u00A0", parser.getText() ); + assertEquals( "#160", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( " ", parser.getText() ); + assertEquals( "nbsp", parser.getName() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "unknown", parser.getName() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( "unknown", parser.getName() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( "p", parser.getName() ); + assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } + + /** + * Ensures correct replacements inside the internal PC array when the new copied array size is shorter than + * previous ones. + * + * Regression test: assure same behavior of MXParser from plexus-utils 3.3.0. + * + * @throws IOException if any. + * + * @since 3.4.2 + */ + @Test + public void testReplacementInPCArrayWithShorterCharArray() + throws IOException + { + String input = "]>" + + "

    &&foo;&tritPos;

    "; + + try + { + MXParser parser = new MXParser(); + parser.setInput( new StringReader( new String(input.getBytes(), "ISO-8859-1" ) ) ); + parser.defineEntityReplacementText( "foo", "ř" ); + parser.defineEntityReplacementText( "tritPos", "𝟭" ); + + assertEquals( XmlPullParser.DOCDECL, parser.nextToken() ); + assertEquals( " test []", parser.getText() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "section", parser.getName() ); + assertEquals( 1, parser.getAttributeCount() ); + assertEquals( "name" , parser.getAttributeName( 0 ) ); + assertEquals( "&ř𝟭" , parser.getAttributeValue( 0 ) ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( "

    ", parser.getText() ); + assertEquals( "p", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "&", parser.getText() ); + assertEquals( "amp", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "ř", parser.getText() ); + assertEquals( "foo", parser.getName() ); + assertEquals( XmlPullParser.ENTITY_REF, parser.nextToken() ); + assertEquals( "𝟭", parser.getText() ); + assertEquals( "tritPos", parser.getName() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( "p", parser.getName() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( "section", parser.getName() ); + assertEquals( XmlPullParser.END_DOCUMENT, parser.nextToken() ); + } + catch ( XmlPullParserException e ) + { + fail( "should not raise exception: " + e ); + } + } } diff --git a/src/test/resources/xml/test-entities-dos.xml b/src/test/resources/xml/test-entities-dos.xml new file mode 100644 index 00000000..e1d6d17a --- /dev/null +++ b/src/test/resources/xml/test-entities-dos.xml @@ -0,0 +1,6 @@ + + + +]> +&myCustomEntity; \ No newline at end of file diff --git a/src/test/resources/xml/test-entities-in-attr-dos.xml b/src/test/resources/xml/test-entities-in-attr-dos.xml new file mode 100644 index 00000000..a423c995 --- /dev/null +++ b/src/test/resources/xml/test-entities-in-attr-dos.xml @@ -0,0 +1,9 @@ + + + + + + +]> +&myCustomEntity; \ No newline at end of file diff --git a/src/test/resources/xml/test-entities-in-attr.xml b/src/test/resources/xml/test-entities-in-attr.xml new file mode 100644 index 00000000..a423c995 --- /dev/null +++ b/src/test/resources/xml/test-entities-in-attr.xml @@ -0,0 +1,9 @@ + + + + + + +]> +&myCustomEntity; \ No newline at end of file diff --git a/src/test/resources/xml/test-entities.xml b/src/test/resources/xml/test-entities.xml new file mode 100644 index 00000000..e1d6d17a --- /dev/null +++ b/src/test/resources/xml/test-entities.xml @@ -0,0 +1,6 @@ + + + +]> +&myCustomEntity; \ No newline at end of file From 298fd8d626a7dd1271dcc4ae8e2029a2eba2c1ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Apr 2022 02:03:30 +0000 Subject: [PATCH 104/133] Bump actions/checkout from 2.4.0 to 3.0.1 Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.0.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3.0.1) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3f39b7e2..9935c621 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From 52d64eadb7d4f8a543d43cc49194cdf74b93f944 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 02:02:37 +0000 Subject: [PATCH 105/133] Bump jmh-core from 1.34 to 1.35 Bumps jmh-core from 1.34 to 1.35. --- updated-dependencies: - dependency-name: org.openjdk.jmh:jmh-core dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a758c676..8a9018e9 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ limitations under the License. org.openjdk.jmh jmh-core - 1.34 + 1.35 test From 11be3b5bf2a8b9853ab2e7f2e1245233220ca46a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Mar 2022 02:02:35 +0000 Subject: [PATCH 106/133] Bump jmh-generator-annprocess from 1.34 to 1.35 Bumps jmh-generator-annprocess from 1.34 to 1.35. --- updated-dependencies: - dependency-name: org.openjdk.jmh:jmh-generator-annprocess dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8a9018e9..beda14b7 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ limitations under the License. org.openjdk.jmh jmh-generator-annprocess - 1.34 + 1.35 test From 10f729542509b039a748fc7085826e43137bba35 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Mar 2022 02:02:38 +0000 Subject: [PATCH 107/133] Bump release-drafter/release-drafter from 5.18.1 to 5.19.0 Bumps [release-drafter/release-drafter](https://github.com/release-drafter/release-drafter) from 5.18.1 to 5.19.0. - [Release notes](https://github.com/release-drafter/release-drafter/releases) - [Commits](https://github.com/release-drafter/release-drafter/compare/v5.18.1...v5.19.0) --- updated-dependencies: - dependency-name: release-drafter/release-drafter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 4ece1c1a..96f54b5d 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -7,6 +7,6 @@ jobs: update_release_draft: runs-on: ubuntu-latest steps: - - uses: release-drafter/release-drafter@v5.18.1 + - uses: release-drafter/release-drafter@v5.19.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 0d384e75ba5f950d389281226e56515be195b604 Mon Sep 17 00:00:00 2001 From: Gabriel Belingueres Date: Sun, 17 Apr 2022 04:01:59 -0300 Subject: [PATCH 108/133] Fix some testing XML files checkout with incorrect eol --- .gitattributes | 4 ++++ .../org/codehaus/plexus/util/xml/pull/MXParserTest.java | 8 ++++---- .../xml/{test-entities-dos.xml => test-entities-DOS.xml} | 0 .../xml/{test-entities.xml => test-entities-UNIX.xml} | 0 ...ties-in-attr-dos.xml => test-entities-in-attr-DOS.xml} | 0 ...ntities-in-attr.xml => test-entities-in-attr-UNIX.xml} | 0 6 files changed, 8 insertions(+), 4 deletions(-) rename src/test/resources/xml/{test-entities-dos.xml => test-entities-DOS.xml} (100%) rename src/test/resources/xml/{test-entities.xml => test-entities-UNIX.xml} (100%) rename src/test/resources/xml/{test-entities-in-attr-dos.xml => test-entities-in-attr-DOS.xml} (100%) rename src/test/resources/xml/{test-entities-in-attr.xml => test-entities-in-attr-UNIX.xml} (100%) 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/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 6fc6e9c6..27ba5f8c 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -1081,7 +1081,7 @@ public void testCustomEntityNotFoundInAttrTokenize() throws Exception public void testDocdeclTextWithEntitiesUnix() throws IOException { - testDocdeclTextWithEntities( "test-entities.xml" ); + testDocdeclTextWithEntities( "test-entities-UNIX.xml" ); } /** @@ -1099,7 +1099,7 @@ public void testDocdeclTextWithEntitiesUnix() public void testDocdeclTextWithEntitiesDOS() throws IOException { - testDocdeclTextWithEntities( "test-entities-dos.xml" ); + testDocdeclTextWithEntities( "test-entities-DOS.xml" ); } private void testDocdeclTextWithEntities( String filename ) @@ -1144,7 +1144,7 @@ private void testDocdeclTextWithEntities( String filename ) public void testDocdeclTextWithEntitiesInAttributesUnix() throws IOException { - testDocdeclTextWithEntitiesInAttributes( "test-entities-in-attr.xml" ); + testDocdeclTextWithEntitiesInAttributes( "test-entities-in-attr-UNIX.xml" ); } /** @@ -1162,7 +1162,7 @@ public void testDocdeclTextWithEntitiesInAttributesUnix() public void testDocdeclTextWithEntitiesInAttributesDOS() throws IOException { - testDocdeclTextWithEntitiesInAttributes( "test-entities-in-attr-dos.xml" ); + testDocdeclTextWithEntitiesInAttributes( "test-entities-in-attr-DOS.xml" ); } private void testDocdeclTextWithEntitiesInAttributes( String filename ) diff --git a/src/test/resources/xml/test-entities-dos.xml b/src/test/resources/xml/test-entities-DOS.xml similarity index 100% rename from src/test/resources/xml/test-entities-dos.xml rename to src/test/resources/xml/test-entities-DOS.xml diff --git a/src/test/resources/xml/test-entities.xml b/src/test/resources/xml/test-entities-UNIX.xml similarity index 100% rename from src/test/resources/xml/test-entities.xml rename to src/test/resources/xml/test-entities-UNIX.xml diff --git a/src/test/resources/xml/test-entities-in-attr-dos.xml b/src/test/resources/xml/test-entities-in-attr-DOS.xml similarity index 100% rename from src/test/resources/xml/test-entities-in-attr-dos.xml rename to src/test/resources/xml/test-entities-in-attr-DOS.xml diff --git a/src/test/resources/xml/test-entities-in-attr.xml b/src/test/resources/xml/test-entities-in-attr-UNIX.xml similarity index 100% rename from src/test/resources/xml/test-entities-in-attr.xml rename to src/test/resources/xml/test-entities-in-attr-UNIX.xml From d3823dc54686cbd268b0cd8f7c6ef6058d163817 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Apr 2022 02:02:31 +0000 Subject: [PATCH 109/133] Bump actions/checkout from 3.0.1 to 3.0.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.0.1 to 3.0.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.0.1...v3.0.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 9935c621..6240fce9 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -32,7 +32,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.0.1 + uses: actions/checkout@v3.0.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From 2f68e930054aae96ca8f694774b07fd63741301c Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 23 Apr 2022 19:43:51 +0200 Subject: [PATCH 110/133] Fix regression and deprecate: FileUtils.fileAppend should create file if not exist. --- src/main/java/org/codehaus/plexus/util/FileUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/util/FileUtils.java b/src/main/java/org/codehaus/plexus/util/FileUtils.java index cac82ba3..4dca8b3c 100644 --- a/src/main/java/org/codehaus/plexus/util/FileUtils.java +++ b/src/main/java/org/codehaus/plexus/util/FileUtils.java @@ -389,6 +389,8 @@ private static InputStreamReader getInputStreamReader( File file, String encodin * @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 @@ -403,11 +405,14 @@ 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 { - try ( OutputStream out = Files.newOutputStream( Paths.get(fileName), StandardOpenOption.APPEND ) ) + try ( OutputStream out = Files.newOutputStream( Paths.get(fileName), + StandardOpenOption.APPEND, StandardOpenOption.CREATE ) ) { if ( encoding != null ) { From 0808fe36dde238e6824043d5ca597b7cec1bd5c7 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 23 Apr 2022 22:33:48 +0200 Subject: [PATCH 111/133] Added Licence file Closes #78 --- LICENSE.txt | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE.txt 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. From 49773f19e43af7d39f441aac06adbc6a4052a063 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 26 Apr 2022 15:42:15 +0200 Subject: [PATCH 112/133] Provides a CachingOuptutStream and a CachingWriter (#184) Provides a CachingOuptutStream and a CachingWriter --- .../plexus/util/io/CachingOutputStream.java | 175 ++++++++++++++++++ .../plexus/util/io/CachingWriter.java | 62 +++++++ .../util/io/CachingOutputStreamTest.java | 145 +++++++++++++++ .../plexus/util/io/CachingWriterTest.java | 143 ++++++++++++++ 4 files changed, 525 insertions(+) create mode 100644 src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java create mode 100644 src/main/java/org/codehaus/plexus/util/io/CachingWriter.java create mode 100644 src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java create mode 100644 src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java 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..521d5373 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java @@ -0,0 +1,175 @@ +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 + { + flush(); + long position = channel.position(); + if ( position != channel.size() ) + { + if ( !modified ) + { + FileTime now = FileTime.from( Instant.now() ); + Files.setLastModifiedTime( path, now ); + 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/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java new file mode 100644 index 00000000..3c329ea9 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java @@ -0,0 +1,145 @@ +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.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import java.util.Objects; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +public class CachingOutputStreamTest +{ + + Path tempDir; + Path checkLastModified; + FileTime lm; + + @Before + public void setup() throws IOException + { + Path dir = Paths.get( "target/io" ); + Files.createDirectories( dir ); + tempDir = Files.createTempDirectory( dir, "temp-" ); + checkLastModified = tempDir.resolve( ".check" ); + Files.newOutputStream( checkLastModified ).close(); + lm = Files.getLastModifiedTime( checkLastModified ); + } + + private void waitLastModified() throws IOException, InterruptedException + { + while ( true ) + { + Files.newOutputStream( checkLastModified ).close(); + FileTime nlm = Files.getLastModifiedTime( checkLastModified ); + if ( !Objects.equals( nlm, lm ) ) + { + lm = nlm; + break; + } + Thread.sleep( 10 ); + } + } + + @Test + public void testWriteNoExistingFile() throws IOException, InterruptedException + { + byte[] data = "Hello world!".getBytes( StandardCharsets.UTF_8 ); + Path path = tempDir.resolve( "file.txt" ); + assertFalse( Files.exists( path ) ); + + try ( CachingOutputStream cos = new CachingOutputStream( path, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + byte[] read = Files.readAllBytes( path ); + assertArrayEquals( data, read ); + FileTime modified = Files.getLastModifiedTime( path ); + + waitLastModified(); + + try ( CachingOutputStream cos = new CachingOutputStream( path, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = Files.readAllBytes( path ); + assertArrayEquals( data, read ); + FileTime newModified = Files.getLastModifiedTime( path ); + assertEquals( modified, newModified ); + modified = newModified; + + waitLastModified(); + + // write longer data + data = "Good morning!".getBytes( StandardCharsets.UTF_8 ); + try ( CachingOutputStream cos = new CachingOutputStream( path, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = Files.readAllBytes( path ); + assertArrayEquals( data, read ); + newModified = Files.getLastModifiedTime( path ); + assertNotEquals( modified, newModified ); + modified = newModified; + + waitLastModified(); + + // different data same size + data = "Good mornong!".getBytes( StandardCharsets.UTF_8 ); + try ( CachingOutputStream cos = new CachingOutputStream( path, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = Files.readAllBytes( path ); + assertArrayEquals( data, read ); + newModified = Files.getLastModifiedTime( path ); + assertNotEquals( modified, newModified ); + modified = newModified; + + waitLastModified(); + + // same data but shorter + data = "Good mornon".getBytes( StandardCharsets.UTF_8 ); + try ( CachingOutputStream cos = new CachingOutputStream( path, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = Files.readAllBytes( path ); + assertArrayEquals( data, read ); + newModified = Files.getLastModifiedTime( path ); + assertNotEquals( modified, newModified ); + modified = newModified; + } + +} diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java new file mode 100644 index 00000000..f5b95903 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java @@ -0,0 +1,143 @@ +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.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import java.util.Objects; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +public class CachingWriterTest +{ + + Path tempDir; + Path checkLastModified; + FileTime lm; + + @Before + public void setup() throws IOException + { + Path dir = Paths.get( "target/io" ); + Files.createDirectories( dir ); + tempDir = Files.createTempDirectory( dir, "temp-" ); + checkLastModified = tempDir.resolve( ".check" ); + Files.newOutputStream( checkLastModified ).close(); + lm = Files.getLastModifiedTime( checkLastModified ); + } + + private void waitLastModified() throws IOException, InterruptedException + { + while ( true ) + { + Files.newOutputStream( checkLastModified ).close(); + FileTime nlm = Files.getLastModifiedTime( checkLastModified ); + if ( !Objects.equals( nlm, lm ) ) + { + lm = nlm; + break; + } + Thread.sleep( 10 ); + } + } + + @Test + public void testWriteNoExistingFile() throws IOException, InterruptedException + { + String data = "Hello world!"; + Path path = tempDir.resolve( "file.txt" ); + assertFalse( Files.exists( path ) ); + + try ( CachingWriter cos = new CachingWriter( path, StandardCharsets.UTF_8, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + String read = new String( Files.readAllBytes( path ), StandardCharsets.UTF_8 ); + assertEquals( data, read ); + FileTime modified = Files.getLastModifiedTime( path ); + + waitLastModified(); + + try ( CachingWriter cos = new CachingWriter( path, StandardCharsets.UTF_8, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = new String( Files.readAllBytes( path ), StandardCharsets.UTF_8 ); + assertEquals( data, read ); + FileTime newModified = Files.getLastModifiedTime( path ); + assertEquals( modified, newModified ); + modified = newModified; + + waitLastModified(); + + // write longer data + data = "Good morning!"; + try ( CachingWriter cos = new CachingWriter( path, StandardCharsets.UTF_8, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = new String( Files.readAllBytes( path ), StandardCharsets.UTF_8 ); + assertEquals( data, read ); + newModified = Files.getLastModifiedTime( path ); + assertNotEquals( modified, newModified ); + modified = newModified; + + waitLastModified(); + + // different data same size + data = "Good mornong!"; + try ( CachingWriter cos = new CachingWriter( path, StandardCharsets.UTF_8, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = new String( Files.readAllBytes( path ), StandardCharsets.UTF_8 ); + assertEquals( data, read ); + newModified = Files.getLastModifiedTime( path ); + assertNotEquals( modified, newModified ); + modified = newModified; + + waitLastModified(); + + // same data but shorter + data = "Good mornon"; + try ( CachingWriter cos = new CachingWriter( path, StandardCharsets.UTF_8, 4 ) ) + { + cos.write( data ); + } + assertTrue( Files.exists( path ) ); + read = new String( Files.readAllBytes( path ), StandardCharsets.UTF_8 ); + assertEquals( data, read ); + newModified = Files.getLastModifiedTime( path ); + assertNotEquals( modified, newModified ); + modified = newModified; + } +} From ee5fe41b032f95f9b39f6ef21256800a6608dfd6 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 26 Apr 2022 17:44:51 +0200 Subject: [PATCH 113/133] Fix last modified time not being updated on linux (#203) Fix test, clean things --- .../plexus/util/io/CachingOutputStream.java | 14 ++++++-------- .../plexus/util/io/CachingOutputStreamTest.java | 7 ++----- .../codehaus/plexus/util/io/CachingWriterTest.java | 7 ++----- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java b/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java index 521d5373..744e6f06 100644 --- a/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java +++ b/src/main/java/org/codehaus/plexus/util/io/CachingOutputStream.java @@ -153,19 +153,17 @@ private void flushBuffer( ByteBuffer writeBuffer ) throws IOException @Override public void close() throws IOException { - flush(); - long position = channel.position(); - if ( position != channel.size() ) + if ( channel.isOpen() ) { - if ( !modified ) + flush(); + long position = channel.position(); + if ( position != channel.size() ) { - FileTime now = FileTime.from( Instant.now() ); - Files.setLastModifiedTime( path, now ); modified = true; + channel.truncate( position ); } - channel.truncate( position ); + channel.close(); } - channel.close(); } public boolean isModified() diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java index 3c329ea9..e7888ad4 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingOutputStreamTest.java @@ -17,7 +17,6 @@ */ import java.io.IOException; -import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -39,7 +38,6 @@ public class CachingOutputStreamTest Path tempDir; Path checkLastModified; - FileTime lm; @Before public void setup() throws IOException @@ -48,19 +46,18 @@ public void setup() throws IOException Files.createDirectories( dir ); tempDir = Files.createTempDirectory( dir, "temp-" ); checkLastModified = tempDir.resolve( ".check" ); - Files.newOutputStream( checkLastModified ).close(); - lm = Files.getLastModifiedTime( checkLastModified ); } private void waitLastModified() throws IOException, InterruptedException { + Files.newOutputStream( checkLastModified ).close(); + FileTime lm = Files.getLastModifiedTime( checkLastModified ); while ( true ) { Files.newOutputStream( checkLastModified ).close(); FileTime nlm = Files.getLastModifiedTime( checkLastModified ); if ( !Objects.equals( nlm, lm ) ) { - lm = nlm; break; } Thread.sleep( 10 ); diff --git a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java index f5b95903..a4ffec91 100644 --- a/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/io/CachingWriterTest.java @@ -27,7 +27,6 @@ import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -38,7 +37,6 @@ public class CachingWriterTest Path tempDir; Path checkLastModified; - FileTime lm; @Before public void setup() throws IOException @@ -47,19 +45,18 @@ public void setup() throws IOException Files.createDirectories( dir ); tempDir = Files.createTempDirectory( dir, "temp-" ); checkLastModified = tempDir.resolve( ".check" ); - Files.newOutputStream( checkLastModified ).close(); - lm = Files.getLastModifiedTime( checkLastModified ); } private void waitLastModified() throws IOException, InterruptedException { + Files.newOutputStream( checkLastModified ).close(); + FileTime lm = Files.getLastModifiedTime( checkLastModified ); while ( true ) { Files.newOutputStream( checkLastModified ).close(); FileTime nlm = Files.getLastModifiedTime( checkLastModified ); if ( !Objects.equals( nlm, lm ) ) { - lm = nlm; break; } Thread.sleep( 10 ); From 8dec9319639a4f9772d99264669b63cc3e9c2fe6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Apr 2022 02:03:21 +0000 Subject: [PATCH 114/133] Bump github/codeql-action from 1 to 2 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v1...v2) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6240fce9..6ede3405 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -36,7 +36,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + 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. @@ -47,7 +47,7 @@ jobs: # 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@v1 + uses: github/codeql-action/autobuild@v2 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -61,4 +61,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 From 407a93cf5bb2864d35462b3d4a05bb293dafc230 Mon Sep 17 00:00:00 2001 From: Fishermans Date: Wed, 30 Mar 2022 20:13:37 +0200 Subject: [PATCH 115/133] SelectorUtils.matchPath(): inconsistent behaviour on POSIX-like and Windows for single Wildcard pattern (#191) This fixes #191 and closes #192 --- .../codehaus/plexus/util/SelectorUtils.java | 27 +++++++--- .../plexus/util/SelectorUtilsTest.java | 52 ++++++++++++++++++- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java index de39f4fe..234a92c5 100644 --- a/src/main/java/org/codehaus/plexus/util/SelectorUtils.java +++ b/src/main/java/org/codehaus/plexus/util/SelectorUtils.java @@ -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 ) diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index ebc2dca0..160aa16d 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -27,7 +27,6 @@ *

    SelectorUtilsTest class.

    * * @author herve - * @version $Id: $Id * @since 3.4.0 */ public class SelectorUtilsTest @@ -92,4 +91,55 @@ public void testMatchPath_WindowsFileSeparator() // Pattern and target don't start with file separator assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false ) ); } + + @Test + public void testPatternMatchSingleWildcardPosix() + { + assertFalse(SelectorUtils.matchPath( + "/com/test/*", + "/com/test/test/hallo")); + } + + + @Test + public void testPatternMatchDoubleWildcardCaseInsensitivePosix() + { + assertTrue(SelectorUtils.matchPath( + "/com/test/**", + "/com/test/test/hallo")); + } + + + @Test + public void testPatternMatchDoubleWildcardPosix() + { + assertTrue(SelectorUtils.matchPath( + "/com/test/**", + "/com/test/test/hallo")); + } + + + @Test + public void testPatternMatchSingleWildcardWindows() + { + assertFalse(SelectorUtils.matchPath( + "D:\\com\\test\\*", + "D:\\com\\test\\test\\hallo")); + + assertFalse(SelectorUtils.matchPath( + "D:/com/test/*", + "D:/com/test/test/hallo")); + } + + @Test + public void testPatternMatchDoubleWildcardWindows() + { + assertTrue(SelectorUtils.matchPath( + "D:\\com\\test\\**", + "D:\\com\\test\\test\\hallo")); + + assertTrue(SelectorUtils.matchPath( + "D:\\com\\test\\**", + "D:/com/test/test/hallo")); + } } From 89b8ef5e9cb4079b2f9cf4f23a6b17370708ad07 Mon Sep 17 00:00:00 2001 From: joehni Date: Mon, 4 Jan 2021 00:32:48 +0100 Subject: [PATCH 116/133] Fix position on MXParser (#121) This closes #121 --- .../plexus/util/xml/pull/MXParser.java | 4 +- .../plexus/util/xml/pull/MXParserTest.java | 45 ++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) 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 e21b66cb..20fdcc8e 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 @@ -464,7 +464,7 @@ private void reset() // System.out.println("reset() called"); location = null; lineNumber = 1; - columnNumber = 0; + columnNumber = 1; seenRoot = false; reachedEnd = false; eventType = START_DOCUMENT; @@ -3156,7 +3156,7 @@ else if ( !seenInnerTag ) { // seenPITarget && !seenQ throw new XmlPullParserException( "processing instruction started on line " + curLine - + " and column " + curColumn + " was not closed", this, null ); + + " and column " + (curColumn -2) + " was not closed", this, null ); } } else if ( ch == '<' ) diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 27ba5f8c..b1dd6139 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -353,6 +353,35 @@ public void testValidCharacterReferenceDecimal() * * @throws java.lang.Exception if any. */ + @Test + public void testParserPosition() + throws Exception + { + String input = " \n \tnnn\n"; + + MXParser parser = new MXParser(); + parser.setInput( new StringReader( input ) ); + + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + assertPosition( 1, 39, parser ); + assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); + assertPosition( 1, 49, parser ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertPosition( 2, 3, parser ); // end when next token starts + assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); + assertPosition( 2, 12, parser ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertPosition( 2, 18, parser ); + assertEquals( XmlPullParser.TEXT, parser.nextToken() ); + assertPosition( 2, 23, parser ); // end when next token starts + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertPosition( 2, 29, parser ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertPosition( 3, 2, parser ); // end when next token starts + assertEquals( XmlPullParser.COMMENT, parser.nextToken() ); + assertPosition( 4, 6, parser ); + } + @Test public void testProcessingInstruction() throws Exception @@ -624,7 +653,7 @@ 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" ) ); } } @@ -657,7 +686,7 @@ 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" ) ); } } @@ -900,6 +929,12 @@ public void testEncodingISO_8859_1_setInputStream() } } + private static void assertPosition( int row, int col, MXParser parser ) + { + assertEquals( "Current line", row, parser.getLineNumber() ); + assertEquals( "Current column", col, parser.getColumnNumber() ); + } + /** * Issue 163: https://github.com/codehaus-plexus/plexus-utils/issues/163 * @@ -958,7 +993,7 @@ public void testCustomEntityNotFoundInText() } catch ( XmlPullParserException e ) { - assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_TAG seen &otherentity;... @1:19)" ) ); + assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_TAG seen &otherentity;... @1:20)" ) ); assertEquals( XmlPullParser.START_TAG, parser.getEventType() ); // not an ENTITY_REF assertEquals( "otherentity", parser.getText() ); } @@ -1025,7 +1060,7 @@ public void testCustomEntityNotFoundInAttr() } catch ( XmlPullParserException e ) { - assertTrue( e.getMessage().contains( "could not resolve entity named 'otherentity' (position: START_DOCUMENT seen Date: Tue, 5 Jan 2021 00:33:34 +0100 Subject: [PATCH 117/133] Fix start position of PI and comment for all reported errors (#124) This closes #124 --- .../java/org/codehaus/plexus/util/xml/pull/MXParser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 20fdcc8e..d1c6ef18 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 @@ -2988,7 +2988,7 @@ private void parseComment() posStart = pos; final int curLine = lineNumber; - final int curColumn = columnNumber; + final int curColumn = columnNumber - 4; try { final boolean normalizeIgnorableWS = tokenize && !roundtripSupported; @@ -3109,7 +3109,7 @@ private 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 && !roundtripSupported; @@ -3156,7 +3156,7 @@ else if ( !seenInnerTag ) { // seenPITarget && !seenQ throw new XmlPullParserException( "processing instruction started on line " + curLine - + " and column " + (curColumn -2) + " was not closed", this, null ); + + " and column " + curColumn + " was not closed", this, null ); } } else if ( ch == '<' ) From 11c749d677176b5b04573a1acd37997ec61dcc05 Mon Sep 17 00:00:00 2001 From: joehni Date: Mon, 4 Jan 2021 00:41:38 +0100 Subject: [PATCH 118/133] Fix endless loop with invalid PI containing XML (#122) This closes #122 --- .../plexus/util/xml/pull/MXParser.java | 4 +++ .../plexus/util/xml/pull/MXParserTest.java | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+) 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 d1c6ef18..30c30fef 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 @@ -3158,6 +3158,10 @@ else if ( !seenInnerTag ) throw new XmlPullParserException( "processing instruction started on line " + curLine + " and column " + curColumn + " was not closed", this, null ); } + else + { + seenInnerTag = false; + } } else if ( ch == '<' ) { diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index b1dd6139..8e8dc231 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -432,6 +432,37 @@ public void testProcessingInstructionsContainingXml() * * @throws java.lang.Exception if any. */ + @Test + public void testMalformedProcessingInstructionsContainingXmlNoClosingQuestionMark() + throws Exception + { + StringBuffer sb = new StringBuffer(); + sb.append( "\n" ); + sb.append( "\n" ); + sb.append( "\n" ); + sb.append( " >\n" ); + + MXParser parser = new MXParser(); + parser.setInput( new StringReader( sb.toString() ) ); + + try + { + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.START_TAG, parser.nextToken() ); + assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); + assertEquals( XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken() ); + assertEquals( XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken() ); + + fail( "Should fail since it has invalid PI" ); + } + catch ( XmlPullParserException ex ) + { + assertTrue( ex.getMessage().contains( "processing instruction started on line 3 and column 1 was not closed" ) ); + } + } + @Test public void testSubsequentProcessingInstructionShort() throws Exception From 0d97c8ba8dfa4663e86c5827555f980fd47c27a9 Mon Sep 17 00:00:00 2001 From: joehni Date: Tue, 5 Jan 2021 00:38:32 +0100 Subject: [PATCH 119/133] Fix endless loop caused by aborted subsequent PI or comment (#124) This closes #124 --- .../plexus/util/xml/pull/MXParser.java | 2 +- .../plexus/util/xml/pull/MXParserTest.java | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) 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 30c30fef..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 @@ -3964,7 +3964,7 @@ private 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 diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 8e8dc231..e5e04708 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -726,6 +726,58 @@ public void testSubsequentMalformedProcessingInstructionNoClosingQuestionMark() * * @throws java.lang.Exception if any. */ + @Test + public void testSubsequentAbortedProcessingInstruction() + throws Exception + { + MXParser parser = new MXParser(); + StringBuilder sb = new StringBuilder(); + sb.append( "" ); + sb.append( "" ); + sb.append( "