Ejemplo n.º 1
0
        private static SoftwareArtefact MapMetricToArtefact(SoftwareArtefact artefact,
                                                            List <SonarQubeComponent> components)
        {
            foreach (var a in artefact.Traverse(a => a.Children))
            {
                if (a.Children.Count != 0)
                {
                    continue;
                }
                var component = components.Find(c => c.key == a.Key);

                if (component == null)
                {
                    continue;
                }
                foreach (var metric in component.measures)
                {
                    a.Metrics = new List <Metric>
                    {
                        new Metric
                        {
                            Key   = metric.metric,
                            Value = (float)Math.Round(metric.value)
                        }
                    };
                }
            }

            return(artefact);
        }
Ejemplo n.º 2
0
        private IEnumerator ComposeArtefacts(string sonarQubeComponentKey)
        {
            totalCalls++;
            // Print key to see progress
            Debug.Log(sonarQubeComponentKey);
            var coroutine = this.StartCoroutine <SonarQubeTree>(GetSonarQubeTree(sonarQubeComponentKey));

            yield return(coroutine.coroutine);

            var tree = coroutine.value;

            // For now in case of an internal SonarQube error, the requested component is discarded comletely
            if (tree == null)
            {
                yield break;
            }

            successfullCalls++;

            // Map the requested component to our abstract software model
            SoftwareArtefact element = MapSonarQubeComponentToSoftwareArtefact(tree.baseComponent);

            // Store child coroutines to be able to join them
            List <Coroutine <SoftwareArtefact> > childCoroutines = tree.components
                                                                   .Select(component => this.StartCoroutine <SoftwareArtefact>(ComposeArtefacts(component.key))).ToList();

            yield return(CoroutineUtils.WaitForAll(childCoroutines));

            element.Children = childCoroutines.Select(c => c.value).Where(value => value != null).ToList();

            // Element and all children are finished
            yield return(element);
        }
Ejemplo n.º 3
0
        public IEnumerator AddMetrics(SoftwareArtefact artefact)
        {
            var baseComponentKey = artefact.Key;

            var components = new List <SonarQubeComponent>();

            var page = 1;

            while (true)
            {
                var coroutine =
                    this.StartCoroutine <SonarQubeTree>(GetSonarQubeMeasures(baseComponentKey, page.ToString()));
                yield return(coroutine.coroutine);

                var sonarQubeTree = coroutine.value;

                if (sonarQubeTree == null)
                {
                    continue;
                }
                components.AddRange(sonarQubeTree.components);

                page++;

                if (page > Math.Ceiling((double)sonarQubeTree.paging.total / sonarQubeTree.paging.pageSize))
                {
                    break;
                }
            }

            yield return(MapMetricToArtefact(artefact, components));
        }
        public static Node Map(SoftwareArtefact artefact)
        {
            if (artefact == null)
            {
                return(null);
            }

            if (artefact.Children?.Count > 0)
            {
                return(new InnerNode
                {
                    Name = artefact.Name,
                    Key = artefact.Key,
                    Edge = null,
                    Children = artefact.Children.Select(Map).ToList(),
                    Data = new List <InnerNodeData>()
                });
            }


            if (artefact.Children == null || artefact.Children.Count == 0)
            {
                return(new Leaf
                {
                    Name = artefact.Name,
                    Key = artefact.Key,
                    Edge = null,
                    Data = artefact.Metrics?.Select(a => new LeafData
                    {
                        Key = a.Key,
                        Value = a.Value
                    }).ToList()
                });
            }

            return(null);
        }