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.io.IOException; 035 036 import org.apache.maven.plugin.logging.Log; 037 import org.apache.maven.shared.model.fileset.FileSet; 038 import org.apache.maven.wagon.Wagon; 039 import org.apache.maven.wagon.WagonException; 040 import org.codehaus.plexus.util.FileUtils; 041 042 /** 043 * Copy a set of files from one wagon repository to another wagon repository 044 * 045 * @plexus.component role="org.codehaus.mojo.wagon.shared.WagonCopy" role-hint="default" 046 */ 047 048 public class DefaultWagonCopy implements WagonCopy { 049 /** 050 * @plexus.requirement role="org.codehaus.mojo.wagon.shared.WagonDownload" 051 */ 052 private WagonDownload downloader; 053 054 /** 055 * @plexus.requirement role="org.codehaus.mojo.wagon.shared.WagonUpload" 056 */ 057 private WagonUpload uploader; 058 059 @Override 060 public void copy(Wagon src, WagonFileSet wagonFileSet, Wagon target, boolean optimize, Log logger) 061 throws WagonException, IOException { 062 if (wagonFileSet == null) { 063 wagonFileSet = new WagonFileSet(); 064 } 065 066 boolean removeDownloadDir = false; 067 068 if (wagonFileSet.getDownloadDirectory() == null) { 069 File downloadSrcDir = File.createTempFile("wagon", "wagon"); 070 downloadSrcDir.delete(); 071 wagonFileSet.setDownloadDirectory(downloadSrcDir); 072 removeDownloadDir = true; 073 } 074 075 try { 076 downloader.download(src, wagonFileSet, logger, false); 077 078 FileSet localFileSet = new FileSet(); 079 localFileSet.setDirectory(wagonFileSet.getDownloadDirectory().getAbsolutePath()); 080 localFileSet.setOutputDirectory(wagonFileSet.getOutputDirectory()); 081 082 uploader.upload(target, localFileSet, optimize, logger); 083 } finally { 084 if (removeDownloadDir) { 085 FileUtils.deleteDirectory(wagonFileSet.getDownloadDirectory()); 086 } 087 } 088 089 } 090 }