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