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

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

commit f336cf32b4144268ba69345ad2f7f5fb328ef6a4
Author: Sylwester Lachiewicz <slachiew...@apache.org>
AuthorDate: Sun Jan 26 14:29:12 2025 +0100

    [MSTAGE-28] Reformat code with spotless:apply and fix checkstyle
---
 pom.xml                                            |  28 +-
 .../maven/plugins/stage/CopyRepositoryMojo.java    |  53 +--
 .../plugins/stage/DefaultRepositoryCopier.java     | 410 +++++++++------------
 .../maven/plugins/stage/RepositoryCopier.java      |  14 +-
 .../maven/plugins/stage/RepositoryCopierTest.java  |  91 +++--
 5 files changed, 258 insertions(+), 338 deletions(-)

diff --git a/pom.xml b/pom.xml
index a1a525f..b247bdd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
+<?xml version="1.0" encoding="UTF-8"?>
 <!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
@@ -18,7 +17,6 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 -->
-
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
   <modelVersion>4.0.0</modelVersion>
 
@@ -33,9 +31,7 @@ under the License.
   <packaging>maven-plugin</packaging>
 
   <name>Apache Maven Stage Plugin</name>
-  <description>
-    The Maven Stage Plugin copies artifacts from one repository to another.
-  </description>
+  <description>The Maven Stage Plugin copies artifacts from one repository to 
another.</description>
 
   <prerequisites>
     <maven>${mavenVersion}</maven>
@@ -44,8 +40,8 @@ under the License.
   <scm>
     
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-stage-plugin.git</connection>
     
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-stage-plugin.git</developerConnection>
-    
<url>https://github.com/apache/maven-stage-plugin/tree/${project.scm.tag}</url>
     <tag>HEAD</tag>
+    
<url>https://github.com/apache/maven-stage-plugin/tree/${project.scm.tag}</url>
   </scm>
   <issueManagement>
     <system>JIRA</system>
@@ -193,17 +189,25 @@ under the License.
             <executions>
               <execution>
                 <id>integration-test</id>
+                <goals>
+                  <goal>run</goal>
+                </goals>
                 <phase>integration-test</phase>
                 <configuration>
                   <target>
-                    <echo /><echo /><echo /><echo /><echo />
+                    <echo />
+                    <echo />
+                    <echo />
+                    <echo />
+                    <echo />
                     <echo level="warning">NO INTEGRATION TESTS DEFINED</echo>
-                    <echo /><echo /><echo /><echo /><echo />
+                    <echo />
+                    <echo />
+                    <echo />
+                    <echo />
+                    <echo />
                   </target>
                 </configuration>
-                <goals>
-                  <goal>run</goal>
-                </goals>
               </execution>
             </executions>
           </plugin>
diff --git 
a/src/main/java/org/apache/maven/plugins/stage/CopyRepositoryMojo.java 
b/src/main/java/org/apache/maven/plugins/stage/CopyRepositoryMojo.java
index 76a2896..18ae8e5 100644
--- a/src/main/java/org/apache/maven/plugins/stage/CopyRepositoryMojo.java
+++ b/src/main/java/org/apache/maven/plugins/stage/CopyRepositoryMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.stage;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,6 +16,9 @@ package org.apache.maven.plugins.stage;
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.maven.plugins.stage;
+
+import java.io.IOException;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -27,21 +28,17 @@ import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.wagon.WagonException;
 import org.apache.maven.wagon.repository.Repository;
 
-import java.io.IOException;
-
 /**
  * Copies artifacts from one repository to another repository.
- * 
+ *
  * @author Jason van Zyl
  */
