Author: brett
Date: Wed Jan 4 08:53:18 2012
New Revision: 1227085
URL: http://svn.apache.org/viewvc?rev=1227085&view=rev
Log:
[NPANDAY-521] make add artifact form use central repository if nothing is
configured
Modified:
incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Digest/Model/Reference.cs
incubator/npanday/trunk/dotnet/assemblies/NPanday.Utils/src/main/csharp/SettingsUtil.cs
incubator/npanday/trunk/dotnet/assemblies/NPanday.VisualStudio.Addin/src/main/csharp/AddArtifactsForm.cs
Modified:
incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Digest/Model/Reference.cs
URL:
http://svn.apache.org/viewvc/incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Digest/Model/Reference.cs?rev=1227085&r1=1227084&r2=1227085&view=diff
==============================================================================
---
incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Digest/Model/Reference.cs
(original)
+++
incubator/npanday/trunk/dotnet/assemblies/NPanday.ProjectImporter/Engine/src/main/csharp/Digest/Model/Reference.cs
Wed Jan 4 08:53:18 2012
@@ -159,64 +159,10 @@ namespace NPanday.ProjectImporter.Digest
{
try
{
- Settings settings =
SettingsUtil.ReadSettings(SettingsUtil.GetUserSettingsPath());
-
- List<string> activeProfiles = new List<string>();
- if (settings.activeProfiles != null)
- {
- activeProfiles.AddRange(settings.activeProfiles);
- }
-
- Dictionary<string, string> mirrors = new Dictionary<string,
string>();
-
- if (settings.mirrors != null)
- {
- foreach (Mirror mirror in settings.mirrors)
- {
- string id = mirror.mirrorOf;
- if (id.StartsWith("external:*"))
- {
- id = "*";
- }
- // TODO: support '!' syntax
- mirrors.Add(id, mirror.url);
- }
- }
-
- Dictionary<string, string> repos = new Dictionary<string,
string>();
- if (settings.profiles != null)
- {
- foreach (Profile profile in settings.profiles)
- {
- if (activeProfiles.Contains(profile.id) &&
profile.repositories != null)
- {
- foreach (Repository repo in profile.repositories)
- {
- repos.Add(repo.id, repo.url);
- }
- }
- }
- }
-
- // Add maven central, as Maven itself does!
- //
https://github.com/apache/maven-3/blob/trunk/maven-core/src/main/java/org/apache/maven/repository/RepositorySystem.java
- if (!repos.ContainsKey("central"))
- {
- repos.Add("central",
"http://repo.maven.apache.org/maven2");
- }
-
- // TODO: sustain correct ordering from settings.xml
+ Dictionary<string, string> repos =
SettingsUtil.GetSettingsRepositories();
foreach (string id in repos.Keys)
{
string url = repos[id];
- if (mirrors.ContainsKey(id))
- {
- url = mirrors[id];
- }
- if (mirrors.ContainsKey("*"))
- {
- url = mirrors["*"];
- }
ArtifactContext artifactContext = new ArtifactContext();
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=1227085&r1=1227084&r2=1227085&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 Jan 4 08:53:18 2012
@@ -594,6 +594,73 @@ namespace NPanday.Utils
return "npanday.repo." + ctr;
}
+ public static Dictionary<string,string> GetSettingsRepositories()
+ {
+ Settings settings = ReadSettings(GetUserSettingsPath());
+
+ List<string> activeProfiles = new List<string>();
+ if (settings.activeProfiles != null)
+ {
+ activeProfiles.AddRange(settings.activeProfiles);
+ }
+
+ Dictionary<string, string> mirrors = new Dictionary<string,
string>();
+
+ if (settings.mirrors != null)
+ {
+ foreach (Mirror mirror in settings.mirrors)
+ {
+ string id = mirror.mirrorOf;
+ if (id.StartsWith("external:*"))
+ {
+ id = "*";
+ }
+ // TODO: support '!' syntax
+ mirrors.Add(id, mirror.url);
+ }
+ }
+
+ Dictionary<string, string> repos = new Dictionary<string,
string>();
+ if (settings.profiles != null)
+ {
+ foreach (Profile profile in settings.profiles)
+ {
+ if (activeProfiles.Contains(profile.id) &&
profile.repositories != null)
+ {
+ foreach (Repository repo in profile.repositories)
+ {
+ if (!repos.ContainsKey(repo.id))
+ {
+ repos.Add(repo.id, repo.url);
+ }
+ }
+ }
+ }
+ }
+
+ // Add maven central, as Maven itself does!
+ //
https://github.com/apache/maven-3/blob/trunk/maven-core/src/main/java/org/apache/maven/repository/RepositorySystem.java
+ if (!repos.ContainsKey("central"))
+ {
+ repos.Add("central", "http://repo.maven.apache.org/maven2");
+ }
+
+ // TODO: sustain correct ordering from settings.xml
+ Dictionary<string, string> newRepos = new Dictionary<string,
string>(repos);
+ foreach (string id in repos.Keys)
+ {
+ if (mirrors.ContainsKey(id))
+ {
+ newRepos[id] = mirrors[id];
+ }
+ if (mirrors.ContainsKey("*"))
+ {
+ newRepos[id] = mirrors["*"];
+ }
+ }
+ return newRepos;
+ }
+
public static Profile GetDefaultProfile(Settings settings)
{
return GetDefaultProfile(settings, false);
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=1227085&r1=1227084&r2=1227085&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 Jan 4 08:53:18 2012
@@ -59,8 +59,7 @@ namespace NPanday.VisualStudio.Addin
private string settingsPath;
private Settings settings;
- private NPanday.Model.Settings.Profile defaultProfile;
- private NPanday.Model.Settings.Repository selectedRepo;
+ private string selectedRepoUrl;
private string prevSelectedRepoUrl = string.Empty;
/// <summary>
@@ -127,27 +126,10 @@ namespace NPanday.VisualStudio.Addin
return;
}
- defaultProfile = getDefaultProfile();
- selectedRepo = getDefaultRepository();
-
- if (selectedRepo == null || string.IsNullOrEmpty(selectedRepo.url))
- {
- MessageBox.Show("Remote repository not yet set: Please set
your Remote Repository.", "Repository Configuration", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
- }
- else
- {
- remoteTreeView_Refresh();
- }
-
- if (selectedRepo == null)
- {
- repoCombo_Refresh(null);
- }
- else
- {
- repoCombo_Refresh(selectedRepo.url);
- }
+ selectedRepoUrl = getDefaultRepositoryUrl();
+ remoteTreeView_Refresh();
+ repoCombo_Refresh(selectedRepoUrl);
}
private void localListView_Refresh()
@@ -168,13 +150,13 @@ namespace NPanday.VisualStudio.Addin
SetUnsafeHttpHeaderParsing();
treeView1.Nodes.Clear();
- List<TreeNode> treeNodes = getNodesFor(selectedRepo.url);
+ List<TreeNode> treeNodes = getNodesFor(selectedRepoUrl);
treeView1.Nodes.AddRange(treeNodes.ToArray());
- prevSelectedRepoUrl = selectedRepo.url;
+ prevSelectedRepoUrl = selectedRepoUrl;
}
- private bool isSelectedRepoModified()
+ private bool isSelectedRepoModified(NPanday.Model.Settings.Repository
selectedRepo)
{
if (selectedRepo == null)
{
@@ -188,6 +170,7 @@ namespace NPanday.VisualStudio.Addin
}
// check if URL is already in NPanday.id profile
+ NPanday.Model.Settings.Profile defaultProfile =
getDefaultProfile();
if (defaultProfile != null)
{
foreach (NPanday.Model.Settings.Repository repo in
defaultProfile.repositories)
@@ -507,7 +490,7 @@ namespace NPanday.VisualStudio.Addin
{
string uri = node.ArtifactUrl;
string paths;
- string repoUrl = selectedRepo.url;
+ string repoUrl = selectedRepoUrl;
if (node.IsFileSystem)
{
//Uri repoUri = new Uri(repoUrl);
@@ -597,13 +580,9 @@ namespace NPanday.VisualStudio.Addin
return;
}
- if (defaultProfile == null)
- {
- defaultProfile = getDefaultProfile();
- }
-
// add repository to profile
- selectedRepo =
SettingsUtil.AddRepositoryToProfile(defaultProfile, selectedUrl,
checkBoxRelease.Checked, checkBoxSnapshot.Checked);
+ NPanday.Model.Settings.Repository repo =
SettingsUtil.AddRepositoryToProfile(getDefaultProfile(), selectedUrl,
checkBoxRelease.Checked, checkBoxSnapshot.Checked);
+ selectedRepoUrl = selectedUrl;
// make NPanday.id profile active
SettingsUtil.AddActiveProfile(settings,
SettingsUtil.defaultProfileID);
@@ -641,10 +620,10 @@ namespace NPanday.VisualStudio.Addin
}
}
- private void repoCheckboxes_Refresh()
+ private void repoCheckboxes_Refresh(NPanday.Model.Settings.Repository
selectedRepo)
{
- checkBoxRelease.Checked = (selectedRepo.releases != null) ?
selectedRepo.releases.enabled : false;
- checkBoxSnapshot.Checked = (selectedRepo.snapshots != null) ?
selectedRepo.snapshots.enabled : false;
+ checkBoxRelease.Checked = (selectedRepo != null &&
selectedRepo.releases != null) ? selectedRepo.releases.enabled : true;
+ checkBoxSnapshot.Checked = (selectedRepo != null &&
selectedRepo.snapshots != null) ? selectedRepo.snapshots.enabled : false;
}
#region GUI Events
@@ -767,8 +746,9 @@ namespace NPanday.VisualStudio.Addin
private void RepoCombo_SelectedIndexChanged(object sender, EventArgs e)
{
- selectedRepo = getRepository(RepoCombo.Text);
- repoCheckboxes_Refresh();
+ NPanday.Model.Settings.Repository selectedRepo =
getRepository(RepoCombo.Text);
+ selectedRepoUrl = RepoCombo.Text;
+ repoCheckboxes_Refresh(selectedRepo);
}
private void artifactTabControl_SelectedIndexChanged(object sender,
EventArgs e)
@@ -786,33 +766,28 @@ namespace NPanday.VisualStudio.Addin
loadSettings();
}
- if (settings == null)
+ NPanday.Model.Settings.Repository selectedRepo;
+ if (selectedRepoUrl == null)
{
- MessageBox.Show("Sorry, but you cannot Access Remote
Repository without a Settings.xml file", "Repository Configuration",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
- artifactTabControl.SelectedIndex = 0;
+ selectedRepo = getRepositoryFromDefaultProfile();
+ selectedRepoUrl = selectedRepo.url;
}
else
{
- if (selectedRepo == null)
- {
- selectedRepo = getDefaultRepository();
- }
+ selectedRepo = getRepository(selectedRepoUrl);
+ }
- if (selectedRepo != null)
- {
- if (isSelectedRepoModified())
- {
- executeRepoUpdate();
- }
+ if (isSelectedRepoModified(selectedRepo))
+ {
+ executeRepoUpdate();
+ }
- if (prevSelectedRepoUrl != selectedRepo.url)
- {
- remoteTreeView_Refresh();
- }
- treeView1.Focus();
- addArtifact.Show();
- }
+ if (prevSelectedRepoUrl != selectedRepoUrl)
+ {
+ remoteTreeView_Refresh();
}
+ treeView1.Focus();
+ addArtifact.Show();
}
else
{
@@ -915,13 +890,9 @@ namespace NPanday.VisualStudio.Addin
return null;
}
- if (defaultProfile == null)
- {
- defaultProfile = getDefaultProfile();
- }
-
// extract from NPanday repositories first
NPanday.Model.Settings.Repository repo;
+ NPanday.Model.Settings.Profile defaultProfile =
getDefaultProfile();
if (defaultProfile != null)
{
repo = SettingsUtil.GetRepositoryFromProfile(defaultProfile,
url);
@@ -935,20 +906,24 @@ namespace NPanday.VisualStudio.Addin
return SettingsUtil.GetRepositoryByUrl(settings, url);
}
- private NPanday.Model.Settings.Repository getDefaultRepository()
+ private NPanday.Model.Settings.Repository
getRepositoryFromDefaultProfile()
{
- if (defaultProfile == null)
- {
- defaultProfile = getDefaultProfile();
- }
+ NPanday.Model.Settings.Profile defaultProfile =
getDefaultProfile();
- if (defaultProfile != null && defaultProfile.repositories.Length >
0)
+ if (defaultProfile != null && defaultProfile.repositories != null
&& defaultProfile.repositories.Length > 0)
{
return defaultProfile.repositories[0];
}
+
return null;
}
+ private string getDefaultRepositoryUrl()
+ {
+ NPanday.Model.Settings.Repository repo =
getRepositoryFromDefaultProfile();
+ return repo != null ? repo.url :
SettingsUtil.GetSettingsRepositories()["central"];
+ }
+
#endregion
}
}