1 package org.apache.maven.scm.provider.svn.svnexe.command.list;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmRevision;
25 import org.apache.maven.scm.ScmVersion;
26 import org.apache.maven.scm.command.list.AbstractListCommand;
27 import org.apache.maven.scm.command.list.ListScmResult;
28 import org.apache.maven.scm.provider.ScmProviderRepository;
29 import org.apache.maven.scm.provider.svn.command.SvnCommand;
30 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
31 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
32 import org.codehaus.plexus.util.StringUtils;
33 import org.codehaus.plexus.util.cli.CommandLineException;
34 import org.codehaus.plexus.util.cli.CommandLineUtils;
35 import org.codehaus.plexus.util.cli.Commandline;
36
37 import java.io.File;
38 import java.util.Iterator;
39
40
41
42
43
44
45
46 public class SvnListCommand
47 extends AbstractListCommand
48 implements SvnCommand
49 {
50 private static final File TMP_DIR = new File( System.getProperty( "java.io.tmpdir" ) );
51
52
53 protected ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet, boolean recursive,
54 ScmVersion version )
55 throws ScmException
56 {
57 Commandline cl = createCommandLine( (SvnScmProviderRepository) repository, fileSet, recursive, version );
58
59 SvnListConsumer consumer = new SvnListConsumer();
60
61 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
62
63 if ( getLogger().isInfoEnabled() )
64 {
65 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
66 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
67 }
68
69 int exitCode;
70
71 try
72 {
73 exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
74 }
75 catch ( CommandLineException ex )
76 {
77 throw new ScmException( "Error while executing command.", ex );
78 }
79
80 if ( exitCode != 0 )
81 {
82 return new ListScmResult( cl.toString(), "The svn command failed.", stderr.getOutput(), false );
83 }
84
85 return new ListScmResult( cl.toString(), consumer.getFiles() );
86 }
87
88 static Commandline createCommandLine( SvnScmProviderRepository repository, ScmFileSet fileSet, boolean recursive,
89 ScmVersion version )
90 {
91 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( TMP_DIR, repository );
92
93 cl.createArg().setValue( "list" );
94
95 if ( recursive )
96 {
97 cl.createArg().setValue( "--recursive" );
98 }
99
100 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
101 {
102 if ( version instanceof ScmRevision )
103 {
104 cl.createArg().setValue( "-r" );
105
106 cl.createArg().setValue( version.getName() );
107 }
108 }
109
110 Iterator<File> it = fileSet.getFileList().iterator();
111
112 while ( it.hasNext() )
113 {
114 File file = it.next();
115
116 cl.createArg().setValue( repository.getUrl() + "/" + file.getPath().replace( '\\', '/' ) );
117 }
118
119 return cl;
120 }
121
122 }