public static YamlMappingNode GetMappingNode(this YamlDocument doc, string[] keys, int index = 0)
        {
            // ROOT DOCUMENT
            YamlMappingNode root = (YamlMappingNode)doc.RootNode;

            return(root.GetMappingNode(keys));
        }
Example #2
0
        void _loadMetadata()
        {
            // YAML parser
            _metadataStream = new YamlStream();

            using (var reader = _metadataFile.OpenText())
            {
                _metadataStream.Load(reader);
            }

            /*
             # This file tracks properties of this Flutter project.
             # Used by Flutter tool to assess capabilities and perform upgrades etc.
             #
             # This file should be version controlled and should not be manually edited.
             #
             # version:
             # revision: 27321ebbad34b0a3fafe99fac037102196d655ff
             # channel: stable
             #
             # project_type: module
             */

            if (_metadataStream.Documents.Count != 1)
            {
                throw new DartProjectException("Invalid .metadata structure!!", DartProjectError.MetadataInvalidFormat);
            }

            _metadataDocument = _metadataStream.Documents[0];
        }
        public static string GetScalarValue(this YamlDocument doc, string[] keys)
        {
            // ROOT DOCUMENT
            YamlMappingNode root = (YamlMappingNode)doc.RootNode;
            // Find the nested value
            YamlScalarNode scalarNode = GetScalarNode(root, keys);

            return(scalarNode?.Value ?? string.Empty);
        }
Example #4
0
        /// <summary>
        /// Returns the path of the Android AAR created when building a Flutter module.
        /// </summary>
        public static string GetAndroidArchivePath(string flutterFolder, YamlDocument pubspecFile, FlutterModuleBuildConfig buildConfig)
        {
            // Please consider a Flutter module created with the following command:
            //
            // flutter create -t module --org com.example hello_world
            //
            // Now, build the module for Android integration:
            //
            // flutter build aar
            //
            // The output AAR for Debug configuration is located under:
            //
            // <MODULE_FOLDER>\build\host\outputs\repo\com\example\hello_world\flutter_debug\1.0\flutter_debug-1.0.aar

            // <MODULE_FOLDER>\build\host\outputs\repo\
            string repoRootFolder = Path.Combine(flutterFolder, "build", "host", "outputs", "repo");

            // Find the 'androidPackage' info from the pubspec.yaml file
            string package = pubspecFile.GetScalarValue(new[] { "flutter", "module", "androidPackage" });

            // <MODULE_FOLDER>\build\host\outputs\repo\com\example\hello_world\
            string packageRootFolder = repoRootFolder;

            string[] packageFolders = string.IsNullOrEmpty(package) ? new string[0] : package.Split(".");
            foreach (string folder in packageFolders)
            {
                packageRootFolder = Path.Combine(packageRootFolder, folder);
            }

            string version = "1.0";
            string build;

            switch (buildConfig)
            {
            case FlutterModuleBuildConfig.Debug:
                build = "debug";
                break;

            case FlutterModuleBuildConfig.Profile:
                build = "profile";
                break;

            case FlutterModuleBuildConfig.Release:
                build = "release";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(buildConfig), buildConfig, null);
            }

            // <MODULE_FOLDER>\build\host\outputs\repo\com\example\hello_world\flutter_debug\1.0\flutter_debug-1.0.aar
            string path = Path.Combine(packageRootFolder, $"flutter_{build}", version, $"flutter_{build}-{version}.aar");

            return(path);
        }
        public static void SetScalarValue(this YamlDocument doc, string[] keys, string value)
        {
            // ROOT DOCUMENT
            YamlMappingNode root = (YamlMappingNode)doc.RootNode;
            // Find the nested value
            YamlScalarNode scalarNode = GetScalarNode(root, keys);

            if (scalarNode == null)
            {
                throw new InvalidOperationException($"Scalar node for keys {string.Join(":", keys)} not found!");
            }
            scalarNode.Value = value;
        }
