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
40 public class Member
41 {
42 private String memberID;
43
44 private String memberName;
45
46 private Date memberTimestamp;
47
48 private String memberDescription;
49
50 private String projectConfigPath;
51
52 private String memberRev;
53
54 private File targetFile;
55
56 private String relativeFile;
57
58 private String lineTerminator;
59
60 private String overwriteExisting;
61
62 private String restoreTimestamp;
63
64
65
66
67
68
69
70
71
72
73
74
75 public Member( WorkItem wi, String configPath, String projectRoot, String workspaceDir )
76 {
77
78 this.projectConfigPath = configPath;
79 this.memberID = wi.getId();
80 this.memberName = wi.getField( "name" ).getValueAsString();
81 this.memberRev = wi.getField( "memberrev" ).getItem().getId();
82 this.memberTimestamp = wi.getField( "membertimestamp" ).getDateTime();
83 if ( null != wi.getField( "memberdescription" ) && null != wi.getField(
84 "memberdescription" ).getValueAsString() )
85 {
86 this.memberDescription = wi.getField( "memberdescription" ).getValueAsString();
87 }
88 else
89 {
90 this.memberDescription = new String( "" );
91 }
92 this.lineTerminator = "native";
93 this.overwriteExisting = "overwriteExisting";
94 this.restoreTimestamp = "restoreTimestamp";
95 this.relativeFile = this.memberName.substring( projectRoot.length() );
96 this.targetFile = new File( workspaceDir + relativeFile );
97 }
98
99
100
101
102
103
104 public String getTargetFilePath()
105 {
106 return targetFile.getAbsolutePath();
107 }
108
109
110
111
112
113
114 public String getRevision()
115 {
116 return memberRev;
117 }
118
119
120
121
122
123
124 public Date getTimestamp()
125 {
126 return memberTimestamp;
127 }
128
129
130
131
132
133
134 public String getDescription()
135 {
136 return memberDescription;
137 }
138
139
140
141
142
143
144 public String getMemberName()
145 {
146 return memberName;
147 }
148
149
150
151
152
153
154 public String getName()
155 {
156 if ( memberID.indexOf( '/' ) > 0 )
157 {
158 return memberID.substring( memberID.lastIndexOf( '/' ) + 1 );
159 }
160 else if ( memberID.indexOf( '\\' ) > 0 )
161 {
162 return memberID.substring( memberID.lastIndexOf( '\\' ) + 1 );
163 }
164 else
165 {
166 return memberID;
167 }
168 }
169
170
171
172
173
174
175 public void setLineTerminator( String lineTerminator )
176 {
177 this.lineTerminator = lineTerminator;
178 }
179
180
181
182
183
184
185 public void setOverwriteExisting( String overwriteExisting )
186 {
187 this.overwriteExisting = overwriteExisting;
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 public boolean checkout( APISession api )
215 throws APIException
216 {
217
218 if ( !targetFile.getParentFile().isDirectory() )
219 {
220 targetFile.getParentFile().mkdirs();
221 }
222
223 Command coCMD = new Command( Command.SI, "projectco" );
224 coCMD.addOption( new Option( overwriteExisting ) );
225 coCMD.addOption( new Option( "nolock" ) );
226 coCMD.addOption( new Option( "project", projectConfigPath ) );
227 coCMD.addOption( new FileOption( "targetFile", targetFile ) );
228 coCMD.addOption( new Option( restoreTimestamp ) );
229 coCMD.addOption( new Option( "lineTerminator", lineTerminator ) );
230 coCMD.addOption( new Option( "revision", memberRev ) );
231
232 coCMD.addSelection( memberID );
233
234
235 Response res = api.runCommand( coCMD );
236
237
238 if ( res.getExitCode() == 0 )
239 {
240 return true;
241 }
242
243 else
244 {
245 return false;
246 }
247 }
248
249
250
251
252 @Override
253 public boolean equals( Object o )
254 {
255 if ( o instanceof Member )
256 {
257 if ( null != o )
258 {
259 return ( (Member) o ).getMemberName().equals( this.getMemberName() );
260 }
261 }
262 return false;
263 }
264 }