This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch MSTAGE-25
in repository https://gitbox.apache.org/repos/asf/maven-stage-plugin.git

commit e0970e12efd878bb0183eb2b9cac304fa6f418a8
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Sat Jun 17 07:03:51 2023 -0400

    [MSTAGE-25] use Apache Commons IO instead of Plexus
---
 .../plugins/stage/DefaultRepositoryCopier.java     | 71 ++++++++++------------
 1 file changed, 33 insertions(+), 38 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/stage/DefaultRepositoryCopier.java 
b/src/main/java/org/apache/maven/plugins/stage/DefaultRepositoryCopier.java
index 8b65ca6..763a17b 100644
--- a/src/main/java/org/apache/maven/plugins/stage/DefaultRepositoryCopier.java
+++ b/src/main/java/org/apache/maven/plugins/stage/DefaultRepositoryCopier.java
@@ -19,6 +19,7 @@ package org.apache.maven.plugins.stage;
  * under the License.
  */
 
+import org.apache.commons.io.IOUtils;
 import org.apache.maven.artifact.manager.WagonManager;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.metadata.Metadata;
@@ -41,7 +42,6 @@ import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.LogEnabled;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
@@ -231,7 +231,7 @@ public class DefaultRepositoryCopier
 
         InputStream is = new FileInputStream( renameScript );
 
-        IOUtil.copy( is, zos );
+        IOUtils.copy( is, zos );
 
         zos.close();
         is.close();
@@ -306,35 +306,33 @@ public class DefaultRepositoryCopier
             }
             else
             {
-                InputStream is = new FileInputStream( f );
-
-                String s = f.getAbsolutePath().substring( 
basedir.getAbsolutePath().length() + 1 );
-                s = s.replace( '\\', '/' );
-
-                // We are marking any version directories with the in-process 
flag so that
-                // anything being unpacked on the target side will not be 
recognized by Maven
-                // and so users cannot download partially uploaded files.
+                try (InputStream is = new FileInputStream( f )) {
+                    String s = f.getAbsolutePath().substring( 
basedir.getAbsolutePath().length() + 1 );
+                    s = s.replace( '\\', '/' );
 
-                String vtag = "/" + version;
+                    // We are marking any version directories with the 
in-process flag so that
+                    // anything being unpacked on the target side will not be 
recognized by Maven
+                    // and so users cannot download partially uploaded files.
 
-                s = s.replace( vtag + "/", vtag + IN_PROCESS_MARKER + "/" );
+                    String vtag = "/" + version;
 
-                ZipEntry e = new ZipEntry( s );
+                    s = s.replace( vtag + "/", vtag + IN_PROCESS_MARKER + "/" 
);
 
-                zos.putNextEntry( e );
+                    ZipEntry e = new ZipEntry( s );
 
-                IOUtil.copy( is, zos );
+                    zos.putNextEntry( e );
 
-                is.close();
+                    IOUtils.copy( is, zos );
 
-                int idx = s.indexOf( IN_PROCESS_MARKER );
+                    int idx = s.indexOf( IN_PROCESS_MARKER );
 
-                if ( idx > 0 )
-                {
-                    String d = s.substring( 0, idx );
+                    if ( idx > 0 )
+                    {
+                        String d = s.substring( 0, idx );
 
-                    moveCommands.add( "mv " + d + IN_PROCESS_MARKER + " " + d 
);
-                }
+                        moveCommands.add( "mv " + d + IN_PROCESS_MARKER + " " 
+ d );
+                    }
+                } 
             }
         }
     }
@@ -360,11 +358,10 @@ public class DefaultRepositoryCopier
 
         existing.merge( staged );
 
-        Writer writer = new FileWriter( existingMetadata );
-
-        this.writer.write( writer, existing );
-
-        writer.close();
+        try (Writer writer = new FileWriter( existingMetadata )) {
+            this.writer.write( writer, existing );
+        }
+        
         stagedMetadataReader.close();
         existingMetadataReader.close();
 
@@ -405,21 +402,19 @@ public class DefaultRepositoryCopier
     {
         MessageDigest md5 = MessageDigest.getInstance( type );
 
-        InputStream is = new FileInputStream( file );
-
-        // CHECKSTYLE_OFF: MagicNumber
-        byte[] buf = new byte[8192];
-        // CHECKSTYLE_ON: MagicNumber
+        try (InputStream is = new FileInputStream( file )) {
+            // CHECKSTYLE_OFF: MagicNumber
+            byte[] buf = new byte[8192];
+            // CHECKSTYLE_ON: MagicNumber
 
-        int i;
+            int i;
 
-        while ( ( i = is.read( buf ) ) >= 0 )
-        {
-            md5.update( buf, 0, i );
+            while ( ( i = is.read( buf ) ) >= 0 )
+            {
+                md5.update( buf, 0, i );
+            }
         }
 
-        is.close();
-
         return encode( md5.digest() );
     }
 

Reply via email to