You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2014/10/22 07:05:30 UTC

svn commit: r1633523 - in /maven/plugins/trunk/maven-assembly-plugin/src: main/java/org/apache/maven/plugin/assembly/archive/phase/ main/java/org/apache/maven/plugin/assembly/archive/task/ main/java/org/apache/maven/plugin/assembly/format/ main/java/or...

Author: krosenvold
Date: Wed Oct 22 05:05:29 2014
New Revision: 1633523

URL: http://svn.apache.org/r1633523
Log:
Added missing files, because I have forgotten how to use SVN

Removed some unused code

Added:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStream.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStream.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStreamTest.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStreamTest.java
Removed:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileSetFormatter.java
    maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/format/FileSetFormatterTest.java
Modified:
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/phase/FileItemAssemblyPhase.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java
    maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/format/FileFormatter.java

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/phase/FileItemAssemblyPhase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/phase/FileItemAssemblyPhase.java?rev=1633523&r1=1633522&r2=1633523&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/phase/FileItemAssemblyPhase.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/phase/FileItemAssemblyPhase.java Wed Oct 22 05:05:29 2014
@@ -87,7 +87,7 @@ public class FileItemAssemblyPhase
             final String outputDirectory =
                 AssemblyFormatUtils.getOutputDirectory( fileItem.getOutputDirectory(), configSource.getProject(), null,
                                                         configSource.getFinalName(), configSource );
-
+                                            ¥
             String target;
 
             // omit the last char if ends with / or \\

Modified: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java?rev=1633523&r1=1633522&r2=1633523&view=diff
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java (original)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/archive/task/AddFileSetsTask.java Wed Oct 22 05:05:29 2014
@@ -139,7 +139,11 @@ public class AddFileSetsTask
 
         if ( fileSetDir.exists() )
         {
-            InputStreamTransformer fileSetTransformers = getFileSetTransformers( configSource, fileSetDir, fileSet );
+            InputStreamTransformer fileSetTransformers = getFileSetTransformers( configSource, fileSet );
+            if (fileSetTransformers == null)
+            {
+                logger.debug( "NOT reformatting any files in " + fileSetDir );
+            }
 
             if ( fileSetDir.getPath().equals( File.separator ) )
             {
@@ -175,8 +179,8 @@ public class AddFileSetsTask
         }
     }
 
-    private InputStreamTransformer getFileSetTransformers( final AssemblerConfigurationSource configSource, File fileSetDir,
-                                                            final org.apache.maven.plugin.assembly.model.FileSet set )
+    private InputStreamTransformer getFileSetTransformers( final AssemblerConfigurationSource configSource,
+                                                           final org.apache.maven.plugin.assembly.model.FileSet set )
         throws AssemblyFormattingException
     {
         final String lineEndingHint = set.getLineEnding();
@@ -230,11 +234,7 @@ public class AddFileSetsTask
             };
             return isf;
         }
-        else
-        {
-            logger.debug( "NOT reformatting any files in " + fileSetDir );
-            return null;
-        }
+        return null;
     }
 
 

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=1633523&r1=1633522&r2=1633523&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 Wed Oct 22 05:05:29 2014
@@ -65,7 +65,7 @@ public class FileFormatter
         return format( source, filter, lineEnding, configSource.getTemporaryRootDirectory(), encoding );
     }
 
