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