示例#1
0
        /// <summary>
        /// Adds a new required JAR file and resolves dependencies
        /// </summary>
        /// <param name="PackageName">Name of the package the JAR belongs to in repository</param>
        /// <param name="BaseName">Directory in repository containing the JAR</param>
        /// <param name="Version">Version of the AAR to use</param>
        public void AddNewJAR(string PackageName, string BaseName, string Version)
        {
            string BasePath = FindPackageFile(PackageName, BaseName, Version);

            if (BasePath == null)
            {
                Log.TraceError("AAR: Unable to find package {0}!", PackageName + "/" + BaseName);
                return;
            }
            string BaseFilename = Path.Combine(BasePath, BaseName + "-" + Version);

            // Check if already added
            uint NewVersionValue = GetVersionValue(Version);

            for (int JARIndex = 0; JARIndex < JARList.Count; JARIndex++)
            {
                if (JARList[JARIndex].BaseName == BaseName)
                {
                    // Is it the same version or older?  ignore if so
                    uint EntryVersionValue = GetVersionValue(JARList[JARIndex].Version);
                    if (NewVersionValue <= EntryVersionValue)
                    {
                        return;
                    }

                    Log.TraceInformation("AAR: {0}: {1} newer than {2}", JARList[JARIndex].BaseName, Version, JARList[JARIndex].Version);

                    // This is a newer version; remove old one
                    JARList.RemoveAt(JARIndex);
                    break;
                }
            }

            //Log.TraceInformation("JAR: {0}", BaseName);
            AndroidAAREntry AAREntry = new AndroidAAREntry(BaseName, Version, BaseFilename);

            JARList.Add(AAREntry);

            // Check for dependencies
            XDocument DependsXML;
            string    DependencyFilename = BaseFilename + ".pom";

            if (File.Exists(DependencyFilename))
            {
                try
                {
                    DependsXML = XDocument.Load(DependencyFilename);
                }
                catch (Exception e)
                {
                    Log.TraceError("AAR Dependency file {0} parsing error! {1}", DependencyFilename, e);
                    return;
                }
            }
            else
            {
                Log.TraceError("AAR: Dependency file {0} missing!", DependencyFilename);
                return;
            }

            string NameSpace      = DependsXML.Root.Name.NamespaceName;
            XName  DependencyName = XName.Get("dependency", NameSpace);
            XName  GroupIdName    = XName.Get("groupId", NameSpace);
            XName  ArtifactIdName = XName.Get("artifactId", NameSpace);
            XName  VersionName    = XName.Get("version", NameSpace);
            XName  ScopeName      = XName.Get("scope", NameSpace);
            XName  TypeName       = XName.Get("type", NameSpace);

            foreach (XElement DependNode in DependsXML.Descendants(DependencyName))
            {
                string DepGroupId    = GetElementValue(DependNode, GroupIdName, "");
                string DepArtifactId = GetElementValue(DependNode, ArtifactIdName, "");
                string DepVersion    = CleanupVersion(DependencyFilename + "." + DepGroupId + "." + DepArtifactId, GetElementValue(DependNode, VersionName, ""));
                string DepScope      = GetElementValue(DependNode, ScopeName, "compile");
                string DepType       = GetElementValue(DependNode, TypeName, "jar");

                //Log.TraceInformation("Dependency: {0} {1} {2} {3} {4}", DepGroupId, DepArtifactId, DepVersion, DepScope, DepType);

                // ignore test scope
                if (DepScope == "test")
                {
                    continue;
                }

                if (DepType == "aar")
                {
                    AddNewAAR(DepGroupId, DepArtifactId, DepVersion);
                }
                else if (DepType == "jar")
                {
                    AddNewJAR(DepGroupId, DepArtifactId, DepVersion);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Adds a new required AAR file and resolves dependencies
        /// </summary>
        /// <param name="PackageName">Name of the package the AAR belongs to in repository</param>
        /// <param name="BaseName">Directory in repository containing the AAR</param>
        /// <param name="Version">Version of the AAR to use</param>
        public void AddNewAAR(string PackageName, string BaseName, string Version)
        {
            string BasePath = FindPackageFile(PackageName, BaseName, Version);

            if (BasePath == null)
            {
                Log.TraceError("AAR: Unable to find package {0}!", PackageName + "/" + BaseName);
                return;
            }
            string BaseFilename = Path.Combine(BasePath, BaseName + "-" + Version);

            // Check if already added
            for (int AARIndex = 0; AARIndex < AARList.Count; AARIndex++)
            {
                if (AARList[AARIndex].BaseName == BaseName)
                {
                    // Is it the same version?
                    if (AARList[AARIndex].Version == Version)
                    {
                        return;
                    }

                    // Ignore if older version
                    string[] EntryVersionParts = AARList[AARIndex].Version.Split('.');
                    string[] NewVersionParts   = Version.Split('.');
                    for (int Index = 0; Index < EntryVersionParts.Length; Index++)
                    {
                        int EntryVersionInt = 0;
                        if (int.TryParse(EntryVersionParts[Index], out EntryVersionInt))
                        {
                            int NewVersionInt = 0;
                            if (int.TryParse(NewVersionParts[Index], out NewVersionInt))
                            {
                                if (NewVersionInt < EntryVersionInt)
                                {
                                    return;
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            return;
                        }
                    }

                    Log.TraceInformation("AAR: {0}: {1} newer than {2}", AARList[AARIndex].BaseName, Version, AARList[AARIndex].Version);

                    // This is a newer version; remove old one
                    // @TODO: be smarter about dependency cleanup (newer AAR might not need older dependencies)
                    AARList.RemoveAt(AARIndex);
                    break;
                }
            }

            //Log.TraceInformation("AAR: {0}", BaseName);
            AndroidAAREntry AAREntry = new AndroidAAREntry(BaseName, Version, BaseFilename);

            AARList.Add(AAREntry);

            // Check for dependencies
            XDocument DependsXML;
            string    DependencyFilename = BaseFilename + ".pom";

            if (File.Exists(DependencyFilename))
            {
                try
                {
                    DependsXML = XDocument.Load(DependencyFilename);
                }
                catch (Exception e)
                {
                    Log.TraceError("AAR Dependency file {0} parsing error! {1}", DependencyFilename, e);
                    return;
                }
            }
            else
            {
                Log.TraceError("AAR: Dependency file {0} missing!", DependencyFilename);
                return;
            }

            string NameSpace      = DependsXML.Root.Name.NamespaceName;
            XName  DependencyName = XName.Get("dependency", NameSpace);
            XName  GroupIdName    = XName.Get("groupId", NameSpace);
            XName  ArtifactIdName = XName.Get("artifactId", NameSpace);
            XName  VersionName    = XName.Get("version", NameSpace);
            XName  ScopeName      = XName.Get("scope", NameSpace);
            XName  TypeName       = XName.Get("type", NameSpace);

            foreach (XElement DependNode in DependsXML.Descendants(DependencyName))
            {
                string DepGroupId    = GetElementValue(DependNode, GroupIdName, "");
                string DepArtifactId = GetElementValue(DependNode, ArtifactIdName, "");
                string DepVersion    = GetElementValue(DependNode, VersionName, "");
                string DepScope      = GetElementValue(DependNode, ScopeName, "compile");
                string DepType       = GetElementValue(DependNode, TypeName, "jar");

                //Log.TraceInformation("Dependency: {0} {1} {2} {3} {4}", DepGroupId, DepArtifactId, DepVersion, DepScope, DepType);

                // ignore test scope
                if (DepScope == "test")
                {
                    continue;
                }

                if (DepType == "aar")
                {
                    // Add dependency
                    AAREntry.AddDependency(DepArtifactId, DepVersion);

                    AddNewAAR(DepGroupId, DepArtifactId, DepVersion);
                }
                else
                if (DepType == "jar")
                {
                    AddNewJAR(DepGroupId, DepArtifactId, DepVersion);
                }
            }
        }
        /// <summary>
        /// Adds a new required AAR file and resolves dependencies
        /// </summary>
        /// <param name="PackageName">Name of the package the AAR belongs to in repository</param>
        /// <param name="BaseName">Directory in repository containing the AAR</param>
        /// <param name="Version">Version of the AAR to use</param>
        public void AddNewAAR(string PackageName, string BaseName, string Version)
        {
            string BasePath = FindPackageFile(PackageName, BaseName, Version);

            if (BasePath == null)
            {
                Log.TraceError("AAR: Unable to find package {0}!", PackageName + "/" + BaseName);
                return;
            }
            string BaseFilename = Path.Combine(BasePath, BaseName + "-" + Version);

            // Do we already have this dependency?
            if (AARList.Contains(BaseFilename))
            {
                return;
            }

            //Log.TraceInformation("AAR: {0}", BaseName);
            AARList.Add(BaseFilename);

            // Check for dependencies
            XDocument DependsXML;
            string    DependencyFilename = BaseFilename + ".pom";

            if (File.Exists(DependencyFilename))
            {
                try
                {
                    DependsXML = XDocument.Load(DependencyFilename);
                }
                catch (Exception e)
                {
                    Log.TraceError("AAR Dependency file {0} parsing error! {1}", DependencyFilename, e);
                    return;
                }
            }
            else
            {
                Log.TraceError("AAR: Dependency file {0} missing!", DependencyFilename);
                return;
            }

            string NameSpace      = DependsXML.Root.Name.NamespaceName;
            XName  DependencyName = XName.Get("dependency", NameSpace);
            XName  GroupIdName    = XName.Get("groupId", NameSpace);
            XName  ArtifactIdName = XName.Get("artifactId", NameSpace);
            XName  VersionName    = XName.Get("version", NameSpace);
            XName  ScopeName      = XName.Get("scope", NameSpace);
            XName  TypeName       = XName.Get("type", NameSpace);

            foreach (XElement DependNode in DependsXML.Descendants(DependencyName))
            {
                string DepGroupId    = GetElementValue(DependNode, GroupIdName, "");
                string DepArtifactId = GetElementValue(DependNode, ArtifactIdName, "");
                string DepVersion    = GetElementValue(DependNode, VersionName, "");
                string DepScope      = GetElementValue(DependNode, ScopeName, "compile");
                string DepType       = GetElementValue(DependNode, TypeName, "jar");

                //Log.TraceInformation("Dependency: {0} {1} {2} {3} {4}", DepGroupId, DepArtifactId, DepVersion, DepScope, DepType);

                if (DepType == "aar")
                {
                    AddNewAAR(DepGroupId, DepArtifactId, DepVersion);
                }
                else
                if (DepType == "jar")
                {
                    AddNewJAR(DepGroupId, DepArtifactId, DepVersion);
                }
            }
        }