[mapguide-commits] r9796 - in sandbox/jng/vanilla_swig/Bindings: . src src/Bindings src/Bindings/DotNet src/Bindings/DotNet/Foundation src/Bindings/Java src/Bindings/MapGuideApi src/Bindings/Php src/Tools/ClassMapGen src/Tools/ClassMapGen/Properties
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri Nov 20 02:04:16 PST 2020
Author: jng
Date: 2020-11-20 02:04:15 -0800 (Fri, 20 Nov 2020)
New Revision: 9796
Added:
sandbox/jng/vanilla_swig/Bindings/src/SwigCommon/
sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Properties/
sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Properties/launchSettings.json
sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/classids.i
Removed:
sandbox/jng/vanilla_swig/Bindings/src/Bindings/SwigCommon/
Modified:
sandbox/jng/vanilla_swig/Bindings/TODO.txt
sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/Foundation/FoundationApiGen.xml
sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore.i
sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore_split.i
sandbox/jng/vanilla_swig/Bindings/src/Bindings/Java/java.i
sandbox/jng/vanilla_swig/Bindings/src/Bindings/MapGuideApi/MapGuideApiGen.xml
sandbox/jng/vanilla_swig/Bindings/src/Bindings/Php/php.i
sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/
sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/ClassMapGen.csproj
sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Program.cs
Log:
- Update ClassMapGen to run SWIG in XML mode as a pre-build. Use this SWIG XML file as the input for class map generation. This means we no longer need classmap_master.json
- Move SwigCommon up one level
Modified: sandbox/jng/vanilla_swig/Bindings/TODO.txt
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/TODO.txt 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/TODO.txt 2020-11-20 10:04:15 UTC (rev 9796)
@@ -11,6 +11,7 @@
- [x] Add .targets files to each C# project so that native dlls are copied properly when consumed by legacy .net framework applications/libraries
- [x] Consolidate TestCommon and TestMapGuideApi .net projects to unified netstandard2.0 libraries
- [x] Tidy mg_exception_callback to no longer take an exception class name argument (it is no longer used or necessary)
+ - [ ] Add sanity test for all class ids generated by ClassMapGen
- Either
- ( ) Add CentOS 6 Dockerfile that
- Install SWIG and common libs tarball (from docker build system)
@@ -67,6 +68,21 @@
- [ ] viewer samples (Java)
- [ ] viewer samples (.net)
- Give the .net viewer samples the same migration plan as mapviewernet
+ - Revise API documentation strategy
+ - [ ] Don't use doxygen. Instead use the appropriate docgen tool for the languages we support:
+ - PHP: phpDocumentor (https://phpdoc.org/)
+ - Java: javadoc (part of the JDK)
+ - .net: docfx (https://dotnet.github.io/docfx/)
+ - [ ] Implement a static umbrella landing site that is the gateway to the 3 generated outputs
+ - mg-desktop
+ - [ ] Rename to MgPortable/mg-portable
+ - [ ] Add SWIG glue library that layers on top of the existing Foundation/Geometry/PlatformBase glue projects
+ - [ ] Add new OSGeo.MapGuide.Portable .net project for the .net portion of the SWIG glue
+ - [ ] Implement a sample asp.net core application that confirms the feasibility of using mg-portable for web applications in addition to desktop applications
+ - Either:
+ - ( ) Migrate the viewer winforms library to target .net 5.0
+ - ( ) Or maintain 2 versions of this library, a new .net 5.0 version of the library and a legacy full framework version
+ - [ ] Port over Java binding
- Old code cleanup/consolidation
- [ ] Remove old IMake
- [ ] Fold FoundationTest into mgserver test suite
Modified: sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/Foundation/FoundationApiGen.xml
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/Foundation/FoundationApiGen.xml 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/Foundation/FoundationApiGen.xml 2020-11-20 10:04:15 UTC (rev 9796)
@@ -53,7 +53,7 @@
%include "FoundationApi_Properties.i" //.net property wrappers
%include "language.i" //typemaps specific for each language
%include "InitializeLibrary.i"
-#if defined(MG_CLASSIDGEN)
+#if defined(CLASSIDGEN)
%include "../../../../../Common/Foundation/System/FoundationClassId.h"
#endif
Modified: sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore.i
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore.i 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore.i 2020-11-20 10:04:15 UTC (rev 9796)
@@ -16,10 +16,10 @@
//
%include <wchar.i>
%include "MapGuideApi_Properties.i"
-%include "../SwigCommon/DotNet/string.i"
-%include "../SwigCommon/DotNet/coreclr_compat.i"
-%include "../SwigCommon/DotNet/sugar.i"
-%include "../SwigCommon/DotNet/custom.i"
+%include "../../SwigCommon/DotNet/string.i"
+%include "../../SwigCommon/DotNet/coreclr_compat.i"
+%include "../../SwigCommon/DotNet/sugar.i"
+%include "../../SwigCommon/DotNet/custom.i"
// Add default namespaces for all generated proxies
%typemap(csimports) SWIGTYPE %{
@@ -42,7 +42,7 @@
%ignore MgObject::GetClassId;
%ignore MgObject::GetClassName;
-%include "../SwigCommon/refcount.i"
+%include "../../SwigCommon/refcount.i"
// Have these collections implement the .net collection interfaces
IMPLEMENT_LIST(MgClassDefinitionCollection, MgClassDefinition)
Modified: sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore_split.i
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore_split.i 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Bindings/DotNet/dotnetcore_split.i 2020-11-20 10:04:15 UTC (rev 9796)
@@ -15,10 +15,10 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
%include <wchar.i>
-%include "../../SwigCommon/DotNet/string.i"
-%include "../../SwigCommon/DotNet/coreclr_compat.i"
-%include "../../SwigCommon/DotNet/sugar.i"
-%include "../../SwigCommon/DotNet/custom.i"
+%include "../../../SwigCommon/DotNet/string.i"
+%include "../../../SwigCommon/DotNet/coreclr_compat.i"
+%include "../../../SwigCommon/DotNet/sugar.i"
+%include "../../../SwigCommon/DotNet/custom.i"
// Add default namespaces for all generated proxies
%typemap(csimports) SWIGTYPE %{
@@ -41,7 +41,7 @@
%ignore MgObject::GetClassId;
%ignore MgObject::GetClassName;
-%include "../../SwigCommon/refcount.i"
+%include "../../../SwigCommon/refcount.i"
// Have these collections implement the .net collection interfaces
IMPLEMENT_LIST(MgClassDefinitionCollection, MgClassDefinition)
Modified: sandbox/jng/vanilla_swig/Bindings/src/Bindings/Java/java.i
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Bindings/Java/java.i 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Bindings/Java/java.i 2020-11-20 10:04:15 UTC (rev 9796)
@@ -15,9 +15,9 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-%include "../SwigCommon/Java/exception.i"
-%include "../SwigCommon/Java/monkey_patch.i"
-%include "../SwigCommon/Java/extensions.i"
+%include "../../SwigCommon/Java/exception.i"
+%include "../../SwigCommon/Java/monkey_patch.i"
+%include "../../SwigCommon/Java/extensions.i"
//Required JNI bootstrap
%pragma(java) jniclasscode=%{
@@ -40,7 +40,7 @@
// These methods have to be invoked C-style
%ignore MgObject::GetClassName;
-%include "../SwigCommon/refcount.i"
+%include "../../SwigCommon/refcount.i"
%typemap(jni) STRINGPARAM "jstring"
%typemap(jtype) STRINGPARAM "String"
Modified: sandbox/jng/vanilla_swig/Bindings/src/Bindings/MapGuideApi/MapGuideApiGen.xml
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Bindings/MapGuideApi/MapGuideApiGen.xml 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Bindings/MapGuideApi/MapGuideApiGen.xml 2020-11-20 10:04:15 UTC (rev 9796)
@@ -63,6 +63,7 @@
<SwigInline>
%include "MapGuideApi_Doc.i" //translated doxygen fragments
%include "language.i" //typemaps specific for each language
+#if defined(MG_CLASSIDGEN)
%include "../../../../Common/Foundation/System/FoundationClassId.h"
%include "../../../../Common/Geometry/GeometryClassId.h"
%include "../../../../Common/PlatformBase/Services/PlatformBaseClassId.h"
@@ -69,6 +70,7 @@
%include "../../../../Common/MapGuideCommon/System/MapGuideCommonClassId.h"
%include "../../../../Web/src/WebApp/WebAppClassId.h"
%include "../../../../Web/src/HttpHandler/HttpHandlerClassId.h"
+#endif
#if defined(PHPSWIG)
// We force UTF-8 encoding for PHP
Modified: sandbox/jng/vanilla_swig/Bindings/src/Bindings/Php/php.i
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Bindings/Php/php.i 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Bindings/Php/php.i 2020-11-20 10:04:15 UTC (rev 9796)
@@ -26,9 +26,9 @@
#include "MapGuideCommon.h"
%}
-%include "../SwigCommon/Php/pointer.i"
-%include "../SwigCommon/Php/exception.i"
-%include "../SwigCommon/Php/monkey_patch.i"
+%include "../../SwigCommon/Php/pointer.i"
+%include "../../SwigCommon/Php/exception.i"
+%include "../../SwigCommon/Php/monkey_patch.i"
%runtime %{
#if defined(_MSC_VER)
@@ -38,7 +38,7 @@
#include "PhpClassMap.cpp"
%}
-%include "../SwigCommon/refcount.i"
+%include "../../SwigCommon/refcount.i"
// These methods have to be invoked C-style
%ignore MgObject::GetClassId;
Index: sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen 2020-11-20 10:04:15 UTC (rev 9796)
Property changes on: sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen
___________________________________________________________________
Modified: svn:ignore
## -1,2 +1,3 ##
bin
obj
+classids_wrap.xml
Modified: sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/ClassMapGen.csproj
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/ClassMapGen.csproj 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/ClassMapGen.csproj 2020-11-20 10:04:15 UTC (rev 9796)
@@ -6,12 +6,14 @@
</PropertyGroup>
<ItemGroup>
+ <PackageReference Include="CommandLineParser" Version="2.8.0" />
+ <PackageReference Include="CoreCLR-NCalc" Version="2.2.92" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
- <None Update="Data\classmap_master.json">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <None Update="classids_wrap.xml">
+ <CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="Data\Templates\dotnet.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -23,5 +25,13 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
+
+ <ItemGroup>
+ <Folder Include="Temp\" />
+ </ItemGroup>
+
+ <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
+ <Exec Command=""..\..\Tools\swig\install\swig.exe" -c++ -xml -nodefaultctor -nodefaultdtor -module MapGuideClassIds classids.i" />
+ </Target>
</Project>
Modified: sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Program.cs
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Program.cs 2020-11-20 08:03:41 UTC (rev 9795)
+++ sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Program.cs 2020-11-20 10:04:15 UTC (rev 9796)
@@ -4,6 +4,9 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
+using CommandLine;
+using System.Xml;
+using NCalc;
namespace ClassMapGen
{
@@ -19,30 +22,40 @@
public List<ModuleDef> Modules { get; set; }
}
+ class Options
+ {
+ [Option("source-base", Required = true)]
+ public string SourceBase { get; set; }
+
+ [Option("swig-xml-file", Required = true)]
+ public string SwigXmlFile { get; set; }
+ }
+
class Program
{
- static int Main(string[] args)
+ static int Run(Options opts)
{
- string srcBase = null;
- if (args.Length == 1)
- {
- srcBase = args[0];
- }
+ var srcBase = opts.SourceBase;
if (!Directory.Exists(srcBase))
{
Console.WriteLine($"ERROR: Source base directory not found: {srcBase}");
return 1;
}
+ if (!File.Exists(opts.SwigXmlFile))
+ {
+ Console.WriteLine($"ERROR: SWIG xml file not found: {opts.SwigXmlFile}");
+ return 1;
+ }
string phpOut = Path.Combine(srcBase, "Bindings/Php/PhpClassMap.cpp");
- string dotNetOut = Path.Combine(srcBase, "Bindings/DotNet/MapGuideDotNetApi/custom/MgClassMap.cs");
- string javaOut = Path.Combine(srcBase, "Bindings/Java/org/osgeo/mapguide/ObjectFactory.java");
+ string dotNetOut = Path.Combine(srcBase, "Managed/DotNet/Common/MgClassMap.cs");
+ string javaOut = Path.Combine(srcBase, "Managed/Java/org/osgeo/mapguide/ObjectFactory.java");
var phpTpl = new StringBuilder(File.ReadAllText("Data/Templates/php.txt"));
var dotNetTpl = new StringBuilder(File.ReadAllText("Data/Templates/dotnet.txt"));
var javaTpl = new StringBuilder(File.ReadAllText("Data/Templates/java.txt"));
- MasterClassMap clsMap = JsonConvert.DeserializeObject<MasterClassMap>(File.ReadAllText("Data/classmap_master.json"));
+ MasterClassMap clsMap = ReadFromSwigXml(opts.SwigXmlFile);
var foundation = clsMap.Modules.FirstOrDefault(m => m.Name == "Foundation");
var geometry = clsMap.Modules.FirstOrDefault(m => m.Name == "Geometry");
@@ -113,7 +126,7 @@
phpTpl.Replace("$CLASS_NAME_MAP_BODY$", phpClassMaps.ToString());
var dotNetClassMaps = new StringBuilder();
-
+
//.net
foreach (var kvp in classMapMasterReverse)
{
@@ -122,7 +135,7 @@
dotNetTpl.Replace("$CLASS_NAME_MAP_BODY$", dotNetClassMaps.ToString());
- var javaClassMaps = new StringBuilder();
+ var javaClassMaps = new StringBuilder();
//Java
foreach (var kvp in classMapMasterReverse)
@@ -141,5 +154,184 @@
return 0;
}
+
+ private static MasterClassMap ReadFromSwigXml(string swigXmlFile)
+ {
+ var doc = new XmlDocument();
+ doc.Load(swigXmlFile);
+
+ var constantNodes = doc.GetElementsByTagName("constant");
+ var modFoundation = new ModuleDef
+ {
+ Name = "Foundation",
+ Classes = new Dictionary<int, string>()
+ };
+ var modGeometry = new ModuleDef
+ {
+ Name = "Geometry",
+ Classes = new Dictionary<int, string>()
+ };
+ var modPlatformBase = new ModuleDef
+ {
+ Name = "PlatformBase",
+ Classes = new Dictionary<int, string>()
+ };
+ var modMapGuideCommon = new ModuleDef
+ {
+ Name = "MapGuideCommon",
+ Classes = new Dictionary<int, string>()
+ };
+ var modWeb = new ModuleDef
+ {
+ Name = "Web",
+ Classes = new Dictionary<int, string>()
+ };
+
+ var modsByName = new Dictionary<string, ModuleDef>
+ {
+ { modFoundation.Name, modFoundation },
+ { modGeometry.Name, modGeometry },
+ { modPlatformBase.Name, modPlatformBase },
+ { modMapGuideCommon.Name, modMapGuideCommon },
+ { modWeb.Name, modWeb }
+ };
+
+ var clsMap = new MasterClassMap
+ {
+ Modules = new List<ModuleDef>
+ {
+ modFoundation,
+ modGeometry,
+ modPlatformBase,
+ modMapGuideCommon,
+ modWeb
+ }
+ };
+
+ foreach (XmlNode cn in constantNodes)
+ {
+ var attrs = cn.FirstChild?.ChildNodes;
+ if (attrs != null)
+ {
+ string name = null;
+ string valueExpr = null;
+ foreach (XmlNode attNode in attrs)
+ {
+ if (attNode.Name != "attribute")
+ {
+ continue;
+ }
+
+ var na = attNode.Attributes["name"]?.Value;
+ var va = attNode.Attributes["value"]?.Value;
+ if (na != null && na == "name" && va != null)
+ {
+ name = va;
+ }
+ if (na != null && na == "value" && va != null)
+ {
+ valueExpr = va;
+ }
+ }
+ if (name != null && valueExpr != null)
+ {
+ Console.WriteLine("Checking symbol: " + name);
+ // Name should be of the form: Module_Category_ClassName
+ var qname = name.Split("_");
+ if (IsCandidateConstant(modsByName, qname, out var modName, out var uqClassName))
+ {
+ // The class id value should be an arithmetic expression, evaluate it
+ var expr = new Expression(valueExpr);
+ var f = expr.ToLambda<int>();
+ var classId = f.Invoke();
+
+ var mod = modsByName[modName];
+ var className = "Mg" + uqClassName;
+
+ // Skip class ids for removed exception classes. The ids are remaining in the
+ // original headers so we don't try to reuse them for any new classes we add to the
+ // MapGuide API in the future
+ if (className.EndsWith("Exception") && className != "MgException")
+ {
+ continue;
+ }
+
+ mod.Classes.Add(classId, className);
+ Console.WriteLine($"Found class id ({classId}) for class: {className}");
+ }
+ }
+ }
+ }
+
+ return clsMap;
+ }
+
+ private static bool IsCandidateConstant(Dictionary<string, ModuleDef> modsByName, string[] qname, out string modName, out string className)
+ {
+ modName = "";
+ className = "";
+ bool isCandidate = false;
+
+ if (qname.Length == 3)
+ {
+ if (modsByName.ContainsKey(qname[0]))
+ {
+ modName = qname[0];
+ className = qname[2];
+ isCandidate = true;
+ }
+ else
+ {
+ switch (qname[0])
+ {
+ case "HttpHandler":
+ modName = "Web";
+ className = qname[2];
+ isCandidate = true;
+ break;
+ case "MapGuide":
+ modName = "MapGuideCommon";
+ className = qname[2];
+ isCandidate = true;
+ break;
+ }
+ }
+ }
+
+
+ if (!isCandidate)
+ {
+ if (qname.Length == 2)
+ {
+ switch (qname[0])
+ {
+ case "CoordinateSystem":
+ case "Geometry":
+ isCandidate = true;
+ modName = "Geometry";
+ className = qname[1];
+ break;
+ case "WebApp":
+ isCandidate = true;
+ modName = "Web";
+ className = qname[1];
+ break;
+ }
+ }
+ }
+ return isCandidate;
+ }
+
+ static int Main(string[] args)
+ {
+ int exitCode = 0;
+ Parser.Default.ParseArguments<Options>(args)
+ .WithParsed(opts =>
+ {
+ exitCode = Run(opts);
+ });
+
+ return exitCode;
+ }
}
}
Added: sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Properties/launchSettings.json
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Properties/launchSettings.json (rev 0)
+++ sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/Properties/launchSettings.json 2020-11-20 10:04:15 UTC (rev 9796)
@@ -0,0 +1,8 @@
+{
+ "profiles": {
+ "ClassMapGen": {
+ "commandName": "Project",
+ "commandLineArgs": "--source-base ..\\..\\..\\..\\.. --swig-xml-file ..\\..\\..\\classids_wrap.xml"
+ }
+ }
+}
\ No newline at end of file
Added: sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/classids.i
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/classids.i (rev 0)
+++ sandbox/jng/vanilla_swig/Bindings/src/Tools/ClassMapGen/classids.i 2020-11-20 10:04:15 UTC (rev 9796)
@@ -0,0 +1,6 @@
+%include "./../../../../Common/Foundation/System/FoundationClassId.h"
+%include "./../../../../Common/Geometry/GeometryClassId.h"
+%include "./../../../../Common/PlatformBase/Services/PlatformBaseClassId.h"
+%include "./../../../../Common/MapGuideCommon/System/MapGuideCommonClassId.h"
+%include "./../../../../Web/src/WebApp/WebAppClassId.h"
+%include "./../../../../Web/src/HttpHandler/HttpHandlerClassId.h"
\ No newline at end of file
More information about the mapguide-commits
mailing list