1 package org.apache.maven.scm.provider.jazz.repository;
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 java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
26 import org.codehaus.plexus.util.StringUtils;
27
28 /**
29 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
30 */
31 public class JazzScmProviderRepository
32 extends ScmProviderRepositoryWithHost
33 {
34 /**
35 * The URI of the repository server.
36 * Of the form <protocol>://<server>:<port>/<path>
37 * For example:
38 * https://rtc:9444/jazz
39 */
40 private String fRepositoryURI;
41
42 /**
43 * The name of the remote repository workspace (as set from the URL).
44 */
45 private String fRepositoryWorkspace;
46
47 // Fields that are *only* set when parsing the output of the "scm status" command.
48 // So, in essence, they are the 'real' values, as returned from the system.
49 // What is in the URL, via the pom, may not be correct.
50 // If the "scm status" command has not been called, then these values will be zero/null.
51
52 /**
53 * The alias of the repository workspace, as returned from the "scm status" command.
54 */
55 private int fWorkspaceAlias;
56
57 /**
58 * The name of the repository workspace, as returned from the "scm status" command.
59 */
60 private String fWorkspace;
61
62 // Note: If there are no flow targets defined, then the repository workspace points to itself,
63 // so fWorkspaceAlias = fStreamAlias and fWorkspace = fStream
64
65 // TODO: Change to enable multiple flow targets, via a List (?).
66
67 // NOTE: We are not parsing the Component Alias nor the Baseline Alias, as they are not currently needed.
68
69 /**
70 * The alias of the flow target, as returned from the "scm status" command.
71 */
72 private int fFlowTargetAlias;
73
74 /**
75 * The name of the flow target, as returned from the "scm status" command.
76 */
77 private String fFlowTarget; // Can also be a repository workspace, possibly the same as fWorkspace
78
79 /**
80 * The name of the component, as returned from the "scm status" command.
81 */
82 private String fComponent;
83
84 /**
85 * The name of the baseline, as returned from the "scm status" command.
86 */
87 private String fBaseline;
88
89 /**
90 * The outgoing aliases of the change sets, as returned from the "scm status" command.
91 */
92 private List<Integer> fOutgoingChangeSetAliases = new ArrayList<Integer>();
93
94 /**
95 * The incoming aliases of the change sets, as returned from the "scm status" command.
96 */
97 private List<Integer> fIncomingChangeSetAliases = new ArrayList<Integer>();
98
99 // TODO In the future we might expand the details of this repository.
100 // For example we might extend the scm url to include a stream (as well as the repository workspace)
101 // This stream could represent the desired flow target of the repository workspace.
102 // We would also need to cater for multiple streams/flow targets.
103 public JazzScmProviderRepository( String repositoryURI, String userName, String password, String hostName, int port,
104 String repositoryWorkspace )
105 {
106 this.fRepositoryURI = repositoryURI;
107 setUser( userName );
108 setPassword( password );
109 setHost( hostName );
110 setPort( port );
111 this.fRepositoryWorkspace = repositoryWorkspace;
112 }
113
114 /**
115 * Return <code>true</code> if we have a valid flow target and pushChanges is <code>true</code>.
116 */
117 public boolean isPushChangesAndHaveFlowTargets()
118 {
119 if ( !isPushChanges() )
120 {
121 return isPushChanges();
122 }
123
124 return isHaveFlowTargets();
125 }
126
127 /**
128 * Return <code>true</code> if we have a valid flow target.
129 * A valid flow target is a destination other than ourselves.
130 * To determine this, we need to parse the output of the 'scm status' command.
131 */
132 public boolean isHaveFlowTargets()
133 {
134 // We have a workspace and a flow target and they are not the same nor are their aliases.
135 return StringUtils.isNotEmpty( getWorkspace() ) && StringUtils.isNotEmpty( getFlowTarget() )
136 && !getWorkspace().equals( getFlowTarget() ) && getWorkspaceAlias() != getFlowTargetAlias();
137 }
138
139 /**
140 * Return the URI of the repository server, as parsed from the URL.
141 *
142 * @return The URI of the repository server, as parsed from the URL.
143 */
144 public String getRepositoryURI()
145 {
146 return fRepositoryURI;
147 }
148
149 /**
150 * Return the name of the remote repository workspace, as parsed from the URL.
151 *
152 * @return The name of the remote repository workspace, as parsed from the URL.
153 */
154 public String getRepositoryWorkspace()
155 {
156 return fRepositoryWorkspace;
157 }
158
159 // NOTE: The following getter/setters are only used when the "scm status" command
160 // has been called. Those commands that need it, need to call the status()
161 // command first. Otherwise these values will be zero or null.
162
163 /**
164 * @return The alias of the repository workspace, as returned from the "scm status" command.
165 */
166 public int getWorkspaceAlias()
167 {
168 return fWorkspaceAlias;
169 }
170
171 /**
172 * @param workspaceAlias the workspaceAlias to set
173 */
174 public void setWorkspaceAlias( int workspaceAlias )
175 {
176 this.fWorkspaceAlias = workspaceAlias;
177 }
178
179 /**
180 * @return The name of the repository workspace, as returned from the "scm status" command.
181 */
182 public String getWorkspace()
183 {
184 return fWorkspace;
185 }
186
187 /**
188 * @param fWorkspace The fWorkspace to set.
189 */
190 public void setWorkspace( String fWorkspace )
191 {
192 this.fWorkspace = fWorkspace;
193 }
194
195 /**
196 * @return The alias of the flow target, as returned from the "scm status" command.
197 */
198 public int getFlowTargetAlias()
199 {
200 return fFlowTargetAlias;
201 }
202
203 /**
204 * @param flowTargetAlias the flowTargetAlias to set
205 */
206 public void setFlowTargetAlias( int flowTargetAlias )
207 {
208 this.fFlowTargetAlias = flowTargetAlias;
209 }
210
211 /**
212 * @return The name of the flow target, as returned from the "scm status" command.
213 */
214 public String getFlowTarget()
215 {
216 return fFlowTarget;
217 }
218
219 /**
220 * @param flowTarget The flowTarget to set.
221 */
222 public void setFlowTarget( String flowTarget )
223 {
224 this.fFlowTarget = flowTarget;
225 }
226
227 /**
228 * @return The name of the component, as returned from the "scm status" command.
229 */
230 public String getComponent()
231 {
232 return fComponent;
233 }
234
235 /**
236 * @param component The component to set.
237 */
238 public void setComponent( String component )
239 {
240 this.fComponent = component;
241 }
242
243 /**
244 * @return The name of the baseline, as returned from the "scm status" command.
245 */
246 public String getBaseline()
247 {
248 return fBaseline;
249 }
250
251 /**
252 * @param baseline The baseline to set.
253 */
254 public void setBaseline( String baseline )
255 {
256 this.fBaseline = baseline;
257 }
258
259 /**
260 * @return The List<Integer> of aliases of the outgoing changesets, as returned from the "scm status" command.
261 */
262 public List<Integer> getOutgoingChangeSetAliases()
263 {
264 return fOutgoingChangeSetAliases;
265 }
266
267 /**
268 * @param outgoingChangeSetAliases The List of Integers of outgoing change set aliases to set
269 */
270 public void setOutgoingChangeSetAliases( List<Integer> outgoingChangeSetAliases )
271 {
272 this.fOutgoingChangeSetAliases = outgoingChangeSetAliases;
273 }
274
275 /**
276 * @return The List<Integer> of aliases of the incoming changesets, as returned from the "scm status" command.
277 */
278 public List<Integer> getIncomingChangeSetAliases()
279 {
280 return fIncomingChangeSetAliases;
281 }
282
283 /**
284 * @param incomingChangeSetAliases The List of Integers of incoming change set aliases to set
285 */
286 public void setIncomingChangeSetAliases( List<Integer> incomingChangeSetAliases )
287 {
288 this.fIncomingChangeSetAliases = incomingChangeSetAliases;
289 }
290
291 /**
292 * {@inheritDoc}
293 */
294 public String toString()
295 {
296 return getRepositoryURI() + ":" + getRepositoryWorkspace();
297 }
298
299 }