001 package org.apache.maven.scm.provider.git.gitexe.command.remoteinfo; 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.remoteinfo.AbstractRemoteInfoCommand; 026 import org.apache.maven.scm.command.remoteinfo.RemoteInfoScmResult; 027 import org.apache.maven.scm.provider.ScmProviderRepository; 028 import org.apache.maven.scm.provider.git.command.GitCommand; 029 import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils; 030 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository; 031 import org.codehaus.plexus.util.cli.CommandLineUtils; 032 import org.codehaus.plexus.util.cli.Commandline; 033 034 /** 035 * @author Bertrand Paquet 036 */ 037 public class GitRemoteInfoCommand 038 extends AbstractRemoteInfoCommand 039 implements GitCommand 040 { 041 042 @Override 043 public RemoteInfoScmResult executeRemoteInfoCommand( ScmProviderRepository repository, ScmFileSet fileSet, 044 CommandParameters parameters ) 045 throws ScmException 046 { 047 GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository; 048 049 CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); 050 051 Commandline clLsRemote = createCommandLine( gitRepository ); 052 053 GitRemoteInfoConsumer consumer = new GitRemoteInfoConsumer( getLogger(), clLsRemote.toString() ); 054 055 int exitCode = GitCommandLineUtils.execute( clLsRemote, consumer, stderr, getLogger() ); 056 if ( exitCode != 0 ) 057 { 058 throw new ScmException( "unbale to execute ls-remote on " + gitRepository.getFetchUrl() ); 059 } 060 061 return consumer.getRemoteInfoScmResult(); 062 } 063 064 // ---------------------------------------------------------------------- 065 // 066 // ---------------------------------------------------------------------- 067 068 public static Commandline createCommandLine( GitScmProviderRepository repository ) 069 { 070 Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( null, "ls-remote" ); 071 072 cl.setWorkingDirectory( System.getProperty( "java.io.tmpdir" ) ); 073 074 String remoteUrl = repository.getPushUrl(); 075 cl.createArg().setValue( remoteUrl ); 076 077 return cl; 078 } 079 080 }