Changeset 56

Show
Ignore:
Timestamp:
07/15/04 03:21:13
Author:
DenisG
Message:

[SubversionSharp] Start revamping the test program to mimic svn cmd-line client

- implement some trickery to use Mono.GetOptions? with sub-commands
- implement checkout but not the notifyfunc

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SubversionSharp/test/src/AssemblyInfo.cs

    r2 r56  
    88// you compile. 
    99 
    10 [assembly: AssemblyTitle("")] 
    11 [assembly: AssemblyDescription("")] 
     10[assembly: AssemblyTitle("SubversionSharp test client")] 
     11[assembly: AssemblyDescription("Client program used to test SubversionSharp library")] 
    1212[assembly: AssemblyConfiguration("")] 
    13 [assembly: AssemblyCompany("")] 
    14 [assembly: AssemblyProduct("")] 
    15 [assembly: AssemblyCopyright("")] 
     13[assembly: AssemblyCompany("SOFTEC sa")] 
     14[assembly: AssemblyProduct("SvnTest")] 
     15[assembly: AssemblyCopyright( 
     16@"  Copyright 2004 by SOFTEC sa 
     17 
     18  This program is free software; you can redistribute it and/or 
     19  modify it under the terms of the GNU General Public License as 
     20  published by the Free Software Foundation; either version 2 of 
     21  the License, or (at your option) any later version. 
     22 
     23  This program is distributed in the hope that it will be useful, 
     24  but WITHOUT ANY WARRANTY; without even the implied warranty of  
     25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     26  See the GNU General Public License for more details. 
     27 
     28  You should have received a copy of the GNU General Public 
     29  License along with this program; if not, write to the Free Software 
     30  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     31")] 
    1632[assembly: AssemblyTrademark("")] 
    1733[assembly: AssemblyCulture("")] 
     34 
     35[assembly: Mono.UsageComplement("\b\b\b\b\b\b\b\b\b\b<subcommand> [options]")] 
     36[assembly: Mono.About("")] 
     37[assembly: Mono.Author("Denis Gervalle")] 
    1838 
    1939// The assembly version has following format : 
  • trunk/SubversionSharp/test/src/Main.cs

    r50 r56  
    1 // project created on 5/13/2004 at 10:00 PM 
     1//  SvnTest, a client program used to test SubversionSharp library 
     2//  Copyright 2004 by SOFTEC sa 
     3// 
     4//  This program is free software; you can redistribute it and/or 
     5//  modify it under the terms of the GNU General Public License as 
     6//  published by the Free Software Foundation; either version 2 of 
     7// the License, or (at your option) any later version. 
     8// 
     9//  This program is distributed in the hope that it will be useful, 
     10//  but WITHOUT ANY WARRANTY; without even the implied warranty of  
     11//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     12//  See the GNU General Public License for more details. 
     13// 
     14//  You should have received a copy of the GNU General Public 
     15//  License along with this program; if not, write to the Free Software 
     16//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     17// 
     18//  Sources, support options and lastest version of the complete library 
     19//  is available from: 
     20//      http://www.softec.st/SubversionSharp 
     21//      Support@softec.st 
     22// 
     23//  Initial authors :  
     24//      Denis Gervalle 
     25//      Olivier Desaive 
     26// 
    227using System; 
    3 using System.Diagnostics; 
    428using System.Collections; 
    5 using System.Runtime.InteropServices; 
    6 using Softec.AprSharp; 
    7 using Softec.SubversionSharp; 
     29using System.Reflection; 
     30using Mono.GetOptions; 
    831 
    9 class MainClass 
    10 
    11     public static void Main(string[] args) 
     32namespace Softec.SubversionSharp.Test { 
     33 
     34    class Application : Options 
    1235    { 
    13         Debug.Listeners.Add(new TextWriterTraceListener(Console.Out)); 
    14          
    15         SvnClient client = new SvnClient(); 
    16          
    17         client.AddSimpleProvider(); 
    18         client.AddUsernameProvider(); 
    19         client.AddSslServerTrustFileProvider(); 
    20         client.AddSslClientCertFileProvider(); 
    21         client.AddSslClientCertPwFileProvider(); 
    22         client.AddPromptProvider( 
    23                         new SvnAuthProviderObject.SimplePrompt(SimpleAuth), 
    24                         IntPtr.Zero, 2); 
    25         client.AddPromptProvider( 
    26                         new SvnAuthProviderObject.UsernamePrompt(UsernameAuth), 
    27                         IntPtr.Zero, 2); 
    28         client.AddPromptProvider( 
    29                         new SvnAuthProviderObject.SslServerTrustPrompt(SslServerTrustAuth), 
    30                         IntPtr.Zero); 
    31         client.OpenAuth(); 
    32          
    33         client.Context.NotifyFunc = new SvnDelegate(new SvnWcNotify.Func(NotifyCallback)); 
    34         client.Context.LogMsgFunc = new SvnDelegate(new SvnClient.GetCommitLog(GetCommitLogCallback)); 
    35         client.Context.CancelFunc = new SvnDelegate(new Svn.CancelFunc(CancelCallback)); 
    36          
    37         client.Checkout("https://www.softec.st/svn/test",  
    38                         "test", 
    39                         100, true); 
    40         client.Update("test", 
    41                       Svn.Revision.Head, true); 
    42  
    43         client.Pool.Destroy();         
    44     } 
    45      
    46     public static void NotifyCallback(IntPtr baton, SvnPath Path,   
    47                                       SvnWcNotify.Action action, Svn.NodeKind kind, 
    48                                       AprString mimeType, SvnWcNotify.State contentState, 
    49                                       SvnWcNotify.State propState, int revNum) 
    50     { 
    51     } 
    52      
    53     public static SvnError GetCommitLogCallback(out AprString logMessage, out SvnPath tmpFile, 
    54                                                 AprArray commitItems, IntPtr baton, 
    55                                                 AprPool pool) 
    56     { 
    57         if (!commitItems.IsNull) 
    58         { 
    59             foreach (SvnClientCommitItem item in commitItems) 
     36        public class SubCommand { 
     37            public string LongName; 
     38            public string ShortName; 
     39            public string Description; 
     40            public Type Impl; 
     41            public SubCommand(string longName, string shortName, string desc, Type impl) 
    6042            { 
    61                 Console.WriteLine("C1: {1} ({2}) r{3}", 
    62                     item.Path, item.Kind, item.Revision); 
    63                 Console.WriteLine("C2: {1} -> {2}", 
    64                     item.Url, 
    65                     item.CopyFromUrl); 
    66             } 
    67             Console.WriteLine(); 
     43                LongName = longName; 
     44                ShortName = shortName; 
     45                Description = desc; 
     46                Impl = impl; 
     47            }  
    6848        } 
    6949         
    70         Console.Write("Enter log message: "); 
    71         logMessage = new AprString(Console.ReadLine(), pool); 
    72         tmpFile = new AprString(); 
    73          
    74         return(SvnError.NoError); 
    75     } 
    76  
     50        private SortedList SubCommands = new SortedList(); 
     51        private SortedList ShortCommands = new SortedList(); 
     52        private bool mPendingHelp = false; 
    7753     
    78     public static SvnError CancelCallback(IntPtr baton) 
    79     { 
    80         return(SvnError.NoError);        
    81     } 
    82      
    83     public static SvnError SimpleAuth(out SvnAuthCredSimple cred, IntPtr baton,  
    84                            AprString realm, AprString username,  
    85                            bool maySave, AprPool pool) 
    86     { 
    87         Console.WriteLine("Simple Authentication"); 
    88         Console.WriteLine("---------------------"); 
    89         Console.WriteLine("Realm: {0}", realm); 
    90         Console.WriteLine(""); 
    91          
    92         bool valid = false; 
    93         string line = ""; 
    94          
    95         while(!valid) 
     54        public Application() 
    9655        { 
    97             if (!username.IsNull) 
    98                 Console.Write("Enter Username ({0}): ", username); 
    99             else 
    100                 Console.Write("Enter Username: "); 
    101  
    102             line = Console.ReadLine(); 
    103  
    104             if (line.Trim().Length == 0 && !username.IsNull) 
     56            Assembly a = Assembly.GetCallingAssembly(); 
     57            foreach(Type t in a.GetTypes()) 
    10558            { 
    106                 line = username.ToString(); 
    107                 valid = true; 
    108             } 
    109             else if (line.Trim().Length > 0) 
    110             { 
    111                 valid = true; 
    112             } 
    113         } 
    114          
    115         cred = SvnAuthCredSimple.Alloc(pool); 
    116         cred.Username = new AprString(line, pool); 
    117         Console.Write("Enter Password: "); 
    118         cred.Password = new AprString(Console.ReadLine(), pool); 
    119         cred.MaySave = maySave; 
    120         return(SvnError.NoError); 
    121     } 
    122      
    123     public static SvnError UsernameAuth(out SvnAuthCredUsername cred, IntPtr baton,  
    124                                         AprString realm, bool maySave, AprPool pool) 
    125     { 
    126         Console.WriteLine("Username Authentication:"); 
    127         Console.WriteLine("------------------------"); 
    128         Console.WriteLine("Realm: {0}", realm); 
    129         Console.WriteLine(""); 
    130  
    131         bool valid = false; 
    132         string line = ""; 
    133          
    134         while(!valid) 
    135         { 
    136             Console.Write("Enter Username: "); 
    137  
    138             line = Console.ReadLine(); 
    139  
    140             if (line.Trim().Length > 0) 
    141             { 
    142                 valid = true; 
    143             } 
    144         } 
    145          
    146         cred = SvnAuthCredUsername.Alloc(pool); 
    147         cred.Username = new AprString(line, pool); 
    148         cred.MaySave = maySave; 
    149         return(SvnError.NoError); 
    150     } 
    151      
    152     public static SvnError SslServerTrustAuth(out SvnAuthCredSslServerTrust cred,  
    153                                               IntPtr baton, AprString realm,  
    154                                               SvnAuthCredSslServerTrust.CertFailures failures,  
    155                                               SvnAuthSslServerCertInfo certInfo,  
    156                                               bool maySave, IntPtr pool) 
    157     { 
    158         Console.WriteLine("Ssl Server Trust Prompt:"); 
    159         Console.WriteLine("------------------------"); 
    160         Console.WriteLine(""); 
    161          
    162         Console.WriteLine("Error validating server certificate for '{0}':", realm); 
    163         if ((failures & SvnAuthCredSslServerTrust.CertFailures.UnknownCA) > 0) 
    164             Console.WriteLine(" - The certificate is not issued by a trusted authority"); 
    165         if ((failures & SvnAuthCredSslServerTrust.CertFailures.CNMismatch) > 0) 
    166             Console.WriteLine(" - The certificate hostname does not match"); 
    167         if ((failures & SvnAuthCredSslServerTrust.CertFailures.NotYetValid) > 0) 
    168             Console.WriteLine(" - The certificate is not yet valid"); 
    169         if ((failures & SvnAuthCredSslServerTrust.CertFailures.Expired) > 0) 
    170             Console.WriteLine(" - The certificate has expired"); 
    171         if ((failures & SvnAuthCredSslServerTrust.CertFailures.Other) > 0) 
    172             Console.WriteLine(" - The certificate has an unknown error"); 
    173      
    174         Console.WriteLine("Certificate informations:"); 
    175         Console.WriteLine("\tHostName:    " + certInfo.Hostname); 
    176         Console.WriteLine("\tIssuer:      " + certInfo.IssuerDName); 
    177         Console.WriteLine("\tValid From:  " + certInfo.ValidFrom); 
    178         Console.WriteLine("\tValid Until: " + certInfo.ValidUntil); 
    179         Console.WriteLine("\tFingerprint: " + certInfo.Fingerprint); 
    180      
    181         cred = SvnAuthCredSslServerTrust.Alloc(pool); 
    182         bool valid = false; 
    183         while (!valid) 
    184         { 
    185             if (maySave) 
    186                 Console.WriteLine("(R)eject, accept (t)emporarily or accept (p)ermanently? "); 
    187             else 
    188                 Console.WriteLine("(R)eject or accept (t)emporarily? "); 
    189                  
    190             string line = Console.ReadLine(); 
    191             if (line.Length > 0) 
    192             { 
    193                 char choice = line.ToLower()[0]; 
    194                 if (choice == 'r') 
     59                object[] o; 
     60                if((o = t.GetCustomAttributes(typeof(SubCommandAttribute),true)) != null 
     61                   && o.Length != 0) 
    19562                { 
    196                     cred.AcceptedFailures = 0; 
    197                     cred.MaySave=false; 
    198                     valid = true; 
    199                 } 
    200                 else if (choice == 't') 
    201                 { 
    202                     cred.AcceptedFailures = failures; 
    203                     cred.MaySave=false; 
    204                     valid = true; 
    205                 } 
    206                 else if (choice == 'p') 
    207                 { 
    208                     cred.AcceptedFailures = failures; 
    209                     cred.MaySave=true; 
    210                     valid = true; 
     63                    SubCommandAttribute sc = (SubCommandAttribute)o[0]; 
     64                    SubCommands.Add(sc.LongName,new SubCommand(sc.LongName,sc.ShortName,sc.Description,t)); 
     65                    if (sc.ShortName != string.Empty) 
     66                        ShortCommands.Add(sc.ShortName,sc.LongName); 
    21167                } 
    21268            } 
    21369        } 
    214         return(SvnError.NoError); 
     70     
     71        private WhatToDoNext UsageAppend(WhatToDoNext ret) 
     72        { 
     73            Console.Write("Subcommands: "); 
     74            bool addSep = false; 
     75            foreach(SubCommand sc in SubCommands.Values) 
     76            { 
     77                if( addSep ) 
     78                    Console.Write(", "); 
     79                else 
     80                    addSep = true; 
     81                Console.Write(sc.LongName); 
     82                if( sc.ShortName != string.Empty ) 
     83                    Console.Write("[{0}]",sc.ShortName); 
     84            } 
     85            Console.WriteLine("\nFor help on subcommands, use the -?/--help subcommand option."); 
     86            return(ret); 
     87        } 
     88             
     89        public override WhatToDoNext DoUsage() 
     90        { 
     91            return WhatToDoNext.GoAhead; 
     92        } 
     93 
     94        public override WhatToDoNext DoHelp() 
     95        { 
     96            mPendingHelp = true; 
     97            return WhatToDoNext.GoAhead; 
     98        } 
     99 
     100        public int Run(string[] args) 
     101        { 
     102            ProcessArgs(args); 
     103 
     104            if( RemainingArguments.Length == 0 ) 
     105            { 
     106                if( mPendingHelp ) 
     107                    UsageAppend(base.DoHelp()); 
     108                else 
     109                    UsageAppend(base.DoUsage()); 
     110                return(0); 
     111            } 
     112 
     113            SubCommand sc; 
     114            if ((sc = (SubCommand) SubCommands[RemainingArguments[0].ToLower()]) == null) 
     115            { 
     116                string shortCmd = (string) ShortCommands[RemainingArguments[0].ToLower()]; 
     117                if( shortCmd == null 
     118                    || (sc = (SubCommand) SubCommands[shortCmd]) == null )  
     119                { 
     120                    if( mPendingHelp ) 
     121                        UsageAppend(base.DoHelp()); 
     122                    else 
     123                        UsageAppend(base.DoUsage()); 
     124                    return(1); 
     125                } 
     126            } 
     127 
     128            ConstructorInfo ctor = sc.Impl.GetConstructor(new Type[0]); 
     129            MethodInfo run = sc.Impl.GetMethod("Run",new Type[] { typeof(SubCommand), typeof(string[]) }); 
     130     
     131            if(ctor == null || run == null || run.ReturnType != typeof(int)) 
     132                throw new InvalidOperationException("Invalid subcommand class");         
     133                             
     134            return((int)run.Invoke(ctor.Invoke(new object[0]),new object[] { sc, args }));           
     135        } 
     136 
     137        public static int Main(string[] args) 
     138        { 
     139            Application progInst = new Application(); 
     140            return( progInst.Run(args) );                
     141        }        
     142    } 
     143 
     144    [AttributeUsage(AttributeTargets.Class)] 
     145    public class SubCommandAttribute : Attribute 
     146    { 
     147        public string ShortName; 
     148        public string LongName; 
     149        public string Description; 
     150         
     151        public SubCommandAttribute(string longName) 
     152        { 
     153            ShortName = string.Empty; 
     154            LongName = longName.ToLower(); 
     155            Description = string.Empty; 
     156        } 
     157         
     158        public SubCommandAttribute(string longName, string shortName) 
     159        { 
     160            ShortName = shortName.ToLower(); 
     161            LongName = longName.ToLower(); 
     162            Description = string.Empty; 
     163        } 
     164 
     165        public SubCommandAttribute(string longName, string shortName, string desc) 
     166        { 
     167            ShortName = shortName.ToLower(); 
     168            LongName = longName.ToLower(); 
     169            Description = desc; 
     170        } 
    215171    } 
    216172} 
  • trunk/SubversionSharp/test/src/SvnTest.prjx

    r7 r56  
    33    <File name="./Main.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
    44    <File name="./AssemblyInfo.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
     5    <File name="./Checkout.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
     6    <File name="./CmdBase.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 
    57  </Contents> 
    68  <References> 
    79    <Reference type="Project" refto="AprSharp" localcopy="True" /> 
    810    <Reference type="Project" refto="SubversionSharp" localcopy="True" /> 
     11    <Reference type="Gac" refto="Mono.GetOptions, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" localcopy="True" /> 
    912  </References> 
    1013  <DeploymentInformation target="" script="" strategy="File" />