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 org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
023import org.codehaus.plexus.util.StringUtils;
024
025/**
026 * @author <a href="mailto:ChrisGWarp@gmail.com">Chris Graham</a>
027 */
028public 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        // 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}