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