Skip to content

Commit

Permalink
BVS-24 - Enusre projects in VCS are checkout before being modified
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone committed Jul 5, 2017
1 parent e1204b7 commit 0c1733d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
13 changes: 13 additions & 0 deletions IceBuilder/DTEUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ public static IceBuilderProjectType IsIceBuilderEnabled(IVsProject project)
return IceBuilderProjectType.None;
}

public static bool EnsureFileIsCheckout(string path)
{
var sc = Package.Instance.DTE.SourceControl;
if(sc != null)
{
if(sc.IsItemUnderSCC(path) && !sc.IsItemCheckedOut(path))
{
return sc.CheckOutItem(path);
}
}
return true;
}

public static readonly Guid cppProjectGUID =
new Guid("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}");
public static readonly Guid cppStoreAppProjectGUID =
Expand Down
18 changes: 16 additions & 2 deletions IceBuilder/MSBuildUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static bool AddProjectFlavorIfNotExists(Microsoft.Build.Evaluation.Projec
{
if(property.Value.IndexOf(flavor) == -1)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
if(string.IsNullOrEmpty(property.Value))
{
property.Value = string.Format("{0};{1}", flavor, CSharpProjectGUI);
Expand All @@ -113,6 +114,7 @@ public static bool AddProjectFlavorIfNotExists(Microsoft.Build.Evaluation.Projec
}

// ProjectTypeGuids not present
DTEUtil.EnsureFileIsCheckout(project.FullPath);
project.Xml.AddProperty("ProjectTypeGuids", string.Format("{0};{1}", flavor, CSharpProjectGUI));
return true;
}
Expand All @@ -124,6 +126,7 @@ public static bool RemoveProjectFlavorIfExists(Microsoft.Build.Evaluation.Projec

if(property != null && property.Value.IndexOf(flavor) != -1)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
property.Value = property.Value.Replace(flavor, "").Trim(new char[] { ';' });
if(property.Value.Equals(CSharpProjectGUI, StringComparison.CurrentCultureIgnoreCase))
{
Expand Down Expand Up @@ -176,6 +179,7 @@ private static bool AddGlobalProperty(Microsoft.Build.Evaluation.Project project
p => p.Label.Equals("Globals", StringComparison.CurrentCultureIgnoreCase));
if(globals == null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
globals = project.Xml.AddPropertyGroup();
globals.Label = "Globals";
globals.Parent.RemoveChild(globals);
Expand All @@ -186,6 +190,7 @@ private static bool AddGlobalProperty(Microsoft.Build.Evaluation.Project project
p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
if(property == null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
property = globals.AddProperty(name, value);
return true;
}
Expand All @@ -198,6 +203,7 @@ public static bool EnsureIceBuilderImports(Microsoft.Build.Evaluation.Project pr
t => t.Name.Equals("EnsureIceBuilderImports", StringComparison.CurrentCultureIgnoreCase));
if(target == null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
target = project.Xml.AddTarget("EnsureIceBuilderImports");
target.BeforeTargets = "PrepareForBuild";

Expand Down Expand Up @@ -227,6 +233,7 @@ private static bool RemoveGlobalProperty(Microsoft.Build.Evaluation.Project proj
p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
if(property != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
globals.RemoveChild(property);
return true;
}
Expand All @@ -239,6 +246,7 @@ private static bool RemoveProperty(Microsoft.Build.Evaluation.Project project, s
p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase));
if(property != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
property.Parent.RemoveChild(property);
return true;
}
Expand All @@ -251,6 +259,7 @@ private static bool AddImportAfter(Microsoft.Build.Evaluation.Project project,
{
if(!HasImport(project, import))
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
ProjectImportElement props = project.Xml.CreateImportElement(import);
props.Condition = string.Format("Exists('{0}')", import);
project.Xml.InsertAfterChild(props, after);
Expand All @@ -265,6 +274,7 @@ private static bool UpdateImport(Microsoft.Build.Evaluation.Project project, str
p => p.Project.Equals(oldValue, StringComparison.CurrentCultureIgnoreCase));
if(import != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
import.Project = newValue;
import.Condition = string.Format("Exists('{0}')", newValue);
return true;
Expand All @@ -278,6 +288,7 @@ private static bool RemoveImport(Microsoft.Build.Evaluation.Project project, str
p => p.Project.Equals(import, StringComparison.CurrentCultureIgnoreCase));
if(element != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
if(element.Parent != null)
{
element.Parent.RemoveChild(element);
Expand Down Expand Up @@ -496,14 +507,14 @@ public static bool RemoveIceBuilderFromProject(Microsoft.Build.Evaluation.Projec
modified = RemoveCsharpGlobalProperties(project);
modified = RemoveImport(project, IceBuilderCSharpProps) || modified;
modified = RemoveImport(project, IceBuilderCSharpTargets) || modified;

RemoveProjectFlavorIfExists(project, IceBuilderProjectFlavorGUID);
modified = RemoveProjectFlavorIfExists(project, IceBuilderProjectFlavorGUID) || modified;
}

ProjectPropertyGroupElement group = project.Xml.PropertyGroups.FirstOrDefault(
g => g.Label.Equals("IceBuilder", StringComparison.CurrentCultureIgnoreCase));
if(group != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
group.Parent.RemoveChild(group);
}

Expand All @@ -514,6 +525,7 @@ public static bool RemoveIceBuilderFromProject(Microsoft.Build.Evaluation.Projec
t => t.Name.Equals("EnsureIceBuilderImports", StringComparison.CurrentCultureIgnoreCase));
if(target != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
if(target.Parent != null)
{
target.Parent.RemoveChild(target);
Expand All @@ -529,6 +541,7 @@ public static bool RemoveIceBuilderFromProject(Microsoft.Build.Evaluation.Projec

public static void SetProperty(Microsoft.Build.Evaluation.Project project, string label, string name, string value)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
ProjectPropertyGroupElement group = project.Xml.PropertyGroups.FirstOrDefault(
g => g.Label.Equals(label, StringComparison.CurrentCultureIgnoreCase));
if(group == null)
Expand Down Expand Up @@ -593,6 +606,7 @@ public static void SetIceHome(List<IVsProject> projects, string iceHome, string
g => g.Label.Equals("IceHome", StringComparison.CurrentCultureIgnoreCase));
if(group != null)
{
DTEUtil.EnsureFileIsCheckout(project.FullPath);
group.SetProperty(Package.IceHomeValue, iceHome);
group.SetProperty(Package.IceVersionValue, iceVersion);
group.SetProperty(Package.IceIntVersionValue, iceIntVersion);
Expand Down
2 changes: 2 additions & 0 deletions IceBuilder/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ public void AddIceBuilderToProject(IVsProject p)
{
String projectPath = ProjectUtil.GetProjectFullPath(p);
bool cppProject = DTEUtil.IsCppProject(p);
DTEUtil.EnsureFileIsCheckout(projectPath);
ProjectUtil.SaveProject(p);
Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(projectPath, cppProject, false);
if(MSBuildUtils.AddIceBuilderToProject(project))
Expand Down Expand Up @@ -1016,6 +1017,7 @@ private void RemoveIceBuilderFromProject(object sender, EventArgs e)
private void RemoveIceBuilderFromProject(IVsProject p)
{
string path = ProjectUtil.GetProjectFullPath(p);
DTEUtil.EnsureFileIsCheckout(path);
foreach(IVsProject p1 in _buildProjects)
{
if(path.Equals(ProjectUtil.GetProjectFullPath(p1)))
Expand Down
5 changes: 3 additions & 2 deletions IceBuilder/ProjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,9 @@ public static void Upgrade(List<IVsProject> projects, UpgradeProgressCallback pr
public static bool Upgrade(IVsProject project)
{
OldConfiguration oldConfiguration = new OldConfiguration();
Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(project), DTEUtil.IsCppProject(project), true);

var fullPath = ProjectUtil.GetProjectFullPath(project);
Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(fullPath, DTEUtil.IsCppProject(project), true);
DTEUtil.EnsureFileIsCheckout(fullPath);
if(oldConfiguration.Load(msbuildProject, true))
{
if(DTEUtil.IsCppProject(project))
Expand Down
4 changes: 3 additions & 1 deletion IceBuilder/ProjectUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ public static string GetProperty(IVsProject project, string name, string default

public static void SetProperty(IVsProject project, string name, string value)
{
MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(GetProjectFullPath(project), DTEUtil.IsCppProject(project), true), "IceBuilder", name, value);
var fullPath = GetProjectFullPath(project);
DTEUtil.EnsureFileIsCheckout(fullPath);
MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(fullPath, DTEUtil.IsCppProject(project), true), "IceBuilder", name, value);
}

public static string GetEvaluatedProperty(IVsProject project, string name)
Expand Down

0 comments on commit 0c1733d

Please sign in to comment.