maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r521294 - in /maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src: main/java/org/apache/maven/scm/provider/svn/ main/java/org/apache/maven/scm/provider/svn/repository/ test/java/org/apache/maven/sc...
Date Thu, 22 Mar 2007 14:40:15 GMT
Author: evenisse
Date: Thu Mar 22 07:40:14 2007
New Revision: 521294

URL: http://svn.apache.org/viewvc?view=rev&rev=521294
Log:
[SCM-185] Allow all tunnels defined in subversion configuration

Added:
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java
  (with props)
Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepository.java
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepositoryTest.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java?view=diff&rev=521294&r1=521293&r2=521294
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
Thu Mar 22 07:40:14 2007
@@ -39,9 +39,11 @@
 import org.apache.maven.scm.provider.svn.command.SvnCommand;
 import org.apache.maven.scm.provider.svn.command.info.SvnInfoScmResult;
 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.provider.svn.util.SvnUtil;
 import org.apache.maven.scm.repository.ScmRepository;
 import org.apache.maven.scm.repository.ScmRepositoryException;
 import org.apache.maven.scm.repository.UnknownRepositoryStructure;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -184,13 +186,36 @@
                 return result;
             }
         }
-        else if ( url.startsWith( "svn+ssh" ) )
+        // Support of tunnels: svn+xxx with xxx defined in subversion conf file
+        else if ( url.startsWith( "svn+" ) )
         {
-            if ( !url.startsWith( "svn+ssh://" ) )
+            if ( url.indexOf( "://" ) < 0 )
             {
-                result.messages.add( "A svn 'svn+ssh' url must be on the form 'svn+ssh://'."
);
+                result.messages.add( "A svn 'svn+xxx' url must be on the form 'svn+xxx://'."
);
 
                 return result;
+            }
+            else
+            {
+                String tunnel = url.substring( "svn+".length(), url.indexOf( "://" ) );
+
+                //ssh is always an allowed tunnel
+                if ( !"ssh".equals( tunnel ) )
+                {
+                    SvnConfigFileReader reader = new SvnConfigFileReader();
+                    if ( SvnUtil.getSettings().getConfigDirectory() != null )
+                    {
+                        reader.setConfigDirectory( new File( SvnUtil.getSettings().getConfigDirectory()
) );
+                    }
+
+                    if ( StringUtils.isEmpty( reader.getProperty( "tunnels", tunnel ) ) )
+                    {
+                        result.messages.add(
+                            "The tunnel '" + tunnel + "' isn't defined in your subversion
configuration file." );
+
+                        return result;
+                    }
+                }
             }
         }
         else if ( url.startsWith( "svn" ) )

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java?view=auto&rev=521294
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java
Thu Mar 22 07:40:14 2007
@@ -0,0 +1,158 @@
+package org.apache.maven.scm.provider.svn;
+
+/*
+ * 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.codehaus.plexus.util.StringUtils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class SvnConfigFileReader
+{
+    private File configDirectory;
+
+    public File getConfigDirectory()
+    {
+        if ( configDirectory == null )
+        {
+            if ( System.getProperty( "os.name" ).toLowerCase().indexOf( "windows" ) >=
0 )
+            {
+                configDirectory = new File( System.getProperty( "user.home" ), "Application
Data/Subversion" );
+            }
+            else
+            {
+                configDirectory = new File( System.getProperty( "user.home" ), ".subversion"
);
+            }
+        }
+
+        return configDirectory;
+    }
+
+    public void setConfigDirectory( File configDirectory )
+    {
+        this.configDirectory = configDirectory;
+    }
+
+    public String getProperty( String group, String propertyName )
+    {
+        List lines = getConfLines();
+
+        boolean inGroup = false;
+        for ( Iterator i = lines.iterator(); i.hasNext(); )
+        {
+            String line = ( (String) i.next() ).trim();
+
+            if ( !inGroup )
+            {
+                if ( ( "[" + group + "]" ).equals( line ) )
+                {
+                    inGroup = true;
+                }
+            }
+            else
+            {
+                if ( line.startsWith( "[" ) && line.endsWith( "]" ) )
+                {
+                    //a new group start
+                    return null;
+                }
+
+                if ( line.startsWith( "#" ) )
+                {
+                    continue;
+                }
+                if ( line.indexOf( '=' ) < 0 )
+                {
+                    continue;
+                }
+
+                String property = line.substring( 0, line.indexOf( '=' ) ).trim();
+
+                if ( !property.equals( propertyName ) )
+                {
+                    continue;
+                }
+
+                String value = line.substring( line.indexOf( '=' ) + 1 );
+                return value.trim();
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Load the svn config file
+     *
+     * @return the list of all lines
+     */
+    private List getConfLines()
+    {
+        List lines = new ArrayList();
+
+        BufferedReader reader = null;
+
+        try
+        {
+            if ( getConfigDirectory().exists() )
+            {
+                reader = new BufferedReader( new FileReader( new File( getConfigDirectory(),
"config" ) ) );
+                String line;
+                while ( ( line = reader.readLine() ) != null )
+                {
+                    if ( !line.startsWith( "#" ) && StringUtils.isNotEmpty( line
) )
+                    {
+                        lines.add( line );
+                    }
+                }
+            }
+        }
+        catch ( IOException e )
+        {
+            lines.clear();
+        }
+        finally
+        {
+            if ( reader != null )
+            {
+                try
+                {
+                    reader.close();
+                }
+                catch ( IOException e )
+                {
+                    //Do nothing
+                }
+                reader = null;
+            }
+        }
+
+        return lines;
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/SvnConfigFileReader.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepository.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepository.java?view=diff&rev=521294&r1=521293&r2=521294
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepository.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepository.java
Thu Mar 22 07:40:14 2007
@@ -143,9 +143,9 @@
         {
             setProtocol( "http://" );
         }
-        else if ( url.startsWith( "svn+ssh" ) )
+        else if ( url.startsWith( "svn+" ) )
         {
-            setProtocol( "svn+ssh://" );
+            setProtocol( url.substring( 0, url.indexOf( "://" ) + 3 ) );
         }
         else if ( url.startsWith( "svn" ) )
         {
@@ -161,7 +161,7 @@
 
         int indexAt = urlPath.indexOf( "@" );
 
-        if ( indexAt > 0 && !"svn+ssh://".equals( getProtocol() ) )
+        if ( indexAt > 0 && !getProtocol().startsWith( "svn+" ) )
         {
             setUser( urlPath.substring( 0, indexAt ) );
 

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepositoryTest.java?view=diff&rev=521294&r1=521293&r2=521294
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepositoryTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/repository/SvnScmProviderRepositoryTest.java
Thu Mar 22 07:40:14 2007
@@ -91,12 +91,28 @@
                  "subversion.tigris.org" );
     }
 
+    /* This test require a specific subversion config file
+    public void testLegalSvnPlusXxxURL()
+        throws Exception
+    {
+        testUrl( "scm:svn:svn+something://subversion.tigris.org", "svn+something://subversion.tigris.org",
null,
+                 "subversion.tigris.org" );
+    }*/
+
     public void testLegalSvnPlusSshPlusUsernameURL()
         throws Exception
     {
         testUrl( "scm:svn:svn+ssh://username@subversion.tigris.org", "svn+ssh://username@subversion.tigris.org",
null,
                  "username@subversion.tigris.org" );
     }
+
+    /* This test require a specific subversion config file
+    public void testLegalSvnPlusXxxPlusUsernameURL()
+        throws Exception
+    {
+        testUrl( "scm:svn:svn+something://username@subversion.tigris.org", "svn+something://username@subversion.tigris.org",
null,
+                 "username@subversion.tigris.org" );
+    }*/
 
     public void testLegalSvnPortUrl()
         throws Exception



Mime
View raw message