001package org.apache.maven.scm.provider.git.gitexe;
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.io.File;
023
024import org.apache.maven.scm.ScmException;
025import org.apache.maven.scm.ScmFileSet;
026import org.apache.maven.scm.command.info.InfoScmResult;
027import org.apache.maven.scm.provider.git.AbstractGitScmProvider;
028import org.apache.maven.scm.provider.git.command.GitCommand;
029import org.apache.maven.scm.provider.git.gitexe.command.add.GitAddCommand;
030import org.apache.maven.scm.provider.git.gitexe.command.blame.GitBlameCommand;
031import org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand;
032import org.apache.maven.scm.provider.git.gitexe.command.changelog.GitChangeLogCommand;
033import org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand;
034import org.apache.maven.scm.provider.git.gitexe.command.checkout.GitCheckOutCommand;
035import org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffCommand;
036import org.apache.maven.scm.provider.git.gitexe.command.info.GitInfoCommand;
037import org.apache.maven.scm.provider.git.gitexe.command.remoteinfo.GitRemoteInfoCommand;
038import org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveCommand;
039import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand;
040import org.apache.maven.scm.provider.git.gitexe.command.tag.GitTagCommand;
041import org.apache.maven.scm.provider.git.gitexe.command.update.GitUpdateCommand;
042import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
043import org.apache.maven.scm.repository.ScmRepositoryException;
044
045/**
046 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
047 *
048 * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="git"
049 */
050public class GitExeScmProvider
051    extends AbstractGitScmProvider
052{
053    /** {@inheritDoc} */
054    protected GitCommand getAddCommand()
055    {
056        return new GitAddCommand();
057    }
058
059    /** {@inheritDoc} */
060    protected GitCommand getBranchCommand()
061    {
062        return new GitBranchCommand();
063    }
064
065    /** {@inheritDoc} */
066    protected GitCommand getChangeLogCommand()
067    {
068        return new GitChangeLogCommand();
069    }
070
071    /** {@inheritDoc} */
072    protected GitCommand getCheckInCommand()
073    {
074        return new GitCheckInCommand();
075    }
076
077    /** {@inheritDoc} */
078    protected GitCommand getCheckOutCommand()
079    {
080        return new GitCheckOutCommand();
081    }
082
083    /** {@inheritDoc} */
084    protected GitCommand getDiffCommand()
085    {
086        return new GitDiffCommand();
087    }
088
089    /** {@inheritDoc} */
090    protected GitCommand getExportCommand()
091    {
092        return null; //X TODO
093    }
094
095    /** {@inheritDoc} */
096    protected GitCommand getRemoveCommand()
097    {
098        return new GitRemoveCommand();
099    }
100
101    /** {@inheritDoc} */
102    protected GitCommand getStatusCommand()
103    {
104        return new GitStatusCommand();
105    }
106
107    /** {@inheritDoc} */
108    protected GitCommand getTagCommand()
109    {
110        return new GitTagCommand();
111    }
112
113    /** {@inheritDoc} */
114    protected GitCommand getUpdateCommand()
115    {
116        return new GitUpdateCommand();
117    }
118
119    /** {@inheritDoc} */
120    public GitCommand getInfoCommand()
121    {
122        return new GitInfoCommand();
123    }
124
125    /** {@inheritDoc} */
126    protected GitCommand getBlameCommand()
127    {
128        return new GitBlameCommand();
129    }
130
131    /** {@inheritDoc} */
132    protected GitCommand getRemoteInfoCommand()
133    {
134        return new GitRemoteInfoCommand();
135    }
136
137    /** {@inheritDoc} */
138    protected String getRepositoryURL( File path )
139        throws ScmException
140    {
141        // Note: I need to supply just 1 absolute path, but ScmFileSet won't let me without
142        // a basedir (which isn't used here anyway), so use a dummy file.
143        // and a dummy ScmProviderRepository
144        InfoScmResult result = info( new GitScmProviderRepository( path.toPath().toUri().toASCIIString() ),
145                                     new ScmFileSet( path ), null );
146
147        if ( result.getInfoItems().size() != 1 )
148        {
149            throw new ScmRepositoryException( "Cannot find URL: "
150                + ( result.getInfoItems().size() == 0 ? "no" : "multiple" ) + " items returned by the info command" );
151        }
152
153        return result.getInfoItems().get( 0 ).getURL();
154    }
155}