Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JazzEditCommand |
|
| 4.5;4,5 |
1 | package org.apache.maven.scm.provider.jazz.command.edit; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
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.edit.AbstractEditCommand; | |
26 | import org.apache.maven.scm.command.edit.EditScmResult; | |
27 | import org.apache.maven.scm.provider.ScmProviderRepository; | |
28 | import org.apache.maven.scm.provider.jazz.command.JazzConstants; | |
29 | import org.apache.maven.scm.provider.jazz.command.JazzScmCommand; | |
30 | import org.apache.maven.scm.provider.jazz.command.consumer.DebugLoggerConsumer; | |
31 | import org.apache.maven.scm.provider.jazz.command.consumer.ErrorConsumer; | |
32 | ||
33 | import java.io.File; | |
34 | import java.util.Iterator; | |
35 | import java.util.List; | |
36 | ||
37 | // In RTC the need to 'edit' or 'lock' a file is not required. It is actually encouraged to not | |
38 | // lock 'text' based files and to only lock binary file types. | |
39 | // | |
40 | // The Maven SCM plugin "edit" goal has been implemented by using the RTC "lock acquire/release" commands. | |
41 | // | |
42 | // See the following links for additional information on the RTC "lock acquire" command: | |
43 | // RTC 2.0.0.2: | |
44 | // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html | |
45 | // RTC 3.0: | |
46 | // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html | |
47 | // RTC 3.0.1: | |
48 | // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_acquire.html | |
49 | // | |
50 | // See the following links for additional information on the RTC "lock release" command: | |
51 | // RTC 2.0.0.2: | |
52 | // http://publib.boulder.ibm.com/infocenter/rtc/v2r0m0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html | |
53 | // RTC 3.0: | |
54 | // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html | |
55 | // RTC 3.0.1: | |
56 | // http://publib.boulder.ibm.com/infocenter/clmhelp/v3r0m1/topic/com.ibm.team.scm.doc/topics/r_scm_cli_lock_release.html | |
57 | // | |
58 | ||
59 | /** | |
60 | * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a> | |
61 | */ | |
62 | 2 | public class JazzEditCommand |
63 | extends AbstractEditCommand | |
64 | { | |
65 | /** | |
66 | * {@inheritDoc} | |
67 | */ | |
68 | protected ScmResult executeEditCommand( ScmProviderRepository repo, ScmFileSet fileSet ) | |
69 | throws ScmException | |
70 | { | |
71 | 0 | if ( getLogger().isDebugEnabled() ) |
72 | { | |
73 | 0 | getLogger().debug( "Executing edit command..." ); |
74 | } | |
75 | ||
76 | 0 | DebugLoggerConsumer editConsumer = new DebugLoggerConsumer( getLogger() ); |
77 | 0 | ErrorConsumer errConsumer = new ErrorConsumer( getLogger() ); |
78 | ||
79 | 0 | JazzScmCommand editCmd = createEditCommand( repo, fileSet ); |
80 | 0 | int status = editCmd.execute( editConsumer, errConsumer ); |
81 | ||
82 | 0 | if ( status != 0 || errConsumer.hasBeenFed() ) |
83 | { | |
84 | 0 | return new EditScmResult( editCmd.getCommandString(), "Error code for Jazz SCM edit command - " + status, |
85 | errConsumer.getOutput(), false ); | |
86 | } | |
87 | ||
88 | 0 | return new EditScmResult( editCmd.getCommandString(), "Successfully Completed.", editConsumer.getOutput(), |
89 | true ); | |
90 | } | |
91 | ||
92 | protected JazzScmCommand createEditCommand( ScmProviderRepository repo, ScmFileSet fileSet ) | |
93 | { | |
94 | 2 | JazzScmCommand command = |
95 | new JazzScmCommand( JazzConstants.CMD_LOCK, JazzConstants.CMD_SUB_ACQUIRE, repo, fileSet, getLogger() ); | |
96 | ||
97 | 2 | List<File> files = fileSet.getFileList(); |
98 | 2 | if ( files != null && !files.isEmpty() ) |
99 | { | |
100 | 1 | Iterator<File> it = files.iterator(); |
101 | 3 | while ( it.hasNext() ) |
102 | { | |
103 | 2 | File file = (File) it.next(); |
104 | 2 | command.addArgument( file.getPath() ); // Lock only the files specified |
105 | 2 | } |
106 | 1 | } |
107 | else | |
108 | { | |
109 | 1 | command.addArgument( "." ); // Lock all files |
110 | } | |
111 | 2 | return command; |
112 | } | |
113 | } |