You are viewing a plain text version of this content. The canonical link for it is here.
Posted to npanday-commits@incubator.apache.org by br...@apache.org on 2013/03/06 16:22:59 UTC

svn commit: r1453403 - in /incubator/npanday/trunk/dotnet/assemblies: NPanday.Utils/src/main/csharp/SettingsUtil.cs NPanday.Utils/src/test/csharp/SettingsUtilTest.cs NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs

Author: brett
Date: Wed Mar  6 16:22:59 2013
New Revision: 1453403

URL: http://svn.apache.org/r1453403
Log:
[NPANDAY-572] ensure repository is used

Consolidate to a single repository in the NPanday.id profile, and change any
relevant mirror entries to the specified URL also.

Modified:
    incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/SettingsUtil.cs
    incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/test/csharp/SettingsUtilTest.cs
    incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs

Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/SettingsUtil.cs
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/SettingsUtil.cs?rev=1453403&r1=1453402&r2=1453403&view=diff
==============================================================================
--- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/SettingsUtil.cs (original)
+++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/SettingsUtil.cs Wed Mar  6 16:22:59 2013
@@ -288,6 +288,15 @@ namespace NPanday.Utils
                 }
             }
 
+            if (settings.mirrors != null)
+            {
+                foreach (Mirror mirror in settings.mirrors)
+                {
+                    // assumes you only changed url of existing ones
+                    settingsXmlDoc.SelectSingleNode("//settings/mirrors/mirror[id = '" + mirror.id + "']/url").InnerText = mirror.url;
+                }
+            }
+
             settingsXmlDoc.Save(path);
         }
 
@@ -504,7 +513,7 @@ namespace NPanday.Utils
         /// <param name="isSnapshotEnabled">True if snapshot is enabled</param>
         /// <param name="settings">The settings</param>
         /// <returns>The repository</returns>
-        public static Repository AddRepositoryToProfile(Profile profile, string url, bool isReleaseEnabled, bool isSnapshotEnabled)
+        public static Repository SetProfileRepository(Profile profile, string url, bool isReleaseEnabled, bool isSnapshotEnabled)
         {
             Repository repository = GetRepositoryFromProfile(profile, url);
 
@@ -514,18 +523,8 @@ namespace NPanday.Utils
                 repository.url = url;
                 UpdateRepository(profile, repository, isReleaseEnabled, isSnapshotEnabled);
 
-                // add repository to profile
-                if (profile.repositories == null)
-                {
-                    profile.repositories = new Repository[] { repository };
-                }
-                else
-                {
-                    List<Repository> repositories = new List<Repository>();
-                    repositories.AddRange(profile.repositories);
-                    repositories.Insert(0, repository);
-                    profile.repositories = repositories.ToArray();
-                }
+                // set repository on profile
+                profile.repositories = new Repository[] { repository };
             }
             return repository;
         }
@@ -568,32 +567,11 @@ namespace NPanday.Utils
             repository.snapshots = snapshotsPolicy;
             if (repository.id == null)
             {
-                repository.id = generateRepositoryId(profile);
+                repository.id = "npanday.repo";
             }
         }
         #endregion
 
-        private static string generateRepositoryId(Profile profile)
-        {
-            int ctr = 0;
-            if (profile.repositories != null)
-            {
-                foreach (Repository repo in profile.repositories)
-                {
-                    if (repo.id != null && repo.id.StartsWith("npanday.repo."))
-                    {
-                        int index = int.Parse(repo.id.Substring(13));
-
-                        if (index >= ctr)
-                        {
-                            ctr = index + 1;
-                        }
-                    }
-                }
-            }
-            return "npanday.repo." + ctr;
-        }
-
         public static Dictionary<string,string> GetSettingsRepositories()
         {
             Settings settings = ReadSettings(GetUserSettingsPath());
@@ -670,6 +648,21 @@ namespace NPanday.Utils
         {
             return GetProfile(settings, SettingsUtil.defaultProfileID, create);
         }
+
+        public static void SetMirrorUrl(Settings settings, string selectedUrl)
+        {
+            // set the mirror, if it already exists
+            if (settings.mirrors != null)
+            {
+                foreach (Mirror mirror in settings.mirrors)
+                {
+                    if (mirror.mirrorOf.Contains("central") || mirror.mirrorOf.EndsWith("*"))
+                    {
+                        mirror.url = selectedUrl;
+                    }
+                }
+            }
+        }
     }
 
     #endregion

Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/test/csharp/SettingsUtilTest.cs
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/test/csharp/SettingsUtilTest.cs?rev=1453403&r1=1453402&r2=1453403&view=diff
==============================================================================
--- incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/test/csharp/SettingsUtilTest.cs (original)
+++ incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/test/csharp/SettingsUtilTest.cs Wed Mar  6 16:22:59 2013
@@ -52,7 +52,7 @@ namespace NPanday.Utils_Test
 
             Profile profile = SettingsUtil.GetDefaultProfile(_settings, true);
             Assert.IsNotNull(profile);
-            SettingsUtil.AddRepositoryToProfile(profile, _repoUrl1, true, false);
+            SettingsUtil.SetProfileRepository(profile, _repoUrl1, true, false);
 
             Assert.AreEqual(1, _settings.profiles.Length, "Settings does not contain a profile");
 
@@ -72,7 +72,7 @@ namespace NPanday.Utils_Test
             Profile profile = SettingsUtil.GetDefaultProfile(_settings, false);
             Assert.IsNotNull(profile);
 
-            SettingsUtil.AddRepositoryToProfile(profile, _repoUrl2, true, false);
+            SettingsUtil.SetProfileRepository(profile, _repoUrl2, true, false);
 
             Assert.AreEqual(1, _settings.profiles.Length, "Settings does not contain a profile");
             Assert.AreEqual(2, _settings.profiles[0].repositories.Length);

Modified: incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs?rev=1453403&r1=1453402&r2=1453403&view=diff
==============================================================================
--- incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs (original)
+++ incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs Wed Mar  6 16:22:59 2013
@@ -585,9 +585,12 @@ namespace NPanday.VisualStudio.Addin
                 }
 
                 // add repository to profile
-                NPanday.Model.Settings.Repository repo = SettingsUtil.AddRepositoryToProfile(getDefaultProfile(), selectedUrl, checkBoxRelease.Checked, checkBoxSnapshot.Checked);
+                NPanday.Model.Settings.Repository repo = SettingsUtil.SetProfileRepository(getDefaultProfile(), selectedUrl, checkBoxRelease.Checked, checkBoxSnapshot.Checked);
                 selectedRepoUrl = selectedUrl;
 
+                // set the mirror too
+                SettingsUtil.SetMirrorUrl(settings, selectedUrl);
+
                 // make NPanday.id profile active
                 SettingsUtil.AddActiveProfile(settings, SettingsUtil.defaultProfileID);