1 package org.apache.maven.scm.provider.integrity;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.mks.api.Command;
23 import com.mks.api.FileOption;
24 import com.mks.api.Option;
25 import com.mks.api.response.APIException;
26 import com.mks.api.response.Response;
27 import com.mks.api.response.WorkItem;
28
29 import java.io.File;
30 import java.util.Date;
31
32
33
34
35
36
37
38
39 public class Member
40 {
41 private String memberID;
42
43 private String memberName;
44
45 private Date memberTimestamp;
46
47 private String memberDescription;
48
49 private String projectConfigPath;
50
51 private String memberRev;
52
53 private File targetFile;
54
55 private String relativeFile;
56
57 private String lineTerminator;
58
59 private String overwriteExisting;
60
61 private String restoreTimestamp;
62
63
64
65
66
67
68
69
70
71
72
73
74 public Member( WorkItem wi, String configPath, String projectRoot, String workspaceDir )
75 {
76
77 this.projectConfigPath = configPath;
78 this.memberID = wi.getId();
79 this.memberName = wi.getField( "name" ).getValueAsString();
80 this.memberRev = wi.getField( "memberrev" ).getItem().getId();
81 this.memberTimestamp = wi.getField( "membertimestamp" ).getDateTime();
82 if ( null != wi.getField( "memberdescription" ) && null != wi.getField(
83 "memberdescription" ).getValueAsString() )
84 {
85 this.memberDescription = wi.getField( "memberdescription" ).getValueAsString();
86 }
87 else
88 {
89 this.memberDescription = new String( "" );
90 }
91 this.lineTerminator = "native";
92 this.overwriteExisting = "overwriteExisting";
93 this.restoreTimestamp = "restoreTimestamp";
94 this.relativeFile = this.memberName.substring( projectRoot.length() );
95 this.targetFile = new File( workspaceDir + relativeFile );
96 }
97
98
99
100
101
102
103 public String getTargetFilePath()
104 {
105 return targetFile.getAbsolutePath();
106 }
107
108
109
110
111
112
113 public String getRevision()
114 {
115 return memberRev;
116 }
117
118
119
120
121
122
123 public Date getTimestamp()
124 {
125 return memberTimestamp;
126 }
127
128
129
130
131
132
133 public String getDescription()
134 {
135 return memberDescription;
136 }
137
138
139
140
141
142
143 public String getMemberName()
144 {
145 return memberName;
146 }
147
148
149
150
151
152
153 public String getName()
154 {
155 if ( memberID.indexOf( '/' ) > 0 )
156 {
157 return memberID.substring( memberID.lastIndexOf( '/' ) + 1 );
158 }
159 else if ( memberID.indexOf( '\\' ) > 0 )
160 {
161 return memberID.substring( memberID.lastIndexOf( '\\' ) + 1 );
162 }
163 else
164 {
165 return memberID;
166 }
167 }
168
169
170
171
172
173
174 public void setLineTerminator( String lineTerminator )
175 {
176 this.lineTerminator = lineTerminator;
177 }
178
179
180
181
182
183
184 public void setOverwriteExisting( String overwriteExisting )
185 {
186 this.overwriteExisting = overwriteExisting;
187 }
188
189
190
191
192
193
194
195 public void setRestoreTimestamp( boolean restoreTime )
196 {
197 if ( restoreTime )
198 {
199 this.restoreTimestamp = "restoreTimestamp";
200 }
201 else
202 {
203 this.restoreTimestamp = "norestoreTimestamp";
204 }
205 }
206
207
208
209
210
211
212
213
214
215 public boolean checkout( APISession api )
216 throws APIException
217 {
218
219 if ( !targetFile.getParentFile().isDirectory() )
220 {
221 targetFile.getParentFile().mkdirs();
222 }
223
224 Command coCMD = new Command( Command.SI, "projectco" );
225 coCMD.addOption( new Option( overwriteExisting ) );
226 coCMD.addOption( new Option( "nolock" ) );
227 coCMD.addOption( new Option( "project", projectConfigPath ) );
228 coCMD.addOption( new FileOption( "targetFile", targetFile ) );
229 coCMD.addOption( new Option( restoreTimestamp ) );
230 coCMD.addOption( new Option( "lineTerminator", lineTerminator ) );
231 coCMD.addOption( new Option( "revision", memberRev ) );
232
233 coCMD.addSelection( memberID );
234
235
236 Response res = api.runCommand( coCMD );
237
238
239 return ( res.getExitCode() == 0 );
240 }
241
242
243
244
245 @Override
246 public boolean equals( Object o )
247 {
248 if ( o instanceof Member )
249 {
250 return ( (Member) o ).getMemberName().equals( this.getMemberName() );
251 }
252 return false;
253 }
254
255 @Override
256 public int hashCode()
257 {
258 return this.getMemberName().hashCode();
259 }
260 }