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;
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 import java.util.Arrays;
036
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.mojo.wagon.shared.WagonUpload;
041 import org.codehaus.plexus.util.StringUtils;
042
043 /**
044 * Upload multiple sets of files.
045 *
046 * @goal upload
047 * @requiresProject true
048 */
049 public class UploadMojo extends AbstractSingleWagonMojo {
050 /**
051 * Local directory to upload to wagon's "url/toDir"
052 *
053 * @parameter expression="${wagon.fromDir}" default-value="${project.basedir}"
054 */
055 private File fromDir;
056
057 /**
058 * Comma separate list of Ant's excludes to scan for local files
059 *
060 * @parameter expression="${wagon.excludes}"
061 *
062 */
063 private String excludes;
064
065 /**
066 * Comma separate list of Ant's includes to scan for local files
067 *
068 * @parameter expression="${wagon.includes}" localDirectory's Ant includes
069 */
070 private String includes;
071
072 /**
073 * Follow local symbolic link if possible
074 *
075 * @parameter expression="${wagon.followSymLink}" default-value="false"
076 */
077 private boolean followSymLink = false;
078
079 /**
080 * Use default exclude sets
081 *
082 * @parameter expression="${wagon.useDefaultExcludes}" default-value="true"
083 */
084 private boolean useDefaultExcludes = true;
085
086 /**
087 * Remote path relative to Wagon's url to upload local files to.
088 *
089 * @parameter expression="${wagon.toDir}" default-value="";
090 */
091 private String toDir = "";
092
093 /**
094 * Optimize the upload by locally compressed all files in one bundle, upload the bundle, and finally remote
095 * uncompress the bundle.
096 *
097 * @parameter expression="${wagon.optimize}" default-value="false";
098 */
099
100 private boolean optimize = false;
101
102 /**
103 * @component
104 */
105 protected WagonUpload wagonUpload;
106
107 @Override
108 protected void execute(Wagon wagon) throws WagonException, IOException {
109 FileSet fileSet = new FileSet();
110
111 fileSet.setDirectory(this.fromDir.getAbsolutePath());
112
113 if (!StringUtils.isBlank(includes)) {
114 fileSet.setIncludes(Arrays.asList(StringUtils.split(this.includes, ",")));
115 }
116
117 if (!StringUtils.isBlank(excludes)) {
118 fileSet.setExcludes(Arrays.asList(StringUtils.split(this.excludes, ",")));
119 }
120
121 fileSet.setFollowSymlinks(this.followSymLink);
122
123 fileSet.setUseDefaultExcludes(this.useDefaultExcludes);
124
125 fileSet.setOutputDirectory(toDir);
126
127 this.wagonUpload.upload(wagon, fileSet, optimize, this.getLog());
128 }
129
130 }