1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.codehaus.mojo.scmchangelog.scm.svn;
25
26 import java.io.File;
27 import java.util.Iterator;
28
29 import java.util.regex.Pattern;
30 import org.apache.maven.scm.ScmBranch;
31 import org.apache.maven.scm.ScmException;
32 import org.apache.maven.scm.ScmFileSet;
33 import org.apache.maven.scm.ScmRevision;
34 import org.apache.maven.scm.ScmTag;
35 import org.apache.maven.scm.ScmVersion;
36 import org.apache.maven.scm.command.list.AbstractListCommand;
37 import org.apache.maven.scm.command.list.ListScmResult;
38 import org.apache.maven.scm.provider.ScmProviderRepository;
39 import org.apache.maven.scm.provider.svn.command.SvnCommand;
40 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
41 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
42 import org.codehaus.plexus.util.StringUtils;
43 import org.codehaus.plexus.util.cli.CommandLineException;
44 import org.codehaus.plexus.util.cli.CommandLineUtils;
45 import org.codehaus.plexus.util.cli.Commandline;
46
47
48
49
50
51
52 public class SvnListCommand
53 extends AbstractListCommand
54 implements SvnCommand
55 {
56
57
58
59 private static final File TMP_DIR = new File( System.getProperty( "java.io.tmpdir" ) );
60
61
62
63
64 private Pattern filter;
65
66
67
68
69
70 public SvnListCommand( Pattern filter )
71 {
72 this.filter = filter;
73 }
74
75
76
77
78
79
80
81
82
83
84 protected ListScmResult executeListCommand( ScmProviderRepository repository, ScmFileSet fileSet,
85 boolean recursive, ScmVersion version )
86 throws ScmException
87 {
88 getLogger().info( "Executing our command " + version );
89 Commandline cl = createCommandLine( ( SvnScmProviderRepository ) repository, fileSet, recursive, version );
90 SvnListConsumer consumer = new SvnListConsumer( this.filter );
91 consumer.setLogger( getLogger() );
92
93 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
94 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
95 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
96 int exitCode;
97 getLogger().info( "Executing this command " + cl.toString() );
98 try
99 {
100 exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
101 }
102 catch ( CommandLineException ex )
103 {
104 getLogger().error( "Error while executing command.", ex );
105 throw new ScmException( "Error while executing command.", ex );
106 }
107
108 if ( exitCode != 0 )
109 {
110 return new ListScmResult( cl.toString(), "The svn command failed.",
111 stderr.getOutput(), false );
112 }
113
114 return new ListScmResult( cl.toString(), consumer.analyse() );
115 }
116
117
118
119
120
121
122
123
124
125 static Commandline createCommandLine( SvnScmProviderRepository repository,
126 ScmFileSet fileSet, boolean recursive, ScmVersion version )
127 {
128 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( TMP_DIR,
129 repository );
130 cl.createArgument().setValue( "list" );
131
132 if ( recursive )
133 {
134 cl.createArgument().setValue( "--recursive" );
135 }
136
137 cl.createArgument().setValue( "--xml" );
138
139 if ( ( version != null )
140 && StringUtils.isNotEmpty( version.getName() )
141 && version instanceof ScmRevision )
142 {
143 cl.createArgument().setValue( "-r" );
144 cl.createArgument().setValue( version.getName() );
145 }
146
147 String baseUrl;
148
149 if ( version instanceof ScmTag )
150 {
151 baseUrl = repository.getTagBase();
152 }
153 else if ( version instanceof ScmBranch )
154 {
155 baseUrl = repository.getBranchBase();
156 }
157 else
158 {
159 baseUrl = repository.getUrl();
160 }
161
162 Iterator it = fileSet.getFileList().iterator();
163
164 while ( it.hasNext() )
165 {
166 File file = ( File ) it.next();
167 cl.createArgument().setValue( baseUrl + "/" + file.getPath().replace( '\\', '/' ) );
168 }
169
170 return cl;
171 }
172 }