001    package org.apache.maven.scm.provider.vss;
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.CommandParameters;
023    import org.apache.maven.scm.ScmException;
024    import org.apache.maven.scm.ScmFileSet;
025    import org.apache.maven.scm.command.add.AddScmResult;
026    import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
027    import org.apache.maven.scm.command.checkin.CheckInScmResult;
028    import org.apache.maven.scm.command.checkout.CheckOutScmResult;
029    import org.apache.maven.scm.command.edit.EditScmResult;
030    import org.apache.maven.scm.command.status.StatusScmResult;
031    import org.apache.maven.scm.command.tag.TagScmResult;
032    import org.apache.maven.scm.command.update.UpdateScmResult;
033    import org.apache.maven.scm.provider.AbstractScmProvider;
034    import org.apache.maven.scm.provider.ScmProviderRepository;
035    import org.apache.maven.scm.provider.vss.commands.add.VssAddCommand;
036    import org.apache.maven.scm.provider.vss.commands.changelog.VssHistoryCommand;
037    import org.apache.maven.scm.provider.vss.commands.checkin.VssCheckInCommand;
038    import org.apache.maven.scm.provider.vss.commands.checkout.VssCheckOutCommand;
039    import org.apache.maven.scm.provider.vss.commands.edit.VssEditCommand;
040    import org.apache.maven.scm.provider.vss.commands.status.VssStatusCommand;
041    import org.apache.maven.scm.provider.vss.commands.tag.VssTagCommand;
042    import org.apache.maven.scm.provider.vss.commands.update.VssUpdateCommand;
043    import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
044    import org.apache.maven.scm.repository.ScmRepositoryException;
045    import org.codehaus.plexus.util.StringUtils;
046    
047    /**
048     * @author <a href="mailto:george@neogrid.com.br">George Gastaldi</a>
049     * @version $Id: VssScmProvider.java 885129 2009-11-28 19:13:15Z olamy $
050     * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="vss"
051     */
052    public class VssScmProvider
053        extends AbstractScmProvider
054    {
055    
056        public static final String VSS_URL_FORMAT = "[username[|password]@]vssdir|projectPath";
057    
058        // ----------------------------------------------------------------------
059        // ScmProvider Implementation
060        // ----------------------------------------------------------------------
061    
062        /** {@inheritDoc} */
063        public String getScmSpecificFilename()
064        {
065            return "vssver.scc";
066        }
067    
068        /** {@inheritDoc} */
069        public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
070            throws ScmRepositoryException
071        {
072            String user = null;
073            String password = null;
074            String vssDir;
075            String project;
076    
077            int index = scmSpecificUrl.indexOf( '@' );
078    
079            String rest = scmSpecificUrl;
080    
081            if ( index != -1 )
082            {
083                String userAndPassword = scmSpecificUrl.substring( 0, index );
084    
085                rest = scmSpecificUrl.substring( index + 1 );
086    
087                index = userAndPassword.indexOf( delimiter );
088    
089                if ( index != -1 )
090                {
091                    user = userAndPassword.substring( 0, index );
092    
093                    password = userAndPassword.substring( index + 1 );
094                }
095                else
096                {
097                    user = userAndPassword;
098                }
099            }
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, CommandParameters parameters )
134            throws ScmException
135        {
136            VssCheckInCommand command = new VssCheckInCommand();
137    
138            command.setLogger( getLogger() );
139    
140            return (CheckInScmResult) command.execute( repository, fileSet, parameters );
141        }
142    
143        /** {@inheritDoc} */
144        public CheckOutScmResult checkout( ScmProviderRepository repository, ScmFileSet fileSet,
145                                           CommandParameters parameters )
146            throws ScmException
147        {
148            VssCheckOutCommand command = new VssCheckOutCommand();
149    
150            command.setLogger( getLogger() );
151    
152            return (CheckOutScmResult) command.execute( repository, fileSet, parameters );
153        }
154    
155        /** {@inheritDoc} */
156        public ChangeLogScmResult changelog( ScmProviderRepository repository, ScmFileSet fileSet,
157                                             CommandParameters parameters )
158            throws ScmException
159        {
160            VssHistoryCommand command = new VssHistoryCommand();
161    
162            command.setLogger( getLogger() );
163    
164            return (ChangeLogScmResult) command.execute( repository, fileSet, parameters );
165        }
166    
167        public TagScmResult tag( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
168            throws ScmException
169        {
170            VssTagCommand command = new VssTagCommand();
171    
172            command.setLogger( getLogger() );
173    
174            return (TagScmResult) command.execute( repository, fileSet, parameters );
175        }
176    
177        /** {@inheritDoc} */
178        public UpdateScmResult update( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
179            throws ScmException
180        {
181            VssUpdateCommand command = new VssUpdateCommand();
182    
183            command.setLogger( getLogger() );
184    
185            return (UpdateScmResult) command.execute( repository, fileSet, parameters );
186        }
187    
188        /** {@inheritDoc} */
189        public StatusScmResult status( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
190            throws ScmException
191        {
192            VssStatusCommand command = new VssStatusCommand();
193    
194            command.setLogger( getLogger() );
195    
196            return (StatusScmResult) command.execute( repository, fileSet, parameters );
197        }
198    
199        /** {@inheritDoc} */
200        public EditScmResult edit( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters )
201            throws ScmException
202        {
203            VssEditCommand command = new VssEditCommand();
204    
205            command.setLogger( getLogger() );
206    
207            return (EditScmResult) command.execute( repository, fileSet, parameters );
208        }
209    
210        /*
211         * public UnEditScmResult unedit( ScmProviderRepository repository, ScmFileSet fileSet,
212         * CommandParameters parameters ) throws ScmException { VssUnEditCommand command = new
213         * VssUnEditCommand();
214         * 
215         * command.setLogger( getLogger() );
216         * 
217         * return (UnEditScmResult) command.execute( repository, fileSet, parameters ); }
218         */
219    
220        /*
221         * protected RemoveScmResult remove( ScmProviderRepository repository, ScmFileSet fileSet,
222         * CommandParameters parameters ) throws ScmException { VssRemoveCommand command = new
223         * VssRemoveCommand();
224         * 
225         * command.setLogger( getLogger() );
226         * 
227         * return (RemoveScmResult) command.execute( repository .getProviderRepository(), fileSet,
228         * parameters ); }
229         */
230    }