maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: maven-wagon/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh ScpWagon.java
Date Thu, 24 Mar 2005 07:37:41 GMT
brett       2005/03/23 23:37:41

  Modified:    wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh
                        ScpWagon.java
  Log:
  remove exception swallowing, correctly handle resource not found on get.
  
  Revision  Changes    Path
  1.16      +40 -22    maven-wagon/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
  
  Index: ScpWagon.java
  ===================================================================
  RCS file: /home/cvs/maven-wagon/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ScpWagon.java	19 Mar 2005 02:47:59 -0000	1.15
  +++ ScpWagon.java	24 Mar 2005 07:37:41 -0000	1.16
  @@ -18,6 +18,7 @@
   
   import com.jcraft.jsch.ChannelExec;
   import com.jcraft.jsch.JSch;
  +import com.jcraft.jsch.JSchException;
   import com.jcraft.jsch.Proxy;
   import com.jcraft.jsch.ProxyHTTP;
   import com.jcraft.jsch.ProxySOCKS5;
  @@ -506,23 +507,13 @@
                   out.flush();
               }
           }
  -        catch ( Exception e )
  +        catch ( JSchException e )
           {
  -            fireTransferError( resource, e );
  -
  -            if ( destination.exists() )
  -            {
  -                boolean deleted = destination.delete();
  -
  -                if ( !deleted )
  -                {
  -                    destination.deleteOnExit();
  -                }
  -            }
  -
  -            String msg = "Error occured while downloading from the remote repository:"
+ getRepository();
  -
  -            throw new TransferFailedException( msg, e );
  +            handleException( resource, e, destination );
  +        }
  +        catch ( IOException e )
  +        {
  +            handleException( resource, e, destination );
           }
           finally
           {
  @@ -539,6 +530,26 @@
           }
       }
   
  +    private void handleException( Resource resource, Exception e, File destination )
  +        throws TransferFailedException
  +    {
  +        fireTransferError( resource, e );
  +
  +        if ( destination.exists() )
  +        {
  +            boolean deleted = destination.delete();
  +
  +            if ( !deleted )
  +            {
  +                destination.deleteOnExit();
  +            }
  +        }
  +
  +        String msg = "Error occured while downloading from the remote repository:" + getRepository();
  +
  +        throw new TransferFailedException( msg, e );
  +    }
  +
       public boolean getIfNewer( String resourceName, File destination, long timestamp )
       {
           throw new UnsupportedOperationException( "getIfNewer is scp wagon must be still
implemented" );
  @@ -591,7 +602,7 @@
       }
   
       static int checkAck( InputStream in )
  -        throws IOException
  +        throws IOException, ResourceDoesNotExistException, TransferFailedException
       {
           int b = in.read();
           // b may be 0 for success,
  @@ -618,17 +629,24 @@
               }
               while ( c != '\n' );
   
  +            String message = sb.toString();
               if ( b == 1 )
               {
  -                // TODO: log (throw exception?)
                   // error
  -                System.out.print( sb.toString() );
  +                if ( message.endsWith( "No such file or directory\n" ) )
  +                {
  +                    // TODO: this might be too hokey?
  +                    throw new ResourceDoesNotExistException( message );
  +                }
  +                else
  +                {
  +                    throw new TransferFailedException( message );
  +                }
               }
               if ( b == 2 )
               {
  -                // TODO: throw exception
                   // fatal error
  -                System.out.print( sb.toString() );
  +                throw new TransferFailedException( message );
               }
           }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org


Mime
View raw message