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