Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: obsolete/Microsoft.VisualStudio.Project/SolutionListenerForBuildDependencyUpdate.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using System.Collections;
5 using System.Collections.Generic;
6 using System.Diagnostics;
7 using Microsoft.VisualStudio;
8 using Microsoft.VisualStudio.Shell.Interop;
9 using IServiceProvider = System.IServiceProvider;
10
11 namespace Microsoft.VisualStudio.Project
12 {
13 /// <summary>
14 /// The purpose of this class is to set a build dependency from a modeli ng project to all its sub projects
15 /// </summary>
16 class SolutionListenerForBuildDependencyUpdate : SolutionListener
17 {
18 #region ctors
19 public SolutionListenerForBuildDependencyUpdate(IServiceProvider serviceProvider)
20 : base(serviceProvider)
21 {
22 }
23 #endregion
24
25 #region overridden methods
26 /// <summary>
27 /// Update build dependency list if solution is fully loaded
28 /// </summary>
29 /// <param name="hierarchy"></param>
30 /// <param name="added"></param>
31 /// <returns></returns>
32 public override int OnAfterOpenProject(IVsHierarchy hierarchy, i nt added)
33 {
34 // Return from here if we are at load time
35 if(added == 0)
36 {
37 return VSConstants.S_OK;
38 }
39
40 IBuildDependencyOnProjectContainer projectNode = hierarc hy as IBuildDependencyOnProjectContainer;
41
42 // We will update only nested project types and the Buil dNestedProjectsOnBuild flag is set to true
43 if(projectNode != null)
44 {
45 if(projectNode.BuildNestedProjectsOnBuild)
46 {
47 // Enum all sub projects and add to depe ndency list
48 UpdateDependencyListWithSubProjects(proj ectNode);
49 }
50 }
51 return VSConstants.S_OK;
52 }
53
54 /// <summary>
55 /// Called at load time when solution has finished opening.
56 /// </summary>
57 /// <param name="pUnkReserved">reserved</param>
58 /// <param name="fNewSolution">true if this is a new solution</p aram>
59 /// <returns></returns>
60 public override int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
61 {
62 // Enum all sub project and add to dependeny list
63 UpdateDependencyListWithSubProjects(null);
64
65 return VSConstants.S_OK;
66 }
67 #endregion
68
69 #region Helper methods
70 /// <summary>
71 /// Update dependency list
72 /// </summary>
73 /// <param name="projectNode">Project node to be updated. If nul l then all ProjectContainer nodes are updated</param>
74 private void UpdateDependencyListWithSubProjects(IBuildDependenc yOnProjectContainer projectNode)
75 {
76 if(projectNode != null)
77 {
78 // Get list of sub projects
79 IList<IVsHierarchy> nestedProjectList = projectN ode.EnumNestedHierachiesForBuildDependency();
80 if(nestedProjectList != null && nestedProjectLis t.Count > 0)
81 {
82 // Loop nested projects and add project dependency (if supported)
83 foreach(IVsHierarchy nestedProject in ne stedProjectList)
84 {
85 AddBuildDependenyToNestedProject (projectNode as IBuildDependencyUpdate, nestedProject);
86 }
87 }
88 }
89 else
90 {
91 // Update all ProjectContainerNode nodes
92 List<IBuildDependencyOnProjectContainer> project List = this.GetListOfProjectContainerNodes();
93 if(projectList != null && projectList.Count > 0)
94 {
95 foreach(IBuildDependencyOnProjectContain er project in projectList)
96 {
97 UpdateDependencyListWithSubProje cts(project);
98 }
99 }
100 }
101 }
102
103 /// <summary>
104 /// Enum all projects in the solution and collect all that deriv es from ProjectContainerNode
105 /// </summary>
106 /// <returns>List of ProjectContainerNode nodes</returns>
107 private List<IBuildDependencyOnProjectContainer> GetListOfProjec tContainerNodes()
108 {
109 List<IBuildDependencyOnProjectContainer> projectList = n ew List<IBuildDependencyOnProjectContainer>();
110
111 Debug.Assert(this.Solution != null, "IVsSolution object not set on this object");
112 if(this.Solution == null)
113 {
114 // Bad state, so we quit
115 return projectList;
116 }
117
118 // Enum projects loaded in the solution (normal projects only)
119 IEnumHierarchies enumHierarchies = null;
120 Guid guid = Guid.Empty;
121 __VSENUMPROJFLAGS flags = __VSENUMPROJFLAGS.EPF_LOADEDIN SOLUTION;
122 ErrorHandler.ThrowOnFailure(this.Solution.GetProjectEnum ((uint)flags, ref guid, out enumHierarchies));
123
124 if(enumHierarchies != null)
125 {
126 // Loop projects found
127 IVsHierarchy[] hierarchy = new IVsHierarchy[1];
128 uint fetched = 0;
129 while(enumHierarchies.Next(1, hierarchy, out fet ched) == VSConstants.S_OK && fetched == 1)
130 {
131 // If this is a ProjectContainerNode the n add to list
132 IBuildDependencyOnProjectContainer proje ctNode = hierarchy[0] as IBuildDependencyOnProjectContainer;
133 if(projectNode != null)
134 {
135 projectList.Add(projectNode);
136 }
137 }
138 }
139
140 return projectList;
141 }
142
143 /// <summary>
144 /// Add build dependency to ProjectContainerNode if IVsBuildDepe ndency is supported by the nested project
145 /// </summary>
146 /// <param name="projectContainer">Project Container where we sh ould add the build dependency</param>
147 /// <param name="nestedProject">Nested project to set a build de pendency against</param>
148 private static void AddBuildDependenyToNestedProject(IBuildDepen dencyUpdate projectContainer, IVsHierarchy nestedProject)
149 {
150 // Validate input
151 Debug.Assert(projectContainer != null, "Project Containe r must not be null");
152 Debug.Assert(nestedProject != null, "Nested Project must not be null");
153 if(projectContainer == null || nestedProject == null)
154 {
155 // Invalid argument
156 return;
157 }
158
159 // Create new NestedProjectBuildDependency
160 NestedProjectBuildDependency dependency = new NestedProj ectBuildDependency(nestedProject);
161 projectContainer.AddBuildDependency(dependency);
162 }
163
164 #endregion
165
166 }
167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698