so it is going to be wagon-maven-plugin? -D
On Thu, Sep 11, 2008 at 8:43 PM, <[EMAIL PROTECTED]> wrote: > Revision 7659 Author james.w.dumay Date 2008-09-11 22:43:14 -0500 (Thu, 11 > Sep 2008) > > Log Message > > Init import > > Added Paths > > trunk/sandbox/maven-wagon-plugin/ > trunk/sandbox/maven-wagon-plugin/pom.xml > trunk/sandbox/maven-wagon-plugin/src/ > trunk/sandbox/maven-wagon-plugin/src/main/ > trunk/sandbox/maven-wagon-plugin/src/main/java/ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/AbstractWagonMojo.java > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/DownloadMojo.java > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/InvalidResourceException.java > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ListMojo.java > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/PathParserUtil.java > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ResourceDescriptor.java > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/UploadMojo.java > trunk/sandbox/maven-wagon-plugin/src/main/resources/ > trunk/sandbox/maven-wagon-plugin/src/site/ > trunk/sandbox/maven-wagon-plugin/src/site/apt/ > trunk/sandbox/maven-wagon-plugin/src/site/apt/index.apt > trunk/sandbox/maven-wagon-plugin/src/site/apt/usage.apt > trunk/sandbox/maven-wagon-plugin/src/site/site.xml > trunk/sandbox/maven-wagon-plugin/src/test/ > trunk/sandbox/maven-wagon-plugin/src/test/java/ > trunk/sandbox/maven-wagon-plugin/src/test/java/org/ > trunk/sandbox/maven-wagon-plugin/src/test/java/org/codehaus/ > trunk/sandbox/maven-wagon-plugin/src/test/java/org/codehaus/mojo/ > trunk/sandbox/maven-wagon-plugin/src/test/java/org/codehaus/mojo/PathParserUtilTest.java > > Diff > > Added: trunk/sandbox/maven-wagon-plugin/pom.xml (0 => 7659) > > --- trunk/sandbox/maven-wagon-plugin/pom.xml (rev 0) > +++ trunk/sandbox/maven-wagon-plugin/pom.xml 2008-09-12 03:43:14 UTC (rev > 7659) > @@ -0,0 +1,54 @@ > +<?xml version="1.0" encoding="UTF-8"?> > +<project xmlns="http://maven.apache.org/POM/4.0.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/maven-v4_0_0.xsd"> > + <modelVersion>4.0.0</modelVersion> > + > + <parent> > + <groupId>org.codehaus.mojo</groupId> > + <artifactId>mojo</artifactId> > + <version>17</version> > + </parent> > + > + <artifactId>maven-wagon-plugin</artifactId> > + <packaging>maven-plugin</packaging> > + <name>Maven Wagon plugin</name> > + <description> > + Maven 2 plugin that can be used to access various operations on a > given URL using a supported maven wagon. > + Supports files and directories and allows glob expressions for > specifying them. > + Provides upload, download and list directory content functionality. > + </description> > + <version>1.0-SNAPSHOT</version> > + > + <dependencies> > + <dependency> > + <groupId>org.apache.maven</groupId> > + <artifactId>maven-plugin-api</artifactId> > + <version>2.0.8</version> > + </dependency> > + <dependency> > + <groupId>org.apache.maven</groupId> > + <artifactId>maven-project</artifactId> > + <version>2.0.8</version> > + </dependency> > + <dependency> > + <groupId>org.apache.maven</groupId> > + <artifactId>maven-settings</artifactId> > + <version>2.0.8</version> > + </dependency> > + <dependency> > + <groupId>org.apache.maven.wagon</groupId> > + <artifactId>wagon-provider-api</artifactId> > + <version>1.0-beta-2</version> > + </dependency> > + <dependency> > + <groupId>commons-io</groupId> > + <artifactId>commons-io</artifactId> > + <version>1.4</version> > + </dependency> > + <dependency> > + <groupId>junit</groupId> > + <artifactId>junit</artifactId> > + <version>3.8.1</version> > + <scope>test</scope> > + </dependency> > + </dependencies> > +</project> > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/AbstractWagonMojo.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/AbstractWagonMojo.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/AbstractWagonMojo.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,206 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import org.apache.maven.artifact.manager.WagonConfigurationException; > +import org.apache.maven.artifact.manager.WagonManager; > +import org.apache.maven.plugin.AbstractMojo; > +import org.apache.maven.plugin.MojoExecutionException; > +import org.apache.maven.settings.Proxy; > +import org.apache.maven.settings.Settings; > +import org.apache.maven.wagon.ConnectionException; > +import org.apache.maven.wagon.UnsupportedProtocolException; > +import org.apache.maven.wagon.Wagon; > +import org.apache.maven.wagon.WagonException; > +import org.apache.maven.wagon.observers.Debug; > +import org.apache.maven.wagon.proxy.ProxyInfo; > +import org.apache.maven.wagon.repository.Repository; > + > + > +/** > + * Provides base functionality for dealing with I/O using wagon. > + * > + * @author Sherali Karimov > + */ > +public abstract class AbstractWagonMojo extends AbstractMojo > +{ > + /** > + * Resource(s) to be uploaded or downloaded or listed. Can be a file or > directory. Also supports > + * wildcards. > + * > + * @see PathParserUtil#toFiles(String) > + * @parameter expression="${io.resourceSrc}" > + * @required > + */ > + protected String resourceSrc; > + > + /** > + * Path on the server to upload/download the resource to. If not > specified - assumed > + * to be "target/wagon-plugin/". > + * > + * For instance: > + * <ul> > + * <li>src=dir1/dir2 dest=xyz will create xyz/dir2 </li> > + * <li>src=dir1/dir2/* dest=xyz will create xyz/ and put all the > content of dir2 there </li> > + * <li>src=dir1/dir2 will create dir2 on the server with all the dir2 > content</li> > + * > + * @parameter expression="${wagon.resourceDest}" > default-value="target/wagon-plugin/" > + */ > + protected String resourceDest; > + > + /** > + * URL to upload to or download from or list. > + * > + * @parameter expression="${wagon.url}" > + * @required > + */ > + protected String url; > + > + /** > + * ID of the server under the above URL. This is used when wagon needs > extra > + * authentication information for instance. > + * > + * @parameter expression="${wagon.serverId}" > + * @required > + */ > + protected String serverId; > + > + /** > + * If true, ignores invalid source resources during execution. > Otherwise - fail the execution. > + * > + * @parameter expression="${wagon.ignoreInvalidResource}" > default-value="false" > + */ > + protected boolean ignoreInvalidResource; > + > + /** > + * @component > + */ > + protected WagonManager wagonManager; > + > + /** > + * The current user system settings for use in Maven. > + * > + * @parameter expression="${settings}" > + * @required > + * @readonly > + */ > + protected Settings settings; > + > + /** > + * If true, performs a case sensitive wildcard matching. Case > insensitive otherwise. > + * > + * @parameter expression="${wagon.caseSensitive}" default-value="false" > + */ > + private boolean isCaseSensitive; > + > + public void execute() throws MojoExecutionException > + { > + final ResourceDescriptor descr = new > ResourceDescriptor(resourceSrc, isCaseSensitive); > + if (url == null) > + { > + throw new MojoExecutionException("The URL is missing."); > + } > + > + final Repository repository = new Repository(serverId, url); > + Debug debug = new Debug(); > + > + try > + { > + final Wagon wagon = wagonManager.getWagon(repository); > + > + try > + { > + wagon.addSessionListener(debug); > + wagon.addTransferListener(debug); > + > + ProxyInfo proxyInfo = getProxyInfo(settings); > + if (proxyInfo != null) > + { > + wagon.connect(repository, > wagonManager.getAuthenticationInfo(repository.getId()), proxyInfo); > + } > + else > + { > + wagon.connect(repository, > wagonManager.getAuthenticationInfo(repository.getId())); > + } > + > + execute(wagon, descr); > + } > + catch (WagonException e) > + { > + throw new MojoExecutionException("Error handling resource", > e); > + } > + finally > + { > + try > + { > + wagon.disconnect(); > + } > + catch (ConnectionException e) > + { > + getLog().debug("Error disconnecting wagon - ignored", > e); > + } > + } > + } > + catch (UnsupportedProtocolException e) > + { > + throw new MojoExecutionException("Unsupported protocol: '" + > repository.getProtocol() + "'", e); > + } > + catch (WagonConfigurationException e) > + { > + throw new MojoExecutionException("Unable to configure Wagon: '" > + repository.getProtocol() + "'", e); > + } > + } > + > + /** > + * Perform the necessary action. To be implemented in the child mojo. > + * > + * @param wagon > + * @param descr > + * @throws MojoExecutionException > + * @throws WagonException > + */ > + protected abstract void execute(Wagon wagon, ResourceDescriptor descr) > throws MojoExecutionException, WagonException; > + > + /** > + * Convenience method to map a <code>Proxy</code> object from the user > + * system settings to a <code>ProxyInfo</code> object. > + * > + * @return a proxyInfo object or null if no active proxy is define in > the > + * settings.xml > + */ > + protected static ProxyInfo getProxyInfo(Settings settings) > + { > + ProxyInfo proxyInfo = null; > + if (settings != null && settings.getActiveProxy() != null) > + { > + Proxy settingsProxy = settings.getActiveProxy(); > + > + proxyInfo = new ProxyInfo(); > + proxyInfo.setHost(settingsProxy.getHost()); > + proxyInfo.setType(settingsProxy.getProtocol()); > + proxyInfo.setPort(settingsProxy.getPort()); > + proxyInfo.setNonProxyHosts(settingsProxy.getNonProxyHosts()); > + proxyInfo.setUserName(settingsProxy.getUsername()); > + proxyInfo.setPassword(settingsProxy.getPassword()); > + } > + > + return proxyInfo; > + } > +} > \ No newline at end of file > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/DownloadMojo.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/DownloadMojo.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/DownloadMojo.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,62 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import java.io.File; > +import java.util.Iterator; > +import java.util.List; > + > +import org.apache.commons.io.FilenameUtils; > +import org.apache.maven.plugin.MojoExecutionException; > +import org.apache.maven.wagon.Wagon; > +import org.apache.maven.wagon.WagonException; > + > + > +/** > + * Downloads files that match specified pattern (resourceSrc) to the given > destination. > + * If destination is not specified, assumes "target/io-plugin/". Assumes > that the destination is always a directory. > + * > + * @author Sherali Karimov > + * @goal download > + */ > +public class DownloadMojo extends AbstractWagonMojo > +{ > + protected void execute(Wagon wagon, ResourceDescriptor descr) throws > MojoExecutionException, WagonException > + { > + List fileList = wagon.getFileList(descr.path); > + > + for (Iterator iterator = fileList.iterator(); iterator.hasNext();) > + { > + String fullPath = (String) iterator.next(); > + String fileName = FilenameUtils.getName(fullPath); > + > + File destination = new File(resourceDest+"/"+fileName); > + > + if(!iterator.hasNext() && descr.path.endsWith(fileName)) > + { > + wagon.get(descr.path, destination); // the source path > points at a single file > + } > + else if(descr.wildcard == null || descr.isMatch(fileName)) > + { > + wagon.get(descr.path+"/"+fileName, destination); > + } > + } > + } > +} > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/InvalidResourceException.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/InvalidResourceException.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/InvalidResourceException.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,33 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import org.apache.maven.plugin.MojoExecutionException; > + > +/** > + * @author <a href="mailto:[EMAIL PROTECTED]">James William Dumay</a> > + */ > +public class InvalidResourceException extends MojoExecutionException > +{ > + public InvalidResourceException(String message) > + { > + super(message); > + } > +} > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ListMojo.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ListMojo.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ListMojo.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,59 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import java.util.Iterator; > +import java.util.List; > + > +import org.apache.maven.plugin.MojoExecutionException; > +import org.apache.maven.wagon.Wagon; > +import org.apache.maven.wagon.WagonException; > + > + > +/** > + * Lists the content of the specified directory (resourceSrc) under a > specified repository (url) according to the given wildcard (part of > resourceSrc). > + * Wildcard can be turned on and off as required. > + * > + * @author Sherali Karimov > + * @goal list > + */ > +public class ListMojo extends AbstractWagonMojo > +{ > + /** > + * If true, applies the provided wildcard to the list of files before > printing simulating the download mojo's behavior. Otherwise prints the full > list. > + * > + * @parameter expression="${wagon.applyWildcard}" default-value="false" > + */ > + protected boolean applyWildcard; > + > + protected void execute(Wagon wagon, ResourceDescriptor descr) throws > MojoExecutionException, WagonException > + { > + List fileList = wagon.getFileList(descr.path); > + getLog().info("Listing: "+descr.path); > + for (Iterator iterator = fileList.iterator(); iterator.hasNext();) > + { > + String file = (String) iterator.next(); > + if(!applyWildcard || descr.wildcard == null || > descr.isMatch(file)) > + { > + getLog().info("\t"+file); > + } > + } > + } > +} > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/PathParserUtil.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/PathParserUtil.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/PathParserUtil.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,160 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import java.io.File; > +import java.io.FileFilter; > +import java.util.HashSet; > +import java.util.Set; > + > +import org.apache.commons.io.IOCase; > +import org.apache.commons.io.filefilter.WildcardFileFilter; > +import org.apache.maven.plugin.MojoExecutionException; > + > +public class PathParserUtil > +{ > + /** > + * Takes a list of paths and converts them to a set of File objects. > Path > + * can be either a relative or absolute path to a file or directory or > a > + * reference to children of a directory using '*' or '?'. For instance: > + * <ul> > + * <li> dir1/dir2/file.txt </li> > + * <li> dir1/dir2/ </li> > + * <li> dir1/dir2 </li> > + * <li> dir1/dir2/*.txt </li> > + * <li> dir1/dir2/Us*Nam?.* </li> > + * </ul> > + * > + * The wildcard '*' must not occur within the path but only at the end > of > + * the path. I.e. the following paths are unsupported: > + * <ul> > + * <li> dir1/*\/dir2 </li> > + * <li> *\/dir2 </li> > + * </ul> > + * > + * @param paths > + * @return > + * @throws MojoExecutionException > + */ > + static Set toFiles(String[] paths, boolean isCaseSensitive) throws > MojoExecutionException > + { > + Set resources = new HashSet(); > + for (int i = 0; i < paths.length; i++) > + { > + Set nextSet = toFiles(paths[i], isCaseSensitive); > + if (nextSet != null) > + resources.addAll(nextSet); > + > + } > + return resources; > + } > + > + /** > + * Parses the given file path into one or more File objects. Path can > be > + * either a relative or absolute path to a file or directory or a > reference > + * to children of a directory using '*' or '?'. For instance: > + * <ul> > + * <li> dir1/dir2/file.txt </li> > + * <li> dir1/dir2/ </li> > + * <li> dir1/dir2 </li> > + * <li> dir1/dir2/*.txt </li> > + * <li> dir1/dir2/Us*Nam?.* </li> > + * </ul> > + * > + * The wildcard '*' must not occur within the path but only at the end > of > + * the path. I.e. the following paths are unsupported: > + * <ul> > + * <li> dir1/*\/dir2 </li> > + * <li> dir1/*\/dir2 </li> > + * <li> dir1/Us*Name?/* </li> > + * <li> *\/dir?/file.txt </li> > + * </ul> > + * > + * @param pathStr > + * @return > + * @throws MojoExecutionException > + */ > + static Set toFiles(final String pathStr, boolean isCaseSensitive) > throws MojoExecutionException > + { > + if (pathStr.length() == 0) > + return null; > + > + ResourceDescriptor descr = new ResourceDescriptor(pathStr, > isCaseSensitive); > + return toFiles(descr); > + } > + > + > + /** > + * Converts the given descriptor to a set of File objects that match > the descriptor. > + * > + * @param descr > + * @return > + */ > + public static Set toFiles(ResourceDescriptor descr) > + { > + Set matchedFiles = new HashSet(); > + > + File parent = new File(descr.path); > + if (parent.exists()) > + { > + if (descr.wildcard != null) > + { > + if (parent.isDirectory()) > + { > + getMatchingChildren(parent, descr.wildcard, > descr.isCaseSensitive, matchedFiles); > + } > + } > + else > + { > + matchedFiles.add(parent); > + } > + } > + > + return matchedFiles; > + } > + > + static void getMatchingChildren(File directory, String wildcard, > boolean isCaseSensitive, Set matchingFileContainer) > + { > + FileFilter filter = new WildcardFileFilter(wildcard, > isCaseSensitive ? IOCase.SENSITIVE : IOCase.INSENSITIVE); > + File children[] = directory.listFiles(filter); > + > + for (int i = 0; i < children.length; i++) > + matchingFileContainer.add(children[i]); > + } > + > + /** > + * Looks for the first occurrence of either '?' or '*' character and > returns > + * its position. Otherwise returns -1; > + * > + * @param path > + * @return position of the first occurrence of either '?' or '*' > character > + * or -1; > + */ > + static int findFirstGlobCharPosition(final String path) > + { > + char[] array = path.toCharArray(); > + for (int i = 0; i < array.length; i++) > + { > + if (array[i] == '?' || array[i] == '*') > + return i; > + } > + return -1; > + } > +} > \ No newline at end of file > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ResourceDescriptor.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ResourceDescriptor.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/ResourceDescriptor.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,104 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import java.util.Set; > + > +import org.apache.commons.io.FilenameUtils; > +import org.apache.commons.io.IOCase; > +import org.apache.maven.plugin.MojoExecutionException; > + > +/** > + * Represents a path to one or more resources. More than once resource can > be described by a wildcard in which case the path MUST be a directory. > + * Wildcard can be treated in a case sensitive/insensitive way as desired. > + */ > +public class ResourceDescriptor > +{ > + final String path; > + final String wildcard; > + final boolean isCaseSensitive; > + > + /** > + * Parses the given file path into one or more File objects. Path can > be > + * either a relative or absolute path to a file or directory or a > + * reference to children of a directory using '*' or '?'. For instance: > + * <ul> > + * <li> dir1/dir2/file.txt </li> > + * <li> dir1/dir2/ </li> > + * <li> dir1/dir2 </li> > + * <li> dir1/dir2/*.txt </li> > + * <li> dir1/dir2/Us*Nam?.* </li> > + * </ul> > + * > + * The wildcard '*' must not occur within the path but only at the end > + * of the path. I.e. the following paths are unsupported: > + * <ul> > + * <li> dir1/*\/dir2 </li> > + * <li> dir1/*\/dir2 </li> > + * <li> dir1/Us*Name?/* </li> > + * <li> *\/dir?/file.txt </li> > + * </ul> > + * > + * @throws MojoExecutionException > + */ > + public ResourceDescriptor(String path, boolean isCaseSensitive) throws > MojoExecutionException > + { > + this.isCaseSensitive = isCaseSensitive; > + int pos = PathParserUtil.findFirstGlobCharPosition(path); > + > + if (pos != -1) > + { > + int dirEndPos = path.replace('\\', '/').lastIndexOf('/'); > + if (dirEndPos >= pos) > + throw new MojoExecutionException("Invalid path - '" + path > + + "'. Wildcards must not contain a path separator > '/' or '\\'."); > + else if (dirEndPos == -1) > + { > + // children of the current dir are being matched > + this.path = ""; > + this.wildcard = path; > + } > + else > + { > + this.path = path.substring(0, dirEndPos + 1); > + this.wildcard = path.substring(dirEndPos + 1); > + } > + } > + else > + { > + this.path = path; > + this.wildcard = null; > + } > + } > + > + /** > + * Convenience method. Delegates to [EMAIL PROTECTED] > PathParserUtil#toFiles(org.apache.maven.plugins.PathParserUtil.ResourceDescriptor)} > + * @return > + */ > + public Set toLocalFiles() > + { > + return PathParserUtil.toFiles(this); > + } > + > + public boolean isMatch(String fileName) > + { > + return FilenameUtils.wildcardMatch(fileName, wildcard, > isCaseSensitive ? IOCase.SENSITIVE : IOCase.INSENSITIVE); > + } > +} > \ No newline at end of file > > Added: > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/UploadMojo.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/UploadMojo.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/main/java/org/codehaus/mojo/UploadMojo.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,83 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import java.io.File; > +import java.util.Iterator; > +import java.util.Set; > + > +import org.apache.maven.plugin.MojoExecutionException; > +import org.apache.maven.wagon.Wagon; > +import org.apache.maven.wagon.WagonException; > + > + > + > +/** > + * Uploads the given resources (files and/or directories) using a suitable > wagon provider. > + * > + * @author Sherali Karimov > + * @goal upload > + */ > +public class UploadMojo extends AbstractWagonMojo > +{ > + protected void execute(Wagon wagon, ResourceDescriptor descr) throws > MojoExecutionException, WagonException > + { > + final Set resources = descr.toLocalFiles(); > + if (resources.isEmpty()) > + { > + final String message = "Resource " + resourceSrc + " does not > match an existing file or directory."; > + if (ignoreInvalidResource) > + { > + getLog().info(message); > + return; > + } > + else > + { > + throw new InvalidResourceException(message); > + } > + } > + > + if (resources == null || resources.isEmpty()) > + { > + throw new MojoExecutionException("The resources to upload are > not specified."); > + } > + > + for (Iterator iterator = resources.iterator(); iterator.hasNext();) > + { > + File resource = (File) iterator.next(); > + if (resource.isDirectory() && !wagon.supportsDirectoryCopy()) > + { > + if(this.ignoreInvalidResource) > + iterator.remove(); > + else > + throw new MojoExecutionException("Wagon protocol '" + > wagon.getRepository().getProtocol() + "' doesn't support directory copying. > " + resource + " will fail the operation."); > + } > + } > + > + for (Iterator iterator = resources.iterator(); iterator.hasNext();) > + { > + File resource = (File) iterator.next(); > + if (resource.isDirectory()) > + wagon.putDirectory(resource, resourceDest + '/' + > resource.getName()); > + else > + wagon.put(resource, resourceDest + '/' + > resource.getName()); > + } > + } > +} > \ No newline at end of file > > Added: trunk/sandbox/maven-wagon-plugin/src/site/apt/index.apt (0 => 7659) > > --- trunk/sandbox/maven-wagon-plugin/src/site/apt/index.apt > (rev 0) > +++ trunk/sandbox/maven-wagon-plugin/src/site/apt/index.apt 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,53 @@ > + ------ > + Maven Wagon Plugin > + ------ > + Sherali Karimov, James Dumay > + ------ > + April 2008 > + ------ > + > +~~ Licensed to the Apache Software Foundation (ASF) under one > +~~ or more contributor license agreements. See the NOTICE file > +~~ distributed with this work for additional information > +~~ regarding copyright ownership. The ASF licenses this file > +~~ to you under the Apache License, Version 2.0 (the > +~~ "License"); you may not use this file except in compliance > +~~ with the License. You may obtain a copy of the License at > +~~ > +~~ http://www.apache.org/licenses/LICENSE-2.0 > +~~ > +~~ Unless required by applicable law or agreed to in writing, > +~~ software distributed under the License is distributed on an > +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > +~~ KIND, either express or implied. See the License for the > +~~ specific language governing permissions and limitations > +~~ under the License. > + > +~~ NOTE: For help with the syntax of this file, see: > +~~ http://maven.apache.org/guides/mini/guide-apt-format.html > + > +Overview > + > + The Wagon Plugin is used when you want to: > + > + * upload generated resources at build-time to a remote location. > + > + * download resources from a repository. > + > + * list the content of a directory in a repository > + > +* Goals Overview > + > + The Wagon Plugin has the following goals. > + > + * {{{upload-mojo.html}wagon:upload}} attempts to upload the specified > data to a remote location. > + > + * {{{download-mojo.html}wagon:download}} attempts to download the > specified data from a remote location. > + > + * {{{list-mojo.html}wagon:list}} attempts to list the content of a > specified location in a remote repository. > + > +* Usage > + > + Instructions on the basic usage of the Wagon Plugin can be found > + {{{usage.html}here}}. > + > > Added: trunk/sandbox/maven-wagon-plugin/src/site/apt/usage.apt (0 => 7659) > > --- trunk/sandbox/maven-wagon-plugin/src/site/apt/usage.apt > (rev 0) > +++ trunk/sandbox/maven-wagon-plugin/src/site/apt/usage.apt 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,95 @@ > + ------ > + Usage > + ------ > + Sherali Karimov, James Dumay > + ------ > + April 4th, 2008 > + > +~~ Licensed to the Apache Software Foundation (ASF) under one > +~~ or more contributor license agreements. See the NOTICE file > +~~ distributed with this work for additional information > +~~ regarding copyright ownership. The ASF licenses this file > +~~ to you under the Apache License, Version 2.0 (the > +~~ "License"); you may not use this file except in compliance > +~~ with the License. You may obtain a copy of the License at > +~~ > +~~ http://www.apache.org/licenses/LICENSE-2.0 > +~~ > +~~ Unless required by applicable law or agreed to in writing, > +~~ software distributed under the License is distributed on an > +~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > +~~ KIND, either express or implied. See the License for the > +~~ specific language governing permissions and limitations > +~~ under the License. > + > +~~ NOTE: For help with the syntax of this file, see: > +~~ http://maven.apache.org/guides/mini/guide-apt-format.html > + > +Introduction > + > + The Maven Wagon Plugin, as the name implies, allows you to use various > functions of a maven wagon. > + It allows you to upload resources from your build to a remote location > using wagon. > + It allows you to download resources from a repository using wagon. > + It allows to list a content of a repository using wagon. > + > +* Configuration Example for upload. > + > ++----- > +<project> > + [...] > + <build> > + <plugin> > + <groupId>org.codehaus.mojo</groupId> > + <artifactId>maven-wagon-plugin</artifactId> > + <version>1.0-SNAPSHOT</version> > + <executions> > + <execution> > + <id>upload-javadoc</id> > + <phase>deploy</phase> > + <goals> > + <goal>upload</goal> > + </goals> > + <configuration> > + <resourceSrc>target/site/apidocs/*</resourceSrc> > + > <resourceDest>${pom.artifactId}/${pom.version}</resourceDest> > + <serverId>atlassian-documentation</serverId> > + <url>dav:https://docs.atlassian.com/</url> > + </configuration> > + </execution> > + </executions> > + </plugin> > + </build> > + [...] > +</project> > ++----- > + > +* Configuration Example for download. > + > ++----- > +<project> > + [...] > + <build> > + <plugin> > + <groupId>org.codehaus.mojo</groupId> > + <artifactId>maven-wagon-plugin</artifactId> > + <version>1.0-SNAPSHOT</version> > + <executions> > + <execution> > + <id>download-test-data</id> > + <phase>pre-integration-test</phase> > + <goals> > + <goal>download</goal> > + </goals> > + <configuration> > + > <resourceSrc>com/atlassian/jira/plugins/jira-plugin-test-resources/${pom.version}/*</resourceSrc> > + <resourceDest>target/test-data/</resourceDest> > + <serverId>atlassian-public</serverId> > + <url>dav:https://maven.atlassian.com/public/</url> > + </configuration> > + </execution> > + </executions> > + </plugin> > + </build> > + [...] > +</project> > ++----- > > Added: trunk/sandbox/maven-wagon-plugin/src/site/site.xml (0 => 7659) > > --- trunk/sandbox/maven-wagon-plugin/src/site/site.xml > (rev 0) > +++ trunk/sandbox/maven-wagon-plugin/src/site/site.xml 2008-09-12 > 03:43:14 > UTC (rev 7659) > @@ -0,0 +1,29 @@ > +<?xml version="1.0" encoding="ISO-8859-1"?> > + > +<!-- > +Licensed to the Apache Software Foundation (ASF) under one > +or more contributor license agreements. See the NOTICE file > +distributed with this work for additional information > +regarding copyright ownership. The ASF licenses this file > +to you under the Apache License, Version 2.0 (the > +"License"); you may not use this file except in compliance > +with the License. You may obtain a copy of the License at > + > + http://www.apache.org/licenses/LICENSE-2.0 > + > +Unless required by applicable law or agreed to in writing, > +software distributed under the License is distributed on an > +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > +KIND, either express or implied. See the License for the > +specific language governing permissions and limitations > +under the License. > +--> > + > +<project> > + <body> > + <menu name="Overview"> > + <item name="Introduction" href="index.html"/> > + <item name="Usage" href="usage.html"/> > + </menu> > + </body> > +</project> > > Added: > trunk/sandbox/maven-wagon-plugin/src/test/java/org/codehaus/mojo/PathParserUtilTest.java > (0 => 7659) > > --- > trunk/sandbox/maven-wagon-plugin/src/test/java/org/codehaus/mojo/PathParserUtilTest.java > > (rev 0) > +++ > trunk/sandbox/maven-wagon-plugin/src/test/java/org/codehaus/mojo/PathParserUtilTest.java > 2008-09-12 > 03:43:14 UTC (rev 7659) > @@ -0,0 +1,241 @@ > +package org.codehaus.mojo; > + > +/* > + * Licensed to the Apache Software Foundation (ASF) under one > + * or more contributor license agreements. See the NOTICE file > + * distributed with this work for additional information > + * regarding copyright ownership. The ASF licenses this file > + * to you under the Apache License, Version 2.0 (the > + * "License"); you may not use this file except in compliance > + * with the License. You may obtain a copy of the License at > + * > + * http://www.apache.org/licenses/LICENSE-2.0 > + * > + * Unless required by applicable law or agreed to in writing, > + * software distributed under the License is distributed on an > + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > + * KIND, either express or implied. See the License for the > + * specific language governing permissions and limitations > + * under the License. > + */ > + > +import org.codehaus.mojo.PathParserUtil; > +import org.codehaus.mojo.ResourceDescriptor; > +import java.io.File; > +import java.io.IOException; > +import java.util.Collections; > +import java.util.HashSet; > +import java.util.Set; > + > +import junit.framework.TestCase; > + > +import org.apache.maven.plugin.MojoExecutionException; > + > +public class PathParserUtilTest extends TestCase > +{ > + private boolean isCaseSensitive = false; > + > + public void testNoWildCards() throws Exception > + { > + assureValid("a/b/c/", "a/b/c/", null); > + assureValid("a/b/c", "a/b/c", null); > + assureValid("/", "/", null); > + assureValid("", "", null); > + } > + > + public void testOneWildCard() throws Exception > + { > + assureValid("a/b/c/*", "a/b/c/", "*"); > + assureValid("/*", "/", "*"); > + assureValid("*", "", "*"); > + assureValid("a/b/c/?", "a/b/c/", "?"); > + assureValid("/?", "/", "?"); > + assureValid("?", "", "?"); > + } > + > + public void testMixedWildCards() throws Exception > + { > + assureValid("a/b/c/*.?.*", "a/b/c/", "*.?.*"); > + assureValid("/*.?.*", "/", "*.?.*"); > + assureValid("*.?.*", "", "*.?.*"); > + assureValid("a/b/c/SomeText*.MoreText?.*", "a/b/c/", > "SomeText*.MoreText?.*"); > + assureValid("/SomeText*.MoreText?.*", "/", > "SomeText*.MoreText?.*"); > + assureValid("SomeText*.MoreText?.*", "", "SomeText*.MoreText?.*"); > + } > + > + public void testInvalidWildCards() throws Exception > + { > + assureInvalid("a/b/*/c/"); > + assureInvalid("*/c/"); > + assureInvalid("*/"); > + assureInvalid("*/"); > + } > + > + public void testValidFiles() throws Exception > + { > + String path = getExistingResourcePath(); > + assureValidFiles(path, Collections.singleton(new File(path))); > + > + ExistingResources res = getExistingResourcesAndWildcard(); > + assureValidFiles(res.path, res.matchedFiles); > + } > + > + public void testCase() throws Exception > + { > + String path = getExistingResourcePath(); > + assureValidFiles(path, Collections.singleton(new File(path))); > + > + ExistingResources res = getExistingResourcesAndWildcard(); > + assureValidFiles(res.path, res.matchedFiles); > + > + isCaseSensitive = true; > + String oldPath = res.path; > + res.invertPathCase(); > + assertFalse(oldPath+" to "+res.path, oldPath.equals(res.path)); // > case invertion worked > + > + assureInvalidFiles(res.path, res.matchedFiles); > + } > + > + /** > + * returns a pointer to an existing file or directory as a relative > path > + */ > + private String getExistingResourcePath() > + { > + File curDir = new File("."); > + String list[] = curDir.list(); > + if (list == null || list.length == 0) > + { > + if (curDir.exists()) > + { > + // return the path looking like: ../parentDir/c* for curDir > + return "../" + curDir.getParentFile().getName() + '/' + > curDir.getName(); > + } > + else > + { > + return null; > + } > + } > + > + // return a path looking like: curDir/c* for childResource > + return curDir.getName() + '/' + list[0]; > + > + } > + > + /** > + * returns a pointer to an existing file or directory as a wildcard > + * expression and a set of Files that will match that wildcard > expression > + */ > + private ExistingResources getExistingResourcesAndWildcard() throws > IOException > + { > + File curDir = new File("."); > + String list[] = curDir.list(); > + if (list == null || list.length == 0) > + { > + if (curDir.exists()) > + { > + // return the path looking like: ../parentDir/c* for curDir > + return new ExistingResources("../" + > curDir.getParentFile().getName(), toWildCard(curDir.getName()), > isCaseSensitive); > + } > + else > + { > + return null; > + } > + } > + > + // return a path looking like: curDir/c* for childResource > + return new ExistingResources(curDir.getName(), toWildCard(list[0]), > isCaseSensitive); > + } > + > + private String toWildCard(String fileName) > + { > + char array[] = fileName.toCharArray(); > + String wildCard = ""; > + for (int i = 0; i < array.length; i++) > + { > + wildCard += array[i]; > + if(Character.isLetter(array[0])) > + { > + break; > + } > + } > + wildCard += "*"; > + return wildCard; > + } > + > + /** > + * makes sure that the given path will match the intended File > + */ > + private void assureValidFiles(String path, Set expectedFiles) throws > MojoExecutionException > + { > + Set set = PathParserUtil.toFiles(path, isCaseSensitive); > + assertEquals(expectedFiles, set); > + } > + > + private void assureInvalidFiles(String path, Set expectedFiles) throws > MojoExecutionException > + { > + Set set = PathParserUtil.toFiles(path, isCaseSensitive); > + assertFalse(expectedFiles+" to "+set, expectedFiles.equals(set)); > + } > + > + > + /** > + * makes sure that the given string is parsed properly into the given > path > + * and given wildcard. > + */ > + private void assureValid(String string, String path, String wildcard) > throws MojoExecutionException > + { > + ResourceDescriptor descr = new ResourceDescriptor(string, > isCaseSensitive); > + assertEquals(path, descr.path); > + assertEquals(wildcard, descr.wildcard); > + > + string = string.replace('/', '\\'); > + > + descr = new ResourceDescriptor(string, isCaseSensitive); > + assertEquals(path.replace('/', '\\'), descr.path); > + assertEquals(wildcard, descr.wildcard); > + } > + > + /** > + * makes sure that the given path can not be parsed or is invalid > + */ > + private void assureInvalid(String path) > + { > + try > + { > + new ResourceDescriptor(path, isCaseSensitive); > + fail("Path is invalid: " + path); > + } > + catch (MojoExecutionException e) > + { > + // expected > + } > + } > + > + private static class ExistingResources > + { > + private String path; > + private final Set matchedFiles = new HashSet(); > + > + ExistingResources(String parentPath, String wildcard, boolean > isCaseSensitive) > + { > + this.path = parentPath + '/' + wildcard; > + PathParserUtil.getMatchingChildren(new File(parentPath), > wildcard, isCaseSensitive, matchedFiles); > + } > + > + public void invertPathCase() > + { > + char[] array = path.toCharArray(); > + for (int i = 0; i < array.length; i++) > + { > + if(Character.isLetter(array[i])) > + { > + if(Character.isLowerCase(array[i])) > + array[i] = Character.toUpperCase(array[i]); > + else > + array[i] = Character.toLowerCase(array[i]); > + } > + } > + path = new String(array); > + } > + } > +} > > ________________________________ > > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
