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