001package org.apache.maven.wagon; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.wagon.authorization.AuthorizationException; 023import org.codehaus.plexus.util.FileUtils; 024 025import java.io.File; 026import java.io.IOException; 027import java.util.LinkedList; 028 029/** 030 * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a> 031 * 032 * @deprecated 033 */ 034public final class WagonUtils 035{ 036 private WagonUtils() 037 { 038 } 039 040 public static String toString( String resource, Wagon wagon ) 041 throws IOException, TransferFailedException, ResourceDoesNotExistException, AuthorizationException 042 { 043 044 File file = null; 045 046 try 047 { 048 file = File.createTempFile( "wagon", "tmp" ); 049 050 wagon.get( resource, file ); 051 052 return FileUtils.fileRead( file ); 053 } 054 finally 055 { 056 if ( file != null ) 057 { 058 boolean deleted = file.delete(); 059 060 if ( !deleted ) 061 { 062 file.deleteOnExit(); 063 } 064 } 065 } 066 067 } 068 069 070 public static void putDirectory( File dir, Wagon wagon, boolean includeBasdir ) 071 throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException 072 { 073 074 LinkedList queue = new LinkedList(); 075 076 if ( includeBasdir ) 077 { 078 queue.add( dir.getName() ); 079 } 080 else 081 { 082 queue.add( "" ); 083 } 084 085 while ( !queue.isEmpty() ) 086 { 087 String path = (String) queue.removeFirst(); 088 089 File currentDir = new File( dir, path ); 090 091 File[] files = currentDir.listFiles(); 092 093 for ( int i = 0; i < files.length; i++ ) 094 { 095 File file = files[i]; 096 097 String resource; 098 099 if ( path.length() > 0 ) 100 { 101 resource = path + "/" + file.getName(); 102 } 103 else 104 { 105 resource = file.getName(); 106 } 107 108 if ( file.isDirectory() ) 109 { 110 queue.add( resource ); 111 } 112 else 113 { 114 wagon.put( file, resource ); 115 } 116 117 } 118 119 } 120 121 } 122}