-@Mojo( name = "copy", requiresProject = false )
-public class CopyRepositoryMojo
-    extends AbstractMojo
-{
+@Mojo(name = "copy", requiresProject = false)
+public class CopyRepositoryMojo extends AbstractMojo {
     /**
      * The URL to the source repository.
      */
-    @Parameter( property = "source" )
+    @Parameter(property = "source")
     private String source;
 
     /**
@@ -52,19 +49,19 @@ public class CopyRepositoryMojo
      * as a target URL.
      * </p>
      */
-    @Parameter( property = "target" )
+    @Parameter(property = "target")
     private String target;
 
     /**
      * The id of the source repository, required if you need the configuration 
from the user settings.
      */
-    @Parameter( property = "sourceRepositoryId", defaultValue = "source" )
+    @Parameter(property = "sourceRepositoryId", defaultValue = "source")
     private String sourceRepositoryId;
 
     /**
      * The id of the target repository, required if you need the configuration 
from the user settings.
      */
-    @Parameter( property = "targetRepositoryId", defaultValue = "target" )
+    @Parameter(property = "targetRepositoryId", defaultValue = "target")
     private String targetRepositoryId;
 
     /**
@@ -74,7 +71,7 @@ public class CopyRepositoryMojo
      * <i>All</i> versions of the artifacts will be copied.
      * </p>
      */
-    @Parameter( property = "version", required = true )
+    @Parameter(property = "version", required = true)
     private String version;
 
     /**
@@ -83,25 +80,15 @@ public class CopyRepositoryMojo
     @Component
     private RepositoryCopier copier;
 
-    public void execute()
-        throws MojoExecutionException
-    {
-        try
-        {
-            Repository sourceRepository = new Repository( sourceRepositoryId, 
source );
-            Repository targetRepository = new Repository( targetRepositoryId, 
target );
-            copier.copy( sourceRepository, targetRepository, version );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException(
-                "Error copying repository from " + source + " to " + target, e 
);
-        }
-        catch ( WagonException e )
-        {
-            throw new MojoExecutionException(
-                "Error copying repository from " + source + " to " + target, e 
);
+    public void execute() throws MojoExecutionException {
+        try {
+            Repository sourceRepository = new Repository(sourceRepositoryId, 
source);
+            Repository targetRepository = new Repository(targetRepositoryId, 
target);
+            copier.copy(sourceRepository, targetRepository, version);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Error copying repository from " 
+ source + " to " + target, e);
+        } catch (WagonException e) {
+            throw new MojoExecutionException("Error copying repository from " 
+ source + " to " + target, e);
         }
     }
 }
-
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 c1994c9..f246f98 100644
--- a/src/main/java/org/apache/maven/plugins/stage/DefaultRepositoryCopier.java
+++ b/src/main/java/org/apache/maven/plugins/stage/DefaultRepositoryCopier.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.stage;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,6 +16,27 @@ package org.apache.maven.plugins.stage;
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.maven.plugins.stage;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -26,8 +45,8 @@ import 
org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.metadata.Metadata;
 import 
org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
 import 
org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
-import org.apache.maven.wagon.CommandExecutor;
 import org.apache.maven.wagon.CommandExecutionException;
+import org.apache.maven.wagon.CommandExecutor;
 import org.apache.maven.wagon.ConnectionException;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
@@ -44,33 +63,11 @@ import org.codehaus.plexus.logging.LogEnabled;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
 /**
  * @author Jason van Zyl
  */
-@Component( role = RepositoryCopier.class )
-public class DefaultRepositoryCopier
-    implements LogEnabled, RepositoryCopier
-{
+@Component(role = RepositoryCopier.class)
+public class DefaultRepositoryCopier implements LogEnabled, RepositoryCopier {
     private MetadataXpp3Reader reader = new MetadataXpp3Reader();
 
     private MetadataXpp3Writer writer = new MetadataXpp3Writer();
@@ -80,59 +77,58 @@ public class DefaultRepositoryCopier
 
     private Logger logger;
 
-    public void copy( Repository sourceRepository, Repository 
targetRepository, String version )
-        throws WagonException, IOException
-    {
+    // CHECKSTYLE_OFF: MethodLength
+    public void copy(Repository sourceRepository, Repository targetRepository, 
String version)
+            throws WagonException, IOException {
+        // CHECKSTYLE_ON: MethodLength
         String prefix = "staging-plugin";
 
         String fileName = prefix + "-" + version + ".zip";
 
-        String tempdir = System.getProperty( "java.io.tmpdir" );
+        String tempdir = System.getProperty("java.io.tmpdir");
 
-        logger.debug( "Writing all output to " + tempdir );
+        logger.debug("Writing all output to " + tempdir);
 
         // Create the renameScript script
 
         String renameScriptName = prefix + "-" + version + "-rename.sh";
 
-        File renameScript = new File( tempdir, renameScriptName );
+        File renameScript = new File(tempdir, renameScriptName);
 
         // Work directory
 
-        File basedir = new File( tempdir, prefix + "-" + version );
+        File basedir = new File(tempdir, prefix + "-" + version);
 
-        FileUtils.deleteDirectory( basedir );
+        FileUtils.deleteDirectory(basedir);
 
         basedir.mkdirs();
 
-        Wagon sourceWagon = wagonManager.getWagon( sourceRepository );
-        AuthenticationInfo sourceAuth = wagonManager.getAuthenticationInfo( 
sourceRepository.getId() );
+        Wagon sourceWagon = wagonManager.getWagon(sourceRepository);
+        AuthenticationInfo sourceAuth = 
wagonManager.getAuthenticationInfo(sourceRepository.getId());
 
-        sourceWagon.connect( sourceRepository, sourceAuth );
+        sourceWagon.connect(sourceRepository, sourceAuth);
 
-        logger.info( "Looking for files in the source repository." );
+        logger.info("Looking for files in the source repository.");
 
         List<String> files = new ArrayList<String>();
 
-        scan( sourceWagon, "", files );
+        scan(sourceWagon, "", files);
 
-        logger.info( "Downloading files from the source repository to: " + 
basedir );
+        logger.info("Downloading files from the source repository to: " + 
basedir);
 
-        for ( String s : files )
-        {
+        for (String s : files) {
 
-            if ( s.contains( ".svn" ) )
-            {
+            if (s.contains(".svn")) {
                 continue;
             }
 
-            File f = new File( basedir, s );
+            File f = new File(basedir, s);
 
-            FileUtils.forceMkdirParent( f );
+            FileUtils.forceMkdirParent(f);
 
-            logger.info( "Downloading file from the source repository: " + s );
+            logger.info("Downloading file from the source repository: " + s);
 
-            sourceWagon.get( s, f );
+            sourceWagon.get(s, f);
         }
 
         // 
----------------------------------------------------------------------------
@@ -141,55 +137,45 @@ public class DefaultRepositoryCopier
         // so that we can merge the metadata.
         // 
----------------------------------------------------------------------------
 
-        logger.info( "Downloading metadata from the target repository." );
+        logger.info("Downloading metadata from the target repository.");
 
-        Wagon targetWagon = wagonManager.getWagon( targetRepository );
+        Wagon targetWagon = wagonManager.getWagon(targetRepository);
 
-        if ( ! ( targetWagon instanceof CommandExecutor ) )
-        {
-            throw new CommandExecutionException( "Wagon class '" + 
targetWagon.getClass().getName()
-                + "' in use for target repository is not a CommandExecutor" );
+        if (!(targetWagon instanceof CommandExecutor)) {
+            throw new CommandExecutionException("Wagon class '"
+                    + targetWagon.getClass().getName() + "' in use for target 
repository is not a CommandExecutor");
         }
 
-        AuthenticationInfo targetAuth = wagonManager.getAuthenticationInfo( 
targetRepository.getId() );
+        AuthenticationInfo targetAuth = 
wagonManager.getAuthenticationInfo(targetRepository.getId());
 
-        targetWagon.connect( targetRepository, targetAuth );
+        targetWagon.connect(targetRepository, targetAuth);
 
-        PrintWriter rw = new PrintWriter( new FileWriter( renameScript ) );
+        PrintWriter rw = new PrintWriter(new FileWriter(renameScript));
 
-        File archive = new File( tempdir, fileName );
+        File archive = new File(tempdir, fileName);
 
-        for ( String s : files )
-        {
+        for (String s : files) {
 
-            if ( s.startsWith( "/" ) )
-            {
-                s = s.substring( 1 );
+            if (s.startsWith("/")) {
+                s = s.substring(1);
             }
 
-            if ( s.endsWith( MAVEN_METADATA ) )
-            {
-                File emf = new File( basedir, s + IN_PROCESS_MARKER );
+            if (s.endsWith(MAVEN_METADATA)) {
+                File emf = new File(basedir, s + IN_PROCESS_MARKER);
 
-                try
-                {
-                    targetWagon.get( s, emf );
-                }
-                catch ( ResourceDoesNotExistException e )
-                {
+                try {
+                    targetWagon.get(s, emf);
+                } catch (ResourceDoesNotExistException e) {
                     // We don't have an equivalent on the targetRepositoryUrl 
side because we have something
                     // new on the sourceRepositoryUrl side so just skip the 
metadata merging.
 
                     continue;
                 }
 
-                try
-                {
-                    mergeMetadata( emf );
-                }
-                catch ( XmlPullParserException e )
-                {
-                    throw new IOException( "Metadata file is corrupt " + s + " 
Reason: " + e.getMessage() );
+                try {
+                    mergeMetadata(emf);
+                } catch (XmlPullParserException e) {
+                    throw new IOException("Metadata file is corrupt " + s + " 
Reason: " + e.getMessage());
                 }
             }
         }
@@ -200,38 +186,37 @@ public class DefaultRepositoryCopier
         // Create the Zip file that we will deploy to the targetRepositoryUrl 
stage
         // 
----------------------------------------------------------------------------
 
-        logger.info( "Creating zip file." );
+        logger.info("Creating zip file.");
 
-        OutputStream os = new FileOutputStream( archive );
+        OutputStream os = new FileOutputStream(archive);
 
-        ZipOutputStream zos = new ZipOutputStream( os );
+        ZipOutputStream zos = new ZipOutputStream(os);
 
-        scanDirectory( basedir, basedir, zos, version, moveCommands );
+        scanDirectory(basedir, basedir, zos, version, moveCommands);
 
         // 
----------------------------------------------------------------------------
         // Create the renameScript script. This is as atomic as we can
         // 
----------------------------------------------------------------------------
 
-        logger.info( "Creating rename script." );
+        logger.info("Creating rename script.");
 
-        for ( Object moveCommand : moveCommands )
-        {
+        for (Object moveCommand : moveCommands) {
             String s = (String) moveCommand;
 
             // We use an explicit unix '\n' line-ending here instead of using 
the println() method.
             // Using println() will cause files and folders to have a '\r' at 
the end if the plugin is run on Windows.
-            rw.print( s + "\n" );
+            rw.print(s + "\n");
         }
 
         rw.close();
 
-        ZipEntry e = new ZipEntry( renameScript.getName() );
+        ZipEntry e = new ZipEntry(renameScript.getName());
 
-        zos.putNextEntry( e );
+        zos.putNextEntry(e);
 
-        InputStream is = new FileInputStream( renameScript );
+        InputStream is = new FileInputStream(renameScript);
 
-        IOUtils.copy( is, zos );
+        IOUtils.copy(is, zos);
 
         zos.close();
         is.close();
@@ -240,11 +225,11 @@ public class DefaultRepositoryCopier
 
         // Push the Zip to the target system
 
-        logger.info( "Uploading zip file to the target repository." );
+        logger.info("Uploading zip file to the target repository.");
 
-        targetWagon.put( archive, fileName );
+        targetWagon.put(archive, fileName);
 
-        logger.info( "Unpacking zip file on the target machine." );
+        logger.info("Unpacking zip file on the target machine.");
 
         String targetRepoBaseDirectory = targetRepository.getBasedir();
 
@@ -252,64 +237,57 @@ public class DefaultRepositoryCopier
 
         String command = "unzip -o -qq -d " + targetRepoBaseDirectory + " " + 
targetRepoBaseDirectory + "/" + fileName;
 
-        ( (CommandExecutor) targetWagon ).executeCommand( command );
+        ((CommandExecutor) targetWagon).executeCommand(command);
 
-        logger.info( "Deleting zip file from the target repository." );
+        logger.info("Deleting zip file from the target repository.");
 
         command = "rm -f " + targetRepoBaseDirectory + "/" + fileName;
 
-        ( (CommandExecutor) targetWagon ).executeCommand( command );
+        ((CommandExecutor) targetWagon).executeCommand(command);
 
-        logger.info( "Running rename script on the target machine." );
+        logger.info("Running rename script on the target machine.");
 
         command = "cd " + targetRepoBaseDirectory + "; sh " + renameScriptName;
 
-        ( (CommandExecutor) targetWagon ).executeCommand( command );
+        ((CommandExecutor) targetWagon).executeCommand(command);
 
-        logger.info( "Deleting rename script from the target repository." );
+        logger.info("Deleting rename script from the target repository.");
 
         command = "rm -f " + targetRepoBaseDirectory + "/" + renameScriptName;
 
-        ( (CommandExecutor) targetWagon ).executeCommand( command );
+        ((CommandExecutor) targetWagon).executeCommand(command);
 
         targetWagon.disconnect();
     }
 
-    private void scanDirectory( File basedir, File dir, ZipOutputStream zos, 
String version, Set<String> moveCommands )
-        throws IOException
-    {
-        if ( dir == null )
-        {
+    private void scanDirectory(File basedir, File dir, ZipOutputStream zos, 
String version, Set<String> moveCommands)
+            throws IOException {
+        if (dir == null) {
             return;
         }
 
         File[] files = dir.listFiles();
 
-        for ( File f : files )
-        {
-            if ( f.isDirectory() )
-            {
-                if ( f.getName().equals( ".svn" ) )
-                {
+        for (File f : files) {
+            if (f.isDirectory()) {
+                if (f.getName().equals(".svn")) {
                     continue;
                 }
 
-                if ( f.getName().endsWith( version ) )
-                {
-                    String s = f.getAbsolutePath().substring( 
basedir.getAbsolutePath().length() + 1 );
-                    s = s.replace( '\\', '/' );
+                if (f.getName().endsWith(version)) {
+                    String s = f.getAbsolutePath()
+                            .substring(basedir.getAbsolutePath().length() + 1);
+                    s = s.replace('\\', '/');
 
-                    moveCommands.add( "mv " + s + IN_PROCESS_MARKER + " " + s 
);
+                    moveCommands.add("mv " + s + IN_PROCESS_MARKER + " " + s);
                 }
 
-                scanDirectory( basedir, f, zos, version, moveCommands );
-            }
-            else
-            {
-                try ( InputStream is = new FileInputStream( f ) )
-                {
-                    String s = f.getAbsolutePath().substring( 
basedir.getAbsolutePath().length() + 1 );
-                    s = s.replace( '\\', '/' );
+                scanDirectory(basedir, f, zos, version, moveCommands);
+            } else {
+                try (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
@@ -317,81 +295,73 @@ public class DefaultRepositoryCopier
 
                     String vtag = "/" + version;
 
-                    s = s.replace( vtag + "/", vtag + IN_PROCESS_MARKER + "/" 
);
+                    s = s.replace(vtag + "/", vtag + IN_PROCESS_MARKER + "/");
 
-                    ZipEntry e = new ZipEntry( s );
+                    ZipEntry e = new ZipEntry(s);
 
-                    zos.putNextEntry( e );
+                    zos.putNextEntry(e);
 
-                    IOUtils.copy( is, zos );
+                    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);
                     }
-                } 
+                }
             }
         }
     }
 
-    private void mergeMetadata( File existingMetadata )
-        throws IOException, XmlPullParserException
-    {
+    private void mergeMetadata(File existingMetadata) throws IOException, 
XmlPullParserException {
         // Existing Metadata in target stage
 
-        Reader existingMetadataReader = new FileReader( existingMetadata );
+        Reader existingMetadataReader = new FileReader(existingMetadata);
 
-        Metadata existing = reader.read( existingMetadataReader );
+        Metadata existing = reader.read(existingMetadataReader);
 
         // Staged Metadata
 
-        File stagedMetadataFile = new File( existingMetadata.getParentFile(), 
MAVEN_METADATA );
+        File stagedMetadataFile = new File(existingMetadata.getParentFile(), 
MAVEN_METADATA);
 
-        Reader stagedMetadataReader = new FileReader( stagedMetadataFile );
+        Reader stagedMetadataReader = new FileReader(stagedMetadataFile);
 
-        Metadata staged = reader.read( stagedMetadataReader );
+        Metadata staged = reader.read(stagedMetadataReader);
 
         // Merge
 
-        existing.merge( staged );
+        existing.merge(staged);
 
-        try ( Writer writer = new FileWriter( existingMetadata ) )
-        {
-            this.writer.write( writer, existing );
+        try (Writer writer = new FileWriter(existingMetadata)) {
+            this.writer.write(writer, existing);
         }
-        
+
         stagedMetadataReader.close();
         existingMetadataReader.close();
 
-
         // Mark all metadata as in-process and regenerate the checksums as 
they will be different
         // after the merger
 
-        try
-        {
-            File newMd5 = new File( existingMetadata.getParentFile(), 
MAVEN_METADATA + ".md5" + IN_PROCESS_MARKER );
+        try {
+            File newMd5 = new File(existingMetadata.getParentFile(), 
MAVEN_METADATA + ".md5" + IN_PROCESS_MARKER);
 
-            FileUtils.writeStringToFile( newMd5, checksum( existingMetadata, 
MD5 ) );
+            FileUtils.writeStringToFile(newMd5, checksum(existingMetadata, 
MD5));
 
-            File oldMd5 = new File( existingMetadata.getParentFile(), 
MAVEN_METADATA + ".md5" );
+            File oldMd5 = new File(existingMetadata.getParentFile(), 
MAVEN_METADATA + ".md5");
 
             oldMd5.delete();
 
-            File newSha1 = new File( existingMetadata.getParentFile(), 
MAVEN_METADATA + ".sha1" + IN_PROCESS_MARKER );
+            File newSha1 = new File(existingMetadata.getParentFile(), 
MAVEN_METADATA + ".sha1" + IN_PROCESS_MARKER);
 
-            FileUtils.writeStringToFile( newSha1, checksum( existingMetadata, 
SHA1 ) );
+            FileUtils.writeStringToFile(newSha1, checksum(existingMetadata, 
SHA1));
 
-            File oldSha1 = new File( existingMetadata.getParentFile(), 
MAVEN_METADATA + ".sha1" );
+            File oldSha1 = new File(existingMetadata.getParentFile(), 
MAVEN_METADATA + ".sha1");
 
             oldSha1.delete();
-        }
-        catch ( NoSuchAlgorithmException e )
-        {
-            throw new RuntimeException( e );
+        } catch (NoSuchAlgorithmException e) {
+            throw new RuntimeException(e);
         }
 
         // We have the new merged copy so we're good
@@ -399,52 +369,42 @@ public class DefaultRepositoryCopier
         stagedMetadataFile.delete();
     }
 
-    private String checksum( File file, String type )
-        throws IOException, NoSuchAlgorithmException
-    {
-        MessageDigest md5 = MessageDigest.getInstance( type );
+    private String checksum(File file, String type) throws IOException, 
NoSuchAlgorithmException {
+        MessageDigest md5 = MessageDigest.getInstance(type);
 
-        try ( InputStream is = new FileInputStream( file ) )
-        {
+        try (InputStream is = new FileInputStream(file)) {
             // CHECKSTYLE_OFF: MagicNumber
             byte[] buf = new byte[8192];
             // CHECKSTYLE_ON: MagicNumber
 
             int i;
 
-            while ( ( i = is.read( buf ) ) >= 0 )
-            {
-                md5.update( buf, 0, i );
+            while ((i = is.read(buf)) >= 0) {
+                md5.update(buf, 0, i);
             }
         }
 
-        return encode( md5.digest() );
+        return encode(md5.digest());
     }
 
-    protected String encode( byte[] binaryData )
-    {
+    protected String encode(byte[] binaryData) {
         // CHECKSTYLE_OFF: MagicNumber
-        if ( binaryData.length != 16 && binaryData.length != 20 )
-        {
+        if (binaryData.length != 16 && binaryData.length != 20) {
             int bitLength = binaryData.length * 8;
-            throw new IllegalArgumentException( "Unrecognised length for 
binary data: " + bitLength + " bits" );
+            throw new IllegalArgumentException("Unrecognised length for binary 
data: " + bitLength + " bits");
         }
         // CHECKSTYLE_ON: MagicNumber
 
         String retValue = "";
 
-        for ( byte aBinaryData : binaryData )
-        {
+        for (byte aBinaryData : binaryData) {
             // CHECKSTYLE_OFF: MagicNumber
-            String t = Integer.toHexString( aBinaryData & 0xff );
+            String t = Integer.toHexString(aBinaryData & 0xff);
             // CHECKSTYLE_ON: MagicNumber
 
-            if ( t.length() == 1 )
-            {
-                retValue += ( "0" + t );
-            }
-            else
-            {
+            if (t.length() == 1) {
+                retValue += ("0" + t);
+            } else {
                 retValue += t;
             }
         }
@@ -452,72 +412,50 @@ public class DefaultRepositoryCopier
         return retValue.trim();
     }
 
-    private void scan( Wagon wagon, String basePath, List<String> collected )
-    {
-        try
-        {
-            List<String> files = wagon.getFileList( basePath );
+    private void scan(Wagon wagon, String basePath, List<String> collected) {
+        try {
+            List<String> files = wagon.getFileList(basePath);
 
-            if ( files.isEmpty() )
-            {
-                collected.add( basePath );
-            }
-            else
-            {
+            if (files.isEmpty()) {
+                collected.add(basePath);
+            } else {
                 basePath = basePath + "/";
-                for ( String file : files )
-                {
-                    logger.info( "Found file in the source repository: " + 
file );
-                    scan( wagon, basePath + file, collected );
+                for (String file : files) {
+                    logger.info("Found file in the source repository: " + 
file);
+                    scan(wagon, basePath + file, collected);
                 }
             }
-        }
-        catch ( TransferFailedException e )
-        {
-            throw new RuntimeException( e );
-        }
-        catch ( ResourceDoesNotExistException e )
-        {
+        } catch (TransferFailedException e) {
+            throw new RuntimeException(e);
+        } catch (ResourceDoesNotExistException e) {
             // is thrown when calling getFileList on a file
-            collected.add( basePath );
+            collected.add(basePath);
+        } catch (AuthorizationException e) {
+            throw new RuntimeException(e);
         }
-        catch ( AuthorizationException e )
-        {
-            throw new RuntimeException( e );
-        }
-
     }
 
-    protected List<String> scanForArtifactPaths( ArtifactRepository repository 
)
-    {
-        try
-        {
-            Wagon wagon = wagonManager.getWagon( repository.getProtocol() );
-            Repository artifactRepository = new Repository( 
repository.getId(), repository.getUrl() );
-            wagon.connect( artifactRepository );
+    protected List<String> scanForArtifactPaths(ArtifactRepository repository) 
{
+        try {
+            Wagon wagon = wagonManager.getWagon(repository.getProtocol());
+            Repository artifactRepository = new Repository(repository.getId(), 
repository.getUrl());
+            wagon.connect(artifactRepository);
             List<String> collected = new ArrayList<String>();
-            scan( wagon, "/", collected );
+            scan(wagon, "/", collected);
             wagon.disconnect();
 
             return collected;
 
-        }
-        catch ( UnsupportedProtocolException e )
-        {
-            throw new RuntimeException( e );
-        }
-        catch ( ConnectionException e )
-        {
-            throw new RuntimeException( e );
-        }
-        catch ( AuthenticationException e )
-        {
-            throw new RuntimeException( e );
+        } catch (UnsupportedProtocolException e) {
+            throw new RuntimeException(e);
+        } catch (ConnectionException e) {
+            throw new RuntimeException(e);
+        } catch (AuthenticationException e) {
+            throw new RuntimeException(e);
         }
     }
 
-    public void enableLogging( Logger logger )
-    {
+    public void enableLogging(Logger logger) {
         this.logger = logger;
     }
 }
diff --git a/src/main/java/org/apache/maven/plugins/stage/RepositoryCopier.java 
b/src/main/java/org/apache/maven/plugins/stage/RepositoryCopier.java
index f18087f..24be645 100644
--- a/src/main/java/org/apache/maven/plugins/stage/RepositoryCopier.java
+++ b/src/main/java/org/apache/maven/plugins/stage/RepositoryCopier.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.stage;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,17 +16,17 @@ package org.apache.maven.plugins.stage;
  * specific language governing permissions and limitations
  * under the License.
  */
+package org.apache.maven.plugins.stage;
+
+import java.io.IOException;
 
 import org.apache.maven.wagon.WagonException;
 import org.apache.maven.wagon.repository.Repository;
 
-import java.io.IOException;
-
 /**
  * @author Jason van Zyl
  */
-public interface RepositoryCopier
-{
+public interface RepositoryCopier {
     String ROLE = RepositoryCopier.class.getName();
 
     String IN_PROCESS_MARKER = ".rip";
@@ -39,6 +37,6 @@ public interface RepositoryCopier
 
     String MAVEN_METADATA = "maven-metadata.xml";
 
-    void copy( Repository sourceRepository, Repository targetRepository, 
String version )
-        throws WagonException, IOException;
+    void copy(Repository sourceRepository, Repository targetRepository, String 
version)
+            throws WagonException, IOException;
 }
diff --git 
a/src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java 
b/src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
index 4b0ab34..5f80092 100644
--- a/src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
+++ b/src/test/java/org/apache/maven/plugins/stage/RepositoryCopierTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.stage;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,13 +16,7 @@ package org.apache.maven.plugins.stage;
  * specific language governing permissions and limitations
  * under the License.
  */
-
-import org.codehaus.plexus.PlexusTestCase;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import 
org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-import org.apache.commons.io.FileUtils;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.wagon.repository.Repository;
+package org.apache.maven.plugins.stage;
 
 import java.io.File;
 import java.io.IOException;
@@ -33,31 +25,34 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.util.List;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import 
org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.apache.maven.wagon.repository.Repository;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
 /** @author Jason van Zyl */
-public class RepositoryCopierTest
-    extends PlexusTestCase
-{
+public class RepositoryCopierTest extends PlexusTestCase {
     private String version = "2.0.6";
 
     private MetadataXpp3Reader reader = new MetadataXpp3Reader();
 
-    public void testCopy()
-        throws Exception
-    {
-        RepositoryCopier copier = (RepositoryCopier) lookup( 
RepositoryCopier.ROLE );
+    public void testCopy() throws Exception {
+        RepositoryCopier copier = (RepositoryCopier) 
lookup(RepositoryCopier.ROLE);
 
-        File targetRepoSource = new File( getBasedir(), 
"src/test/target-repository" );
+        File targetRepoSource = new File(getBasedir(), 
"src/test/target-repository");
 
-        File targetRepo = new File( getBasedir(), "target/target-repository" );
+        File targetRepo = new File(getBasedir(), "target/target-repository");
 
-        FileUtils.copyDirectory( targetRepoSource, targetRepo );
+        FileUtils.copyDirectory(targetRepoSource, targetRepo);
 
-        File stagingRepo = new File( getBasedir(), 
"src/test/staging-repository" );
+        File stagingRepo = new File(getBasedir(), 
"src/test/staging-repository");
 
-        Repository sourceRepository = new Repository( "source", "file://" + 
stagingRepo );
-        Repository targetRepository = new Repository( "target", 
"scp://localhost/" + targetRepo );
+        Repository sourceRepository = new Repository("source", "file://" + 
stagingRepo);
+        Repository targetRepository = new Repository("target", 
"scp://localhost/" + targetRepo);
 
-        copier.copy( sourceRepository, targetRepository, version );
+        copier.copy(sourceRepository, targetRepository, version);
 
         String s[] = {
             "maven",
@@ -78,7 +73,8 @@ public class RepositoryCopierTest
             "maven-script",
             "maven-script-ant",
             "maven-script-beanshell",
-            "maven-settings" };
+            "maven-settings"
+        };
 
         for (String value : s) {
             testMavenArtifact(targetRepo, value);
@@ -95,37 +91,34 @@ public class RepositoryCopierTest
         // Test new artifacts are present
     }
 
-    private void testMavenArtifact( File repo, String artifact )
-        throws IOException, XmlPullParserException
-    {
-        File basedir = new File( repo, "org/apache/maven/" + artifact );
+    private void testMavenArtifact(File repo, String artifact) throws 
IOException, XmlPullParserException {
+        File basedir = new File(repo, "org/apache/maven/" + artifact);
+
+        File versionDir = new File(basedir, version);
 
-        File versionDir = new File( basedir, version );
+        assertTrue(versionDir.exists());
 
-        assertTrue( versionDir.exists() );
+        File file = new File(basedir, RepositoryCopier.MAVEN_METADATA);
+        try (Reader r = Files.newBufferedReader(file.toPath(), 
StandardCharsets.UTF_8)) {
+            Metadata metadata = reader.read(r);
 
-        File file = new File( basedir, RepositoryCopier.MAVEN_METADATA );
-        try ( Reader r = Files.newBufferedReader( file.toPath(), 
StandardCharsets.UTF_8 ) )
-        {
-            Metadata metadata = reader.read( r );
-    
             // Make sure our new version has been setup as the release.
-            assertEquals( version, metadata.getVersioning().getRelease() );
-    
-            assertEquals( "20070327020553", 
metadata.getVersioning().getLastUpdated() );
-    
+            assertEquals(version, metadata.getVersioning().getRelease());
+
+            assertEquals("20070327020553", 
metadata.getVersioning().getLastUpdated());
+
             // Make sure we didn't whack old versions.
             List<String> versions = metadata.getVersioning().getVersions();
-    
-            assertTrue( versions.contains( "2.0.1" ) );
-    
-            assertTrue( versions.contains( "2.0.2" ) );
-    
-            assertTrue( versions.contains( "2.0.3" ) );
-            
-            assertTrue( versions.contains( "2.0.4" ) );
-    
-            assertTrue( versions.contains( "2.0.5" ) );
+
+            assertTrue(versions.contains("2.0.1"));
+
+            assertTrue(versions.contains("2.0.2"));
+
+            assertTrue(versions.contains("2.0.3"));
+
+            assertTrue(versions.contains("2.0.4"));
+
+            assertTrue(versions.contains("2.0.5"));
         }
     }
 }


Reply via email to