From 001baa7d7b534f1cec4bc509e750c03e53a695ce Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 23 Mar 2020 16:29:34 -0400 Subject: [PATCH] fix a number of small warnings and formatting issues (#10) * fix a number of small warnings and formatting issues * setters shouldn't return values --- .../maven/shared/utils/io/FileUtils.java | 8 --- .../maven/shared/utils/xml/Xpp3Dom.java | 9 ---- .../shared/utils/XmlStreamReaderTest.java | 54 +++++++------------ .../utils/cli/CommandLineUtilsTest.java | 26 +++++---- .../shared/utils/io/SymlinkTestSetup.java | 15 +++--- 5 files changed, 41 insertions(+), 71 deletions(-) diff --git a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java index 63a5aa38..e5264b2e 100644 --- a/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java @@ -106,11 +106,6 @@ protected FileUtils() */ private static final int ONE_MB = ONE_KB * ONE_KB; - /** - * The number of bytes in a gigabyte. - */ - private static final int ONE_GB = ONE_KB * ONE_MB; - /** * The file copy buffer size (30 MB) */ @@ -497,9 +492,6 @@ public static void fileDelete( @Nonnull String fileName ) /** * Given a directory and an array of extensions return an array of compliant files. *

- * TODO Should an ignore list be passed in? - * TODO Should a recurse flag be passed in? - *

* The given extensions should be like "java" and not like ".java" * * @param directory The path of the directory. diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java index 5efa8fc9..1b2f1b66 100644 --- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java +++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java @@ -311,15 +311,6 @@ public void setParent( Xpp3Dom parent ) this.parent = parent; } - // Todo: Support writing to serializer (>1.0) - // public void writeToSerializer( String namespace, XmlSerializer serializer ) - // throws IOException - - private static Xpp3Dom merge( Xpp3Dom dominant, Xpp3Dom recessive, Boolean childMergeOverride ) - { - return Xpp3DomUtils.merge( dominant, recessive, childMergeOverride ); - } - /** * @param dominant The dominant part. * @param recessive The recessive part. diff --git a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java index 05715c1a..3ffb98d3 100644 --- a/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java +++ b/src/test/java/org/apache/maven/shared/utils/XmlStreamReaderTest.java @@ -55,8 +55,6 @@ public class XmlStreamReaderTest private static final byte[] BOM_UTF8 = { (byte)0xEF, (byte)0xBB, (byte)0xBF }; private static final byte[] BOM_UTF16BE = { (byte)0xFE, (byte)0xFF }; private static final byte[] BOM_UTF16LE = { (byte)0xFF, (byte)0xFE }; - private static final byte[] BOM_UTF32BE = { (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFE }; - private static final byte[] BOM_UTF32LE = { (byte)0xFF, (byte)0xFE, (byte)0x00, (byte)0x00 }; private static String createXmlContent( String text, String encoding ) { @@ -74,8 +72,7 @@ private static void checkXmlContent( String xml, String encoding ) checkXmlContent( xml, encoding, null ); } - private static void checkXmlContent( String xml, String encoding, byte[] bom ) - throws IOException + private static void checkXmlContent( String xml, String encoding, byte[] bom ) throws IOException { byte[] xmlContent = xml.getBytes( encoding ); InputStream in = new ByteArrayInputStream( xmlContent ); @@ -92,104 +89,90 @@ private static void checkXmlContent( String xml, String encoding, byte[] bom ) } private static void checkXmlStreamReader( String text, String encoding, String effectiveEncoding ) - throws IOException + throws IOException { checkXmlStreamReader( text, encoding, effectiveEncoding, null ); } - private static void checkXmlStreamReader( String text, String encoding ) - throws IOException + private static void checkXmlStreamReader( String text, String encoding ) throws IOException { checkXmlStreamReader( text, encoding, encoding, null ); } - private static void checkXmlStreamReader( String text, String encoding, byte[] bom ) - throws IOException + private static void checkXmlStreamReader( String text, String encoding, byte[] bom ) throws IOException { checkXmlStreamReader( text, encoding, encoding, bom ); } private static void checkXmlStreamReader( String text, String encoding, String effectiveEncoding, byte[] bom ) - throws IOException + throws IOException { String xml = createXmlContent( text, encoding ); checkXmlContent( xml, effectiveEncoding, bom ); } - public void testNoXmlHeader() - throws IOException + public void testNoXmlHeader() throws IOException { String xml = "text with no XML header"; checkXmlContent( xml, "UTF-8" ); checkXmlContent( xml, "UTF-8", BOM_UTF8 ); } - public void testDefaultEncoding() - throws IOException + public void testDefaultEncoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8" ); checkXmlStreamReader( TEXT_UNICODE, null, "UTF-8", BOM_UTF8 ); } - public void testUTF8Encoding() - throws IOException + public void testUTF8Encoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, "UTF-8" ); checkXmlStreamReader( TEXT_UNICODE, "UTF-8", BOM_UTF8 ); } - public void testUTF16Encoding() - throws IOException + public void testUTF16Encoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", null ); checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16LE", BOM_UTF16LE ); checkXmlStreamReader( TEXT_UNICODE, "UTF-16", "UTF-16BE", BOM_UTF16BE ); } - public void testUTF16BEEncoding() - throws IOException + public void testUTF16BEEncoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, "UTF-16BE" ); } - public void testUTF16LEEncoding() - throws IOException + public void testUTF16LEEncoding() throws IOException { checkXmlStreamReader( TEXT_UNICODE, "UTF-16LE" ); } - public void testLatin1Encoding() - throws IOException + public void testLatin1Encoding() throws IOException { checkXmlStreamReader( TEXT_LATIN1, "ISO-8859-1" ); } - public void testLatin7Encoding() - throws IOException + public void testLatin7Encoding() throws IOException { checkXmlStreamReader( TEXT_LATIN7, "ISO-8859-7" ); } - public void testLatin15Encoding() - throws IOException + public void testLatin15Encoding() throws IOException { checkXmlStreamReader( TEXT_LATIN15, "ISO-8859-15" ); } - public void testEUC_JPEncoding() - throws IOException + public void testEUC_JPEncoding() throws IOException { checkXmlStreamReader( TEXT_EUC_JP, "EUC-JP" ); } - public void testEBCDICEncoding() - throws IOException + public void testEBCDICEncoding() throws IOException { checkXmlStreamReader( "simple text in EBCDIC", "CP1047" ); } - public void testInappropriateEncoding() - throws IOException + public void testInappropriateEncoding() throws IOException { try { @@ -202,8 +185,7 @@ public void testInappropriateEncoding() } } - public void testEncodingAttribute() - throws IOException + public void testEncodingAttribute() throws IOException { String xml = ""; checkXmlContent( xml, "US-ASCII" ); diff --git a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java index 44835278..50d9336c 100644 --- a/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/apache/maven/shared/utils/cli/CommandLineUtilsTest.java @@ -127,33 +127,37 @@ public void givenASingleQuoteMarkInArgument_whenExecutingCode_thenExitCode0Retur } @Test - public void givenASingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkIsNotEscaped() throws Exception + public void givenASingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkIsNotEscaped() + throws Exception { final String command = "echo \"let's go\""; - final String[] expected = new String[]{"echo", "let's go"}; - assertCmdLineArgs(expected, command); + final String[] expected = new String[] { "echo", "let's go" }; + assertCmdLineArgs( expected, command ); } @Test - public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() throws Exception + public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() + throws Exception { final String command = "echo \"let\\\"s go\""; - final String[] expected = new String[]{"echo", "let\\\"s go"}; - assertCmdLineArgs(expected, command); + final String[] expected = new String[] { "echo", "let\\\"s go" }; + assertCmdLineArgs( expected, command ); } @Test - public void givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() throws Exception + public void givenAnEscapedSingleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenTheQuotationMarkRemainsEscaped() + throws Exception { final String command = "echo \"let\\\'s go\""; - final String[] expected = new String[]{"echo", "let\\\'s go"}; - assertCmdLineArgs(expected, command); + final String[] expected = new String[] { "echo", "let\\\'s go" }; + assertCmdLineArgs( expected, command ); } @Test - public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenNoExceptionIsThrown() throws Exception + public void givenAnEscapedDoubleQuoteMarkInArgument_whenTranslatingToCmdLineArgs_thenNoExceptionIsThrown() + throws Exception { - new Commandline("echo \"let\\\"s go\"").execute(); + new Commandline( "echo \"let\\\"s go\"" ).execute(); } private void assertCmdLineArgs( final String[] expected, final String cmdLine ) diff --git a/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java b/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java index 63bcd237..6ae3ba94 100644 --- a/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java +++ b/src/test/java/org/apache/maven/shared/utils/io/SymlinkTestSetup.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import static org.apache.commons.io.FileUtils.write; @@ -36,18 +37,18 @@ public static File createStandardSymlinkTestDir( File root ) srcDir.mkdirs(); File target = new File( srcDir, "targetDir" ); target.mkdirs(); - write( new File( target, "targetFile.txt" ), "a regular File payload" ); + write( new File( target, "targetFile.txt" ), "a regular File payload", StandardCharsets.UTF_8 ); File aRegularDir = new File( srcDir, "aRegularDir" ); aRegularDir.mkdirs(); - write( new File( aRegularDir, "aRegularFile.txt" ), "a regular File payload" ); + write( new File( aRegularDir, "aRegularFile.txt" ), "a regular File payload", StandardCharsets.UTF_8 ); File dirOnTheOutside = new File( root, "dirOnTheOutside" ); dirOnTheOutside.mkdirs(); - write( new File( dirOnTheOutside, "FileInDirOnTheOutside.txt" ), "a file in dir on the outside" ); - write( new File( root, "onTheOutside.txt" ), "A file on the outside" ); - write( new File( srcDir, "fileR.txt" ), "FileR payload" ); - write( new File( srcDir, "fileW.txt" ), "FileW payload" ); - write( new File( srcDir, "fileX.txt" ), "FileX payload" ); + write( new File( dirOnTheOutside, "FileInDirOnTheOutside.txt" ), "a file in dir on the outside", StandardCharsets.UTF_8 ); + write( new File( root, "onTheOutside.txt" ), "A file on the outside", StandardCharsets.UTF_8 ); + write( new File( srcDir, "fileR.txt" ), "FileR payload", StandardCharsets.UTF_8 ); + write( new File( srcDir, "fileW.txt" ), "FileW payload", StandardCharsets.UTF_8 ); + write( new File( srcDir, "fileX.txt" ), "FileX payload", StandardCharsets.UTF_8 ); // todo: set file attributes (not used here) Java7Support.createSymbolicLink( new File( srcDir, "symDir" ), new File( "targetDir" ) );