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