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