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