Add failing Uri test
[mono.git] / mcs / tools / wsdl / MonoWSDL2.cs
old mode 100755 (executable)
new mode 100644 (file)
index e7aa82b..71eaf7a
@@ -7,6 +7,8 @@
 /// Copyright (C) 2003, Erik LeBel,\r
 ///\r
 \r
+#if NET_2_0\r
+\r
 using System;\r
 using System.Xml;\r
 using System.Xml.Serialization;\r
@@ -32,7 +34,9 @@ namespace Mono.WebServices
                        "wsdl [options] {path | URL} {path | URL} ...\n\n"\r
                        + "   -d, -domain:domain           Domain of username for server authentication.\n"\r
                        + "   -l, -language:language       Language of generated code. Allowed CS (default)\n"\r
-                       + "                                and VB.\n"\r
+                       + "                                and VB. You can also specify the fully qualified\n"\r
+                       + "                                name of a class that implements the\n"\r
+                       + "                                System.CodeDom.Compiler.CodeDomProvider Class.\n"\r
                        + "   -n, -namespace:ns            The namespace of the generated code, default\n"\r
                        + "                                namespace if none.\n"\r
                        + "   -nologo                      Surpress the startup logo.\n"\r
@@ -123,32 +127,33 @@ namespace Mono.WebServices
                                codeUnit.Namespaces.Add (proxyCode);\r
                                \r
                                WebReferenceCollection references = new WebReferenceCollection ();\r
+\r
+                               DiscoveryClientProtocol dcc = CreateClient ();\r
+\r
                                foreach (string murl in urls) \r
                                {\r
-                                       DiscoveryClientProtocol dcc = CreateClient ();\r
 \r
                                        string url = murl;\r
                                        if (!url.StartsWith ("http://") && !url.StartsWith ("https://") && !url.StartsWith ("file://"))\r
-                                               url = "file://" + Path.GetFullPath (url);\r
+                                               url = new Uri (Path.GetFullPath (url)).ToString ();\r
 \r
                                        dcc.DiscoverAny (url);\r
                                        dcc.ResolveAll ();\r
                                        \r
-                                       WebReference reference = new WebReference (dcc.Documents, proxyCode, protocol, appSettingURLKey, appSettingBaseURL);\r
-                                       references.Add (reference);\r
-                                       \r
-                                       if (sampleSoap != null)\r
-                                               ConsoleSampleGenerator.Generate (descriptions, schemas, sampleSoap, protocol);\r
                                }\r
                                \r
+                               WebReference reference = new WebReference (dcc.Documents, proxyCode, protocol, appSettingURLKey, appSettingBaseURL);\r
+                               references.Add (reference);\r
+                               \r
+                               if (sampleSoap != null)\r
+                                       ConsoleSampleGenerator.Generate (descriptions, schemas, sampleSoap, protocol);\r
+                               \r
                                if (sampleSoap != null)\r
                                        return 0;\r
                                        \r
                                // generate the code\r
