1 package org.apache.maven.scm.provider.git.gitexe.command.remove;
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.ScmResult;
25 import org.apache.maven.scm.command.remove.AbstractRemoveCommand;
26 import org.apache.maven.scm.command.remove.RemoveScmResult;
27 import org.apache.maven.scm.provider.ScmProviderRepository;
28 import org.apache.maven.scm.provider.git.command.GitCommand;
29 import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils;
30 import org.codehaus.plexus.util.cli.CommandLineUtils;
31 import org.codehaus.plexus.util.cli.Commandline;
32
33 import java.io.File;
34 import java.util.List;
35
36
37
38
39
40
41 public class GitRemoveCommand
42 extends AbstractRemoveCommand
43 implements GitCommand
44 {
45
46
47
48 protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message )
49 throws ScmException
50 {
51
52 if ( fileSet.getFileList().isEmpty() )
53 {
54 throw new ScmException( "You must provide at least one file/directory to remove" );
55 }
56
57 Commandline cl = createCommandLine( fileSet.getBasedir(), fileSet.getFileList() );
58
59 GitRemoveConsumer consumer = new GitRemoveConsumer( getLogger() );
60
61 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
62
63 int exitCode;
64
65 exitCode = GitCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
66 if ( exitCode != 0 )
67 {
68 return new RemoveScmResult( cl.toString(), "The git command failed.", stderr.getOutput(), false );
69 }
70
71 return new RemoveScmResult( cl.toString(), consumer.getRemovedFiles() );
72 }
73
74 public static Commandline createCommandLine( File workingDirectory, List<File> files )
75 throws ScmException
76 {
77 Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "rm" );
78
79 for ( File file : files )
80 {
81 if ( file.isAbsolute() )
82 {
83 if ( file.isDirectory() )
84 {
85 cl.createArg().setValue( "-r" );
86 break;
87 }
88 }
89 else
90 {
91 File absFile = new File( workingDirectory, file.getPath() );
92 if ( absFile.isDirectory() )
93 {
94 cl.createArg().setValue( "-r" );
95 break;
96 }
97 }
98 }
99
100 GitCommandLineUtils.addTarget( cl, files );
101
102 return cl;
103 }
104
105 }