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