-                               if (GenerateCode (references, codeUnit))\r
-                                       return 1;\r
-                               else\r
-                                       return 0;\r
+                               GenerateCode (references, codeUnit);\r
+                               return 0;\r
                        }\r
                        catch (Exception exception)\r
                        {\r
@@ -170,17 +175,20 @@ namespace Mono.WebServices
                        bool hasWarnings = false;\r
                        \r
                        CodeDomProvider provider = GetProvider();\r
-                       ICodeGenerator generator = provider.CreateGenerator();\r
                                \r
                        StringCollection validationWarnings;\r
-                       validationWarnings = ServiceDescriptionImporter.GenerateWebReferences (references, options, style, generator, codeUnit, verbose);\r
+                       WebReferenceOptions opts = new WebReferenceOptions ();\r
+                       opts.CodeGenerationOptions = options;\r
+                       opts.Style = style;\r
+                       opts.Verbose = verbose;\r
+                       validationWarnings = ServiceDescriptionImporter.GenerateWebReferences (references, provider, codeUnit, opts);\r
                        \r
                        for (int n=0; n<references.Count; n++)\r
                        {\r
                                WebReference wr  = references [n];\r
                                \r
                                BasicProfileViolationCollection violations = new BasicProfileViolationCollection ();\r
-                               if (!WebServicesInteroperability.CheckConformance (WsiClaims.BP10, wr, violations)) {\r
+                               if (String.Compare (protocol, "SOAP", StringComparison.OrdinalIgnoreCase) == 0 && !WebServicesInteroperability.CheckConformance (WsiProfiles.BasicProfile1_1, wr, violations)) {\r
                                        wr.Warnings |= ServiceDescriptionImportWarnings.WsiConformance;\r
                                }\r
                                \r
@@ -188,14 +196,14 @@ namespace Mono.WebServices
                                {\r
                                        if (!hasWarnings) {\r
                                                WriteText ("", 0, 0);\r
-                                               WriteText ("There where some warnings while generating the code:", 0, 0);\r
+                                               WriteText ("There were some warnings while generating the code:", 0, 0);\r
                                        }\r
                                        \r
                                        WriteText ("", 0, 0);\r
                                        WriteText (urls[n], 2, 2);\r
                                        \r
                                        if ((wr.Warnings & ServiceDescriptionImportWarnings.WsiConformance) > 0) {\r
-                                               WriteText ("- This web reference does not conform to WS-I Basic Profile v1.0", 4, 6); \r
+                                               WriteText ("- This web reference does not conform to WS-I Basic Profile v1.1", 4, 6); \r
                                                foreach (BasicProfileViolation vio in violations) {\r
                                                        WriteText (vio.NormativeStatement + ": " + vio.Details, 8, 8);\r
                                                        foreach (string ele in vio.Elements)\r
@@ -219,7 +227,7 @@ namespace Mono.WebServices
                                        hasWarnings = true;\r
                                }\r
                        }\r
-                       
+                       \r
                        if (hasWarnings) WriteText ("",0,0);\r
                                \r
                        string filename = outFilename;\r
@@ -229,23 +237,23 @@ namespace Mono.WebServices
                        {\r
                                ServiceDescription desc = doc as ServiceDescription;\r
                                if (desc == null) continue;\r
-                               
+                               \r
                                if (desc.Services.Count > 0 && filename == null)\r
                                        filename = desc.Services[0].Name + "." + provider.FileExtension;\r
-                                       
+                                       \r
                                if (desc.Bindings.Count > 0 || desc.Services.Count > 0)\r
                                        hasBindings = true;\r
                        }\r
                        \r
                        if (filename == null)\r
-                               filename = "output." + provider.FileExtension;
+                               filename = "output." + provider.FileExtension;\r
                        \r
                        if (hasBindings) {\r
                                WriteText ("Writing file '" + filename + "'", 0, 0);\r
                                StreamWriter writer = new StreamWriter(filename);\r
                                \r
                                CodeGeneratorOptions compilerOptions = new CodeGeneratorOptions();\r
-                               generator.GenerateCodeFromCompileUnit (codeUnit, writer, compilerOptions);\r
+                               provider.GenerateCodeFromCompileUnit (codeUnit, writer, compilerOptions);\r
                                writer.Close();\r
                        }\r
                        \r
@@ -297,23 +305,30 @@ namespace Mono.WebServices
                ///\r
                private CodeDomProvider GetProvider()\r
                {\r
-                       // FIXME these should be loaded dynamically using reflection\r
                        CodeDomProvider provider;\r
+                       Type type;\r
                        \r
-                       switch (language.ToUpper())\r
-                       {\r
-                           case "CS":\r
-                                   provider = new CSharpCodeProvider();\r
-                                   break;\r
-                           \r
-                               case "VB":\r
-                                       provider = new Microsoft.VisualBasic.VBCodeProvider();\r
-                                       break;\r
-                                       \r
-                           default:\r
-                                   throw new Exception("Unknow language");\r
+                       switch (language.ToUpper ()) {\r
+                       case "CS":\r
+                               provider = new CSharpCodeProvider ();\r
+                               break;\r
+                       case "VB":\r
+                               provider = new Microsoft.VisualBasic.VBCodeProvider ();\r
+                               break;\r
+                       case "BOO":\r
+                               type = Type.GetType("Boo.Lang.CodeDom.BooCodeProvider, Boo.Lang.CodeDom, Version=1.0.0.0, Culture=neutral, PublicKeyToken=32c39770e9a21a67");\r
+                               if (type != null){\r
+                                       return (CodeDomProvider) Activator.CreateInstance (type);\r
+                               }\r
+                               throw new Exception ("Boo.Lang.CodeDom.BooCodeProvider not available");\r
+                               \r
+                       default:\r
+                               type = Type.GetType(language);\r
+                               if (type != null) {\r
+                                       return (CodeDomProvider) Activator.CreateInstance (type);\r
+                               }       \r
+                               throw new Exception ("Unknown language");\r
                        }\r
-\r
                        return provider;\r
                }\r
                \r
@@ -532,4 +547,6 @@ namespace Mono.WebServices
                        }\r
                }\r
        }\r
-}
+}\r
+\r
+#endif\r