You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-commits@maven.apache.org by jv...@apache.org on 2008/04/05 23:58:57 UTC
svn commit: r645182 [2/5] - in
/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git: ./
maven-scm-provider-git-commons/ maven-scm-provider-git-commons/src/
maven-scm-provider-git-commons/src/main/
maven-scm-provider-git-commons/src/main/java/ m...
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,258 @@
+package org.apache.maven.scm.provider.git.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class GitScmProviderRepository
+ extends ScmProviderRepositoryWithHost
+{
+ /** */
+ private String url;
+
+ /**
+ * the protocol to use
+ */
+ private String protocol;
+
+ /** use local file as transport*/
+ public final static String PROTOCOL_FILE = "file";
+
+ /** use gits internal protocol */
+ public final static String PROTOCOL_GIT = "git";
+
+ /** use secure shell protocol */
+ public final static String PROTOCOL_SSH = "ssh";
+
+ /** use the standard port 80 http protocol */
+ public final static String PROTOCOL_HTTP = "http";
+
+ /** use the standard port 443 https protocol */
+ public final static String PROTOCOL_HTTPS = "https";
+
+ /** use rsync for retrieving the data
+ * TODO implement! */
+ public final static String PROTOCOL_RSYNC = "rsync";
+
+
+ public GitScmProviderRepository( String url )
+ {
+ parseUrl( url );
+ }
+
+ public GitScmProviderRepository( String url, String user, String password )
+ {
+ this( url );
+
+ setUser( user );
+
+ setPassword( password );
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+
+ private void setProtocol( String protocol )
+ {
+ this.protocol = protocol;
+ }
+
+ /**
+ * @return the protocol used in this repository (file, http, https, git, ...)
+ */
+ public String getProtocol()
+ {
+ return protocol;
+ }
+
+ private void parseUrl( String url )
+ {
+ if ( url.startsWith( PROTOCOL_FILE ) )
+ {
+ setProtocol( PROTOCOL_FILE );
+ }
+ else if ( url.startsWith( PROTOCOL_HTTPS ) )
+ {
+ setProtocol( PROTOCOL_HTTPS );
+ }
+ else if ( url.startsWith( PROTOCOL_HTTP ) )
+ {
+ setProtocol( PROTOCOL_HTTP );
+ }
+ else if ( url.startsWith( PROTOCOL_SSH ) )
+ {
+ setProtocol( PROTOCOL_SSH );
+ }
+ else if ( url.startsWith( PROTOCOL_GIT ) )
+ {
+ setProtocol( PROTOCOL_GIT );
+ }
+ else if ( url.startsWith( PROTOCOL_RSYNC ) )
+ {
+ setProtocol( PROTOCOL_RSYNC );
+ }
+
+ if ( getProtocol() == null )
+ {
+ return;
+ }
+
+ String urlPath = url.substring( getProtocol().length() );
+
+ if ( urlPath.startsWith( "://" ) ) {
+ urlPath = urlPath.substring( 3 );
+ }
+ int indexAt = urlPath.indexOf( "@" );
+
+ if ( indexAt > 0 )
+ {
+ String userPassword = urlPath.substring( 0, indexAt );
+ if ( userPassword.indexOf( ":" ) < 0 )
+ {
+ setUser( userPassword );
+ }
+ else
+ {
+ setUser( userPassword.substring( 0, userPassword.indexOf( ":" ) ) );
+ setPassword( userPassword.substring( userPassword.indexOf( ":" ) + 1 ) );
+ }
+
+ urlPath = urlPath.substring( indexAt + 1 );
+
+ if ( PROTOCOL_SSH.equals( getProtocol() ) )
+ {
+ StringBuffer urlSb = new StringBuffer( getProtocol() );
+
+ urlSb.append( "://" );
+
+ if ( getUser() != null )
+ {
+ urlSb.append( getUser() );
+
+ if ( getPassword() != null )
+ {
+ urlSb.append( ':' ).append( getPassword() );
+ }
+
+ urlSb.append( '@' );
+ }
+
+ urlSb.append( urlPath );
+
+ this.url = urlSb.toString();
+ }
+ else
+ {
+ this.url = getProtocol() + "://" + urlPath;
+ }
+ }
+ else
+ {
+ this.url = getProtocol() + "://" + urlPath;
+ }
+
+ if ( !PROTOCOL_FILE.equals( getProtocol() ) )
+ {
+ int indexSlash = urlPath.indexOf( "/" );
+
+ String hostPort = urlPath;
+
+ if ( indexSlash > 0 )
+ {
+ hostPort = urlPath.substring( 0, indexSlash );
+ }
+
+ int indexColon = hostPort.indexOf( ":" );
+
+ if ( indexColon > 0 )
+ {
+ setHost( hostPort.substring( 0, indexColon ) );
+ setPort( Integer.parseInt( hostPort.substring( indexColon + 1 ) ) );
+ }
+ else
+ {
+ setHost( hostPort );
+ }
+
+ }
+ }
+
+ /**
+ * A ScmProviderRepository like this but with the parent url (stripping the last directory)
+ *
+ * @return the parent repository or <code>null</null> if this is the top level repository
+ */
+ public ScmProviderRepository getParent()
+ {
+ String newUrl = getUrl().substring( getProtocol().length() );
+
+ while ( newUrl.endsWith( "/." ) )
+ {
+ newUrl = newUrl.substring( 0, newUrl.length() - 1 );
+ }
+
+ while ( newUrl.endsWith( "/" ) )
+ {
+ newUrl = newUrl.substring( 0, newUrl.length() );
+ }
+
+ int i = newUrl.lastIndexOf( "/" );
+
+ if ( i < 0 )
+ {
+ return null;
+ }
+ newUrl = newUrl.substring( 0, i );
+
+ return new GitScmProviderRepository( getProtocol() + newUrl, getUser(), getPassword() );
+ }
+
+ /**
+ * Get the relative path from the ancestor to this repository
+ */
+ public String getRelativePath( ScmProviderRepository ancestor )
+ {
+ if ( ancestor instanceof GitScmProviderRepository )
+ {
+ GitScmProviderRepository gitAncestor = (GitScmProviderRepository) ancestor;
+
+ String path = getUrl().replaceFirst( gitAncestor.getUrl() + "/", "" );
+
+ if ( !path.equals( getUrl() ) )
+ {
+ return path;
+ }
+ }
+ return null;
+ }
+
+ public String toString()
+ {
+ return getUrl();
+ }
+
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepository.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,71 @@
+package org.apache.maven.scm.provider.git.util;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.providers.gitlib.settings.Settings;
+import org.apache.maven.scm.providers.gitlib.settings.io.xpp3.GitXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class GitUtil
+{
+ private GitUtil()
+ {
+ }
+
+ public static Settings getSettings()
+ {
+ File scmUserDir = new File( System.getProperty( "user.home" ), ".scm" );
+ File settingsFile = new File( scmUserDir, "git-settings.xml" );
+
+ if ( settingsFile.exists() )
+ {
+ GitXpp3Reader reader = new GitXpp3Reader();
+ try
+ {
+ return reader.read( new FileReader( settingsFile ) );
+ }
+ catch ( FileNotFoundException e )
+ {
+ //Nothing to do
+ }
+ catch ( IOException e )
+ {
+ //Nothing to do
+ }
+ catch ( XmlPullParserException e )
+ {
+ String message = settingsFile.getAbsolutePath() + " isn't well formed. SKIPPED." + e.getMessage();
+
+ System.out.println( message );
+ }
+ }
+
+ return new Settings();
+ }
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/mdo/git-settings.mdo
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/mdo/git-settings.mdo?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/mdo/git-settings.mdo (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/mdo/git-settings.mdo Sat Apr 5 14:58:41 2008
@@ -0,0 +1,39 @@
+<model>
+ <id>git</id>
+ <name>Git</name>
+ <description>git Provider Model.</description>
+ <defaults>
+ <default>
+ <key>package</key>
+ <value>org.apache.maven.scm.providers.gitlib.settings</value>
+ </default>
+ </defaults>
+
+ <classes>
+ <class rootElement="true" xml.tagName="git-settings">
+ <name>Settings</name>
+ <version>1.0.0+</version>
+ <fields>
+ <field>
+ <name>revParseDateFormat</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <defaultValue>yyyy-MM-dd HH:mm:ss</defaultValue>
+ <description><![CDATA[
+ git format allowed by changelog command.
+ ]]></description>
+ </field>
+ <field>
+ <name>traceGitCommand</name>
+ <version>1.0.0+</version>
+ <type>String</type>
+ <defaultValue></defaultValue>
+ <description><![CDATA[
+ Traces the execution of a git command.
+ could be 1,2, true or a file location
+ ]]></description>
+ </field>
+ </fields>
+ </class>
+ </classes>
+</model>
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/TestGitScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/TestGitScmProvider.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/TestGitScmProvider.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/TestGitScmProvider.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,98 @@
+package org.apache.maven.scm.provider.git;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.provider.git.command.GitCommand;
+
+import java.io.File;
+
+public class TestGitScmProvider
+ extends AbstractGitScmProvider
+{
+ protected GitCommand getAddCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getBranchCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getChangeLogCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getCheckInCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getCheckOutCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getDiffCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getExportCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getRemoveCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getStatusCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getTagCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getUpdateCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getListCommand()
+ {
+ return null;
+ }
+
+ protected GitCommand getInfoCommand()
+ {
+ return null;
+ }
+
+ protected String getRepositoryURL( File path )
+ {
+ return null;
+ }
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/TestGitScmProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/TestGitScmProvider.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/command/diff/GitDiffConsumerTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/command/diff/GitDiffConsumerTest.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/command/diff/GitDiffConsumerTest.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/command/diff/GitDiffConsumerTest.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,134 @@
+package org.apache.maven.scm.provider.git.command.diff;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.log.DefaultLog;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class GitDiffConsumerTest
+ extends PlexusTestCase
+{
+
+ public void testEmptyLogConsumer()
+ throws Exception
+ {
+ GitDiffConsumer consumer = new GitDiffConsumer( new DefaultLog(), null );
+
+ File f = getTestFile( "/src/test/resources/git/diff/git-diff-empty.log" );
+
+ BufferedReader r = new BufferedReader( new FileReader( f ) );
+
+ String line;
+
+ while ( ( line = r.readLine() ) != null )
+ {
+ consumer.consumeLine( line );
+ }
+
+ List changedFiles = consumer.getChangedFiles();
+
+ assertEquals( 0, changedFiles.size() );
+ }
+
+ public void testLog1Consumer()
+ throws Exception
+ {
+ GitDiffConsumer consumer = new GitDiffConsumer( new DefaultLog(), null );
+
+ File f = getTestFile( "src/test/resources/git/diff/git-diff1.log" );
+
+ BufferedReader r = new BufferedReader( new FileReader( f ) );
+
+ String line;
+
+ while ( ( line = r.readLine() ) != null )
+ {
+ consumer.consumeLine( line );
+ }
+
+ List changedFiles = consumer.getChangedFiles();
+
+ assertEquals( 1, changedFiles.size() );
+
+ testScmFile( (ScmFile) changedFiles.get( 0 ), "readme.txt" , ScmFileStatus.MODIFIED );
+
+ Map differences = consumer.getDifferences();
+ assertNotNull( differences );
+
+ StringBuffer readmeDiffs = (StringBuffer) differences.get( "readme.txt" );
+ assertNotNull( readmeDiffs );
+ assertTrue( readmeDiffs.indexOf( "-/readme.txt" ) >= 0 );
+ }
+
+ public void testLog2Consumer()
+ throws Exception
+ {
+ GitDiffConsumer consumer = new GitDiffConsumer( new DefaultLog(), null );
+
+ File f = getTestFile( "src/test/resources/git/diff/git-diff2.log" );
+
+ BufferedReader r = new BufferedReader( new FileReader( f ) );
+
+ String line;
+
+ while ( ( line = r.readLine() ) != null )
+ {
+ consumer.consumeLine( line );
+ }
+
+ List changedFiles = consumer.getChangedFiles();
+
+ assertEquals( 12, changedFiles.size() );
+
+ testScmFile( (ScmFile) changedFiles.get( 0 ),
+ "maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java",
+ ScmFileStatus.MODIFIED );
+
+ testScmFile( (ScmFile) changedFiles.get( 1 ),
+ "maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java",
+ ScmFileStatus.MODIFIED );
+
+ Map differences = consumer.getDifferences();
+ assertNotNull( differences );
+
+ StringBuffer addDiffs = (StringBuffer) differences.get( "maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java" );
+ assertNotNull( addDiffs );
+ assertTrue( addDiffs.indexOf( "verbosity needed for consumer" ) >= 0 );
+ }
+
+
+ private void testScmFile( ScmFile fileToTest, String expectedFilePath, ScmFileStatus expectedStatus )
+ {
+ assertEquals( expectedFilePath, fileToTest.getPath() );
+ assertEquals( expectedStatus, fileToTest.getStatus() );
+ }
+
+}
\ No newline at end of file
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/command/diff/GitDiffConsumerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/command/diff/GitDiffConsumerTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepositoryTest.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepositoryTest.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepositoryTest.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,217 @@
+package org.apache.maven.scm.provider.git.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class GitScmProviderRepositoryTest
+ extends ScmTestCase
+{
+ private ScmManager scmManager;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ scmManager = getScmManager();
+ }
+
+ // ----------------------------------------------------------------------
+ // Testing legal URLs
+ // ----------------------------------------------------------------------
+
+ public void testLegalFileURL()
+ throws Exception
+ {
+ testUrl( "scm:git:file:///tmp/repo", "file:///tmp/repo", null, null, null );
+ }
+
+ public void testLegalLocalhostFileURL()
+ throws Exception
+ {
+ testUrl( "scm:git:file://localhost/tmp/repo", "file://localhost/tmp/repo", null, null, null );
+ }
+
+ public void testLegalHistnameFileURL()
+ throws Exception
+ {
+ testUrl( "scm:git:file://my_server/tmp/repo", "file://my_server/tmp/repo", null, null, null );
+ }
+
+ public void testLegalHttpURL()
+ throws Exception
+ {
+ testUrl( "scm:git:http://gitrepos.apache.org", "http://gitrepos.apache.org", null, null,
+ "gitrepos.apache.org" );
+ }
+
+ public void testLegalHttpURLWithUser()
+ throws Exception
+ {
+ testUrl( "scm:git:http://user@gitrepos.apache.org", "http://gitrepos.apache.org", "user", null,
+ "gitrepos.apache.org" );
+ }
+
+ public void testLegalHttpURLWithUserPassword()
+ throws Exception
+ {
+ testUrl( "scm:git:http://user:password@gitrepos.apache.org", "http://gitrepos.apache.org", "user",
+ "password", "gitrepos.apache.org" );
+ }
+
+ public void testLegalHttpsURL()
+ throws Exception
+ {
+ testUrl( "scm:git:https://gitrepos.apache.org", "https://gitrepos.apache.org", null, null,
+ "gitrepos.apache.org" );
+ }
+
+ public void testLegalHttpsURLWithUser()
+ throws Exception
+ {
+ testUrl( "scm:git:https://user@gitrepos.apache.org", "https://gitrepos.apache.org", "user", null,
+ "gitrepos.apache.org" );
+ }
+
+ public void testLegalHttpsURLWithUserPassword()
+ throws Exception
+ {
+ testUrl( "scm:git:https://user:password@gitrepos.apache.org", "https://gitrepos.apache.org", "user",
+ "password", "gitrepos.apache.org" );
+ }
+
+ public void testLegalSshURLWithUser()
+ throws Exception
+ {
+ testUrl( "scm:git:ssh://user@gitrepos.apache.org", "ssh://user@gitrepos.apache.org", "user", null,
+ "gitrepos.apache.org" );
+ }
+
+ public void testLegalSshURLWithUserPassword()
+ throws Exception
+ {
+ testUrl( "scm:git:ssh://user:password@gitrepos.apache.org", "ssh://user:password@gitrepos.apache.org", "user",
+ "password", "gitrepos.apache.org" );
+ }
+
+ public void testLegalGitURL()
+ throws Exception
+ {
+ testUrl( "scm:git:git://gitrepos.apache.org", "git://gitrepos.apache.org", null, null,
+ "gitrepos.apache.org" );
+ }
+
+ public void testLegalGitPortUrl()
+ throws Exception
+ {
+ testUrl( "scm:git:http://username@gitrepos.apache.org:8800/pmgt/trunk",
+ "http://gitrepos.apache.org:8800/pmgt/trunk", "username", "gitrepos.apache.org", 8800 );
+
+ testUrl( "scm:git:https://username@gitrepos.apache.org:20443/pmgt/trunk",
+ "https://gitrepos.apache.org:20443/pmgt/trunk", "username", "gitrepos.apache.org", 8080 );
+
+ testUrl( "scm:git:git://username@gitrepos.apache.org:8800/pmgt/trunk",
+ "git://gitrepos.apache.org:8800/pmgt/trunk", "username", "gitrepos.apache.org", 8800 );
+
+ testUrl( "scm:git:ssh://username@gitrepos.apache.org:8080/pmgt/trunk",
+ "ssh://username@gitrepos.apache.org:8080/pmgt/trunk", "username", "gitrepos.apache.org", 8080 );
+
+ testUrl( "scm:git:ssh://username:password@gitrepos.apache.org/pmgt/trunk",
+ "ssh://username:password@gitrepos.apache.org/pmgt/trunk",
+ "username", "password", "gitrepos.apache.org" );
+ }
+
+ // ----------------------------------------------------------------------
+ // Testing illegal URLs
+ // ----------------------------------------------------------------------
+
+ public void testIllegalFileUrl()
+ throws Exception
+ {
+ testIllegalUrl( "file:/tmp/git" );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ private void testUrl( String scmUrl, String expectedUrl, String expectedUser, String expectedPassword,
+ String expectedHost )
+ throws Exception
+ {
+ ScmRepository repository = scmManager.makeScmRepository( scmUrl );
+
+ assertNotNull( "ScmManager.makeScmRepository() returned null", repository );
+
+ assertNotNull( "The provider repository was null.", repository.getProviderRepository() );
+
+ assertTrue( "The SCM Repository isn't a " + GitScmProviderRepository.class.getName() + ".",
+ repository.getProviderRepository() instanceof GitScmProviderRepository );
+
+ GitScmProviderRepository providerRepository = (GitScmProviderRepository) repository.getProviderRepository();
+
+ assertEquals( "url is incorrect", expectedUrl, providerRepository.getUrl() );
+
+ assertEquals( "url string is incorrect", "git:" + expectedUrl, repository.toString() );
+
+ assertEquals( "User is incorrect", expectedUser, providerRepository.getUser() );
+
+ assertEquals( "Password is incorrect", expectedPassword, providerRepository.getPassword() );
+
+ assertEquals( "Host is incorrect", expectedHost,
+ ( (GitScmProviderRepository) repository.getProviderRepository() ).getHost() );
+ }
+
+ private void testUrl( String scmUrl, String expectedUrl, String expectedUser, String expectedHost,
+ int expectedPort )
+ throws Exception
+ {
+ testUrl( scmUrl, expectedUrl, expectedUser, null, expectedHost );
+ }
+
+ private void testIllegalUrl( String url )
+ throws Exception
+ {
+ try
+ {
+ scmManager.makeScmRepository( "scm:git:" + url );
+
+ fail( "Expected a ScmRepositoryException while testing the url '" + url + "'." );
+ }
+ catch ( ScmRepositoryException e )
+ {
+ // expected
+ }
+ }
+
+ public void testGetParent()
+ {
+ new GitScmProviderRepository( "http://gitrepos.apache.org" );
+ }
+
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepositoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/repository/GitScmProviderRepositoryTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/resources/META-INF/plexus/components.xml?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/resources/META-INF/plexus/components.xml (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/resources/META-INF/plexus/components.xml Sat Apr 5 14:58:41 2008
@@ -0,0 +1,28 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<component-set>
+ <components>
+ <component>
+ <role>org.apache.maven.scm.provider.ScmProvider</role>
+ <role-hint>git</role-hint>
+ <implementation>org.apache.maven.scm.provider.git.TestGitScmProvider</implementation>
+ </component>
+ </components>
+</component-set>
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/resources/META-INF/plexus/components.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml Sat Apr 5 14:58:41 2008
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>maven-scm-providers-git</artifactId>
+ <groupId>org.apache.maven.scm</groupId>
+ <version>1.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>maven-scm-provider-gitexe</artifactId>
+ <name>Maven SCM git Provider - git Executable Impl.</name>
+ <version>1.1-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-git-commons</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-gittest</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>regexp</groupId>
+ <artifactId>regexp</artifactId>
+ <version>1.3</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>descriptor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/GitExeScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/GitExeScmProvider.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/GitExeScmProvider.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/GitExeScmProvider.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,132 @@
+package org.apache.maven.scm.provider.git.gitexe;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.provider.git.AbstractGitScmProvider;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.apache.maven.scm.provider.git.command.info.GitInfoItem;
+import org.apache.maven.scm.provider.git.command.info.GitInfoScmResult;
+import org.apache.maven.scm.provider.git.gitexe.command.add.GitAddCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.branch.GitBranchCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.changelog.GitChangeLogCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.checkin.GitCheckInCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.checkout.GitCheckOutCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.diff.GitDiffCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.remove.GitRemoveCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.tag.GitTagCommand;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ * @plexus.component role="org.apache.maven.scm.provider.ScmProvider" role-hint="git"
+ */
+public class GitExeScmProvider
+ extends AbstractGitScmProvider
+{
+ protected GitCommand getAddCommand()
+ {
+ return new GitAddCommand();
+ }
+
+ protected GitCommand getBranchCommand()
+ {
+ return new GitBranchCommand();
+ }
+
+ protected GitCommand getChangeLogCommand()
+ {
+ return new GitChangeLogCommand();
+ }
+
+ protected GitCommand getCheckInCommand()
+ {
+ return new GitCheckInCommand();
+ }
+
+ protected GitCommand getCheckOutCommand()
+ {
+ return new GitCheckOutCommand();
+ }
+
+ protected GitCommand getDiffCommand()
+ {
+ return new GitDiffCommand();
+ }
+
+ protected GitCommand getExportCommand()
+ {
+ return null; //X TODO
+ }
+
+ protected GitCommand getRemoveCommand()
+ {
+ return new GitRemoveCommand();
+ }
+
+ protected GitCommand getStatusCommand()
+ {
+ return new GitStatusCommand();
+ }
+
+ protected GitCommand getTagCommand()
+ {
+ return new GitTagCommand();
+ }
+
+ protected GitCommand getUpdateCommand()
+ {
+ return null; //X TODO
+ }
+
+ protected GitCommand getListCommand()
+ {
+ return null; //X TODO
+ }
+
+ public GitCommand getInfoCommand()
+ {
+ return null; //X TODO
+ }
+
+ /**
+ * Implements retrieving the repository url for a certain path using the 'git info' command.
+ */
+ protected String getRepositoryURL( File path )
+ throws ScmException
+ {
+ // Note: I need to supply just 1 absolute path, but ScmFileSet won't let me without
+ // a basedir (which isn't used here anyway), so use a dummy file.
+ GitInfoScmResult result = info( null, new ScmFileSet( new File( "" ), path ), null );
+
+ if ( result.getInfoItems().size() != 1 )
+ {
+ throw new ScmRepositoryException( "Cannot find URL: " +
+ ( result.getInfoItems().size() == 0 ? "no" : "multiple" ) + " items returned by the info command" );
+ }
+
+ return ( (GitInfoItem) result.getInfoItems().get( 0 ) ).getURL();
+ }
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/GitExeScmProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/GitExeScmProvider.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AbstractFileCheckingConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AbstractFileCheckingConsumer.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AbstractFileCheckingConsumer.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AbstractFileCheckingConsumer.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,107 @@
+package org.apache.maven.scm.provider.git.gitexe.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.log.ScmLogger;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
+ */
+public abstract class AbstractFileCheckingConsumer
+ implements StreamConsumer
+{
+ protected ScmLogger logger;
+
+ protected File workingDirectory;
+
+ private List files = new ArrayList();
+
+ protected int revision;
+
+ private boolean filtered;
+
+ public AbstractFileCheckingConsumer( ScmLogger logger, File workingDirectory )
+ {
+ this.logger = logger;
+ this.workingDirectory = workingDirectory;
+ }
+
+ public final void consumeLine( String line )
+ {
+ if ( line.length() <= 3 )
+ {
+ return;
+ }
+
+ logger.debug( line );
+
+ parseLine( line );
+ }
+
+ protected abstract void parseLine( String line );
+
+ protected List getFiles()
+ {
+ if ( !filtered )
+ {
+ for ( Iterator it = files.iterator(); it.hasNext(); )
+ {
+ if ( !new File( workingDirectory, ( (ScmFile) it.next() ).getPath() ).isFile() )
+ {
+ it.remove();
+ }
+ }
+
+ filtered = true;
+ }
+
+ return files;
+ }
+
+ protected final int parseInt( String revisionString )
+ {
+ try
+ {
+ return Integer.parseInt( revisionString );
+ }
+ catch ( NumberFormatException ex )
+ {
+ return 0;
+ }
+ }
+
+ protected void addFile( ScmFile file )
+ {
+ files.add( file );
+ }
+
+ public final int getRevision()
+ {
+ return revision;
+ }
+
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AbstractFileCheckingConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AbstractFileCheckingConsumer.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,129 @@
+package org.apache.maven.scm.provider.git.gitexe.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.log.ScmLogger;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Command line construction utility.
+ *
+ * @author Brett Porter
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class GitCommandLineUtils
+{
+ public static void addTarget( Commandline cl, List/*<File>*/ files )
+ {
+ if ( files == null || files.isEmpty() )
+ {
+ return;
+ }
+
+ for ( Iterator i = files.iterator(); i.hasNext(); )
+ {
+ File f = (File) i.next();
+ String relativeFile = f.getPath();
+
+ if ( f.getAbsolutePath().startsWith( cl.getWorkingDirectory().getAbsolutePath() ))
+ {
+ // so we can omit the starting characters
+ relativeFile = relativeFile.substring( cl.getWorkingDirectory().getAbsolutePath().length() );
+
+ if ( relativeFile.startsWith( File.separator ) )
+ {
+ relativeFile = relativeFile.substring( File.separator.length() );
+ }
+ }
+
+ // no setFile() since this screws up the working directory!
+ cl.createArgument().setValue( relativeFile );
+ }
+
+ }
+
+ public static Commandline getBaseGitCommandLine( File workingDirectory, String command )
+ {
+ if ( command == null || command.length() == 0)
+ {
+ return null;
+ }
+
+ Commandline cl = new Commandline();
+
+ cl.setExecutable( "git" );
+
+ cl.createArgument().setValue( command );
+
+ cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+
+ return cl;
+ }
+
+ public static int execute( Commandline cl, StreamConsumer consumer, CommandLineUtils.StringStreamConsumer stderr,
+ ScmLogger logger )
+ throws ScmException
+ {
+ logger.info( "Executing: " + cl );
+ logger.info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
+
+ int exitCode;
+ try
+ {
+ exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr );
+ }
+ catch ( CommandLineException ex )
+ {
+ throw new ScmException( "Error while executing command.", ex );
+ }
+
+ return exitCode;
+ }
+
+ public static int execute( Commandline cl, CommandLineUtils.StringStreamConsumer stdout,
+ CommandLineUtils.StringStreamConsumer stderr, ScmLogger logger )
+ throws ScmException
+ {
+ logger.info( "Executing: " + cl );
+ logger.info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() );
+
+ int exitCode;
+ try
+ {
+ exitCode = CommandLineUtils.executeCommandLine( cl, stdout, stderr );
+ }
+ catch ( CommandLineException ex )
+ {
+ throw new ScmException( "Error while executing command.", ex );
+ }
+
+ return exitCode;
+ }
+
+
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,114 @@
+package org.apache.maven.scm.provider.git.gitexe.command.add;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.add.AbstractAddCommand;
+import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils;
+import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.status.GitStatusConsumer;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class GitAddCommand extends AbstractAddCommand implements GitCommand
+{
+ protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
+ boolean binary )
+ throws ScmException
+ {
+ GitScmProviderRepository repository = (GitScmProviderRepository) repo;
+
+ if ( fileSet.getFileList().isEmpty() )
+ {
+ throw new ScmException( "You must provide at least one file/directory to add" );
+ }
+
+ Commandline cl = createCommandLine( fileSet.getBasedir(), fileSet.getFileList() );
+
+ CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+ CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
+
+ int exitCode;
+
+ exitCode = GitCommandLineUtils.execute( cl, stdout, stderr, getLogger() );
+ if ( exitCode != 0 )
+ {
+ return new AddScmResult( cl.toString(), "The git-add command failed.", stderr.getOutput(), false );
+ }
+
+ // git-add doesn't show single files, but only summary :/
+ // so we must run git-status and consume the output
+ // borrow a few things from the git-status command
+ Commandline clStatus = GitStatusCommand.createCommandLine( repository, fileSet );
+
+ GitStatusConsumer statusConsumer = new GitStatusConsumer( getLogger(), fileSet.getBasedir() );
+ exitCode = GitCommandLineUtils.execute( clStatus, statusConsumer, stderr, getLogger() );
+ if ( exitCode != 0 )
+ {
+ // git-status returns non-zero if nothing to do
+ getLogger().info( "nothing added to commit but untracked files present (use \"git add\" to track)" );
+ }
+
+ List changedFiles = new ArrayList();
+
+ // rewrite all detected files to now have status 'checked_in'
+ for ( Iterator it = statusConsumer.getChangedFiles().iterator(); it.hasNext(); )
+ {
+ ScmFile scmfile = (ScmFile) it.next();
+
+ // if a specific fileSet is given, we have to check if the file is really tracked
+ for ( Iterator itfl = fileSet.getFileList().iterator(); itfl.hasNext(); )
+ {
+ File f = (File) itfl.next();
+ if ( f.toString().equals( scmfile.getPath() ))
+ {
+ changedFiles.add( scmfile );
+ }
+ }
+ }
+ return new AddScmResult( cl.toString(), changedFiles );
+ }
+
+ public static Commandline createCommandLine( File workingDirectory, List/*File*/ files )
+ throws ScmException
+ {
+ Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "add" );
+
+ GitCommandLineUtils.addTarget( cl, files );
+
+ return cl;
+ }
+
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/add/GitAddCommand.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,132 @@
+package org.apache.maven.scm.provider.git.gitexe.command.branch;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFile;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.branch.AbstractBranchCommand;
+import org.apache.maven.scm.command.branch.BranchScmResult;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils;
+import org.apache.maven.scm.provider.git.gitexe.command.list.GitListCommand;
+import org.apache.maven.scm.provider.git.gitexe.command.list.GitListConsumer;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class GitBranchCommand extends AbstractBranchCommand implements GitCommand
+{
+ public ScmResult executeBranchCommand( ScmProviderRepository repo, ScmFileSet fileSet, String branch,
+ String message )
+ throws ScmException
+ {
+ if ( branch == null || StringUtils.isEmpty( branch.trim() ) )
+ {
+ throw new ScmException( "branch name must be specified" );
+ }
+
+ if ( !fileSet.getFileList().isEmpty() )
+ {
+ throw new ScmException( "This provider doesn't support branching subsets of a directory" );
+ }
+
+ GitScmProviderRepository repository = (GitScmProviderRepository) repo;
+
+ Commandline cl = createCommandLine( repository, fileSet.getBasedir(), branch );
+
+ CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
+ CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+ int exitCode;
+
+ exitCode = GitCommandLineUtils.execute( cl, stdout, stderr, getLogger() );
+ if ( exitCode != 0 )
+ {
+ return new BranchScmResult( cl.toString(), "The git-branch command failed.", stderr.getOutput(), false );
+ }
+
+ // and now push the branch to the origin repository
+ Commandline clPush = createPushCommandLine( repository, fileSet, branch );
+
+ exitCode = GitCommandLineUtils.execute( clPush, stdout, stderr, getLogger() );
+ if ( exitCode != 0 )
+ {
+ return new BranchScmResult( clPush.toString(), "The git-push command failed.", stderr.getOutput(), false );
+ }
+
+ // as last action we search for the branched files
+ GitListConsumer listConsumer = new GitListConsumer( getLogger()
+ , fileSet.getBasedir()
+ , ScmFileStatus.TAGGED);
+
+ Commandline clList = GitListCommand.createCommandLine( repository, fileSet.getBasedir() );
+
+ exitCode = GitCommandLineUtils.execute( clList, listConsumer, stderr, getLogger() );
+ if ( exitCode != 0 )
+ {
+ return new BranchScmResult( clList.toString(), "The git-ls-files command failed.", stderr.getOutput(), false );
+ }
+
+ return new BranchScmResult( cl.toString(), listConsumer.getListedFiles() );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ public static Commandline createCommandLine( GitScmProviderRepository repository, File workingDirectory,
+ String branch )
+ {
+ Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "branch" );
+
+ cl.createArgument().setValue( branch );
+
+ return cl;
+ }
+
+ public static Commandline createPushCommandLine( GitScmProviderRepository repository, ScmFileSet fileSet,
+ String branch )
+ throws ScmException
+ {
+ Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "push");
+
+ cl.createArgument().setValue( "origin" );
+ cl.createArgument().setValue( branch );
+
+ return cl;
+ }
+
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/branch/GitBranchCommand.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,132 @@
+package org.apache.maven.scm.provider.git.gitexe.command.changelog;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ScmBranch;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.command.changelog.AbstractChangeLogCommand;
+import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
+import org.apache.maven.scm.command.changelog.ChangeLogSet;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.git.command.GitCommand;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class GitChangeLogCommand
+ extends AbstractChangeLogCommand
+ implements GitCommand
+{
+ private final static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss Z";
+
+ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ ScmVersion startVersion, ScmVersion endVersion,
+ String datePattern )
+ throws ScmException
+ {
+ return executeChangeLogCommand( repo, fileSet, null, null, null, datePattern, startVersion, endVersion );
+ }
+
+ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ Date startDate, Date endDate, ScmBranch branch,
+ String datePattern )
+ throws ScmException
+ {
+ return executeChangeLogCommand( repo, fileSet, startDate, endDate, branch, datePattern, null, null );
+ }
+
+ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+ Date startDate, Date endDate, ScmBranch branch,
+ String datePattern, ScmVersion startVersion,
+ ScmVersion endVersion )
+ throws ScmException
+ {
+ Commandline cl = createCommandLine( (GitScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate,
+ endDate, startVersion, endVersion );
+
+ GitChangeLogConsumer consumer = new GitChangeLogConsumer( getLogger(), datePattern );
+
+ CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+
+ int exitCode;
+
+ exitCode = GitCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
+ if ( exitCode != 0 )
+ {
+ return new ChangeLogScmResult( cl.toString(), "The git-log command failed.", stderr.getOutput(), false );
+ }
+ ChangeLogSet changeLogSet = new ChangeLogSet( consumer.getModifications(), startDate, endDate );
+ changeLogSet.setStartVersion( startVersion );
+ changeLogSet.setEndVersion( endVersion );
+
+ return new ChangeLogScmResult( cl.toString(), changeLogSet );
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ public static Commandline createCommandLine( GitScmProviderRepository repository, File workingDirectory,
+ ScmBranch branch, Date startDate, Date endDate,
+ ScmVersion startVersion, ScmVersion endVersion )
+ {
+ SimpleDateFormat dateFormat = new SimpleDateFormat( DATE_FORMAT );
+ dateFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
+
+ Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "log" );
+
+ if ( startVersion != null ) {
+ cl.createArgument().setValue( "--since=" + StringUtils.escape( startVersion.getName() ) );
+ }
+ else
+ {
+ if ( startDate != null )
+ {
+ cl.createArgument().setValue( "--since=" + StringUtils.escape( dateFormat.format( startDate ) ) );
+ }
+ }
+
+ if ( endVersion != null ) {
+ cl.createArgument().setValue( "--until=" + StringUtils.escape( endVersion.getName() ) );
+ }
+ else
+ {
+ if ( endDate != null )
+ {
+ cl.createArgument().setValue( "--until=" + StringUtils.escape( dateFormat.format( endDate ) ) );
+ }
+ }
+
+ return cl;
+ }
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogConsumer.java?rev=645182&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogConsumer.java (added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogConsumer.java Sat Apr 5 14:58:41 2008
@@ -0,0 +1,337 @@
+package org.apache.maven.scm.provider.git.gitexe.command.changelog;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.scm.ChangeFile;
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.git.GitChangeSet;
+import org.apache.maven.scm.util.AbstractConsumer;
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ */
+public class GitChangeLogConsumer
+ extends AbstractConsumer
+{
+ /**
+ * Date formatter for git timestamp
+ */
+ private static final String GIT_TIMESTAMP_PATTERN = "MMM dd HH:mm:ss yyyy Z";
+
+ /**
+ * State machine constant: expecting header
+ */
+ private static final int STATUS_GET_HEADER = 1;
+
+ /**
+ * State machine constant: expecting author information
+ */
+ private static final int STATUS_GET_AUTHOR = 2;
+
+ /**
+ * State machine constant: expecting date information
+ */
+ private static final int STATUS_GET_DATE = 3;
+
+ /**
+ * State machine constant: expecting file information
+ */
+ private static final int STATUS_GET_FILE = 4;
+
+ /**
+ * State machine constant: expecting comments
+ */
+ private static final int STATUS_GET_COMMENT = 5;
+
+
+ /**
+ * The pattern used to match git header lines
+ */
+ private static final String HEADER_PATTERN = "^commit (.*)";
+
+ /**
+ * The pattern used to match git author lines
+ */
+ private static final String AUTHOR_PATTERN = "^Author: (.*)";
+
+ /**
+ * The pattern used to match git date lines
+ */
+ private static final String DATE_PATTERN = "^Date:\\s*\\w\\w\\w\\s(.*)";
+
+ /**
+ * The pattern used to match git file lines
+ */
+//X private static final String FILE_PATTERN = "^:\\d* \\d* [:xdigit:]*\\.* [:xdigit:]*\\.* ([:upper:]) (.*)";
+ private static final String FILE_PATTERN = "^:\\d* \\d* [:xdigit:]*\\.* [:xdigit:]*\\.* ([:upper:])\\t(.*)";
+
+ /**
+ * Current status of the parser
+ */
+ private int status = STATUS_GET_HEADER;
+
+ /**
+ * List of change log entries
+ */
+ private List entries = new ArrayList();
+
+ /**
+ * The current log entry being processed by the parser
+ */
+ private GitChangeSet currentChange;
+
+ /**
+ * The current revision of the entry being processed by the parser
+ */
+ private String currentRevision;
+
+ /**
+ * The current comment of the entry being processed by the parser
+ */
+ private StringBuffer currentComment;
+
+ /**
+ * The regular expression used to match header lines
+ */
+ private RE headerRegexp;
+
+ /**
+ * The regular expression used to match author lines
+ */
+ private RE authorRegexp;
+
+ /**
+ * The regular expression used to match date lines
+ */
+ private RE dateRegexp;
+
+ /**
+ * The regular expression used to match file lines
+ */
+ private RE fileRegexp;
+
+
+ private String userDateFormat;
+
+ /**
+ * Default constructor.
+ */
+ public GitChangeLogConsumer( ScmLogger logger, String userDateFormat )
+ {
+ super( logger );
+
+ this.userDateFormat = userDateFormat;
+
+ try
+ {
+ headerRegexp = new RE( HEADER_PATTERN );
+ authorRegexp = new RE( AUTHOR_PATTERN );
+ dateRegexp = new RE( DATE_PATTERN );
+ fileRegexp = new RE( FILE_PATTERN );
+ }
+ catch ( RESyntaxException ex )
+ {
+ throw new RuntimeException(
+ "INTERNAL ERROR: Could not create regexp to parse git log file. This shouldn't happen. Something is probably wrong with the oro installation.",
+ ex );
+ }
+ }
+
+ public List getModifications()
+ {
+ // this is needed since the processFile does not always get a the end-sequence correctly.
+ processGetFile( "" );
+
+ return entries;
+ }
+
+ // ----------------------------------------------------------------------
+ // StreamConsumer Implementation
+ // ----------------------------------------------------------------------
+
+ public void consumeLine( String line )
+ {
+ switch ( status )
+ {
+ case STATUS_GET_HEADER:
+ processGetHeader( line );
+ break;
+ case STATUS_GET_AUTHOR:
+ processGetAuthor( line );
+ break;
+ case STATUS_GET_DATE:
+ processGetDate( line );
+ break;
+ case STATUS_GET_COMMENT:
+ processGetComment( line );
+ break;
+ case STATUS_GET_FILE:
+ processGetFile( line );
+ break;
+ default:
+ throw new IllegalStateException( "Unknown state: " + status );
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ //
+ // ----------------------------------------------------------------------
+
+ /**
+ * Process the current input line in the GET_HEADER state. The
+ * author, date, and the revision of the entry are gathered. Note,
+ * Subversion does not have per-file revisions, instead, the entire
+ * repository is given a single revision number, which is used for
+ * the revision number of each file.
+ *
+ * @param line A line of text from the git log output
+ */
+ private void processGetHeader( String line )
+ {
+ if ( !headerRegexp.match( line ) )
+ {
+ return;
+ }
+
+ currentRevision = headerRegexp.getParen( 1 );
+
+ currentChange = new GitChangeSet();
+
+ status = STATUS_GET_AUTHOR;
+ }
+
+ /**
+ * Process the current input line in the STATUS_GET_AUTHOR state. This
+ * state gathers all of the author information that are part of a log entry.
+ *
+ * @param line a line of text from the git log output
+ */
+ private void processGetAuthor( String line )
+ {
+ if ( !authorRegexp.match( line ) )
+ {
+ return;
+ }
+ String author = authorRegexp.getParen( 1 );
+
+ currentChange.setAuthor( author );
+
+ status = STATUS_GET_DATE;
+ }
+
+ /**
+ * Process the current input line in the STATUS_GET_DATE state. This
+ * state gathers all of the date information that are part of a log entry.
+ *
+ * @param line a line of text from the git log output
+ */
+ private void processGetDate( String line )
+ {
+ if ( !dateRegexp.match( line ) )
+ {
+ return;
+ }
+
+ String datestring = dateRegexp.getParen( 1 );
+
+ Date date = parseDate( datestring.trim() , userDateFormat, GIT_TIMESTAMP_PATTERN );
+
+ currentChange.setDate( date );
+
+ status = STATUS_GET_COMMENT;
+ }
+
+ /**
+ * Process the current input line in the GET_COMMENT state. This
+ * state gathers all of the comments that are part of a log entry.
+ *
+ * @param line a line of text from the git log output
+ */
+ private void processGetComment( String line )
+ {
+ if ( line.length() < 4 )
+ {
+ if (currentComment == null)
+ {
+ currentComment = new StringBuffer();
+ }
+ else
+ {
+ currentChange.setComment( currentComment.toString() );
+ status = STATUS_GET_FILE;
+ }
+ }
+ else
+ {
+ if ( currentComment.length() > 0 ) {
+ currentComment.append( '\n' );
+ }
+
+ currentComment.append( line.substring( 4 ) );
+ }
+ }
+
+ /**
+ * Process the current input line in the GET_FILE state. This state
+ * adds each file entry line to the current change log entry. Note,
+ * the revision number for the entire entry is used for the revision
+ * number of each file.
+ *
+ * @param line A line of text from the git log output
+ */
+ private void processGetFile( String line )
+ {
+ if ( line.length() == 0 )
+ {
+ if ( currentChange != null )
+ {
+ entries.add( currentChange );
+ }
+
+ resetChangeLog();
+
+ status = STATUS_GET_HEADER;
+ }
+ else
+ {
+ if ( !fileRegexp.match( line ) )
+ {
+ return;
+ }
+ // String action = fileRegexp.getParen( 1 );
+ // action is currently not used
+
+ String name = fileRegexp.getParen( 2 );
+
+ currentChange.addFile( new ChangeFile( name, currentRevision ) );
+ }
+ }
+
+ private void resetChangeLog() {
+ currentComment = null;
+ currentChange = null;
+ }
+}
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogConsumer.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"