Пример #1
0
        private void ParseExports(OSGiProject osgiProject, JSONObject fieldExports, int bundleIndex)
        {
            if (fieldExports == null)
            {
                return;
            }

            List <Vector2> exportIndices =
                _referenceResolver.ResolvePackageFragmentReferenceList(fieldExports.list);

            foreach (Vector2 index in exportIndices)
            {
                Package resolvedFragment = osgiProject.GetPackage(index);
                resolvedFragment.IsExported = true;
                osgiProject.Bundles[bundleIndex].ExportedPackages.Add(resolvedFragment);
            }
        }
Пример #2
0
        private void ParseImports(OSGiProject osgiProject, JSONObject fieldImports, int bundleIndex)
        {
            if (fieldImports == null)
            {
                return;
            }

            List <Vector2> importIndices =
                _referenceResolver.ResolvePackageFragmentReferenceList(fieldImports.list);

            foreach (Vector2 index in importIndices)
            {
                Package resolvedFragment = osgiProject.GetPackage(index);
                if (string.Compare(osgiProject.Bundles[bundleIndex].Name, resolvedFragment.Bundle.Name) != 0)
                {
                    osgiProject.Bundles[bundleIndex].ImportedPackages.Add(resolvedFragment);

                    // TODO: Refactor.
                    List <GraphVertex> allVertices  = osgiProject.DependencyGraph.Vertices.ToList();
                    Bundle             sourceBundle = osgiProject.Bundles[bundleIndex];
                    Bundle             targetBundle = osgiProject.Bundles[(int)index.x];

                    GraphVertex vert1 = allVertices.Find(v => (string.Equals(v.Name, sourceBundle.Name)));
                    GraphVertex vert2 = allVertices.Find(v => (string.Equals(v.Name, targetBundle.Name)));

                    if (vert1 == null)
                    {
                        vert1 = new GraphVertex(sourceBundle.Name);
                    }
                    if (vert2 == null)
                    {
                        vert2 = new GraphVertex(targetBundle.Name);
                    }

                    osgiProject.DependencyGraph.AddVertex(vert1);
                    osgiProject.DependencyGraph.AddVertex(vert2);

                    GraphEdge edge;
                    bool      edgePresent = osgiProject.DependencyGraph.TryGetEdge(vert1, vert2, out edge);
                    if (edgePresent && osgiProject.DependencyGraph.AllowParallelEdges)
                    {
                        edge.Weight++;
                    }
                    else
                    {
                        edge = new GraphEdge(vert1, vert2);
                        osgiProject.DependencyGraph.AddEdge(edge);
                    }

                    GraphEdge opposingEdge;
                    float     bidirectionalEdgeWeight = edge.Weight;
                    bool      oppEdgePresent          = osgiProject.DependencyGraph.TryGetEdge(vert2, vert1, out opposingEdge);
                    if (oppEdgePresent)
                    {
                        bidirectionalEdgeWeight += opposingEdge.Weight;
                    }

                    if (bidirectionalEdgeWeight > osgiProject.MaximalImportCount)
                    {
                        osgiProject.MaximalImportCount = (int)bidirectionalEdgeWeight;
                    }

                    if (bidirectionalEdgeWeight > osgiProject.MaximalImportCount)
                    {
                        osgiProject.MaximalImportCount = (int)bidirectionalEdgeWeight;
                    }
                }
            }
        }