View Javadoc
1   package org.apache.maven.scm.provider.vss;
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.CommandParameters;
23  import org.apache.maven.scm.ScmException;
24  import org.apache.maven.scm.ScmFileSet;
25  import org.apache.maven.scm.command.add.AddScmResult;
26  import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
27  import org.apache.maven.scm.command.checkin.CheckInScmResult;
28  import org.apache.maven.scm.command.checkout.CheckOutScmResult;
29  import org.apache.maven.scm.command.edit.EditScmResult;
30  import org.apache.maven.scm.command.status.StatusScmResult;
31  import org.apache.maven.scm.command.tag.TagScmResult;
32  import org.apache.maven.scm.command.update.UpdateScmResult;
33  import org.apache.maven.scm.provider.AbstractScmProvider;
34  import org.apache.maven.scm.provider.ScmProviderRepository;
35  import org.apache.maven.scm.provider.vss.commands.add.VssAddCommand;
36  import org.apache.maven.scm.provider.vss.commands.changelog.VssHistoryCommand;
37  import org.apache.maven.scm.provider.vss.commands.checkin.VssCheckInCommand;
38  import org.apache.maven.scm.provider.vss.commands.checkout.VssCheckOutCommand;
39  import org.apache.maven.scm.provider.vss.commands.edit.VssEditCommand;
40  import org.apache.maven.scm.provider.vss.commands.status.VssStatusCommand;
41  import org.apache.maven.scm.provider.vss.commands.tag.VssTagCommand;
42  import org.apache.maven.scm.provider.vss.commands.update.VssUpdateCommand;
43  import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
44  import org.apache.maven.scm.repository.ScmRepositoryException;
45  import org.codehaus.plexus.util.StringUtils;
46  
47  /**
48   * @author <a href="mailto:george@neogrid.com.br">George Gastaldi</a>
49   *
50   * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="vss"
51   */
52  public class VssScmProvider
53      extends AbstractScmProvider
54  {
55  
56      public static final String VSS_URL_FORMAT = "[username[|password]@]vssdir|projectPath";
57  
58      // ----------------------------------------------------------------------
59      // ScmProvider Implementation
60      // ----------------------------------------------------------------------
61  
62      /** {@inheritDoc} */
63      public String getScmSpecificFilename()
64      {
65          return "vssver.scc";
66      }
67  
68      /** {@inheritDoc} */
69      public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
70          throws ScmRepositoryException
71      {
72          String user = null;
73          String password = null;
74          String vssDir;
75          String project;
76  
77          int index = scmSpecificUrl.indexOf( '@' );
78  
79          String rest = scmSpecificUrl;
80  
81          if ( index != -1 )
82          {
83              String userAndPassword = scmSpecificUrl.substring( 0, index );
84  
85              rest = scmSpecificUrl.substring( index + 1 );
86  
87              index = userAndPassword.indexOf( delimiter );
88  
89              if ( index != -1 )
90              {
91                  user = userAndPassword.substring( 0, index );
92  
93                  password = userAndPassword.substring( index + 1 );
94              }
95              else
96              {
97                  user = userAndPassword;
98              }
99          }
100         String[] tokens = StringUtils.split( rest, String.valueOf( delimiter ) );
101 
102         if ( tokens.length < 2 )
103         {
104             throw new ScmRepositoryException( "Invalid SCM URL: The url has to be on the form: " + VSS_URL_FORMAT );
105         }
106         else
107         {
108             vssDir = tokens[0];
109 
110             project = tokens[1];
111         }
112 
113         return new VssScmProviderRepository( user, password, vssDir, project );
114     }
115 
116     /** {@inheritDoc} */
117     public String getScmType()
118     {
119         return "vss";
120     }
121 
122     /** {@inheritDoc} */
123     public AddScmResult add( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
124         throws ScmException
125     {
126         // TODO: Check whether the CREATE command must be called
127         VssAddCommand command = new VssAddCommand();
128         command.setLogger( getLogger() );
129 
130         return (AddScmResult) command.execute( repository, fileSet, parameters );
131     }
132 
133     public CheckInScmResult checkin( ScmProviderRepository repository, ScmFileSet fileSet,
134                                      CommandParameters parameters )
135         throws ScmException
136     {
137         VssCheckInCommand command = new VssCheckInCommand();
138 
139         command.setLogger( getLogger() );
140 
141         return (CheckInScmResult) command.execute( repository, fileSet, parameters );
142     }
143 
144     /** {@inheritDoc} */
145     public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
146                                        CommandParameters parameters )
147         throws ScmException
148     {
149         VssCheckOutCommand command = new VssCheckOutCommand();
150 
151         command.setLogger( getLogger() );
152 
153         return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
154     }
155 
156     /** {@inheritDoc} */
157     public ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
158                                          CommandParameters parameters )
159         throws ScmException
160     {
161         VssHistoryCommand command = new VssHistoryCommand();
162 
163         command.setLogger( getLogger() );
164 
165         return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
166     }
167 
168     public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
169         throws ScmException
170     {
171         VssTagCommand command = new VssTagCommand();
172 
173         command.setLogger( getLogger() );
174 
175         return (TagScmResult) command.execute( repository, fileSet, parameters );
176     }
177 
178     /** {@inheritDoc} */
179     public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
180         throws ScmException
181     {
182         VssUpdateCommand command = new VssUpdateCommand();
183 
184         command.setLogger( getLogger() );
185 
186         return (UpdateScmResult) command.execute( repository, fileSet, parameters );
187     }
188 
189     /** {@inheritDoc} */
190     public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
191         throws ScmException
192     {
193         VssStatusCommand command = new VssStatusCommand();
194 
195         command.setLogger( getLogger() );
196 
197         return (StatusScmResult) command.execute( repository, fileSet, parameters );
198     }
199 
200     /** {@inheritDoc} */
201     public EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
202         throws ScmException
203     {
204         VssEditCommand command = new VssEditCommand();
205 
206         command.setLogger( getLogger() );
207 
208         return (EditScmResult) command.execute( repository, fileSet, parameters );
209     }
210 
211     /*
212      * public UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet,
213      * CommandParameters parameters ) throws ScmException { VssUnEditCommand command = new
214      * VssUnEditCommand();
215      * 
216      * command.setLogger( getLogger() );
217      * 
218      * return (UnEditScmResult) command.execute( repository, fileSet, parameters ); }
219      */
220 
221     /*
222      * protected RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet,
223      * CommandParameters parameters ) throws ScmException { VssRemoveCommand command = new
224      * VssRemoveCommand();
225      * 
226      * command.setLogger( getLogger() );
227      * 
228      * return (RemoveScmResult) command.execute( repository .getProviderRepository(), fileSet,
229      * parameters ); }
230      */
231 }