001 package org.codehaus.mojo.wagon.shared; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 005 * agreements. See the NOTICE file distributed with this work for additional information regarding 006 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance with the License. You may obtain a 008 * copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed under the License 013 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 014 * or implied. See the License for the specific language governing permissions and limitations under 015 * the License. 016 */ 017 018 import java.io.File; 019 import java.util.Iterator; 020 import java.util.List; 021 022 import org.apache.maven.plugin.logging.Log; 023 import org.apache.maven.wagon.Wagon; 024 import org.apache.maven.wagon.WagonException; 025 import org.codehaus.plexus.util.StringUtils; 026 027 /** 028 * @plexus.component role="org.codehaus.mojo.wagon.shared.WagonDownload" role-hint="default" 029 */ 030 031 public class DefaultWagonDownload implements WagonDownload { 032 033 @Override 034 public List<?> getFileList(Wagon wagon, WagonFileSet fileSet, Log logger) throws WagonException { 035 logger.info("Scanning remote file system: " + wagon.getRepository().getUrl() + " ..."); 036 037 WagonDirectoryScanner dirScan = new WagonDirectoryScanner(); 038 dirScan.setLogger(logger); 039 dirScan.setWagon(wagon); 040 dirScan.setExcludes(fileSet.getExcludes()); 041 dirScan.setIncludes(fileSet.getIncludes()); 042 dirScan.setCaseSensitive(fileSet.isCaseSensitive()); 043 dirScan.setDirectory(fileSet.getDirectory()); 044 if (fileSet.isUseDefaultExcludes()) { 045 dirScan.addDefaultExcludes(); 046 } 047 048 dirScan.scan(); 049 050 return dirScan.getFilesIncluded(); 051 } 052 053 @Override 054 public void download(Wagon wagon, WagonFileSet remoteFileSet, Log logger) throws WagonException { 055 List<?> fileList = this.getFileList(wagon, remoteFileSet, logger); 056 057 String url = wagon.getRepository().getUrl() + "/"; 058 059 if (fileList.size() == 0) { 060 logger.info("Nothing to download."); 061 return; 062 } 063 064 for (Iterator<?> iterator = fileList.iterator(); iterator.hasNext();) { 065 String remoteFile = (String) iterator.next(); 066 067 File destination = new File(remoteFileSet.getDownloadDirectory() + "/" + remoteFile); 068 069 if (!StringUtils.isBlank(remoteFileSet.getDirectory())) { 070 remoteFile = remoteFileSet.getDirectory() + "/" + remoteFile; 071 } 072 073 logger.info("Downloading " + url + remoteFile + " to " + destination + " ..."); 074 075 wagon.get(remoteFile, destination); 076 } 077 } 078 079 /** 080 * 081 * @param wagon 082 * - a Wagon instance 083 * @param resource 084 * - Remote resource to check 085 * @throws WagonException 086 */ 087 @Override 088 public boolean exists(Wagon wagon, String resource) throws WagonException { 089 return wagon.resourceExists(resource); 090 } 091 092 }