Author: khmarbaise
Date: Mon Sep 1 20:50:32 2014
New Revision: 1621884
URL: http://svn.apache.org/r1621884
Log:
- Refactored out LineEnding code into
separate class to make later extraction into
shared component simpler.
Added:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtilsTest.java
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java?rev=1621884&r1=1621883&r2=1621884&view=diff
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
(original)
+++
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java
Mon Sep 1 20:50:32 2014
@@ -19,8 +19,18 @@ package org.apache.maven.plugin.assembly
* under the License.
*/
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.Locale;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.apache.maven.plugin.assembly.utils.LineEndingsUtils;
import org.apache.maven.shared.filtering.MavenFileFilterRequest;
import org.apache.maven.shared.filtering.MavenFilteringException;
import org.codehaus.plexus.logging.Logger;
@@ -29,15 +39,6 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.Reader;
-import java.util.Locale;
-
/**
* @version $Id$
*/
@@ -79,7 +80,7 @@ public class FileFormatter
result = doFileFilter( source, tempRoot, encoding,
configSource.getEscapeString() );
}
- String lineEndingChars = AssemblyFileUtils.getLineEndingCharacters(
lineEnding );
+ String lineEndingChars = LineEndingsUtils.getLineEndingCharacters(
lineEnding );
if ( lineEndingChars != null )
{
result = formatLineEndings( lineEndingChars, result, tempRoot,
encoding );
@@ -121,7 +122,7 @@ public class FileFormatter
{
File target = FileUtils.createTempFile( source.getName() + ".",
".formatted", tempRoot );
- AssemblyFileUtils.convertLineEndings( source, target,
lineEndingChars, null, encoding );
+ LineEndingsUtils.convertLineEndings( source, target,
lineEndingChars, null, encoding );
return target;
}
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java?rev=1621884&r1=1621883&r2=1621884&view=diff
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
(original)
+++
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
Mon Sep 1 20:50:32 2014
@@ -19,17 +19,19 @@ package org.apache.maven.plugin.assembly
* under the License.
*/
+import java.io.File;
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+
import org.apache.maven.plugin.assembly.AssemblerConfigurationSource;
import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.apache.maven.plugin.assembly.utils.LineEndingsUtils;
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.shared.model.fileset.util.FileSetManager;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
-import javax.annotation.Nonnull;
-import java.io.File;
-import java.io.IOException;
-
/**
* @version $Id$
*/
@@ -51,7 +53,7 @@ public class FileSetFormatter
{
String lineEndingHint = set.getLineEnding();
- String lineEnding = AssemblyFileUtils.getLineEndingCharacters(
lineEndingHint );
+ String lineEnding = LineEndingsUtils.getLineEndingCharacters(
lineEndingHint );
if ( ( lineEnding != null ) || set.isFiltered() )
{
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java?rev=1621884&r1=1621883&r2=1621884&view=diff
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
(original)
+++
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtils.java
Mon Sep 1 20:50:32 2014
@@ -19,27 +19,18 @@ package org.apache.maven.plugin.assembly
* under the License.
*/
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
+import javax.annotation.Nonnull;
+
import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
-import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.codehaus.plexus.util.IOUtil;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
/**
* @version $Id$
@@ -47,18 +38,6 @@ import javax.annotation.Nullable;
public final class AssemblyFileUtils
{
- public static final String LINE_ENDING_KEEP = "keep";
-
- public static final String LINE_ENDING_DOS = "dos";
-
- public static final String LINE_ENDING_WINDOWS = "windows";
-
- public static final String LINE_ENDING_UNIX = "unix";
-
- public static final String LINE_ENDING_CRLF = "crlf";
-
- public static final String LINE_ENDING_LF = "lf";
-
private AssemblyFileUtils()
{
// no op
@@ -138,137 +117,6 @@ public final class AssemblyFileUtils
}
}
- /**
- * Converts the line endings of a file, writing a new file.
- * The encoding of reading and writing can be specified.
- *
- * @param source The source file, not null
- * @param dest The destination file, not null
- * @param lineEndings This is the result of the getLineEndingChars(..)
method in this utility class; the actual
- * line-ending characters, not null.
- * @param atEndOfFile The end-of-file line ending,
- * if true then the resulting file will have a new line
at the end even if the input didn't have one,
- * if false then the resulting file will have no new
line at the end even if the input did have one,
- * null to determine whether to have a new line at the
end of the file based on the input file
- * @param encoding The encoding to use, null for platform encoding
- */
- public static void convertLineEndings( @Nonnull File source, @Nonnull File
dest, String lineEndings,
- Boolean atEndOfFile, String
encoding )
- throws IOException
- {
- // MASSEMBLY-637, MASSEMBLY-96
- // find characters at the end of the file
- // needed to preserve the last line ending
- // only check for LF (as CRLF also ends in LF)
- String eofChars = "";
- if ( atEndOfFile == null )
- {
- RandomAccessFile raf = null;
- try
- {
- if ( source.length() >= 1 )
- {
- raf = new RandomAccessFile( source, "r" );
- raf.seek( source.length() - 1 );
- byte last = raf.readByte();
- if ( last == '\n' )
- {
- eofChars = lineEndings;
- }
- }
- }
- finally
- {
- if ( raf != null )
- {
- try
- {
- raf.close();
- }
- catch ( IOException ex )
- {
- // ignore
- }
- }
- }
- }
- else if (atEndOfFile == true )
- {
- eofChars = lineEndings;
- }
-
- BufferedReader in = null;
- BufferedWriter out = null;
- try
- {
- if ( encoding == null )
- {
- // platform encoding
- in = new BufferedReader( new InputStreamReader( new
FileInputStream( source ) ) );
- out = new BufferedWriter( new OutputStreamWriter( new
FileOutputStream( dest ) ) );
- }
- else
- {
- // MASSEMBLY-371
- in = new BufferedReader( new InputStreamReader( new
FileInputStream( source ), encoding ) );
- out = new BufferedWriter( new OutputStreamWriter( new
FileOutputStream( dest ), encoding ) );
- }
-
- String line;
-
- line = in.readLine();
- while ( line != null )
- {
- out.write( line );
- line = in.readLine();
- if ( line != null )
- {
- out.write( lineEndings );
- }
- else
- {
- out.write( eofChars );
- }
- }
-
- out.flush();
- }
- finally
- {
- IOUtil.close( in );
- IOUtil.close( out );
- }
- }
-
- @Nullable
- public static String getLineEndingCharacters( @Nullable String lineEnding )
- throws AssemblyFormattingException
- {
- String value = lineEnding;
- if ( lineEnding != null )
- {
- if ( LINE_ENDING_KEEP.equals( lineEnding ) )
- {
- value = null;
- }
- else if ( LINE_ENDING_DOS.equals( lineEnding ) ||
LINE_ENDING_WINDOWS.equals( lineEnding )
- || LINE_ENDING_CRLF.equals( lineEnding ) )
- {
- value = "\r\n";
- }
- else if ( LINE_ENDING_UNIX.equals( lineEnding ) ||
LINE_ENDING_LF.equals( lineEnding ) )
- {
- value = "\n";
- }
- else
- {
- throw new AssemblyFormattingException( "Illegal lineEnding
specified: '" + lineEnding + "'" );
- }
- }
-
- return value;
- }
-
public static void copyFile( File src, File dst )
throws IOException
{
Added:
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java?rev=1621884&view=auto
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
(added)
+++
maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LineEndingsUtils.java
Mon Sep 1 20:50:32 2014
@@ -0,0 +1,193 @@
+package org.apache.maven.plugin.assembly.utils;
+
+/*
+ * 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.
+ */
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.RandomAccessFile;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Line Ending class which contains
+ * convenience methods to change line endings.
+ *
+ */
+public final class LineEndingsUtils
+{
+
+ public static final String LINE_ENDING_KEEP = "keep";
+
+ public static final String LINE_ENDING_DOS = "dos";
+
+ public static final String LINE_ENDING_WINDOWS = "windows";
+
+ public static final String LINE_ENDING_UNIX = "unix";
+
+ public static final String LINE_ENDING_CRLF = "crlf";
+
+ public static final String LINE_ENDING_LF = "lf";
+
+ private LineEndingsUtils()
+ {
+ // prevent creations of instances.
+ }
+
+ /**
+ * Converts the line endings of a file, writing a new file. The encoding
of reading and writing can be specified.
+ *
+ * @param source The source file, not null
+ * @param dest The destination file, not null
+ * @param lineEndings This is the result of the getLineEndingChars(..)
method in this utility class; the actual
+ * line-ending characters, not null.
+ * @param atEndOfFile The end-of-file line ending, if true then the
resulting file will have a new line at the end
+ * even if the input didn't have one, if false then the
resulting file will have no new line at the end
+ * even if the input did have one, null to determine whether to
have a new line at the end of the file
+ * based on the input file
+ * @param encoding The encoding to use, null for platform encoding
+ */
+ public static void convertLineEndings( @Nonnull File source, @Nonnull File
dest, String lineEndings,
+ Boolean atEndOfFile, String
encoding )
+ throws IOException
+ {
+ // MASSEMBLY-637, MASSEMBLY-96
+ // find characters at the end of the file
+ // needed to preserve the last line ending
+ // only check for LF (as CRLF also ends in LF)
+ String eofChars = "";
+ if ( atEndOfFile == null )
+ {
+ RandomAccessFile raf = null;
+ try
+ {
+ if ( source.length() >= 1 )
+ {
+ raf = new RandomAccessFile( source, "r" );
+ raf.seek( source.length() - 1 );
+ byte last = raf.readByte();
+ if ( last == '\n' )
+ {
+ eofChars = lineEndings;
+ }
+ }
+ }
+ finally
+ {
+ if ( raf != null )
+ {
+ try
+ {
+ raf.close();
+ }
+ catch ( IOException ex )
+ {
+ // ignore
+ }
+ }
+ }
+ }
+ else if ( atEndOfFile == true )
+ {
+ eofChars = lineEndings;
+ }
+
+ BufferedReader in = null;
+ BufferedWriter out = null;
+ try
+ {
+ if ( encoding == null )
+ {
+ // platform encoding
+ in = new BufferedReader( new InputStreamReader( new
FileInputStream( source ) ) );
+ out = new BufferedWriter( new OutputStreamWriter( new
FileOutputStream( dest ) ) );
+ }
+ else
+ {
+ // MASSEMBLY-371
+ in = new BufferedReader( new InputStreamReader( new
FileInputStream( source ), encoding ) );
+ out = new BufferedWriter( new OutputStreamWriter( new
FileOutputStream( dest ), encoding ) );
+ }
+
+ String line;
+
+ line = in.readLine();
+ while ( line != null )
+ {
+ out.write( line );
+ line = in.readLine();
+ if ( line != null )
+ {
+ out.write( lineEndings );
+ }
+ else
+ {
+ out.write( eofChars );
+ }
+ }
+
+ out.flush();
+ }
+ finally
+ {
+ IOUtil.close( in );
+ IOUtil.close( out );
+ }
+ }
+
+ @Nullable
+ public static String getLineEndingCharacters( @Nullable String lineEnding )
+ throws AssemblyFormattingException
+ {
+ String value = lineEnding;
+ if ( lineEnding != null )
+ {
+ if ( LINE_ENDING_KEEP.equals( lineEnding ) )
+ {
+ value = null;
+ }
+ else if ( LINE_ENDING_DOS.equals( lineEnding ) ||
LINE_ENDING_WINDOWS.equals( lineEnding )
+ || LINE_ENDING_CRLF.equals( lineEnding ) )
+ {
+ value = "\r\n";
+ }
+ else if ( LINE_ENDING_UNIX.equals( lineEnding ) ||
LINE_ENDING_LF.equals( lineEnding ) )
+ {
+ value = "\n";
+ }
+ else
+ {
+ throw new AssemblyFormattingException( "Illegal lineEnding
specified: '" + lineEnding + "'" );
+ }
+ }
+
+ return value;
+ }
+
+}
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java?rev=1621884&r1=1621883&r2=1621884&view=diff
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
(original)
+++
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
Mon Sep 1 20:50:32 2014
@@ -29,7 +29,7 @@ import org.apache.maven.plugin.assembly.
import org.apache.maven.plugin.assembly.model.FileSet;
import org.apache.maven.plugin.assembly.testutils.MockManager;
import org.apache.maven.plugin.assembly.testutils.TestFileManager;
-import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
+import org.apache.maven.plugin.assembly.utils.LineEndingsUtils;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.logging.Logger;
@@ -92,7 +92,7 @@ public class FileSetFormatterTest
throws AssemblyFormattingException, IOException
{
final FileSet fs = new FileSet();
- fs.setLineEnding( AssemblyFileUtils.LINE_ENDING_KEEP );
+ fs.setLineEnding( LineEndingsUtils.LINE_ENDING_KEEP );
final FileSetFormatter formatter = new FileSetFormatter( configSource,
logger );
@@ -110,7 +110,7 @@ public class FileSetFormatterTest
final FileSet fs = new FileSet();
- fs.setLineEnding( AssemblyFileUtils.LINE_ENDING_LF );
+ fs.setLineEnding( LineEndingsUtils.LINE_ENDING_LF );
fs.setDirectory( dir.getCanonicalPath() );
fs.addExclude( "**/*" );
@@ -133,7 +133,7 @@ public class FileSetFormatterTest
final FileSet fs = new FileSet();
- fs.setLineEnding( AssemblyFileUtils.LINE_ENDING_CRLF );
+ fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
fs.setDirectory( dir.getCanonicalPath() );
fs.addInclude( "**/*.txt" );
@@ -175,7 +175,7 @@ public class FileSetFormatterTest
final FileSet fs = new FileSet();
- fs.setLineEnding( AssemblyFileUtils.LINE_ENDING_CRLF );
+ fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
fs.setDirectory( dir.getCanonicalPath() );
fs.addExclude( "**/two.txt" );
@@ -217,7 +217,7 @@ public class FileSetFormatterTest
final FileSet fs = new FileSet();
- fs.setLineEnding( AssemblyFileUtils.LINE_ENDING_CRLF );
+ fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
fs.setDirectory( dir.getCanonicalPath() );
fs.addInclude( "**/one.txt" );
@@ -258,7 +258,7 @@ public class FileSetFormatterTest
final FileSet fs = new FileSet();
- fs.setLineEnding( AssemblyFileUtils.LINE_ENDING_CRLF );
+ fs.setLineEnding( LineEndingsUtils.LINE_ENDING_CRLF );
fs.setDirectory( dir.getCanonicalPath() );
final FileSetFormatter formatter = new FileSetFormatter( configSource,
logger );
Modified:
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtilsTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtilsTest.java?rev=1621884&r1=1621883&r2=1621884&view=diff
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtilsTest.java
(original)
+++
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/AssemblyFileUtilsTest.java
Mon Sep 1 20:50:32 2014
@@ -20,23 +20,17 @@ package org.apache.maven.plugin.assembly
*/
import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
import junit.framework.TestCase;
import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
-import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
import org.apache.maven.plugin.assembly.testutils.MockManager;
import org.apache.maven.plugin.assembly.testutils.TestFileManager;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.archiver.manager.ArchiverManager;
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
-import org.codehaus.plexus.util.IOUtil;
import org.easymock.MockControl;
public class AssemblyFileUtilsTest
@@ -98,222 +92,4 @@ public class AssemblyFileUtilsTest
mockManager.verifyAll();
}
- public void testGetLineEndingChars_ShouldReturnDosLineEnding()
- throws AssemblyFormattingException
- {
- assertEquals( "\r\n", AssemblyFileUtils.getLineEndingCharacters(
"windows" ) );
- assertEquals( "\r\n", AssemblyFileUtils.getLineEndingCharacters( "dos"
) );
- assertEquals( "\r\n", AssemblyFileUtils.getLineEndingCharacters(
"crlf" ) );
- }
-
- public void testGetLineEndingChars_ShouldReturnUnixLineEnding()
- throws AssemblyFormattingException
- {
- assertEquals( "\n", AssemblyFileUtils.getLineEndingCharacters( "unix"
) );
- assertEquals( "\n", AssemblyFileUtils.getLineEndingCharacters( "lf" )
);
- }
-
- public void testGetLineEndingChars_ShouldReturnNullLineEnding()
- throws AssemblyFormattingException
- {
- assertNull( AssemblyFileUtils.getLineEndingCharacters( "keep" ) );
- }
-
- public void
testGetLineEndingChars_ShouldThrowFormattingExceptionWithInvalidHint()
- {
- try
- {
- AssemblyFileUtils.getLineEndingCharacters( "invalid" );
-
- fail( "Invalid line-ending hint should throw a formatting
exception." );
- }
- catch ( AssemblyFormattingException e )
- {
- }
- }
-
- public void testConvertLineEndings_ShouldReplaceLFWithCRLF()
- throws IOException
- {
- String test = "This is a \ntest.";
- String check = "This is a \r\ntest.";
-
- testConversion( test, check, "\r\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceLFWithCRLFAtEOF()
- throws IOException
- {
- String test = "This is a \ntest.\n";
- String check = "This is a \r\ntest.\r\n";
-
- testConversion( test, check, "\r\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceCRLFWithLF()
- throws IOException
- {
- String test = "This is a \r\ntest.";
- String check = "This is a \ntest.";
-
- testConversion( test, check, "\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceCRLFWithLFAtEOF()
- throws IOException
- {
- String test = "This is a \r\ntest.\r\n";
- String check = "This is a \ntest.\n";
-
- testConversion( test, check, "\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceLFWithLF()
- throws IOException
- {
- String test = "This is a \ntest.";
- String check = "This is a \ntest.";
-
- testConversion( test, check, "\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceLFWithLFAtEOF()
- throws IOException
- {
- String test = "This is a \ntest.\n";
- String check = "This is a \ntest.\n";
-
- testConversion( test, check, "\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceCRLFWithCRLF()
- throws IOException
- {
- String test = "This is a \r\ntest.";
- String check = "This is a \r\ntest.";
-
- testConversion( test, check, "\r\n", null );
- }
-
- public void testConvertLineEndings_ShouldReplaceCRLFWithCRLFAtEOF()
- throws IOException
- {
- String test = "This is a \r\ntest.\r\n";
- String check = "This is a \r\ntest.\r\n";
-
- testConversion( test, check, "\r\n", null );
- }
-
- public void testConvertLineEndings_LFToCRLFNoEOFForceEOF()
- throws IOException
- {
- String test = "This is a \ntest.";
- String check = "This is a \r\ntest.\r\n";
-
- testConversion( test, check, "\r\n", true );
- }
-
- public void testConvertLineEndings_LFToCRLFWithEOFForceEOF()
- throws IOException
- {
- String test = "This is a \ntest.\n";
- String check = "This is a \r\ntest.\r\n";
-
- testConversion( test, check, "\r\n", true );
- }
-
- public void testConvertLineEndings_LFToCRLFNoEOFStripEOF()
- throws IOException
- {
- String test = "This is a \ntest.";
- String check = "This is a \r\ntest.";
-
- testConversion( test, check, "\r\n", false );
- }
-
- public void testConvertLineEndings_LFToCRLFWithEOFStripEOF()
- throws IOException
- {
- String test = "This is a \ntest.\n";
- String check = "This is a \r\ntest.";
-
- testConversion( test, check, "\r\n", false );
- }
-
- public void testConvertLineEndings_CRLFToLFNoEOFForceEOF()
- throws IOException
- {
- String test = "This is a \r\ntest.";
- String check = "This is a \ntest.\n";
-
- testConversion( test, check, "\n", true );
- }
-
- public void testConvertLineEndings_CRLFToLFWithEOFForceEOF()
- throws IOException
- {
- String test = "This is a \r\ntest.\r\n";
- String check = "This is a \ntest.\n";
-
- testConversion( test, check, "\n", true );
- }
-
- public void testConvertLineEndings_CRLFToLFNoEOFStripEOF()
- throws IOException
- {
- String test = "This is a \r\ntest.";
- String check = "This is a \ntest.";
-
- testConversion( test, check, "\n", false );
- }
-
- public void testConvertLineEndings_CRLFToLFWithEOFStripEOF()
- throws IOException
- {
- String test = "This is a \r\ntest.\r\n";
- String check = "This is a \ntest.";
-
- testConversion( test, check, "\n", false );
- }
-
- private void testConversion( String test, String check, String
lineEndingChars, Boolean eof )
- throws IOException
- {
- File source = File.createTempFile( "line-conversion-test-in.", "" );
- source.deleteOnExit();
- File dest = File.createTempFile( "line-conversion-test-out.", "" );
- dest.deleteOnExit();
-
- FileWriter sourceWriter = null;
- StringReader sourceReader = new StringReader( test );
- try
- {
- sourceWriter = new FileWriter( source );
-
- IOUtil.copy( sourceReader, sourceWriter );
- }
- finally
- {
- IOUtil.close( sourceWriter );
- }
-
- // Using platform encoding for the conversion tests in this class is OK
- AssemblyFileUtils.convertLineEndings( source, dest, lineEndingChars,
eof, null );
-
- FileReader destReader = null;
- StringWriter destWriter = new StringWriter();
- try
- {
- destReader = new FileReader( dest );
-
- IOUtil.copy( destReader, destWriter );
- }
- finally
- {
- IOUtil.close( destReader );
- }
-
- assertEquals( check, destWriter.toString() );
- }
-
}
Added:
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java?rev=1621884&view=auto
==============================================================================
---
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
(added)
+++
maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LineEndingUtilsTest.java
Mon Sep 1 20:50:32 2014
@@ -0,0 +1,319 @@
+package org.apache.maven.plugin.assembly.utils;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
+import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
+import org.apache.maven.plugin.assembly.testutils.MockManager;
+import org.apache.maven.plugin.assembly.testutils.TestFileManager;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
+import org.codehaus.plexus.util.IOUtil;
+import org.easymock.MockControl;
+
+public class LineEndingUtilsTest
+ extends TestCase
+{
+
+ private TestFileManager fileManager = new TestFileManager(
"file-utils.test.", "" );
+
+ public void tearDown()
+ throws IOException
+ {
+ fileManager.cleanUp();
+ }
+
+ public void testUnpack_ShouldSetSourceAndDestinationAndCallExtract()
+ throws IOException, ArchiveExpansionException, NoSuchArchiverException
+ {
+ MockManager mockManager = new MockManager();
+
+ File source = fileManager.createTempFile();
+ File destDir = fileManager.createTempDir();
+
+ MockControl unarchiverCtl = MockControl.createControl(
UnArchiver.class );
+ mockManager.add( unarchiverCtl );
+
+ UnArchiver unarchiver = (UnArchiver) unarchiverCtl.getMock();
+
+ MockControl archiverManagerCtl = MockControl.createControl(
ArchiverManager.class );
+ mockManager.add( archiverManagerCtl );
+
+ ArchiverManager archiverManager = (ArchiverManager)
archiverManagerCtl.getMock();
+
+ try
+ {
+ archiverManager.getUnArchiver( source );
+ archiverManagerCtl.setReturnValue( unarchiver );
+ }
+ catch ( NoSuchArchiverException e )
+ {
+ fail( "Should never happen." );
+ }
+
+ unarchiver.setSourceFile( source );
+ unarchiver.setDestDirectory( destDir );
+
+ try
+ {
+ unarchiver.extract();
+ }
+ catch ( ArchiverException e )
+ {
+ fail( "Should never happen." );
+ }
+
+ mockManager.replayAll();
+
+ AssemblyFileUtils.unpack( source, destDir, archiverManager );
+
+ mockManager.verifyAll();
+ }
+
+ public void testGetLineEndingChars_ShouldReturnDosLineEnding()
+ throws AssemblyFormattingException
+ {
+ assertEquals( "\r\n", LineEndingsUtils.getLineEndingCharacters(
"windows" ) );
+ assertEquals( "\r\n", LineEndingsUtils.getLineEndingCharacters( "dos"
) );
+ assertEquals( "\r\n", LineEndingsUtils.getLineEndingCharacters( "crlf"
) );
+ }
+
+ public void testGetLineEndingChars_ShouldReturnUnixLineEnding()
+ throws AssemblyFormattingException
+ {
+ assertEquals( "\n", LineEndingsUtils.getLineEndingCharacters( "unix" )
);
+ assertEquals( "\n", LineEndingsUtils.getLineEndingCharacters( "lf" ) );
+ }
+
+ public void testGetLineEndingChars_ShouldReturnNullLineEnding()
+ throws AssemblyFormattingException
+ {
+ assertNull( LineEndingsUtils.getLineEndingCharacters( "keep" ) );
+ }
+
+ public void
testGetLineEndingChars_ShouldThrowFormattingExceptionWithInvalidHint()
+ {
+ try
+ {
+ LineEndingsUtils.getLineEndingCharacters( "invalid" );
+
+ fail( "Invalid line-ending hint should throw a formatting
exception." );
+ }
+ catch ( AssemblyFormattingException e )
+ {
+ }
+ }
+
+ public void testConvertLineEndings_ShouldReplaceLFWithCRLF()
+ throws IOException
+ {
+ String test = "This is a \ntest.";
+ String check = "This is a \r\ntest.";
+
+ testConversion( test, check, "\r\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceLFWithCRLFAtEOF()
+ throws IOException
+ {
+ String test = "This is a \ntest.\n";
+ String check = "This is a \r\ntest.\r\n";
+
+ testConversion( test, check, "\r\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceCRLFWithLF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.";
+ String check = "This is a \ntest.";
+
+ testConversion( test, check, "\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceCRLFWithLFAtEOF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.\r\n";
+ String check = "This is a \ntest.\n";
+
+ testConversion( test, check, "\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceLFWithLF()
+ throws IOException
+ {
+ String test = "This is a \ntest.";
+ String check = "This is a \ntest.";
+
+ testConversion( test, check, "\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceLFWithLFAtEOF()
+ throws IOException
+ {
+ String test = "This is a \ntest.\n";
+ String check = "This is a \ntest.\n";
+
+ testConversion( test, check, "\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceCRLFWithCRLF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.";
+ String check = "This is a \r\ntest.";
+
+ testConversion( test, check, "\r\n", null );
+ }
+
+ public void testConvertLineEndings_ShouldReplaceCRLFWithCRLFAtEOF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.\r\n";
+ String check = "This is a \r\ntest.\r\n";
+
+ testConversion( test, check, "\r\n", null );
+ }
+
+ public void testConvertLineEndings_LFToCRLFNoEOFForceEOF()
+ throws IOException
+ {
+ String test = "This is a \ntest.";
+ String check = "This is a \r\ntest.\r\n";
+
+ testConversion( test, check, "\r\n", true );
+ }
+
+ public void testConvertLineEndings_LFToCRLFWithEOFForceEOF()
+ throws IOException
+ {
+ String test = "This is a \ntest.\n";
+ String check = "This is a \r\ntest.\r\n";
+
+ testConversion( test, check, "\r\n", true );
+ }
+
+ public void testConvertLineEndings_LFToCRLFNoEOFStripEOF()
+ throws IOException
+ {
+ String test = "This is a \ntest.";
+ String check = "This is a \r\ntest.";
+
+ testConversion( test, check, "\r\n", false );
+ }
+
+ public void testConvertLineEndings_LFToCRLFWithEOFStripEOF()
+ throws IOException
+ {
+ String test = "This is a \ntest.\n";
+ String check = "This is a \r\ntest.";
+
+ testConversion( test, check, "\r\n", false );
+ }
+
+ public void testConvertLineEndings_CRLFToLFNoEOFForceEOF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.";
+ String check = "This is a \ntest.\n";
+
+ testConversion( test, check, "\n", true );
+ }
+
+ public void testConvertLineEndings_CRLFToLFWithEOFForceEOF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.\r\n";
+ String check = "This is a \ntest.\n";
+
+ testConversion( test, check, "\n", true );
+ }
+
+ public void testConvertLineEndings_CRLFToLFNoEOFStripEOF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.";
+ String check = "This is a \ntest.";
+
+ testConversion( test, check, "\n", false );
+ }
+
+ public void testConvertLineEndings_CRLFToLFWithEOFStripEOF()
+ throws IOException
+ {
+ String test = "This is a \r\ntest.\r\n";
+ String check = "This is a \ntest.";
+
+ testConversion( test, check, "\n", false );
+ }
+
+ private void testConversion( String test, String check, String
lineEndingChars, Boolean eof )
+ throws IOException
+ {
+ File source = File.createTempFile( "line-conversion-test-in.", "" );
+ source.deleteOnExit();
+ File dest = File.createTempFile( "line-conversion-test-out.", "" );
+ dest.deleteOnExit();
+
+ FileWriter sourceWriter = null;
+ StringReader sourceReader = new StringReader( test );
+ try
+ {
+ sourceWriter = new FileWriter( source );
+
+ IOUtil.copy( sourceReader, sourceWriter );
+ }
+ finally
+ {
+ IOUtil.close( sourceWriter );
+ }
+
+ // Using platform encoding for the conversion tests in this class is OK
+ LineEndingsUtils.convertLineEndings( source, dest, lineEndingChars,
eof, null );
+
+ FileReader destReader = null;
+ StringWriter destWriter = new StringWriter();
+ try
+ {
+ destReader = new FileReader( dest );
+
+ IOUtil.copy( destReader, destWriter );
+ }
+ finally
+ {
+ IOUtil.close( destReader );
+ }
+
+ assertEquals( check, destWriter.toString() );
+ }
+
+}