001 package 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 022 import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; 023 import org.codehaus.plexus.util.StringUtils; 024 025 /** 026 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a> 027 */ 028 public class JazzScmProviderRepository 029 extends ScmProviderRepositoryWithHost 030 { 031 /** 032 * The URI of the repository server. 033 * Of the form <protocol>://<server>:<port>/<path> 034 * For example: 035 * https://rtc:9444/jazz 036 */ 037 private String fRepositoryURI; 038 039 /** 040 * The name of the remote repository workspace (as set from the URL). 041 */ 042 private String fRepositoryWorkspace; 043 044 // Fields that are *only* set when parsing the output of the "scm status" command. 045 // So, in essence, they are the 'real' values, as returned from the system. 046 // What is in the URL, via the pom, may not be correct. 047 // If the "scm status" command has not been called, then these values will be zero/null. 048 049 /** 050 * The alias of the repository workspace, as returned from the "scm status" command. 051 */ 052 private int fWorkspaceAlias; 053 054 /** 055 * The name of the repository workspace, as returned from the "scm status" command. 056 */ 057 private String fWorkspace; 058 059 // Note: If there are no flow targets defined, then the repository workspace points to itself, 060 // so fWorkspaceAlias = fStreamAlias and fWorkspace = fStream 061 062 // TODO: Change to enable multiple flow targets, via a List (?). 063 064 // NOTE: We are not parsing the Component Alias nor the Baseline Alias, as they are not currently needed. 065 066 /** 067 * The alias of the flow target, as returned from the "scm status" command. 068 */ 069 private int fFlowTargetAlias; 070 071 /** 072 * The name of the flow target, as returned from the "scm status" command. 073 */ 074 private String fFlowTarget; // Can also be a repository workspace, possibly the same as fWorkspace 075 076 /** 077 * The name of the component, as returned from the "scm status" command. 078 */ 079 private String fComponent; 080 081 /** 082 * The name of the baseline, as returned from the "scm status" command. 083 */ 084 private String fBaseline; 085 086 // TODO In the future we might expand the details of this repository. 087 // For example we might extend the scm url to include a stream (as well as the repository workspace) 088 // This stream could represent the desired flow target of the repository workspace. 089 // We would also need to cater for multiple streams/flow targets. 090 public JazzScmProviderRepository( String repositoryURI, String userName, String password, String hostName, int port, 091 String repositoryWorkspace ) 092 { 093 this.fRepositoryURI = repositoryURI; 094 setUser( userName ); 095 setPassword( password ); 096 setHost( hostName ); 097 setPort( port ); 098 this.fRepositoryWorkspace = repositoryWorkspace; 099 } 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 }