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