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