Coverage Report - org.apache.maven.wagon.providers.coreit.CoreItHttpWagon
 
Classes in this File Line Coverage Branch Coverage Complexity
CoreItHttpWagon
0 %
0/54
0 %
0/10
2,857
 
 1  
 package org.apache.maven.wagon.providers.coreit;
 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  
  * Shamelessly copied from ScpExternalWagon in this same project...
 43  
  *
 44  
  * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="http-coreit" instantiation-strategy="per-lookup"
 45  
  */
 46  0
 public class CoreItHttpWagon
 47  
     extends AbstractWagon
 48  
 {
 49  
     public void get( String resourceName, File destination )
 50  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 51  
     {
 52  0
         InputData inputData = new InputData();
 53  
 
 54  0
         Resource resource = new Resource( resourceName );
 55  
 
 56  0
         fireGetInitiated( resource, destination );
 57  
 
 58  0
         inputData.setResource( resource );
 59  
 
 60  0
         fillInputData( inputData );
 61  
 
 62  0
         InputStream is = inputData.getInputStream();
 63  
 
 64  0
         if ( is == null )
 65  
         {
 66  0
             throw new TransferFailedException( getRepository().getUrl()
 67  
                 + " - Could not open input stream for resource: '" + resource + "'" );
 68  
         }
 69  
 
 70  0
         createParentDirectories( destination );
 71  
 
 72  0
         getTransfer( inputData.getResource(), destination, is );
 73  0
     }
 74  
 
 75  
     public boolean getIfNewer( String resourceName, File destination, long timestamp )
 76  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 77  
     {
 78  0
         return false;
 79  
     }
 80  
 
 81  
     public void put( File source, String resourceName )
 82  
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
 83  
     {
 84  0
         OutputData outputData = new OutputData();
 85  
 
 86  0
         Resource resource = new Resource( resourceName );
 87  
 
 88  0
         firePutInitiated( resource, source );
 89  
 
 90  0
         outputData.setResource( resource );
 91  
 
 92  0
         fillOutputData( outputData );
 93  
 
 94  0
         OutputStream os = outputData.getOutputStream();
 95  
 
 96  0
         if ( os == null )
 97  
         {
 98  0
             throw new TransferFailedException( getRepository().getUrl()
 99  
                 + " - Could not open output stream for resource: '" + resource + "'" );
 100  
         }
 101  
 
 102  0
         putTransfer( outputData.getResource(), source, os, true );
 103  0
     }
 104  
 
 105  
     public void closeConnection()
 106  
         throws ConnectionException
 107  
     {
 108  0
         File f = new File( "target/wagon-data" );
 109  
         try
 110  
         {
 111  0
             f.getParentFile().mkdirs();
 112  0
             f.createNewFile();
 113  
         }
 114  0
         catch ( IOException e )
 115  
         {
 116  0
             throw new ConnectionException( e.getMessage(), e );
 117  0
         }
 118  0
     }
 119  
 
 120  
     public void fillInputData( InputData inputData )
 121  
         throws TransferFailedException, ResourceDoesNotExistException
 122  
     {
 123  
         try
 124  
         {
 125  0
             inputData.setInputStream( new ByteArrayInputStream( "<metadata />".getBytes( "UTF-8" ) ) );
 126  
         }
 127  0
         catch ( IOException e )
 128  
         {
 129  0
             throw new TransferFailedException( "Broken JVM", e );
 130  0
         }
 131  0
     }
 132  
 
 133  
     public void fillOutputData( OutputData outputData )
 134  
         throws TransferFailedException
 135  
     {
 136  0
         Properties props = new Properties();
 137  0
         if ( getRepository().getPermissions() != null )
 138  
         {
 139  0
             String dirPerms = getRepository().getPermissions().getDirectoryMode();
 140  
 
 141  0
             if ( dirPerms != null )
 142  
             {
 143  0
                 props.setProperty( "directory.mode", dirPerms );
 144  
             }
 145  
 
 146  0
             String filePerms = getRepository().getPermissions().getFileMode();
 147  0
             if ( filePerms != null )
 148  
             {
 149  0
                 props.setProperty( "file.mode", filePerms );
 150  
             }
 151  
         }
 152  
 
 153  
         try
 154  
         {
 155  0
             new File( "target" ).mkdirs();
 156  
     
 157  0
             OutputStream os = new FileOutputStream( "target/wagon.properties" );
 158  
             try
 159  
             {
 160  0
                 props.store( os, "MAVEN-CORE-IT-WAGON" );
 161  
             }
 162  
             finally
 163  
             {
 164  0
                 os.close();
 165  0
             }
 166  
         }
 167  0
         catch ( IOException e )
 168  
         {
 169  0
             throw new TransferFailedException( e.getMessage(), e );
 170  0
         }
 171  
 
 172  0
         outputData.setOutputStream( new ByteArrayOutputStream() );
 173  0
     }
 174  
 
 175  
     public void openConnection()
 176  
         throws ConnectionException, AuthenticationException
 177  
     {
 178  
         // TODO Auto-generated method stub
 179  
 
 180  0
     }
 181  
 }