1 | |
package org.apache.maven.scm.provider.clearcase.command.tag; |
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.ScmTagParameters; |
29 | |
import org.apache.maven.scm.command.tag.AbstractTagCommand; |
30 | |
import org.apache.maven.scm.command.tag.TagScmResult; |
31 | |
import org.apache.maven.scm.provider.ScmProviderRepository; |
32 | |
import org.apache.maven.scm.provider.clearcase.command.ClearCaseCommand; |
33 | |
import org.apache.maven.scm.provider.clearcase.command.checkin.ClearCaseCheckInConsumer; |
34 | |
import org.codehaus.plexus.util.cli.CommandLineException; |
35 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
36 | |
import org.codehaus.plexus.util.cli.Commandline; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class ClearCaseTagCommand |
44 | |
extends AbstractTagCommand |
45 | |
implements ClearCaseCommand |
46 | |
{ |
47 | |
|
48 | |
protected ScmResult executeTagCommand( ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag, |
49 | |
String message ) |
50 | |
throws ScmException |
51 | |
{ |
52 | 0 | return executeTagCommand( scmProviderRepository, fileSet, tag, new ScmTagParameters( message ) ); |
53 | |
} |
54 | |
|
55 | |
|
56 | |
protected ScmResult executeTagCommand( ScmProviderRepository scmProviderRepository, ScmFileSet fileSet, String tag, |
57 | |
ScmTagParameters scmTagParameters ) |
58 | |
throws ScmException |
59 | |
{ |
60 | 0 | if ( getLogger().isDebugEnabled() ) |
61 | |
{ |
62 | 0 | getLogger().debug( "executing tag command..." ); |
63 | |
} |
64 | 0 | Commandline cl = createCommandLine( fileSet, tag ); |
65 | |
|
66 | 0 | ClearCaseCheckInConsumer consumer = new ClearCaseCheckInConsumer( getLogger() ); |
67 | |
|
68 | 0 | CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); |
69 | |
|
70 | |
int exitCode; |
71 | |
|
72 | |
try |
73 | |
{ |
74 | 0 | if ( getLogger().isDebugEnabled() ) |
75 | |
{ |
76 | 0 | getLogger().debug( "Creating label: " + tag ); |
77 | |
} |
78 | 0 | Commandline newLabelCommandLine = createNewLabelCommandLine( fileSet, tag ); |
79 | 0 | if ( getLogger().isDebugEnabled() ) |
80 | |
{ |
81 | 0 | getLogger().debug( |
82 | |
"Executing: " + newLabelCommandLine.getWorkingDirectory().getAbsolutePath() |
83 | |
+ ">>" + newLabelCommandLine.toString() ); |
84 | |
} |
85 | 0 | exitCode = CommandLineUtils.executeCommandLine( newLabelCommandLine, |
86 | |
new CommandLineUtils.StringStreamConsumer(), stderr ); |
87 | |
|
88 | 0 | if ( exitCode == 0 ) |
89 | |
{ |
90 | 0 | getLogger().debug( "Executing: " + cl.getWorkingDirectory().getAbsolutePath() + ">>" + cl.toString() ); |
91 | 0 | exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); |
92 | |
} |
93 | |
} |
94 | 0 | catch ( CommandLineException ex ) |
95 | |
{ |
96 | 0 | throw new ScmException( "Error while executing clearcase command.", ex ); |
97 | 0 | } |
98 | |
|
99 | 0 | if ( exitCode != 0 ) |
100 | |
{ |
101 | 0 | return new TagScmResult( cl.toString(), "The cleartool command failed.", stderr.getOutput(), false ); |
102 | |
} |
103 | |
|
104 | 0 | return new TagScmResult( cl.toString(), consumer.getCheckedInFiles() ); |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public static Commandline createCommandLine( ScmFileSet scmFileSet, String tag ) |
112 | |
{ |
113 | 1 | Commandline command = new Commandline(); |
114 | |
|
115 | 1 | File workingDirectory = scmFileSet.getBasedir(); |
116 | |
|
117 | 1 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
118 | |
|
119 | 1 | command.setExecutable( "cleartool" ); |
120 | |
|
121 | 1 | command.createArg().setValue( "mklabel" ); |
122 | 1 | List<File> files = scmFileSet.getFileList(); |
123 | 1 | if ( files.isEmpty() ) |
124 | |
{ |
125 | 0 | command.createArg().setValue( "-recurse" ); |
126 | |
} |
127 | 1 | command.createArg().setValue( tag ); |
128 | |
|
129 | 1 | if ( files.size() > 0 ) |
130 | |
{ |
131 | 1 | for ( File file : files ) |
132 | |
{ |
133 | 1 | command.createArg().setValue( file.getName() ); |
134 | |
} |
135 | |
} |
136 | |
else |
137 | |
{ |
138 | 0 | command.createArg().setValue( "." ); |
139 | |
} |
140 | |
|
141 | 1 | return command; |
142 | |
} |
143 | |
|
144 | |
private static Commandline createNewLabelCommandLine( ScmFileSet scmFileSet, String tag ) |
145 | |
{ |
146 | 0 | Commandline command = new Commandline(); |
147 | |
|
148 | 0 | File workingDirectory = scmFileSet.getBasedir(); |
149 | |
|
150 | 0 | command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); |
151 | |
|
152 | 0 | command.setExecutable( "cleartool" ); |
153 | |
|
154 | 0 | command.createArg().setValue( "mklbtype" ); |
155 | 0 | command.createArg().setValue( "-nc" ); |
156 | 0 | command.createArg().setValue( tag ); |
157 | |
|
158 | 0 | return command; |
159 | |
} |
160 | |
} |