001package org.apache.maven.scm.provider.jazz.repository; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; 026import org.codehaus.plexus.util.StringUtils; 027 028/** 029 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a> 030 */ 031public class JazzScmProviderRepository 032 extends ScmProviderRepositoryWithHost 033{ 034 /** 035 * The URI of the repository server. 036 * Of the form <protocol>://<server>:<port>/<path> 037 * For example: 038 * https://rtc:9444/jazz 039 */ 040 private String fRepositoryURI; 041 042 /** 043 * The name of the remote repository workspace (as set from the URL). 044 */ 045 private String fRepositoryWorkspace; 046 047 // Fields that are *only* set when parsing the output of the "scm status" command. 048 // So, in essence, they are the 'real' values, as returned from the system. 049 // What is in the URL, via the pom, may not be correct. 050 // If the "scm status" command has not been called, then these values will be zero/null. 051 052 /** 053 * The alias of the repository workspace, as returned from the "scm status" command. 054 */ 055 private int fWorkspaceAlias; 056 057 /** 058 * The name of the repository workspace, as returned from the "scm status" command. 059 */ 060 private String fWorkspace; 061 062 // Note: If there are no flow targets defined, then the repository workspace points to itself, 063 // so fWorkspaceAlias = fStreamAlias and fWorkspace = fStream 064 065 // TODO: Change to enable multiple flow targets, via a List (?). 066 067 // NOTE: We are not parsing the Component Alias nor the Baseline Alias, as they are not currently needed. 068 069 /** 070 * The alias of the flow target, as returned from the "scm status" command. 071 */ 072 private int fFlowTargetAlias; 073 074 /** 075 * The name of the flow target, as returned from the "scm status" command. 076 */ 077 private String fFlowTarget; // Can also be a repository workspace, possibly the same as fWorkspace 078 079 /** 080 * The name of the component, as returned from the "scm status" command. 081 */ 082 private String fComponent; 083 084 /** 085 * The name of the baseline, as returned from the "scm status" command. 086 */ 087 private String fBaseline; 088 089 /** 090 * The outgoing aliases of the change sets, as returned from the "scm status" command. 091 */ 092 private List<Integer> fOutgoingChangeSetAliases = new ArrayList<Integer>(); 093 094 /** 095 * The incoming aliases of the change sets, as returned from the "scm status" command. 096 */ 097 private List<Integer> fIncomingChangeSetAliases = new ArrayList<Integer>(); 098 099 // 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}