Coverage Report - org.apache.maven.wagon.providers.ssh.external.ScpExternalWagon
 
Classes in this File Line Coverage Branch Coverage Complexity
ScpExternalWagon
0 %
0/49
0 %
0/10
2,375
 
 1  
 package org.apache.maven.wagon.providers.ssh.external;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.ByteArrayInputStream;
 23  
 import java.io.ByteArrayOutputStream;
 24  
 import java.io.File;
 25  
 import java.io.FileOutputStream;
 26  
 import java.io.IOException;
 27  
 import java.io.InputStream;
 28  
 import java.io.OutputStream;
 29  
 import java.util.Properties;
 30  
 
 31  
 import org.apache.maven.wagon.AbstractWagon;
 32  
 import org.apache.maven.wagon.ConnectionException;
 33  
 import org.apache.maven.wagon.InputData;
 34  
 import org.apache.maven.wagon.OutputData;
 35  
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 36  
 import org.apache.maven.wagon.TransferFailedException;
 37  
 import org.apache.maven.wagon.authentication.AuthenticationException;
 38  
 import org.apache.maven.wagon.authorization.AuthorizationException;
 39  
 import org.apache.maven.wagon.resource.Resource;
 40  
 
 41  
 /**
 42  
  * NOTE: Plexus will only pick this correctly if the Class package and name are the same as that in core. This is
 43  
  * because the core component descriptor is read, but the class is read from the latter JAR.
 44  
  * 
 45  
  * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="scpexe" instantiation-strategy="per-lookup"
 46  
  */
 47  0
 public class ScpExternalWagon
 48  
     extends AbstractWagon
 49  
 {
 50  
     public void get( String resourceName, File destination )
 51  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 52  
     {
 53  0
         InputData inputData = new InputData();
 54  
 
 55  0
         Resource resource = new Resource( resourceName );
 56  
 
 57  0
         fireGetInitiated( resource, destination );
 58  
 
 59  0
         inputData.setResource( resource );
 60  
 
 61  0
         fillInputData( inputData );
 62  
 
 63  0
         InputStream is = inputData.getInputStream();
 64  
 
 65  0
         if ( is == null )
 66  
         {
 67  0
             throw new TransferFailedException( getRepository().getUrl()
 68  
                 + " - Could not open input stream for resource: '" + resource + "'" );
 69  
         }
 70  
 
 71  0
         createParentDirectories( destination );
 72  
 
 73  0
         getTransfer( inputData.getResource(), destination, is );
 74  0
     }
 75  
 
 76  
     public boolean getIfNewer( String resourceName, File destination, long timestamp )
 77  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 78  
     {
 79  0
         return false;
 80  
     }
 81  
 
 82  
     public void put( File source, String resourceName )
 83  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 84  
     {
 85  0
         OutputData outputData = new OutputData();
 86  
 
 87  0
         Resource resource = new Resource( resourceName );
 88  
 
 89  0
         firePutInitiated( resource, source );
 90  
 
 91  0
         outputData.setResource( resource );
 92  
 
 93  0
         writeTestProperties( source.getParentFile() );
 94  
 
 95  0
         fillOutputData( outputData );
 96  
 
 97  0
         OutputStream os = outputData.getOutputStream();
 98  
 
 99  0
         if ( os == null )
 100  
         {
 101  0
             throw new TransferFailedException( getRepository().getUrl()
 102  
                 + " - Could not open output stream for resource: '" + resource + "'" );
 103  
         }
 104  
 
 105  0
         putTransfer( outputData.getResource(), source, os, true );
 106  0
     }
 107  
 
 108  
     public void closeConnection()
 109  
         throws ConnectionException
 110  
     {
 111  0
     }
 112  
 
 113  
     public void fillInputData( InputData inputData )
 114  
         throws TransferFailedException, ResourceDoesNotExistException
 115  
     {
 116  
         try
 117  
         {
 118  0
             inputData.setInputStream( new ByteArrayInputStream( "<metadata />".getBytes( "UTF-8" ) ) );
 119  
         }
 120  0
         catch ( IOException e )
 121  
         {
 122  0
             throw new TransferFailedException( "Broken JVM", e );
 123  0
         }
 124  0
     }
 125  
 
 126  
     public void writeTestProperties( File dir )
 127  
         throws TransferFailedException
 128  
     {
 129  0
         Properties props = new Properties();
 130  0
         if ( getRepository().getPermissions() != null )
 131  
         {
 132  0
             String dirPerms = getRepository().getPermissions().getDirectoryMode();
 133  
 
 134  0
             if ( dirPerms != null )
 135  
             {
 136  0
                 props.setProperty( "directory.mode", dirPerms );
 137  
             }
 138  
 
 139  0
             String filePerms = getRepository().getPermissions().getFileMode();
 140  0
             if ( filePerms != null )
 141  
             {
 142  0
                 props.setProperty( "file.mode", filePerms );
 143  
             }
 144  
         }
 145  
 
 146  
         try
 147  
         {
 148  0
             OutputStream os = new FileOutputStream( new File( dir, "wagon.properties" ) );
 149  
             try
 150  
             {
 151  0
                 props.store( os, "MAVEN-CORE-IT-WAGON" );
 152  
             }
 153  
             finally
 154  
             {
 155  0
                 os.close();
 156  0
             }
 157  
         }
 158  0
         catch ( IOException e )
 159  
         {
 160  0
             throw new TransferFailedException( e.getMessage(), e );
 161  0
         }
 162  0
     }
 163  
 
 164  
     public void fillOutputData( OutputData outputData )
 165  
         throws TransferFailedException
 166  
     {
 167  0
         outputData.setOutputStream( new ByteArrayOutputStream() );
 168  0
     }
 169  
 
 170  
     public void openConnection()
 171  
         throws ConnectionException, AuthenticationException
 172  
     {
 173  0
     }
 174  
 }