1 package org.apache.maven.scm.provider.svn.svnexe.command.checkout;
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.ScmBranch;
23 import org.apache.maven.scm.ScmException;
24 import org.apache.maven.scm.ScmFileSet;
25 import org.apache.maven.scm.ScmRevision;
26 import org.apache.maven.scm.ScmTag;
27 import org.apache.maven.scm.ScmVersion;
28 import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
29 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
30 import org.apache.maven.scm.provider.ScmProviderRepository;
31 import org.apache.maven.scm.provider.svn.SvnCommandUtils;
32 import org.apache.maven.scm.provider.svn.SvnTagBranchUtils;
33 import org.apache.maven.scm.provider.svn.command.SvnCommand;
34 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
35 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
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 import java.io.File;
42
43
44
45
46
47
48 public class SvnCheckOutCommand
49 extends AbstractCheckOutCommand
50 implements SvnCommand
51 {
52
53
54
55 protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet,
56 ScmVersion version, boolean recursive )
57 throws ScmException
58 {
59 SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
60
61 String url = repository.getUrl();
62
63 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
64 {
65 if ( version instanceof ScmTag )
66 {
67 url = SvnTagBranchUtils.resolveTagUrl( repository, (ScmTag) version );
68 }
69 else if ( version instanceof ScmBranch )
70 {
71 url = SvnTagBranchUtils.resolveBranchUrl( repository, (ScmBranch) version );
72 }
73 }
74
75 url = SvnCommandUtils.fixUrl( url, repository.getUser() );
76
77 Commandline cl = createCommandLine( repository, fileSet.getBasedir(), version, url, recursive );
78
79 SvnCheckOutConsumer consumer = new SvnCheckOutConsumer( getLogger(), fileSet.getBasedir() );
80
81 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
82
83 int exitCode;
84
85 if ( getLogger().isInfoEnabled() )
86 {
87 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
88 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
89 }
90
91 try
92 {
93 exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
94 }
95 catch ( CommandLineException ex )
96 {
97 throw new ScmException( "Error while executing command.", ex );
98 }
99
100 if ( exitCode != 0 )
101 {
102 return new CheckOutScmResult( cl.toString(), "The svn command failed.", stderr.getOutput(), false );
103 }
104
105 return new CheckOutScmResult( cl.toString(), Integer.toString( consumer.getRevision() ),
106 consumer.getCheckedOutFiles() );
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 public static Commandline createCommandLine( SvnScmProviderRepository repository, File workingDirectory,
124 ScmVersion version, String url )
125 {
126 return createCommandLine( repository, workingDirectory, version, url, true );
127 }
128
129
130
131
132
133
134
135
136
137
138
139
140 public static Commandline createCommandLine( SvnScmProviderRepository repository, File workingDirectory,
141 ScmVersion version, String url, boolean recursive )
142 {
143 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( workingDirectory.getParentFile(), repository );
144
145 cl.createArg().setValue( "checkout" );
146
147
148 if ( !recursive )
149 {
150 cl.createArg().setValue( "-N" );
151 }
152
153 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
154 {
155 if ( version instanceof ScmRevision )
156 {
157 cl.createArg().setValue( "-r" );
158
159 cl.createArg().setValue( version.getName() );
160 }
161 }
162
163 cl.createArg().setValue( url );
164
165 cl.createArg().setValue( workingDirectory.getAbsolutePath() );
166
167 return cl;
168 }
169 }