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