1 | |
package org.apache.maven.scm.provider.clearcase.command.unedit; |
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 | |
import java.util.List; |
24 | |
|
25 | |
import org.apache.maven.scm.ScmException; |
26 | |
import org.apache.maven.scm.ScmFileSet; |
27 | |
import org.apache.maven.scm.ScmResult; |
28 | |
import org.apache.maven.scm.command.status.StatusScmResult; |
29 | |
import org.apache.maven.scm.command.unedit.AbstractUnEditCommand; |
30 | |
import org.apache.maven.scm.log.ScmLogger; |
31 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
32 | |
import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand; |
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 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class ClearCaseUnEditCommand |
43 | |
extends AbstractUnEditCommand |
44 | |
implements ClearCaseCommand |
45 | |
{ |
46 | |
|
47 | |
protected ScmResult executeUnEditCommand( ScmProviderRepository repository, ScmFileSet fileSet ) |
48 | |
throws ScmException |
49 | |
{ |
50 | 0 | if ( getLogger().isDebugEnabled() ) |
51 | |
{ |
52 | 0 | getLogger().debug( "executing unedit command..." ); |
53 | |
} |
54 | 0 | Commandline cl = createCommandLine( getLogger(), fileSet ); |
55 | |
|
56 | 0 | ClearCaseUnEditConsumer consumer = new ClearCaseUnEditConsumer( getLogger() ); |
57 | |
|
58 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
59 | |
|
60 | |
int exitCode; |
61 | |
|
62 | |
try |
63 | |
{ |
64 | 0 | if ( getLogger().isDebugEnabled() ) |
65 | |
{ |
66 | 0 | getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() ); |
67 | |
} |
68 | 0 | exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
69 | |
} |
70 | 0 | catch ( CommandLineException ex ) |
71 | |
{ |
72 | 0 | throw new ScmException( "Error while executing clearcase command.", ex ); |
73 | 0 | } |
74 | |
|
75 | 0 | if ( exitCode != 0 ) |
76 | |
{ |
77 | 0 | return new StatusScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false ); |
78 | |
} |
79 | |
|
80 | 0 | return new StatusScmResult( cl.toString(), consumer.getUnEditFiles() ); |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet ) |
88 | |
{ |
89 | 1 | Commandline command = new Commandline(); |
90 | |
|
91 | 1 | File workingDirectory = scmFileSet.getBasedir(); |
92 | |
|
93 | 1 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
94 | |
|
95 | 1 | command.setExecutable( "cleartool" ); |
96 | |
|
97 | 1 | command.createArg().setValue( "unco" ); |
98 | 1 | command.createArg().setValue( "-keep" ); |
99 | |
|
100 | 1 | List<File> files = scmFileSet.getFileList(); |
101 | 1 | for ( File file : files ) |
102 | |
{ |
103 | 1 | command.createArg().setValue( file.getName() ); |
104 | |
} |
105 | |
|
106 | 1 | return command; |
107 | |
} |
108 | |
} |