View Javadoc

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         if ( !StringUtils.isEmpty( getWorkspace() ) &&                          // We have a workspace
122             !StringUtils.isEmpty( getFlowTarget() ) &&                          // and a flow target
123             !getWorkspace().equals( getFlowTarget() ) &&                        // and they are not the same
124             getWorkspaceAlias() != getFlowTargetAlias() )                       // nor are their aliases.
125         {
126             // The workspace and stream are not null, not empty and not equal to each other.
127             return true;
128         }
129         else
130         {
131             // We're the same, so no flow targets.
132             return false;
133         }
134     }
135 
136     /**
137      * Return the URI of the repository server, as parsed from the URL.
138      *
139      * @return The URI of the repository server, as parsed from the URL.
140      */
141     public String getRepositoryURI()
142     {
143         return fRepositoryURI;
144     }
145 
146     /**
147      * Return the name of the remote repository workspace, as parsed from the URL.
148      *
149      * @return The name of the remote repository workspace, as parsed from the URL.
150      */
151     public String getRepositoryWorkspace()
152     {
153         return fRepositoryWorkspace;
154     }
155 
156     // NOTE: The following getter/setters are only used when the "scm status" command
157     //       has been called. Those commands that need it, need to call the status()
158     //       command first. Otherwise these values will be zero or null.
159 
160     /**
161      * @return The alias of the repository workspace, as returned from the "scm status" command.
162      */
163     public int getWorkspaceAlias()
164     {
165         return fWorkspaceAlias;
166     }
167 
168     /**
169      * @param workspaceAlias the workspaceAlias to set
170      */
171     public void setWorkspaceAlias( int workspaceAlias )
172     {
173         this.fWorkspaceAlias = workspaceAlias;
174     }
175 
176     /**
177      * @return The name of the repository workspace, as returned from the "scm status" command.
178      */
179     public String getWorkspace()
180     {
181         return fWorkspace;
182     }
183 
184     /**
185      * @param fWorkspace The fWorkspace to set.
186      */
187     public void setWorkspace( String fWorkspace )
188     {
189         this.fWorkspace = fWorkspace;
190     }
191 
192     /**
193      * @return The alias of the flow target, as returned from the "scm status" command.
194      */
195     public int getFlowTargetAlias()
196     {
197         return fFlowTargetAlias;
198     }
199 
200     /**
201      * @param streamAlias the streamAlias to set
202      */
203     public void setFlowTargetAlias( int flowTargetAlias )
204     {
205         this.fFlowTargetAlias = flowTargetAlias;
206     }
207 
208     /**
209      * @return The name of the flow target, as returned from the "scm status" command.
210      */
211     public String getFlowTarget()
212     {
213         return fFlowTarget;
214     }
215 
216     /**
217      * @param flowTarget The flowTarget to set.
218      */
219     public void setFlowTarget( String flowTarget )
220     {
221         this.fFlowTarget = flowTarget;
222     }
223 
224     /**
225      * @return The name of the component, as returned from the "scm status" command.
226      */
227     public String getComponent()
228     {
229         return fComponent;
230     }
231 
232     /**
233      * @param component The component to set.
234      */
235     public void setComponent( String component )
236     {
237         this.fComponent = component;
238     }
239 
240     /**
241      * @return The name of the baseline, as returned from the "scm status" command.
242      */
243     public String getBaseline()
244     {
245         return fBaseline;
246     }
247 
248     /**
249      * @param baseline The baseline to set.
250      */
251     public void setBaseline( String baseline )
252     {
253         this.fBaseline = baseline;
254     }
255 
256     /**
257      * {@inheritDoc}
258      */
259     public String toString()
260     {
261         return getRepositoryURI() + ":" + getRepositoryWorkspace();
262     }
263 }