1 /**
2 * Copyright 2008-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.codehaus.mojo.wagon.shared;
17
18 /*
19 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
20 * agreements. See the NOTICE file distributed with this work for additional information regarding
21 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
22 * "License"); you may not use this file except in compliance with the License. You may obtain a
23 * copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software distributed under the License
28 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29 * or implied. See the License for the specific language governing permissions and limitations under
30 * the License.
31 */
32
33 import java.io.File;
34 import java.io.IOException;
35
36 import org.apache.maven.plugin.logging.Log;
37 import org.apache.maven.shared.model.fileset.FileSet;
38 import org.apache.maven.wagon.Wagon;
39 import org.apache.maven.wagon.WagonException;
40 import org.codehaus.plexus.util.FileUtils;
41
42 /**
43 * Copy a set of files from one wagon repository to another wagon repository
44 *
45 * @plexus.component role="org.codehaus.mojo.wagon.shared.WagonCopy" role-hint="default"
46 */
47
48 public class DefaultWagonCopy implements WagonCopy {
49 /**
50 * @plexus.requirement role="org.codehaus.mojo.wagon.shared.WagonDownload"
51 */
52 private WagonDownload downloader;
53
54 /**
55 * @plexus.requirement role="org.codehaus.mojo.wagon.shared.WagonUpload"
56 */
57 private WagonUpload uploader;
58
59 @Override
60 public void copy(Wagon src, WagonFileSet wagonFileSet, Wagon target, boolean optimize, Log logger)
61 throws WagonException, IOException {
62 if (wagonFileSet == null) {
63 wagonFileSet = new WagonFileSet();
64 }
65
66 boolean removeDownloadDir = false;
67
68 if (wagonFileSet.getDownloadDirectory() == null) {
69 File downloadSrcDir = File.createTempFile("wagon", "wagon");
70 downloadSrcDir.delete();
71 wagonFileSet.setDownloadDirectory(downloadSrcDir);
72 removeDownloadDir = true;
73 }
74
75 try {
76 downloader.download(src, wagonFileSet, logger, false);
77
78 FileSet localFileSet = new FileSet();
79 localFileSet.setDirectory(wagonFileSet.getDownloadDirectory().getAbsolutePath());
80 localFileSet.setOutputDirectory(wagonFileSet.getOutputDirectory());
81
82 uploader.upload(target, localFileSet, optimize, logger);
83 } finally {
84 if (removeDownloadDir) {
85 FileUtils.deleteDirectory(wagonFileSet.getDownloadDirectory());
86 }
87 }
88
89 }
90 }