Skip to content

Commit

Permalink
fix a number of small warnings and formatting issues (#10)
Browse files Browse the repository at this point in the history
* fix a number of small warnings and formatting issues
* setters shouldn't return values
  • Loading branch information
elharo authored Mar 23, 2020
1 parent 4264899 commit 001baa7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 71 deletions.
8 changes: 0 additions & 8 deletions src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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.
* <p/>
* TODO Should an ignore list be passed in?
* TODO Should a recurse flag be passed in?
* <p/>
* The given extensions should be like "java" and not like ".java"
*
* @param directory The path of the directory.
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/org/apache/maven/shared/utils/xml/Xpp3Dom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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 );
Expand All @@ -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>text with no XML header</text>";
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
{
Expand All @@ -202,8 +185,7 @@ public void testInappropriateEncoding()
}
}

public void testEncodingAttribute()
throws IOException
public void testEncodingAttribute() throws IOException
{
String xml = "<?xml version='1.0' encoding='US-ASCII'?><element encoding='attribute value'/>";
checkXmlContent( xml, "US-ASCII" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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" ) );
Expand Down

0 comments on commit 001baa7

Please sign in to comment.