1 package org.apache.maven.scm.provider.svn.svnexe.command.checkin;
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.ScmException;
23 import org.apache.maven.scm.ScmFileSet;
24 import org.apache.maven.scm.ScmVersion;
25 import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
26 import org.apache.maven.scm.command.checkin.CheckInScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.svn.command.SvnCommand;
29 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
30 import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
31 import org.codehaus.plexus.util.FileUtils;
32 import org.codehaus.plexus.util.StringUtils;
33 import org.codehaus.plexus.util.cli.CommandLineException;
34 import org.codehaus.plexus.util.cli.CommandLineUtils;
35 import org.codehaus.plexus.util.cli.Commandline;
36
37 import java.io.File;
38 import java.io.IOException;
39
40
41
42
43
44
45 public class SvnCheckInCommand
46 extends AbstractCheckInCommand
47 implements SvnCommand
48 {
49
50 protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
51 ScmVersion version )
52 throws ScmException
53 {
54 if ( version != null && StringUtils.isNotEmpty( version.getName() ) )
55 {
56 throw new ScmException( "This provider command can't handle tags." );
57 }
58
59 File messageFile = FileUtils.createTempFile( "maven-scm-", ".commit", null );
60
61 try
62 {
63 FileUtils.fileWrite( messageFile.getAbsolutePath(), message );
64 }
65 catch ( IOException ex )
66 {
67 return new CheckInScmResult( null, "Error while making a temporary file for the commit message: "
68 + ex.getMessage(), null, false );
69 }
70
71 Commandline cl = createCommandLine( (SvnScmProviderRepository) repo, fileSet, messageFile );
72
73 SvnCheckInConsumer consumer = new SvnCheckInConsumer( getLogger(), fileSet.getBasedir() );
74
75 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
76
77 if ( getLogger().isInfoEnabled() )
78 {
79 getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
80 getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
81 }
82
83 int exitCode;
84
85 try
86 {
87 exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
88 }
89 catch ( CommandLineException ex )
90 {
91 throw new ScmException( "Error while executing command.", ex );
92 }
93 finally
94 {
95 try
96 {
97 FileUtils.forceDelete( messageFile );
98 }
99 catch ( IOException ex )
100 {
101
102 }
103 }
104
105 if ( exitCode != 0 )
106 {
107 return new CheckInScmResult( cl.toString(), "The svn command failed.", stderr.getOutput(), false );
108 }
109
110 return new CheckInScmResult( cl.toString(), consumer.getCheckedInFiles(),
111 Integer.toString( consumer.getRevision() ) );
112 }
113
114
115
116
117
118 public static Commandline createCommandLine( SvnScmProviderRepository repository, ScmFileSet fileSet,
119 File messageFile )
120 throws ScmException
121 {
122 Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( fileSet.getBasedir(), repository );
123
124 cl.createArg().setValue( "commit" );
125
126 cl.createArg().setValue( "--file" );
127
128 cl.createArg().setValue( messageFile.getAbsolutePath() );
129
130 try
131 {
132 SvnCommandLineUtils.addTarget( cl, fileSet.getFileList() );
133 }
134 catch ( IOException e )
135 {
136 throw new ScmException( "Can't create the targets file", e );
137 }
138
139 return cl;
140 }
141 }