1 package org.apache.maven.scm.provider.clearcase.command.edit;
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.edit.AbstractEditCommand;
29 import org.apache.maven.scm.command.edit.EditScmResult;
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 public class ClearCaseEditCommand
42 extends AbstractEditCommand
43 implements ClearCaseCommand
44 {
45
46 protected ScmResult executeEditCommand( ScmProviderRepository repository, ScmFileSet fileSet )
47 throws ScmException
48 {
49 if ( getLogger().isDebugEnabled() )
50 {
51 getLogger().debug( "executing edit command..." );
52 }
53 Commandline cl = createCommandLine( getLogger(), fileSet );
54
55 ClearCaseEditConsumer consumer = new ClearCaseEditConsumer( getLogger() );
56
57 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
58
59 int exitCode;
60
61 try
62 {
63 if ( getLogger().isDebugEnabled() )
64 {
65 getLogger().debug(
66 "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>"
67 + cl.toString() );
68 }
69 exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
70 }
71 catch ( CommandLineException ex )
72 {
73 throw new ScmException( "Error while executing clearcase command.", ex );
74 }
75
76 if ( exitCode != 0 )
77 {
78 return new EditScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false );
79 }
80
81 return new EditScmResult( cl.toString(), consumer.getEditFiles() );
82 }
83
84
85
86
87
88 public static Commandline createCommandLine( ScmLogger logger, ScmFileSet scmFileSet )
89 {
90 Commandline command = new Commandline();
91
92 File workingDirectory = scmFileSet.getBasedir();
93
94 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
95
96 command.setExecutable( "cleartool" );
97
98 command.createArg().setValue( "co" );
99
100 command.createArg().setValue( "-nc" );
101
102 List<File> files = scmFileSet.getFileList();
103 for ( File file : files )
104 {
105 if ( logger.isInfoEnabled() )
106 {
107 logger.info( "edit file: " + file.getAbsolutePath() );
108 }
109 command.createArg().setValue( file.getAbsolutePath() );
110 }
111
112 return command;
113 }
114
115 public static Commandline createCheckoutCurrentDirCommandLine( ScmFileSet scmFileSet )
116 {
117 Commandline command = new Commandline();
118
119 File workingDirectory = scmFileSet.getBasedir();
120
121 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
122
123 command.setExecutable( "cleartool" );
124
125 command.createArg().setValue( "co" );
126
127 command.createArg().setValue( "-nc" );
128
129 command.createArg().setValue( "." );
130
131 return command;
132 }
133
134 public static Commandline createCheckinCurrentDirCommandLine( ScmFileSet scmFileSet )
135 {
136 Commandline command = new Commandline();
137
138 File workingDirectory = scmFileSet.getBasedir();
139
140 command.setWorkingDirectory( workingDirectory.getAbsolutePath() );
141
142 command.setExecutable( "cleartool" );
143
144 command.createArg().setValue( "ci" );
145
146 command.createArg().setValue( "-nc" );
147
148 command.createArg().setValue( "." );
149
150 return command;
151 }
152
153 }