-    public File format( @Nonnull File source, boolean filter, String lineEndingCharacters, @Nullable File tempRoot,
+    private File format( @Nonnull File source, boolean filter, String lineEndingCharacters, @Nullable File tempRoot,
                         String encoding )
         throws AssemblyFormattingException
     {

Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStream.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStream.java?rev=1633523&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStream.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStream.java Wed Oct 22 05:05:29 2014
@@ -0,0 +1,109 @@
+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.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Kristian Rosenvold
+ */
+class LinuxLineFeedInputStream
+    extends InputStream
+{
+
+    private boolean slashNSeen = false;
+
+    private boolean eofSeen = false;
+
+    private final InputStream target;
+
+    private final boolean ensureLineFeedAtEndOfFile;
+
+    public LinuxLineFeedInputStream( InputStream in, boolean ensureLineFeedAtEndOfFile )
+    {
+        this.target = in;
+        this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
+    }
+
+    private int readWithUpdate()
+        throws IOException
+    {
+        final int target = this.target.read();
+        eofSeen = target == -1;
+        if ( eofSeen )
+        {
+            return target;
+        }
+        slashNSeen = target == '\n';
+        return target;
+    }
+
+    @Override public int read()
+        throws IOException
+    {
+        if ( eofSeen )
+        {
+            return eofGame();
+        }
+        else
+        {
+            int target = readWithUpdate();
+            if ( eofSeen )
+            {
+                return eofGame();
+            }
+            if ( target == '\r' )
+            {
+                target = readWithUpdate();
+            }
+            return target;
+        }
+    }
+
+    private int eofGame()
+    {
+        if ( !ensureLineFeedAtEndOfFile )
+        {
+            return -1;
+        }
+        if ( !slashNSeen )
+        {
+            slashNSeen = true;
+            return '\n';
+        }
+        else
+        {
+            return -1;
+        }
+    }
+
+    @Override public void close()
+        throws IOException
+    {
+        super.close();
+        target.close();
+    }
+
+    @Override public synchronized void mark( int readlimit )
+    {
+        throw new UnsupportedOperationException( "Mark not implemented yet" );
+    }
+}

Added: maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStream.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStream.java?rev=1633523&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStream.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/main/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStream.java Wed Oct 22 05:05:29 2014
@@ -0,0 +1,130 @@
+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.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Kristian Rosenvold
+ */
+class WindowsLineFeedInputStream
+    extends InputStream
+{
+
+    private boolean slashRSeen = false;
+
+    private boolean slashNSeen = false;
+
+    private boolean injectSlashN = false;
+
+    private boolean eofSeen = false;
+
+    private final InputStream target;
+
+    private final boolean ensureLineFeedAtEndOfFile;
+
+    public WindowsLineFeedInputStream( InputStream in, boolean ensureLineFeedAtEndOfFile )
+    {
+        this.target = in;
+        this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
+    }
+
+    private int readWithUpdate()
+        throws IOException
+    {
+        final int target = this.target.read();
+        eofSeen = target == -1;
+        if ( eofSeen )
+        {
+            return target;
+        }
+        slashRSeen = target == '\r';
+        slashNSeen = target == '\n';
+        return target;
+    }
+
+    @Override public int read()
+        throws IOException
+    {
+        if ( eofSeen )
+        {
+            return eofGame();
+        }
+        else if ( injectSlashN )
+        {
+            injectSlashN = false;
+            return '\n';
+        }
+        else
+        {
+            boolean prevWasSlashR = slashRSeen;
+            int target = readWithUpdate();
+            if ( eofSeen )
+            {
+                return eofGame();
+            }
+            if ( target == '\n' )
+            {
+                if ( !prevWasSlashR )
+                {
+                    injectSlashN = true;
+                    return '\r';
+                }
+            }
+            return target;
+        }
+    }
+
+    private int eofGame()
+    {
+        if ( !ensureLineFeedAtEndOfFile )
+        {
+            return -1;
+        }
+        if ( !slashNSeen && !slashRSeen )
+        {
+            slashRSeen = true;
+            return '\r';
+        }
+        if ( !slashNSeen )
+        {
+            slashRSeen = false;
+            slashNSeen = true;
+            return '\n';
+        }
+        else
+        {
+            return -1;
+        }
+    }
+
+    @Override public void close()
+        throws IOException
+    {
+        super.close();
+        target.close();
+    }
+
+    @Override public synchronized void mark( int readlimit )
+    {
+        throw new UnsupportedOperationException( "Mark not implemented yet" );
+    }
+}

Added: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStreamTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStreamTest.java?rev=1633523&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStreamTest.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/LinuxLineFeedInputStreamTest.java Wed Oct 22 05:05:29 2014
@@ -0,0 +1,87 @@
+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 junit.framework.TestCase;
+import org.codehaus.plexus.components.io.resources.LinefeedMode;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import static org.codehaus.plexus.components.io.resources.LinefeedMode.unix;
+
+public class LinuxLineFeedInputStreamTest
+    extends TestCase
+{
+
+    public void testSimpleString()
+        throws Exception
+    {
+        assertEquals( "abc\n", roundtrip( "abc", unix ) );
+    }
+
+    public void testInTheMiddleOfTheLine()
+        throws Exception
+    {
+        assertEquals( "a\nbc\n", roundtrip( "a\r\nbc", unix ) );
+    }
+
+    public void testMultipleBlankLines()
+        throws Exception
+    {
+        assertEquals( "a\n\nbc\n", roundtrip( "a\r\n\r\nbc", unix ) );
+    }
+
+    public void testTwoLinesAtEnd()
+        throws Exception
+    {
+        assertEquals( "a\n\n", roundtrip( "a\r\n\r\n", unix ) );
+    }
+
+    public void testMalformed()
+        throws Exception
+    {
+        assertEquals( "abc", roundtrip( "a\rbc", false ) );
+    }
+
+    public void testRetainLineFeed()
+        throws Exception
+    {
+        assertEquals( "a\n\n", roundtrip( "a\r\n\r\n", false ) );
+        assertEquals( "a", roundtrip( "a", false ) );
+    }
+
+    private String roundtrip( String msg, LinefeedMode linefeedMode )
+        throws IOException
+    {
+        return roundtrip( msg, true );
+    }
+
+    private String roundtrip( String msg, boolean ensure )
+        throws IOException
+    {
+        ByteArrayInputStream baos = new ByteArrayInputStream( msg.getBytes() );
+        LinuxLineFeedInputStream lf = new LinuxLineFeedInputStream( baos, ensure );
+        byte[] buf = new byte[100];
+        final int read = lf.read( buf );
+        return new String( buf, 0, read );
+    }
+
+}
\ No newline at end of file

Added: maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStreamTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStreamTest.java?rev=1633523&view=auto
==============================================================================
--- maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStreamTest.java (added)
+++ maven/plugins/trunk/maven-assembly-plugin/src/test/java/org/apache/maven/plugin/assembly/utils/WindowsLineFeedInputStreamTest.java Wed Oct 22 05:05:29 2014
@@ -0,0 +1,93 @@
+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 junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class WindowsLineFeedInputStreamTest
+    extends TestCase
+{
+
+    public void testSimpleString()
+        throws Exception
+    {
+        assertEquals( "abc\r\n", roundtrip( "abc" ) );
+    }
+
+    public void testInTheMiddleOfTheLine()
+        throws Exception
+    {
+        assertEquals( "a\r\nbc\r\n", roundtrip( "a\r\nbc" ) );
+    }
+
+    public void testMultipleBlankLines()
+        throws Exception
+    {
+        assertEquals( "a\r\n\r\nbc\r\n", roundtrip( "a\r\n\r\nbc" ) );
+    }
+
+    public void testTwoLinesAtEnd()
+        throws Exception
+    {
+        assertEquals( "a\r\n\r\n", roundtrip( "a\r\n\r\n" ) );
+    }
+
+    public void testLinuxLinefeeds()
+        throws Exception
+    {
+        final String roundtrip = roundtrip( "ab\nc", false );
+        assertEquals( "ab\r\nc", roundtrip );
+    }
+
+
+    public void testMalformed()
+        throws Exception
+    {
+        assertEquals( "a\rbc", roundtrip( "a\rbc", false ) );
+    }
+
+    public void testRetainLineFeed()
+        throws Exception
+    {
+        assertEquals( "a\r\n\r\n", roundtrip( "a\r\n\r\n", false ) );
+        assertEquals( "a", roundtrip( "a", false ) );
+    }
+
+    private String roundtrip( String msg )
+        throws IOException
+    {
+        return roundtrip( msg, true );
+    }
+
+    private String roundtrip( String msg, boolean ensure )
+        throws IOException
+    {
+        ByteArrayInputStream baos = new ByteArrayInputStream( msg.getBytes() );
+        WindowsLineFeedInputStream lf = new WindowsLineFeedInputStream( baos, ensure );
+        byte[] buf = new byte[100];
+        final int read = lf.read( buf );
+        return new String( buf, 0, read );
+    }
+
+
+}
\ No newline at end of file