maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joak...@apache.org
Subject svn commit: r468577 [1/2] - in /maven/scm/trunk/sandbox/maven-scm-provider-hg: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/scm/ src/main/java/org/apache/ma...
Date Fri, 27 Oct 2006 22:54:51 GMT
Author: joakime
Date: Fri Oct 27 15:54:48 2006
New Revision: 468577

URL: http://svn.apache.org/viewvc?view=rev&rev=468577
Log:
[SCM-230] Adding Mercurial (hg) scm system to sandbox.


Added:
    maven/scm/trunk/sandbox/maven-scm-provider-hg/   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/remove/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/remove/HgRemoveCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/remove/HgRemoveConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/status/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/status/HgStatusCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/status/HgStatusConsumer.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/update/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/update/HgUpdateCommand.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/repository/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/repository/HgScmProviderRepository.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/resources/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/HgTestUtils.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/changelog/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommandTckTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/checkin/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommandTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/checkout/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommandTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/diff/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommandTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/status/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/status/HgStatusCommandTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/update/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/command/update/HgUpdateCommandTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/repository/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/java/org/apache/maven/scm/provider/hg/repository/HgScmProviderRepositoryTest.java   (with props)
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/resources/
    maven/scm/trunk/sandbox/maven-scm-provider-hg/src/test/resources/hg/

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Oct 27 15:54:48 2006
@@ -0,0 +1,14 @@
+target
+*~
+.*.swp
+*.log
+*.patch
+*.diff
+*.ipr
+*.iws
+*.iml
+.classpath
+.project
+.settings
+.wtpmodules
+cobertura.ser

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml Fri Oct 27 15:54:48 2006
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?><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</artifactId>
+    <groupId>org.apache.maven.scm</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>maven-scm-provider-hg</artifactId>
+  <name>Maven SCM Mercurial (Hg) Provider</name>
+  <version>1.0-SNAPSHOT</version>
+
+  <contributors>
+    <contributor>
+      <name>Thurner Rupert</name>
+      <email>thurner.rupert@ymono.net</email>
+    </contributor>
+    <contributor>
+      <name>Alain Hoang</name>
+      <email>hoanga@alum.rpi.edu</email>
+    </contributor>
+    <contributor>
+      <name>Ryan Daum</name>
+      <email>ryan@darksleep.com</email>
+    </contributor>
+  </contributors>
+
+  <dependencies>
+    <dependency>
+      <groupId>regexp</groupId>
+      <artifactId>regexp</artifactId>
+      <version>1.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-7</version>
+    </dependency>
+  </dependencies>
+
+  <repositories>
+    <repository>
+      <id>apache.snapshots</id>
+      <url>http://people.apache.org/repo/m2-snapshot-repository</url>
+    </repository>
+  </repositories>
+
+  <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/sandbox/maven-scm-provider-hg/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt Fri Oct 27 15:54:48 2006
@@ -0,0 +1,6 @@
+how to build mercurial (hg) scm provider?
+
+you must have mercurial (hg) installed on your machine. mercurial is available at http://selenic.com/mercurial. 
+
+the mercurial provider is basically a copy of the bzr provider written by mailto:torbjorn@smorgrav.org">torbjørn eikli smørgrav.
+

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/readme.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,274 @@
+package org.apache.maven.scm.provider.hg;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmFileStatus;
+import org.apache.maven.scm.log.DefaultLog;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Check hg installation.
+ *
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgConfig
+{
+    //TODO: change BAZAAR to HG, correct versions, and only test for necessary things
+    //Minimum version for the Hg SCM
+    private static final float BAZAAR_REQ = 0.7f;
+
+    private static final float PYTHON_REQ = 2.4f;
+
+    //Hg spesific
+    private static final String BAZAAR_VERSION_TAG = "hg (hg-ng) ";
+
+    private static final String BAZAAR_INSTALL_URL = "'http://hg-vcs.org/Installation'";
+
+    //Python spesific
+    private static final String PYTHON_EXEC = "python";
+
+    private static final String PYTHON_VERSION = "-V";
+
+    private static final String PYTHON_VERSION_TAG = "Python ";
+
+    //Python modules
+    private static final String PARAMIKO = "\"import paramiko\"";
+
+    private static final String CCRYPT = "\"import Crypto\"";
+
+    private static final String CELEMENTREE = "\"import cElementTree\"";
+
+    //Configuration to check with default values (not installed)
+    private VersionConsumer hgVersion = new VersionConsumer( null );
+
+    private VersionConsumer pythonVersion = new VersionConsumer( null );
+
+    private boolean cElementTree = false;
+
+    private boolean paramiko = false;
+
+    private boolean cCrypt = false;
+
+    HgConfig( File workingDir )
+    {
+        try
+        {
+            pythonVersion = getPythonVersion( workingDir );
+            paramiko = checkPyModules( workingDir, PARAMIKO ); //does not throw
+            cCrypt = checkPyModules( workingDir, CCRYPT ); //does not throw
+            cElementTree = checkPyModules( workingDir, CELEMENTREE ); //does not throw
+            hgVersion = getHgVersion( workingDir );
+        }
+        catch ( ScmException e )
+        {
+            //Ignore - Either python and/or hg is not installed.
+            //This is already recorded thus we do not generate more info.
+        }
+
+    }
+
+    private boolean checkPyModules( File workingDir, String cmd )
+    {
+        PythonConsumer consumer = new PythonConsumer();
+        int exitCode;
+        try
+        {
+            Commandline cmdLine = buildPythonCmd( workingDir, new String[] { "-c", cmd } );
+            exitCode = HgUtils.executeCmd( consumer, cmdLine );
+        }
+        catch ( ScmException e )
+        {
+            //Ignore - error here is likly to manifest itself when checking python anyway.
+            exitCode = -1;
+        }
+
+        return exitCode == 0 && consumer.getConsumedAndClear().equals( "" );
+    }
+
+    /**
+     * @return True if one can run basic hg commands
+     */
+    private boolean isInstalled()
+    {
+        return pythonVersion.isVersionOk( PYTHON_REQ ) && hgVersion.isVersionOk( BAZAAR_REQ );
+    }
+
+    /**
+     * @return True if all modules for hg are installed.
+     */
+    private boolean isComplete()
+    {
+        return isInstalled() && cElementTree && paramiko && cCrypt;
+    }
+
+    public static VersionConsumer getHgVersion( File workingDir )
+        throws ScmException
+    {
+        String[] versionCmd = new String[] { HgCommand.VERSION };
+        VersionConsumer consumer = new VersionConsumer( BAZAAR_VERSION_TAG );
+        Commandline cmd = HgUtils.buildCmd( workingDir, versionCmd );
+
+        // Execute command
+        HgUtils.executeCmd( consumer, cmd );
+
+        // Return result
+        return consumer;
+    }
+
+    public static VersionConsumer getPythonVersion( File workingDir )
+        throws ScmException
+    {
+        String[] versionCmd = new String[] { PYTHON_VERSION };
+        VersionConsumer consumer = new VersionConsumer( PYTHON_VERSION_TAG );
+        Commandline cmd = buildPythonCmd( workingDir, versionCmd );
+
+        // Execute command
+        HgUtils.executeCmd( consumer, cmd );
+
+        // Return result
+        return consumer;
+    }
+
+    private static Commandline buildPythonCmd( File workingDir, String[] cmdAndArgs )
+        throws ScmException
+    {
+        Commandline cmd = new Commandline();
+        cmd.setExecutable( PYTHON_EXEC );
+        cmd.setWorkingDirectory( workingDir.getAbsolutePath() );
+        cmd.addArguments( cmdAndArgs );
+
+        if ( !workingDir.exists() )
+        {
+            boolean success = workingDir.mkdirs();
+            if ( !success )
+            {
+                String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir;
+                throw new ScmException( msg );
+            }
+        }
+        return cmd;
+    }
+
+    /**
+     * Get version of the executable.
+     * Version is resolved to the last match of a defined regexp in the command output.
+     */
+    private static class VersionConsumer
+        extends HgConsumer
+    {
+
+        private static Pattern VERSION_PATTERN = Pattern.compile( "[\\d]+.?[\\d]*" );
+
+        private final String version_tag;
+
+        private String versionStr = "NA";
+
+        private float version = -1;
+
+        VersionConsumer( String version_tag )
+        {
+            super( new DefaultLog() );
+            this.version_tag = version_tag;
+        }
+
+        public void doConsume( ScmFileStatus status, String line )
+        {
+            if ( line.startsWith( version_tag ) )
+            {
+                versionStr = line.substring( version_tag.length() );
+            }
+        }
+
+        String getVersion()
+        {
+            return versionStr;
+        }
+
+        boolean isVersionOk( float min )
+        {
+
+            Matcher matcher = VERSION_PATTERN.matcher( versionStr );
+            if ( matcher.find() )
+            {
+                String subStr = versionStr.substring( matcher.start(), matcher.end() );
+                try
+                {
+                    version = Float.valueOf( subStr ).floatValue();
+                }
+                catch ( NumberFormatException e )
+                {
+                    //Print diagnostics and continue (this is not a major error)
+                    getLogger().error( "Regexp for version did not result in a number: " + subStr, e );
+                }
+            }
+
+            return min <= version;
+        }
+    }
+
+    private static class PythonConsumer
+        extends HgConsumer
+    {
+
+        private String consumed = "";
+
+        PythonConsumer()
+        {
+            super( new DefaultLog() );
+        }
+
+        public void doConsume( ScmFileStatus status, String line )
+        {
+            consumed = line;
+        }
+
+        String getConsumedAndClear()
+        {
+            String tmp = consumed;
+            consumed = "";
+            return tmp;
+        }
+    }
+
+    private String getInstalledStr()
+    {
+        if ( isComplete() )
+        {
+            return "valid and complete.";
+        }
+        return ( isInstalled() ? "incomplete. " : "invalid. " ) + "Consult " + BAZAAR_INSTALL_URL;
+    }
+
+    public String toString( File workingDir )
+    {
+        boolean hgOk = hgVersion.isVersionOk( BAZAAR_REQ );
+        boolean pyOk = pythonVersion.isVersionOk( PYTHON_REQ );
+        return "\n  Your Hg installation seems to be " + getInstalledStr() + "\n    Python version: "
+            + pythonVersion.getVersion() + ( pyOk ? " (OK)" : " (May be INVALID)" ) + "\n    Hg version: "
+            + hgVersion.getVersion() + ( hgOk ? " (OK)" : " (May be INVALID)" ) + "\n    Paramiko installed: "
+            + paramiko + " (For remote access eg. sftp) " + "\n    cCrypt installed: " + cCrypt
+            + " (For remote access eg. sftp) " + "\n    cElementTree installed: " + cElementTree + " (Not mandatory) "
+            + "\n";
+    }
+}
\ No newline at end of file

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgConfig.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,227 @@
+package org.apache.maven.scm.provider.hg;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.CommandParameters;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.command.diff.DiffScmResult;
+import org.apache.maven.scm.command.remove.RemoveScmResult;
+import org.apache.maven.scm.command.status.StatusScmResult;
+import org.apache.maven.scm.command.update.UpdateScmResult;
+import org.apache.maven.scm.provider.AbstractScmProvider;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+import org.apache.maven.scm.provider.hg.command.add.HgAddCommand;
+import org.apache.maven.scm.provider.hg.command.changelog.HgChangeLogCommand;
+import org.apache.maven.scm.provider.hg.command.checkin.HgCheckInCommand;
+import org.apache.maven.scm.provider.hg.command.checkout.HgCheckOutCommand;
+import org.apache.maven.scm.provider.hg.command.diff.HgDiffCommand;
+import org.apache.maven.scm.provider.hg.command.remove.HgRemoveCommand;
+import org.apache.maven.scm.provider.hg.command.status.HgStatusCommand;
+import org.apache.maven.scm.provider.hg.command.update.HgUpdateCommand;
+import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.apache.maven.scm.repository.UnknownRepositoryStructure;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Mercurial (HG) is a decentralized revision control system.
+ * <a href="http://www.selenic.com/mercurial">http://www.selenic.com/mercurial</a> 
+ *
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ * @plexus.component role="org.apache.maven.scm.provider.ScmProvider"
+ *                   role-hint="hg"
+ */
+public class HgScmProvider
+    extends AbstractScmProvider
+{
+    public String getScmSpecificFilename()
+    {
+        return ".hg";
+    }
+
+    public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter )
+        throws ScmRepositoryException
+    {
+        return new HgScmProviderRepository( scmSpecificUrl );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#makeProviderScmRepository(java.io.File)
+     */
+    public ScmProviderRepository makeProviderScmRepository( File path )
+        throws ScmRepositoryException, UnknownRepositoryStructure
+    {
+        if ( path == null || !path.isDirectory() )
+        {
+            throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a valid directory." );
+        }
+
+        File hgDir = new File( path, ".hg" );
+
+        if ( !hgDir.exists() )
+        {
+            throw new ScmRepositoryException( path.getAbsolutePath() + " isn't a hg directory." );
+        }
+
+        return makeProviderScmRepository( path.getAbsolutePath(), ':' );
+    }
+
+    public List validateScmUrl( String scmSpecificUrl, char delimiter )
+    {
+
+        List errorMessages = new ArrayList();
+
+        String[] checkCmd = new String[] { HgCommand.CHECK, scmSpecificUrl };
+        ScmResult result;
+        try
+        {
+            File tmpDir = new File( System.getProperty( "java.io.tmpdir" ) );
+            result = HgUtils.execute( tmpDir, checkCmd );
+            if ( !result.isSuccess() )
+            {
+                errorMessages.add( result.getCommandOutput() );
+                errorMessages.add( result.getProviderMessage() );
+            }
+        }
+        catch ( ScmException e )
+        {
+            errorMessages.add( e.getMessage() );
+        }
+
+        return errorMessages;
+    }
+
+    public String getScmType()
+    {
+        return "hg";
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#add(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public AddScmResult add( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgAddCommand command = new HgAddCommand();
+
+        command.setLogger( getLogger() );
+
+        return (AddScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#changelog(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public ChangeLogScmResult changelog( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgChangeLogCommand command = new HgChangeLogCommand();
+
+        command.setLogger( getLogger() );
+
+        return (ChangeLogScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#checkin(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public CheckInScmResult checkin( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgCheckInCommand command = new HgCheckInCommand();
+
+        command.setLogger( getLogger() );
+
+        return (CheckInScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#checkout(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public CheckOutScmResult checkout( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgCheckOutCommand command = new HgCheckOutCommand();
+
+        command.setLogger( getLogger() );
+
+        return (CheckOutScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#diff(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public DiffScmResult diff( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgDiffCommand command = new HgDiffCommand();
+
+        command.setLogger( getLogger() );
+
+        return (DiffScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#remove(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public RemoveScmResult remove( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgRemoveCommand command = new HgRemoveCommand();
+
+        command.setLogger( getLogger() );
+
+        return (RemoveScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#status(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public StatusScmResult status( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgStatusCommand command = new HgStatusCommand();
+
+        command.setLogger( getLogger() );
+
+        return (StatusScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+
+    /**
+     * @see org.apache.maven.scm.provider.AbstractScmProvider#update(org.apache.maven.scm.repository.ScmRepository, org.apache.maven.scm.ScmFileSet, org.apache.maven.scm.CommandParameters)
+     */
+    public UpdateScmResult update( ScmRepository repository, ScmFileSet fileSet, CommandParameters parameters )
+        throws ScmException
+    {
+        HgUpdateCommand command = new HgUpdateCommand();
+
+        command.setLogger( getLogger() );
+
+        return (UpdateScmResult) command.execute( repository.getProviderRepository(), fileSet, parameters );
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgScmProvider.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,221 @@
+package org.apache.maven.scm.provider.hg;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmFileStatus;
+import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.log.DefaultLog;
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+import org.codehaus.plexus.util.cli.CommandLineException;
+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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Common code for executing hg commands.
+ *
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgUtils
+{
+    /**
+     * Map between command and its valid exit codes
+     */
+    private static final Map exitCodeMap = new HashMap();
+
+    /**
+     * Default exit codes for entries not in exitCodeMap
+     */
+    private static final List defaultExitCodes = new ArrayList();
+
+    /** Setup exit codes*/
+    static
+    {
+        defaultExitCodes.add( new Integer( 0 ) );
+
+        //Diff is different
+        List diffExitCodes = new ArrayList();
+        diffExitCodes.add( new Integer( 0 ) ); //No difference
+        diffExitCodes.add( new Integer( 1 ) ); //Conflicts in merge-like or changes in diff-like
+        diffExitCodes.add( new Integer( 2 ) ); //Unrepresentable diff changes
+        exitCodeMap.put( HgCommand.DIFF_CMD, diffExitCodes );
+    }
+
+    public static ScmResult execute( HgConsumer consumer, ScmLogger logger, File workingDir, String[] cmdAndArgs )
+        throws ScmException
+    {
+        try
+        {
+            //Build commandline
+            Commandline cmd = buildCmd( workingDir, cmdAndArgs );
+            logger.info( "EXECUTING: " + cmd );
+
+            //Execute command
+            int exitCode = executeCmd( consumer, cmd );
+
+            //Return result
+            List exitCodes = defaultExitCodes;
+            if ( exitCodeMap.containsKey( cmdAndArgs[0] ) )
+            {
+                exitCodes = (List) exitCodeMap.get( cmdAndArgs[0] );
+            }
+            boolean success = exitCodes.contains( new Integer( exitCode ) );
+
+            //On failure (and not due to exceptions) - run diagnostics
+            String providerMsg = "Execution of hg command succeded";
+            if ( !success )
+            {
+                HgConfig config = new HgConfig( workingDir );
+                providerMsg = "\nEXECUTION FAILED" + "\n  Execution of cmd : " + cmdAndArgs[0]
+                    + " failed with exit code: " + exitCode + "." + "\n  Working directory was: " + "\n    "
+                    + workingDir.getAbsolutePath() + config.toString( workingDir ) + "\n";
+                logger.error( providerMsg );
+            }
+
+            return new ScmResult( cmd.toString(), providerMsg, consumer.getStdErr(), success );
+        }
+        catch ( ScmException se )
+        {
+            String msg = "EXECUTION FAILED" + "\n  Execution failed before invoking the Hg command. Last exception:"
+                + "\n    " + se.getMessage();
+
+            //Add nested cause if any
+            if ( se.getCause() != null )
+            {
+                msg += "\n  Nested exception:" + "\n    " + se.getCause().getMessage();
+            }
+
+            //log and return
+            logger.error( msg );
+            throw se;
+        }
+    }
+
+    static Commandline buildCmd( File workingDir, String[] cmdAndArgs )
+        throws ScmException
+    {
+        Commandline cmd = new Commandline();
+        cmd.setExecutable( HgCommand.EXEC );
+        cmd.setWorkingDirectory( workingDir.getAbsolutePath() );
+        cmd.addArguments( cmdAndArgs );
+
+        if ( !workingDir.exists() )
+        {
+            boolean success = workingDir.mkdirs();
+            if ( !success )
+            {
+                String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir;
+                throw new ScmException( msg );
+            }
+        }
+        return cmd;
+    }
+
+    static int executeCmd( HgConsumer consumer, Commandline cmd )
+        throws ScmException
+    {
+        final int exitCode;
+        try
+        {
+            exitCode = CommandLineUtils.executeCommandLine( cmd, consumer, consumer );
+        }
+        catch ( CommandLineException ex )
+        {
+            throw new ScmException( "Command could not be executed: " + cmd, ex );
+        }
+        return exitCode;
+    }
+
+    public static ScmResult execute( File workingDir, String[] cmdAndArgs )
+        throws ScmException
+    {
+        ScmLogger logger = new DefaultLog();
+        return execute( new HgConsumer( logger ), logger, workingDir, cmdAndArgs );
+    }
+
+    public static String[] expandCommandLine( String[] cmdAndArgs, ScmFileSet additionalFiles )
+    {
+        File[] files = additionalFiles.getFiles();
+        String[] cmd = new String[files.length + cmdAndArgs.length];
+
+        // Copy command into array
+        System.arraycopy( cmdAndArgs, 0, cmd, 0, cmdAndArgs.length );
+
+        // Add files as additional parameter into the array
+        for ( int i = 0; i < files.length; i++ )
+        {
+            String file = files[i].getPath().replace( '\\', File.separatorChar );
+            cmd[i + cmdAndArgs.length] = file;
+        }
+
+        return cmd;
+    }
+
+    public static int getCurrentRevisionNumber( ScmLogger logger, File workingDir )
+        throws ScmException
+    {
+
+        String[] revCmd = new String[] { HgCommand.REVNO_CMD };
+        HgRevNoConsumer consumer = new HgRevNoConsumer( logger );
+        HgUtils.execute( consumer, logger, workingDir, revCmd );
+
+        return consumer.getCurrentRevisionNumber();
+    }
+
+    /**
+     * Get current (working) revision.
+     * <p/>
+     * Resolve revision to the last integer found in the command output.
+     */
+    private static class HgRevNoConsumer
+        extends HgConsumer
+    {
+
+        private int revNo;
+
+        HgRevNoConsumer( ScmLogger logger )
+        {
+            super( logger );
+        }
+
+        public void doConsume( ScmFileStatus status, String line )
+        {
+            try
+            {
+                revNo = Integer.valueOf( line ).intValue();
+            }
+            catch ( NumberFormatException e )
+            {
+                // ignore
+            }
+        }
+
+        int getCurrentRevisionNumber()
+        {
+            return revNo;
+        }
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/HgUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,111 @@
+package org.apache.maven.scm.provider.hg.command;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.command.Command;
+
+/**
+ * Available/Used hg commands.
+ * <p/>
+ * These commands do not necessarily correspond to the SCM API.
+ * Eg. "check in" is translated to be "commit" and "push".
+ *
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public interface HgCommand
+    extends Command
+{
+    /**
+     * Executable for Hg
+     */
+    public static final String EXEC = "hg";
+
+    /**
+     * Use to create an empty branch or before importing an existing project
+     */
+    public static final String INIT_CMD = "init";
+
+    /**
+     * Default recursive. Common option: --dry-run and --no-recursive
+     */
+    public static final String ADD_CMD = "add";
+
+    /**
+     * Reports the following states: added, removed, modified, unchanged, unknown
+     */
+    public static final String STATUS_CMD = "status";
+
+    /**
+     * Make a file unversioned
+     */
+    public static final String REMOVE_CMD = "remove";
+
+    /**
+     * Create a new copy of a branch. Alias get or clone
+     */
+    public static final String BRANCH_CMD = "clone";
+
+    /**
+     * Commit changes into a new revision
+     */
+    public static final String COMMIT_CMD = "commit";
+
+    /**
+     * Pull any changes from another branch into the current one
+     */
+    public static final String PULL_CMD = "pull";
+
+    /**
+     * Show log of this branch Common option: --revision
+     */
+    public static final String LOG_CMD = "log";
+
+    /**
+     * Show differences in workingtree. Common option: --revision
+     */
+    public static final String DIFF_CMD = "diff";
+
+    /**
+     * Push this branch into another branch
+     */
+    public static final String PUSH_CMD = "push";
+
+    /**
+     * Show current revision number
+     */
+    public static final String REVNO_CMD = "id";
+
+    /**
+     * Show inventory of the current working copy or a revision
+     */
+    public static final String INVENTORY_CMD = "locate";
+
+    /**
+     * no recurse option does not exist in mercurial
+     */
+    public static final String NO_RECURSE_OPTION = ""; 
+
+    public static final String MESSAGE_OPTION = "--message";
+
+    public static final String REVISION_OPTION = "-r";
+
+    public static final String VERBOSE_OPTION = "--verbose";
+
+    public static final String VERSION = "version";
+
+    public static final String CHECK = "check";
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,181 @@
+package org.apache.maven.scm.provider.hg.command;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmFileStatus;
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.util.AbstractConsumer;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Base consumer to do common parsing for all hg commands.
+ * <p/>
+ * More specific: log line each line if debug is enabled, get file status
+ * and detect warnings from hg
+ *
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgConsumer
+    extends AbstractConsumer
+{
+
+    /**
+     * A list of known keywords from hg
+     */
+    private static final Map identifiers = new HashMap();
+
+    /**
+     * A list of known message prefixes from hg
+     */
+    private static final Map messages = new HashMap();
+
+    /**
+     * Number of lines to keep from Std.Err
+     * This size is set to ensure that we capture enough info
+     * but still keeps a low memory footprint.
+     */
+    private static final int MAX_STDERR_SIZE = 10;
+
+    /**
+     * A list of the MAX_STDERR_SIZE last errors or warnings.
+     */
+    private final List stderr = new ArrayList();
+
+    static
+    {
+        /** Statuses from hg add
+         */
+        identifiers.put( "adding", ScmFileStatus.ADDED );
+        identifiers.put( "unknown", ScmFileStatus.UNKNOWN );
+        identifiers.put( "modified", ScmFileStatus.MODIFIED );
+        identifiers.put( "removed", ScmFileStatus.DELETED );
+        identifiers.put( "renamed", ScmFileStatus.MODIFIED );
+
+        /** Statuses from hg status;
+         *  TODO "! deleted but still tracked"
+         *  d 
+         */
+        identifiers.put( "A", ScmFileStatus.ADDED);
+        identifiers.put( "?", ScmFileStatus.UNKNOWN);
+        identifiers.put( "M", ScmFileStatus.MODIFIED);
+        identifiers.put( "R", ScmFileStatus.DELETED);
+        identifiers.put( "I", ScmFileStatus.UNKNOWN); // not precisely the same, but i think semantics work? - rwd
+
+        messages.put( "hg: WARNING:", "WARNING" );
+        messages.put( "hg: ERROR:", "ERROR" );
+        messages.put( "'hg' ", "ERROR" ); // hg isn't found in windows path
+    }
+
+    public HgConsumer( ScmLogger logger )
+    {
+        super( logger );
+    }
+
+    public void doConsume( ScmFileStatus status, String trimmedLine )
+    {
+        //override this
+    }
+
+    public void consumeLine( String line )
+    {
+        getLogger().debug( line );
+        String trimmedLine = line.trim();
+
+        String statusStr = processInputForKnownIdentifiers( trimmedLine );
+
+        //If its not a status report - then maybe its a message?
+        if ( statusStr == null )
+        {
+            boolean isMessage = processInputForKnownMessages( trimmedLine );
+            //If it is then its already processed and we can ignore futher processing
+            if ( isMessage )
+            {
+                return;
+            }
+        }
+        else
+        {
+            //Strip away identifier
+            trimmedLine = trimmedLine.substring( statusStr.length() );
+            trimmedLine = trimmedLine.trim(); //one or more spaces
+        }
+
+        ScmFileStatus status = statusStr != null ? ( (ScmFileStatus) identifiers.get( statusStr.intern() ) ) : null;
+        doConsume( status, trimmedLine );
+    }
+
+    /**
+     * Warnings and errors is usually printed out in Std.Err, thus for derived consumers
+     * operating on Std.Out this would typically return an empty string.
+     *
+     * @return Return the last lines interpreted as an warning or an error
+     */
+    public String getStdErr()
+    {
+        String str = "";
+        for ( Iterator it = stderr.iterator(); it.hasNext(); )
+        {
+            str += it.next();
+        }
+        return str;
+    }
+
+    private static String processInputForKnownIdentifiers( String line )
+    {
+        for ( Iterator it = identifiers.keySet().iterator(); it.hasNext(); )
+        {
+            String id = (String) it.next();
+            if ( line.startsWith( id ) )
+            {
+                return id;
+            }
+        }
+        return null;
+    }
+
+    private boolean processInputForKnownMessages( String line )
+    {
+        for ( Iterator it = messages.keySet().iterator(); it.hasNext(); )
+        {
+            String prefix = (String) it.next();
+            if ( line.startsWith( prefix ) )
+            {
+                stderr.add( line ); //Add line
+                if ( stderr.size() > MAX_STDERR_SIZE )
+                {
+                    stderr.remove( 0 ); //Rotate list
+                }
+                String message = line.substring( prefix.length() );
+                if ( messages.get( prefix ).equals( "WARNING" ) )
+                {
+                    getLogger().warn( message );
+                }
+                else
+                {
+                    getLogger().error( message );
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/HgConsumer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,68 @@
+package org.apache.maven.scm.provider.hg.command.add;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.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.hg.HgUtils;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+
+import java.io.File;
+import java.util.Iterator;
+
+/**
+ * Add no recursive.
+ *
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgAddCommand
+    extends AbstractAddCommand
+    implements HgCommand
+{
+    protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
+                                           boolean binary )
+        throws ScmException
+    {
+        //String[] addCmd = new String[] { ADD_CMD, NO_RECURSE_OPTION };
+        String[] addCmd = new String[] { ADD_CMD, VERBOSE_OPTION };
+        addCmd = HgUtils.expandCommandLine( addCmd, fileSet );
+
+        File workingDir = fileSet.getBasedir();
+        HgAddConsumer consumer = new HgAddConsumer( getLogger(), workingDir );
+        ScmResult result = HgUtils.execute( consumer, getLogger(), workingDir, addCmd );
+
+        AddScmResult addScmResult = new AddScmResult( consumer.getAddedFiles(), result );
+
+        // add in bogus 'added' results for empty directories.  only need to do this because the maven scm unit test
+        // seems to think that this is the way we should behave.  it's pretty hacky. -rwd
+        for ( Iterator iterator = fileSet.getFileList().iterator(); iterator.hasNext(); )
+        {
+            File workingFile = (File) iterator.next();
+            File file = new File( workingDir, workingFile.getPath() );
+            if ( file.isDirectory() && file.listFiles().length == 0 )
+            {
+                addScmResult.getAddedFiles().add( workingFile );
+            }
+        }
+
+        return addScmResult;
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,67 @@
+package org.apache.maven.scm.provider.hg.command.add;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmLogger;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgAddConsumer
+    extends HgConsumer
+{
+    private final File workingDir;
+
+    private final List addedFiles = new ArrayList();
+
+    public HgAddConsumer( ScmLogger logger, File workingDir )
+    {
+        super( logger );
+        this.workingDir = workingDir;
+    }
+
+    public void doConsume( ScmFileStatus status, String trimmedLine )
+    {
+        if ( status != null && status == ScmFileStatus.ADDED )
+        {
+            //Only include real files (not directories)
+            File tmpFile = new File( workingDir, trimmedLine );
+            if ( !tmpFile.exists() )
+            {
+                getLogger().warn( "Not a file: " + tmpFile + ". Ignored" );
+            }
+            else
+            {
+                ScmFile scmFile = new ScmFile( trimmedLine, ScmFileStatus.ADDED );
+                getLogger().info( scmFile.toString() );
+                addedFiles.add( scmFile );
+            }
+        }
+    }
+
+    public List getAddedFiles()
+    {
+        return addedFiles;
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/add/HgAddConsumer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,71 @@
+package org.apache.maven.scm.provider.hg.command.changelog;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ChangeSet;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmResult;
+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.hg.HgUtils;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgChangeLogCommand
+    extends AbstractChangeLogCommand
+    implements HgCommand
+{
+    protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet,
+                                                          Date startDate, Date endDate, String branch,
+                                                          String datePattern )
+        throws ScmException
+    {
+        String[] cmd = new String[]{LOG_CMD, VERBOSE_OPTION};
+        HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern );
+        ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd );
+
+        List logEntries = consumer.getModifications();
+        List inRangeAndValid = new ArrayList();
+        startDate = startDate == null ? new Date( 0 ) : startDate; //From 1. Jan 1970
+        endDate = endDate == null ? new Date() : endDate; //Upto now
+
+        for ( Iterator it = logEntries.iterator(); it.hasNext(); )
+        {
+            ChangeSet change = (ChangeSet) it.next();
+            if ( change.getFiles().size() > 0 )
+            {
+                if ( !change.getDate().before( startDate ) && !change.getDate().after( endDate ) )
+                {
+                    inRangeAndValid.add( change );
+                }
+            }
+        }
+
+        ChangeLogSet changeLogSet = new ChangeLogSet( inRangeAndValid, startDate, endDate );
+        return new ChangeLogScmResult( changeLogSet, result );
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,208 @@
+package org.apache.maven.scm.provider.hg.command.changelog;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ChangeSet;
+import org.apache.maven.scm.ScmFileStatus;
+import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgChangeLogConsumer
+    extends HgConsumer
+{
+
+    private static final String TIME_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z";
+
+    private static final String REVNO_TAG = "changeset: ";
+
+    private static final String REPO_TAG   = "tag:         ";
+
+    private static final String AUTHOR_TAG = "user: ";
+
+    private static final String TIME_STAMP_TOKEN = "date: ";
+
+    private static final String MESSAGE_TOKEN = "description:";
+
+    private static final String MERGED_TOKEN = "merged: ";
+
+    private static final String FILES_TOKEN = "files: ";
+
+    private String prevLine = "";
+    private String prevPrevLine = "";
+
+    private ArrayList logEntries = new ArrayList();
+
+    private ChangeSet currentChange;
+
+    private ChangeSet lastChange;
+
+    private boolean isMergeEntry;
+
+    private String currentRevision;
+
+    private String currentTag;
+
+    private String userDatePattern;
+
+    private boolean spoolingComments;
+
+    private List currentComment = null;
+
+    /**
+     * Null means not parsing message nor files, UNKNOWN means parsing message
+     */
+    private ScmFileStatus currentStatus = null;
+
+    public HgChangeLogConsumer( ScmLogger logger, String userDatePattern )
+    {
+        super( logger );
+
+        this.userDatePattern = userDatePattern;
+    }
+
+    public List getModifications()
+    {
+        return logEntries;
+    }
+
+    public void consumeLine(String line) {
+        // override default behaviour which tries to pick through things for some standard messages.  that
+        // does not apply here
+        doConsume(null, line);
+    }
+
+    public void doConsume( ScmFileStatus status, String line )
+    {
+        String tmpLine = line;
+        // If current status == null then this is a new entry
+        // If the line == "" and previous line was "", then this is also a new entry
+        if ((line.equals("") && (prevLine.equals("") && prevPrevLine.equals(""))) || currentComment == null)
+        {
+            if (currentComment != null) {
+                StringBuffer comment = new StringBuffer();
+                for (int i = 0; i < currentComment.size() - 1; i++) {
+                    comment.append(currentComment.get(i));
+                    if (i + 1 < currentComment.size() - 1)
+                        comment.append('\n');
+                }
+                currentChange.setComment( comment.toString() );
+            }
+
+            spoolingComments = false;
+
+            //If last entry was part a merged entry
+            if ( isMergeEntry && lastChange != null )
+            {
+                String comment = lastChange.getComment();
+                comment += "\n[MAVEN]: Merged from " + currentChange.getAuthor();
+                comment += "\n[MAVEN]:    " + currentChange.getDateFormatted();
+                comment += "\n[MAVEN]:    " + currentChange.getComment();
+                lastChange.setComment( comment );
+            }
+
+            //Init a new changeset
+            currentChange = new ChangeSet();
+            currentChange.setFiles( new ArrayList() );
+            logEntries.add( currentChange );
+
+            //Reset memeber vars
+            currentComment = new ArrayList();
+            currentStatus = null;
+            currentRevision = "";
+            isMergeEntry = false;
+        }
+
+        if (spoolingComments)
+        {
+            currentComment.add( line );
+        }
+        else if ( line.startsWith( MESSAGE_TOKEN ) )
+        {
+            spoolingComments = true;
+        }
+        else if ( line.startsWith( MERGED_TOKEN ) )
+        {
+            //This is part of lastChange and is not a separate log entry
+            isMergeEntry = true;
+            logEntries.remove( currentChange );
+            if ( logEntries.size() > 0 )
+            {
+                lastChange = (ChangeSet) logEntries.get( logEntries.size() - 1 );
+            }
+            else
+            {
+                getLogger().warn( "First entry was unexpectedly a merged entry" );
+                lastChange = null;
+            }
+        }
+        else if ( line.startsWith( REVNO_TAG ) )
+        {
+            tmpLine = line.substring( REVNO_TAG.length() );
+            tmpLine = tmpLine.trim();
+            currentRevision = tmpLine;
+        }
+        else if ( line.startsWith( REPO_TAG ) )
+        {
+            // TODO: Get the tag name of the file?
+            currentTag = "tagged";
+        }
+        else if ( line.startsWith( AUTHOR_TAG ) )
+        {
+            tmpLine = line.substring( AUTHOR_TAG.length() );
+            tmpLine = tmpLine.trim();
+            currentChange.setAuthor( tmpLine );
+        }
+        else if ( line.startsWith( TIME_STAMP_TOKEN ) )
+        {
+            // TODO: FIX Date Parsing to match Mercurial or fix with template
+            tmpLine = line.substring( TIME_STAMP_TOKEN.length() ).trim();
+            Date date = parseDate( tmpLine, userDatePattern, TIME_PATTERN );
+            currentChange.setDate( date );
+        }
+        else if (line.startsWith(FILES_TOKEN))
+        {
+            tmpLine = line.substring( FILES_TOKEN.length() ).trim();
+            String[] files = tmpLine.split(" ");
+            for (int i = 0; i < files.length; i++) {
+                String file = files[i];
+                ChangeFile changeFile = new ChangeFile( file, currentRevision );
+                currentChange.addFile( changeFile );
+            }
+        }
+        else
+        {
+            getLogger().warn( "Could not figure out: " + line );
+        }
+
+        if ( status != null )
+        {
+            currentStatus = status;
+        }
+
+        // record previous line
+        prevLine = line;
+        prevPrevLine = prevLine;
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/changelog/HgChangeLogConsumer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,102 @@
+package org.apache.maven.scm.provider.hg.command.checkin;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.checkin.AbstractCheckInCommand;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.command.status.StatusScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.hg.HgUtils;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+import org.apache.maven.scm.provider.hg.command.status.HgStatusCommand;
+import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgCheckInCommand
+    extends AbstractCheckInCommand
+{
+
+    protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, ScmFileSet fileSet, String message,
+                                                     String tag )
+        throws ScmException
+    {
+
+        if ( !StringUtils.isEmpty( tag ) )
+        {
+            throw new ScmException( "This provider can't handle tags." );
+        }
+
+        // Get files that will be committed (if not specified in fileSet)
+        List commitedFiles = new ArrayList();
+        File[] files = fileSet.getFiles();
+        if ( files.length == 0 )
+        { //Either commit all changes
+            HgStatusCommand statusCmd = new HgStatusCommand();
+            statusCmd.setLogger( getLogger() );
+            StatusScmResult status = statusCmd.executeStatusCommand( repo, fileSet );
+            List statusFiles = status.getChangedFiles();
+            for ( Iterator it = statusFiles.iterator(); it.hasNext(); )
+            {
+                ScmFile file = (ScmFile) it.next();
+                if ( file.getStatus() == ScmFileStatus.ADDED || file.getStatus() == ScmFileStatus.DELETED
+                    || file.getStatus() == ScmFileStatus.MODIFIED )
+                {
+                    commitedFiles.add( new ScmFile( file.getPath(), ScmFileStatus.CHECKED_IN ) );
+                }
+            }
+
+        }
+        else
+        { //Or commit spesific files
+            for ( int i = 0; i < files.length; i++ )
+            {
+                commitedFiles.add( new ScmFile( files[i].getPath(), ScmFileStatus.CHECKED_IN ) );
+            }
+        }
+
+        // Commit to local branch
+        String[] commitCmd = new String[] { HgCommand.COMMIT_CMD, HgCommand.MESSAGE_OPTION, message };
+        commitCmd = HgUtils.expandCommandLine( commitCmd, fileSet );
+        ScmResult result = HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(),
+                                                commitCmd );
+
+        // Push to parent branch if any
+        HgScmProviderRepository repository = (HgScmProviderRepository) repo;
+        if ( !repository.getURI().equals( fileSet.getBasedir().getAbsolutePath() ) )
+        {
+            String[] push_cmd = new String[] { HgCommand.PUSH_CMD, repository.getURI() };
+            result = HgUtils.execute( new HgConsumer( getLogger() ), getLogger(), fileSet.getBasedir(),
+                                          push_cmd );
+        }
+
+        return new CheckInScmResult( commitedFiles, result );
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkin/HgCheckInCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,78 @@
+package org.apache.maven.scm.provider.hg.command.checkout;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmResult;
+import org.apache.maven.scm.command.checkout.AbstractCheckOutCommand;
+import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.hg.HgUtils;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+import org.apache.maven.scm.provider.hg.repository.HgScmProviderRepository;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgCheckOutCommand
+    extends AbstractCheckOutCommand
+    implements HgCommand
+{
+
+    protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag )
+        throws ScmException
+    {
+
+        if ( !StringUtils.isEmpty( tag ) )
+        {
+            throw new ScmException( "This provider can't handle tags." );
+        }
+
+        HgScmProviderRepository repository = (HgScmProviderRepository) repo;
+        String url = repository.getURI();
+
+        File checkoutDir = fileSet.getBasedir();
+        try
+        {
+            getLogger().info( "Removing " + checkoutDir );
+            FileUtils.deleteDirectory( checkoutDir );
+        }
+        catch ( IOException e )
+        {
+            throw new ScmException( "Cannot remove " + checkoutDir );
+        }
+
+        // Do the actual checkout
+        String[] checkout_cmd = new String[] { BRANCH_CMD, url, checkoutDir.getAbsolutePath() };
+        HgConsumer checkout_consumer = new HgConsumer( getLogger() );
+        HgUtils.execute( checkout_consumer, getLogger(), checkoutDir.getParentFile(), checkout_cmd );
+
+        // Do inventory to find list of checkedout files
+        String[] inventory_cmd = new String[] { INVENTORY_CMD };
+        HgCheckOutConsumer consumer = new HgCheckOutConsumer( getLogger(), checkoutDir );
+        ScmResult result = HgUtils.execute( consumer, getLogger(), checkoutDir, inventory_cmd );
+
+        return new CheckOutScmResult( consumer.getCheckedOutFiles(), result );
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,58 @@
+package org.apache.maven.scm.provider.hg.command.checkout;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmLogger;
+import org.apache.maven.scm.provider.hg.command.HgConsumer;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgCheckOutConsumer
+    extends HgConsumer
+{
+
+    private final File workingDirectory;
+
+    private final ArrayList checkedOut = new ArrayList();
+
+    public HgCheckOutConsumer( ScmLogger logger, File workingDirectory )
+    {
+        super( logger );
+        this.workingDirectory = workingDirectory;
+    }
+
+    public void doConsume( ScmFileStatus status, String line )
+    {
+        File file = new File( workingDirectory, line );
+        if ( file.isFile() )
+        {
+            checkedOut.add( new ScmFile( line, ScmFileStatus.CHECKED_OUT ) );
+        }
+    }
+
+    List getCheckedOutFiles()
+    {
+        return checkedOut;
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/checkout/HgCheckOutConsumer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java?view=auto&rev=468577
==============================================================================
--- maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java (added)
+++ maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java Fri Oct 27 15:54:48 2006
@@ -0,0 +1,64 @@
+package org.apache.maven.scm.provider.hg.command.diff;
+
+/*
+ * Copyright 2001-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ScmResult;
+import org.apache.maven.scm.command.diff.AbstractDiffCommand;
+import org.apache.maven.scm.command.diff.DiffScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.hg.HgUtils;
+import org.apache.maven.scm.provider.hg.command.HgCommand;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
+ */
+public class HgDiffCommand
+    extends AbstractDiffCommand
+    implements HgCommand
+{
+
+    protected DiffScmResult executeDiffCommand( ScmProviderRepository repo, ScmFileSet fileSet, String startRevision,
+                                               String endRevision )
+        throws ScmException
+    {
+
+        String[] diffCmd;
+        if ( !StringUtils.isEmpty( startRevision ) )
+        {
+            String revArg = startRevision;
+            if ( !StringUtils.isEmpty( endRevision ) )
+            {
+                revArg += ".." + endRevision;
+            }
+            diffCmd = new String[] { DIFF_CMD, REVISION_OPTION, revArg };
+        }
+        else
+        {
+            diffCmd = new String[] { DIFF_CMD };
+        }
+
+        diffCmd = HgUtils.expandCommandLine( diffCmd, fileSet );
+        HgDiffConsumer consumer = new HgDiffConsumer( getLogger(), fileSet.getBasedir() );
+
+        ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), diffCmd );
+
+        return new DiffScmResult( consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch(), result );
+    }
+}

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/sandbox/maven-scm-provider-hg/src/main/java/org/apache/maven/scm/provider/hg/command/diff/HgDiffCommand.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message