Example #1
0
        public static JavaApi FromXml(TextReader textReader)
        {
            XmlReader reader = XmlReader.Create(
                textReader,
                new XmlReaderSettings {
                ConformanceLevel = ConformanceLevel.Document
            });
            JavaApi javaApi = (JavaApi) new XmlSerializer(typeof(JavaApi)).Deserialize(reader);

            return(javaApi);
        }
Example #2
0
        void GenerateAndroidCSharpBindingsProject(bool includeAdapters, ICollection <string> referencePaths = null)
        {
            Log.Important("Generating Android C# bindings project at\n" + this.bindingsProject);

            string project          = Utils.ExtractResourceText(ProjectFiles.Project);
            string assemblyName     = this.PluginInfo.Assembly.Name;
            string tempAssemblyName = "temp";

            project = project.Replace($"$({MsbuildProperties.JavadocPath})", Path.GetFullPath(this.javadocPath));
            project = project.Replace(
                $"$({MsbuildProperties.AssemblyName})", (includeAdapters ? assemblyName : tempAssemblyName));
            project = project.Replace(
                "<ItemGroup Label=\"Jars\">", "<ItemGroup Label=\"Jars\">\n" + this.GetMsbuildJarItems());
            project = project.Replace(
                "<ItemGroup Label=\"Libs\">", "<ItemGroup Label=\"Libs\">\n" + this.GetMsbuildLibItems());

            File.WriteAllText(this.bindingsProject, project);

            string propertiesPath = Path.Combine(this.PlatformIntermediatePath, "Properties");

            if (!Directory.Exists(propertiesPath))
            {
                Directory.CreateDirectory(propertiesPath);
            }

            this.GenerateAssemblyInfo(Path.Combine(propertiesPath, ProjectFiles.AssemblyInfo));

            string adaptersPath = Path.Combine(this.PlatformIntermediatePath, "Adapters");

            if (!Directory.Exists(adaptersPath))
            {
                Directory.CreateDirectory(adaptersPath);
            }

            string transformsPath = Path.Combine(this.PlatformIntermediatePath, "Transforms");

            if (!Directory.Exists(transformsPath))
            {
                Directory.CreateDirectory(transformsPath);
            }

            if (includeAdapters)
            {
                string apiXmlPath = Path.Combine(
                    this.PlatformIntermediatePath, "obj", (this.DebugConfiguration ? "Debug" : "Release"), "api.xml");
                if (!File.Exists(apiXmlPath))
                {
                    throw new FileNotFoundException("Exported Java API XML file not found at " + apiXmlPath);
                }

                JavaApi javaApi;
                using (StreamReader reader = File.OpenText(apiXmlPath))
                {
                    javaApi = JavaApi.FromXml(reader);
                }

                string tempPath = Path.Combine(
                    Path.GetDirectoryName(this.BuiltBindingsAssemblyPath), tempAssemblyName + ".dll");
                Assembly androidApi = ClrApi.LoadFrom(
                    tempPath,
                    referencePaths);
                AndroidApiAdapter adapter = new AndroidApiAdapter();
                adapter.PluginInfo          = this.PluginInfo;
                adapter.JavaApi             = javaApi;
                adapter.OutputDirectoryPath = adaptersPath;
                adapter.GenerateAdapterCodeForApi(androidApi);
            }

            this.GenerateBindingMetadata(transformsPath);

            string enumFields = "<enum-field-mappings></enum-field-mappings>";

            File.WriteAllText(Path.Combine(transformsPath, ProjectFiles.EnumFields), enumFields);

            string enumMethods = "<enum-method-mappings></enum-method-mappings>";

            File.WriteAllText(Path.Combine(transformsPath, ProjectFiles.EnumMethods), enumMethods);
        }