1 package com.codehaus.mojo.vfs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.commons.vfs2.FileObject;
25 import org.apache.commons.vfs2.FileSystemException;
26 import org.apache.commons.vfs2.FileSystemOptions;
27 import org.apache.maven.plugin.MojoExecutionException;
28 import org.apache.maven.plugin.MojoFailureException;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.codehaus.mojo.vfs.VfsFileSet;
32 import org.codehaus.mojo.vfs.VfsFileSetManager;
33 import org.codehaus.mojo.vfs.VfsUtils;
34 import org.codehaus.mojo.vfs.internal.DefaultVfsFileSetManager;
35 import org.codehaus.plexus.util.StringUtils;
36 import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException;
37
38
39
40
41 @Mojo( name = "list", requiresProject = false, threadSafe = true )
42 public class ListVfsMojo
43 extends AbstractVfsMojo
44 {
45
46
47
48
49 @Parameter( property = "source", required = true )
50 private String source;
51
52
53
54
55
56 @Parameter( property = "sourceId", required = false )
57 private String sourceId;
58
59
60
61
62
63 @Parameter( property = "includes", required = false )
64 private String includes;
65
66
67
68
69
70 @Parameter( property = "excludes", required = false )
71 private String excludes;
72
73 public void execute()
74 throws MojoExecutionException, MojoFailureException
75 {
76 if ( skip )
77 {
78 this.getLog().info( "Skip VFS list operation" );
79 return;
80 }
81
82 MojoVfsFileSet fileset = new MojoVfsFileSet();
83
84 fileset.setSource( source );
85 fileset.setSourceId( sourceId );
86
87 if ( !StringUtils.isBlank( includes ) )
88 {
89 fileset.setIncludes( StringUtils.split( includes, "," ) );
90 }
91
92 if ( !StringUtils.isBlank( excludes ) )
93 {
94 fileset.setExcludes( StringUtils.split( excludes, "," ) );
95 }
96
97 try
98 {
99 FileSystemOptions serverOptions = this.getFileSystemOptions( sourceId, source );
100 VfsFileSet vfsFileSet = new VfsFileSet();
101 vfsFileSet.copyBase( fileset );
102
103 FileObject sourceObj = getFileSystemManager().resolveFile( fileset.getSource(), serverOptions );
104 vfsFileSet.setSource( sourceObj );
105
106 VfsFileSetManager fileSetManager = new DefaultVfsFileSetManager();
107 List<FileObject> list = fileSetManager.list( vfsFileSet );
108
109 this.getLog().info( "Directory list: " );
110 for ( FileObject fo : list )
111 {
112 this.getLog().info( VfsUtils.getRelativePath( sourceObj, fo ) );
113 }
114 }
115 catch ( FileSystemException e )
116 {
117 throw new MojoFailureException( "Unable to perform a list operation", e );
118 }
119 catch ( SecDispatcherException e )
120 {
121 throw new MojoFailureException( "Unable to perform a list operation", e );
122 }
123 }
124 }