Example #6
0
        private static string GetIosFrameworkPathCore(string flutterFolder, YamlDocument pubspecFile, FlutterModuleBuildConfig buildConfig, bool xcframework)
        {
            // Please consider a Flutter module created with the following command:
            //
            // flutter create -t module --org com.example hello_world
            //
            // Now, build the module for iOS integration:
            //
            // flutter build ios-framework
            //
            // The output framework for Debug configuration is located under:
            //
            // <MODULE_FOLDER>\build\ios\Debug\App.xcframework (Flutter 2.*)
            //
            // or
            //
            // <MODULE_FOLDER>\build\ios\Debug\App.framework   (Flutter 1.*)


            // <MODULE_FOLDER>\build\ios\framework\
            string frameworkRootFolder = Path.Combine(flutterFolder, "build", "ios", "framework");

            // Find the 'iosBundleIdentifier' info from the pubspec.yaml file
            string bundle = pubspecFile.GetScalarValue(new[] { "flutter", "module", "iosBundleIdentifier" });

            string build;

            switch (buildConfig)
            {
            case FlutterModuleBuildConfig.Debug:
                build = "Debug";
                break;

            case FlutterModuleBuildConfig.Profile:
                build = "Profile";
                break;

            case FlutterModuleBuildConfig.Release:
                build = "Release";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(buildConfig), buildConfig, null);
            }

            // <MODULE_FOLDER>\build\ios\Debug\App.framework
            string path = Path.Combine(frameworkRootFolder, build, xcframework ? "App.xcframework" : "App.framework");

            return(path);
        }
Example #7
0
        static void AddDevDependencyToDoc(YamlDocument doc, DartProjectDependency dependency, bool forceUpdate = false)
        {
            YamlMappingNode devDependencies = doc.GetMappingNode(new[] { _devDependeciesYaml });

            if (devDependencies == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_devDependeciesYaml}' section !!!", DartProjectError.PubspecInvalidFormat);
            }

            var dependecyNode = dependency.ToYamlNode();

            if (devDependencies.Children.ContainsKey(dependecyNode.Key) == false || forceUpdate)
            {
                devDependencies.Children[dependecyNode.Key] = dependecyNode.Value;
            }
        }
Example #8
0
        void _loadPubspecYaml()
        {
            // YAML parser
            _pubspecStream = new YamlStream();

            using (var reader = _pubspecFile.OpenText())
            {
                _pubspecStream.Load(reader);
            }

            /*
             * name: flutter_xamarin_protocol
             * description: A new Flutter package project.
             * version: 0.0.1
             * author:
             * homepage:
             *
             * environment:
             * sdk: ">=2.1.0 <3.0.0"
             *
             * dependencies:
             * flutter:
             * sdk: flutter
             # Your other regular dependencies here
             # json_annotation: ^2.0.0
             #
             # dev_dependencies:
             # flutter_test:
             # sdk: flutter
             # Your other dev_dependencies here
             # build_runner: ^1.0.0
             # json_serializable: ^2.0.0
             */


            if (_pubspecStream.Documents.Count != 1)
            {
                throw new DartProjectException("Invalid YAML structure!!", DartProjectError.PubspecInvalidFormat);
            }

            _pubspecDocument = _pubspecStream.Documents[0];
        }
Example #9
0
        static List <DartProjectDependency> GetDevDependencies(YamlDocument doc)
        {
            YamlMappingNode dependencies = doc.GetMappingNode(new[] { _devDependeciesYaml });

            if (dependencies == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_devDependeciesYaml}' section !!!", DartProjectError.PubspecInvalidFormat);
            }

            List <DartProjectDependency> dartDependencies = new List <DartProjectDependency>();

            foreach (KeyValuePair <YamlNode, YamlNode> dependency in dependencies)
            {
                DartProjectDependency d = DartProjectDependencyExtension.FromYamlNode(dependency);

                if (d != null)
                {
                    dartDependencies.Add(d);
                }
            }

            return(dartDependencies);
        }
Example #10
0
            public void AssignAnchors(YamlDocument document)
            {
                existingAnchors.Clear();
                visitedNodes.Clear();

                document.Accept(this);

                Random random = new Random();

                foreach (var visitedNode in visitedNodes)
                {
                    if (visitedNode.Value)
                    {
                        string anchor;
                        do
                        {
                            anchor = random.Next().ToString(CultureInfo.InvariantCulture);
                        } while (existingAnchors.Contains(anchor));
                        existingAnchors.Add(anchor);

                        visitedNode.Key.Anchor = anchor;
                    }
                }
            }
            public void AssignAnchors(YamlDocument document)
            {
                existingAnchors.Clear();
                visitedNodes.Clear();

                document.Accept(this);

                Random random = new Random();
                foreach (var visitedNode in visitedNodes)
                {
                    if (visitedNode.Value)
                    {
                        string anchor;
                        do
                        {
                            anchor = random.Next().ToString(CultureInfo.InvariantCulture);
                        } while (existingAnchors.Contains(anchor));
                        existingAnchors.Add(anchor);

                        visitedNode.Key.Anchor = anchor;
                    }
                }
            }
