Search in sources :

Example 1 with LineEndings

use of org.apache.maven.plugins.assembly.utils.LineEndings in project maven-plugins by apache.

the class ReaderFormatter method getFileSetTransformers.

@Nullable
public static InputStreamTransformer getFileSetTransformers(final AssemblerConfigurationSource configSource, final boolean isFiltered, String fileSetLineEnding) throws AssemblyFormattingException {
    final LineEndings lineEndingToUse = LineEndingsUtils.getLineEnding(fileSetLineEnding);
    final boolean transformLineEndings = !LineEndings.keep.equals(lineEndingToUse);
    if (transformLineEndings || isFiltered) {
        return new InputStreamTransformer() {

            @Override
            @Nonnull
            public InputStream transform(@Nonnull PlexusIoResource plexusIoResource, @Nonnull InputStream inputStream) throws IOException {
                InputStream result = inputStream;
                if (isFiltered) {
                    boolean isPropertyFile = AssemblyFileUtils.isPropertyFile(plexusIoResource.getName());
                    final String encoding = isPropertyFile ? "ISO-8859-1" : configSource.getEncoding();
                    Reader source = encoding != null ? new InputStreamReader(inputStream, encoding) : // wtf platform encoding ? TODO: Fix this
                    new InputStreamReader(inputStream);
                    Reader filtered = createReaderFilter(source, configSource.getEscapeString(), configSource.getDelimiters(), configSource, isPropertyFile);
                    result = encoding != null ? new ReaderInputStream(filtered, encoding) : new ReaderInputStream(filtered);
                }
                if (transformLineEndings) {
                    checkifFileTypeIsAppropriateForLineEndingTransformation(plexusIoResource);
                    result = LineEndingsUtils.lineEndingConverter(result, lineEndingToUse);
                }
                return result;
            }
        };
    }
    return null;
}
Also used : LineEndings(org.apache.maven.plugins.assembly.utils.LineEndings) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) PlexusIoResource(org.codehaus.plexus.components.io.resources.PlexusIoResource) InputStreamReader(java.io.InputStreamReader) Nonnull(javax.annotation.Nonnull) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStream(java.io.InputStream) InputStreamTransformer(org.codehaus.plexus.components.io.functions.InputStreamTransformer) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Nullable(javax.annotation.Nullable)

Aggregations

InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)1 LineEndings (org.apache.maven.plugins.assembly.utils.LineEndings)1 InputStreamTransformer (org.codehaus.plexus.components.io.functions.InputStreamTransformer)1 PlexusIoResource (org.codehaus.plexus.components.io.resources.PlexusIoResource)1