Example #12
0
        static void CheckPubspecDocument(YamlDocument doc, DartProjectType type)
        {
            // Exists "name"
            YamlScalarNode name = doc.GetScalarNode(new[] { _nameYaml });

            if (name == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_nameYaml}' !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "description"
            YamlScalarNode description = doc.GetScalarNode(new[] { _descriptionYaml });

            if (description == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_descriptionYaml}' !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "author"
            YamlScalarNode author = doc.GetScalarNode(new[] { _authorYaml });

            if (author == null && type == DartProjectType.Package)
            {
                throw new DartProjectException($"Dart project error: missing '{_authorYaml}' !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "homepage"
            YamlScalarNode homepage = doc.GetScalarNode(new[] { _homepageYaml });

            if (homepage == null && type == DartProjectType.Package)
            {
                throw new DartProjectException($"Dart project error: missing '{_homepageYaml}' !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "version"
            YamlScalarNode version = doc.GetScalarNode(new[] { _versionYaml });

            if (version == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_versionYaml}' !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "dependencies"
            YamlMappingNode dependencies = doc.GetMappingNode(new[] { _dependeciesYaml });

            if (dependencies == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_dependeciesYaml}' section !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "dev_dependencies"
            YamlMappingNode devDependencies = doc.GetMappingNode(new[] { _devDependeciesYaml });

            if (devDependencies == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_devDependeciesYaml}' section !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "environment"
            YamlMappingNode environment = doc.GetMappingNode(new[] { _environmentYaml });

            if (environment == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_environmentYaml}' section !!!", DartProjectError.PubspecInvalidFormat);
            }

            // Exists "sdk"
            YamlScalarNode sdk = doc.GetScalarNode(new[] { _environmentYaml, _sdkYaml });

            if (sdk == null)
            {
                throw new DartProjectException($"Dart project error: missing '{_sdkYaml}' section !!!", DartProjectError.PubspecInvalidFormat);
            }
        }
Example #13
0
 /// <summary>
 /// Called after this object finishes visiting a <see cref="YamlDocument"/>.
 /// </summary>
 /// <param name="document">
 /// The <see cref="YamlDocument"/> that has been visited.
 /// </param>
 protected virtual void Visited(YamlDocument document)
 {
     // Do nothing.
 }
 protected override void Visit(YamlDocument document)
 {
     WriteIndent();
     Console.WriteLine("Visit(YamlDocument)");
     ++indent;
 }
Example #15
0
 void IYamlVisitor.Visit(YamlDocument document)
 {
     Visit(document);
     VisitChildren(document);
     Visited(document);
 }
Example #16
0
		/// <summary>
		/// Called after this object finishes visiting a <see cref="YamlDocument"/>.
		/// </summary>
		/// <param name="document">
		/// The <see cref="YamlDocument"/> that has been visited.
		/// </param>
		protected virtual void Visited (YamlDocument document)
		{
			// Do nothing.
		}
Example #17
0
		void IYamlVisitor.Visit (YamlDocument document)
		{
			Visit(document);
			VisitChildren(document);
			Visited(document);
		}
Example #18
0
		/// <summary>
		/// Visits every child of a <see cref="YamlDocument"/>.
		/// </summary>
		/// <param name="document">
		/// The <see cref="YamlDocument"/> that is being visited.
		/// </param>
		protected virtual void VisitChildren(YamlDocument document) {
			if(document.RootNode != null) {
				document.RootNode.Accept(this);
			}
		}
Example #19
0
 /// <summary>
 /// Returns the path of the iOS Framework created when building a Flutter 1.* module with Flutter.
 /// </summary>
 public static string GetIosFrameworkPath(string flutterFolder, YamlDocument pubspecFile, FlutterModuleBuildConfig buildConfig)
 {
     return(GetIosFrameworkPathCore(flutterFolder, pubspecFile, buildConfig, false));
 }