/vsaddin/src/Builder.cs
C# | 3605 lines | 3476 code | 79 blank | 50 comment | 117 complexity | 53895246aad3d943126a122f84da7a35 MD5 | raw file
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014, GPL-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- // **********************************************************************
- //
- // Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
- //
- // This copy of Ice is licensed to you under the terms described in the
- // ICE_LICENSE file included in this distribution.
- //
- // **********************************************************************
- using System;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- using System.Collections.Generic;
- using Extensibility;
- using EnvDTE;
- using EnvDTE80;
- using Microsoft.VisualStudio;
- using Microsoft.VisualStudio.CommandBars;
- using Microsoft.VisualStudio.VCProjectEngine;
- using Microsoft.VisualStudio.Shell;
- using Microsoft.VisualStudio.Shell.Interop;
- using System.Resources;
- using System.Reflection;
- using VSLangProj;
- using System.Globalization;
- using Microsoft.VisualStudio.OLE.Interop;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using DependenciesMap = System.Collections.Generic.Dictionary<string,
- System.Collections.Generic.Dictionary<string,
- System.Collections.Generic.List<string>>>;
- namespace Ice.VisualStudio
- {
- //
- // This class is used to asynchronously read the output of a Slice compiler
- // process.
- //
- public class StreamReader
- {
- public void appendData(object sendingProcess, DataReceivedEventArgs outLine)
- {
- if(outLine.Data != null)
- {
- _data += outLine.Data + "\n";
- }
- }
- public string data()
- {
- return _data;
- }
- private string _data = "";
- }
- public class Builder : IDisposable, IVsTrackProjectDocumentsEvents2
- {
- protected virtual void Dispose(bool disposing)
- {
- if(disposing)
- {
- if(_serviceProvider != null)
- {
- _serviceProvider.Dispose();
- }
- if(_errorListProvider != null)
- {
- _errorListProvider.Dispose();
- }
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- public DTE getCurrentDTE()
- {
- return _applicationObject.DTE;
- }
- public DTE2 getApplicationObject()
- {
- return _applicationObject;
- }
- public void init(DTE2 application, ext_ConnectMode connectMode, AddIn addInInstance)
- {
- _applicationObject = application;
- _addInInstance = addInInstance;
- _connectMode = connectMode;
- //
- // Subscribe to solution events.
- //
- if(_connectMode != ext_ConnectMode.ext_cm_CommandLine)
- {
- _solutionEvents = application.Events.SolutionEvents;
- _solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(solutionOpened);
- _solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(afterClosing);
- _solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(projectAdded);
- _solutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(projectRemoved);
- _solutionEvents.ProjectRenamed += new _dispSolutionEvents_ProjectRenamedEventHandler(projectRenamed);
- _selectionEvents = application.Events.SelectionEvents;
- _selectionEvents.OnChange += new _dispSelectionEvents_OnChangeEventHandler(selectionChange);
- }
- _buildEvents = _applicationObject.Events.BuildEvents;
- _buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(buildBegin);
- _buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(buildDone);
-
- if(_connectMode != ext_ConnectMode.ext_cm_CommandLine)
- {
- beginTrackDocumentEvents();
- //
- // Ensure DEVPATH isn't empty, if there is a project in development mode and DEVPATH is
- // empty vshosting process will crash.
- //
- string devPath = Environment.GetEnvironmentVariable("DEVPATH");
- if(String.IsNullOrEmpty(devPath))
- {
- setDotNetDevPath(Util.getIceHome() + "\\bin\\");
- }
- //
- // Subscribe to command events.
- //
- foreach(Command c in _applicationObject.Commands)
- {
- if(c.Name.Equals("Project.AddNewItem"))
- {
- _addNewItemEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _addNewItemEvent.AfterExecute +=
- new _dispCommandEvents_AfterExecuteEventHandler(afterAddNewItem);
- }
- else if(c.Name.Equals("Edit.Remove"))
- {
- _editRemoveEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _editRemoveEvent.AfterExecute +=
- new _dispCommandEvents_AfterExecuteEventHandler(editDeleteEvent);
- }
- else if(c.Name.Equals("Edit.Delete"))
- {
- _editDeleteEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _editDeleteEvent.AfterExecute +=
- new _dispCommandEvents_AfterExecuteEventHandler(editDeleteEvent);
- }
- else if(c.Name.Equals("Project.ExcludeFromProject"))
- {
- _excludeFromProjectEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _excludeFromProjectEvent.BeforeExecute +=
- new _dispCommandEvents_BeforeExecuteEventHandler(beforeExcludeFromProjectEvent);
- _excludeFromProjectEvent.AfterExecute +=
- new _dispCommandEvents_AfterExecuteEventHandler(afterExcludeFromProjectEvent);
- }
- else if(c.Name.Equals("Project.AddExistingItem"))
- {
- _addExistingItemEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _addExistingItemEvent.AfterExecute +=
- new _dispCommandEvents_AfterExecuteEventHandler(afterAddExistingItem);
- }
- else if(c.Name.Equals("Build.Cancel"))
- {
- _buildCancelEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _buildCancelEvent.AfterExecute +=
- new _dispCommandEvents_AfterExecuteEventHandler(afterBuildCancel);
- }
- else if(c.Name.Equals("Debug.Start"))
- {
- _debugStartEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _debugStartEvent.BeforeExecute +=
- new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentStartupProject);
- }
- else if(c.Name.Equals("Debug.StepInto"))
- {
- _debugStepIntoEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _debugStepIntoEvent.BeforeExecute +=
- new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentStartupProject);
- }
- else if(c.Name.Equals("ClassViewContextMenus.ClassViewProject.Debug.StepIntonewinstance"))
- {
- _debugStepIntoNewInstance = application.Events.get_CommandEvents(c.Guid, c.ID);
- _debugStepIntoNewInstance.BeforeExecute +=
- new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentActiveProject);
- }
- else if (c.Name.Equals("Debug.StartWithoutDebugging"))
- {
- _debugStartWithoutDebuggingEvent = application.Events.get_CommandEvents(c.Guid, c.ID);
- _debugStartWithoutDebuggingEvent.BeforeExecute +=
- new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentStartupProject);
- }
- else if (c.Name.Equals("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance"))
- {
- _debugStartNewInstance = application.Events.get_CommandEvents(c.Guid, c.ID);
- _debugStartNewInstance.BeforeExecute +=
- new _dispCommandEvents_BeforeExecuteEventHandler(setDebugEnvironmentActiveProject);
- }
- else if (c.Guid.Equals(Util.refreshCommandGUID) && c.ID == Util.refreshCommandID)
- {
- Util.setRefreshCommand(c);
- }
- }
- }
- _serviceProvider =
- new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject.DTE);
- initErrorListProvider();
- if(connectMode != ext_ConnectMode.ext_cm_CommandLine)
- {
- setupCommandBars();
- }
- }
- void selectionChange()
- {
- try
- {
- Project p = getActiveProject();
- if(p != null && Util.isSliceBuilderEnabled(p))
- {
- initializeProject(p);
- }
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- void initializeProject(Project p)
- {
- DependenciesMap dependenciesMap = getDependenciesMap();
- if(p != null && !dependenciesMap.ContainsKey(p.FullName))
- {
- if((Util.isCSharpProject(p) || Util.isCppProject(p)) && Util.isSliceBuilderEnabled(p))
- {
- Util.fix(p);
- Util.getCurrentDTE().StatusBar.Text = "Ice Add-in: checking/updating settings for project '" + p.FullName + "'";
- Util.verifyProjectSettings(p);
- Util.getCurrentDTE().StatusBar.Text = "Ice Add-in: loading project '" + p.FullName + "'";
- if(!Util.isVBProject(p))
- {
- dependenciesMap[p.FullName] = new Dictionary<string, List<string>>();
- buildProject(p, true, vsBuildScope.vsBuildScopeSolution, false);
- }
- }
- }
- if(hasErrors())
- {
- bringErrorsToFront();
- }
- }
- void editDeleteEvent(string Guid, int ID, object CustomIn, object CustomOut)
- {
- try
- {
- if(_deletedFile == null)
- {
- return;
- }
- Project project = getActiveProject();
- if(project == null)
- {
- return;
- }
- removeDependency(project, _deletedFile);
- _deletedFile = null;
- clearErrors(project);
- buildProject(project, false, vsBuildScope.vsBuildScopeProject, false);
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- //
- // In C# project type the delete event isn't triggered by exclude item command.
- // We use the before and after events of the command to remove generated items
- // when a slice file is excluded. C++ projects handle that as part of delete item
- // event.
- //
- void afterExcludeFromProjectEvent(string Guid, int ID, object CustomIn, object CustomOut)
- {
- try
- {
- if(String.IsNullOrEmpty(_excludedItem))
- {
- return;
- }
-
- Project p = getActiveProject();
- if(!Util.isCSharpProject(p) || !Util.isSliceBuilderEnabled(p))
- {
- return;
- }
- ProjectItem item = Util.findItem(_excludedItem, p.ProjectItems);
- if(item != null)
- {
- item.Delete();
- }
- updateDependencies(p);
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- //
- // In C# project type the delete event isn't triggered by exclude item command.
- // We use the before and after events of the command to remove generated items
- // when a slice file is excluded. C++ projects handle that as part of delete item
- // event.
- //
- public void beforeExcludeFromProjectEvent(string Guid, int ID, object obj, object CustomOut, ref bool done)
- {
- try
- {
- Project p = getActiveProject();
- if(!Util.isCSharpProject(p) || !Util.isSliceBuilderEnabled(p))
- {
- return;
- }
- ProjectItem item = Util.getSelectedProjectItem(p.DTE);
- if(item == null)
- {
- return;
- }
- if(!Util.isSliceFilename(item.Name))
- {
- return;
- }
-
- _excludedItem = getCSharpGeneratedFileName(p, item, "cs");
- return;
- }
- catch(Exception ex)
- {
- Util.write(null, Util.msgLevel.msgError, ex.ToString() + "\n");
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- public IVsSolution getIVsSolution()
- {
- return (IVsSolution) _serviceProvider.GetService(typeof(IVsSolution));
- }
- public void buildDone(vsBuildScope Scope, vsBuildAction Action)
- {
- try
- {
- Util.solutionExplorerRefresh();
- _sliceBuild = false;
- //
- // If a Slice file has changed during the build, we rebuild that project's
- // Slice files now that the build is done.
- //
- List<Project> rebuildProjects = getRebuildProjects();
- foreach(Project p in rebuildProjects)
- {
- buildProject(p, false, vsBuildScope.vsBuildScopeProject, false);
- }
- rebuildProjects.Clear();
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- finally
- {
- _buildProject = null;
- _building = false;
- }
- }
- //
- // Return true if the project build is in process.
- //
- public bool isBuilding(Project project)
- {
- if(!isBuilding())
- {
- return false;
- }
- if(_buildScope == vsBuildScope.vsBuildScopeSolution)
- {
- return true;
- }
- if(_buildScope == vsBuildScope.vsBuildScopeProject &&
- _buildProject == project)
- {
- return true;
- }
- return false;
- }
-
- //
- // Is our project building?
- //
- public bool isBuilding()
- {
- return _building;
- }
-
- //
- // If a Slice file created with "Add New Item" command cannot be added
- // to the project because the generated items will override an existing item,
- // the Slice file must be deleted from disk, here, after the command has
- // been executed.
- //
- public void afterAddNewItem(string Guid, int ID, object obj, object CustomOut)
- {
- try
- {
- foreach(String path in _deleted)
- {
- ProjectItem item = Util.findItem(path);
- if(item != null)
- {
- item.Remove();
- }
- if(String.IsNullOrEmpty(path))
- {
- continue;
- }
- if(File.Exists(path))
- {
- try
- {
- File.Delete(path);
- }
- catch(System.SystemException)
- {
- // Can happen if the file is used by another process.
- }
- }
- }
- _deleted.Clear();
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- //
- // If a Slice file added with "Add Existing Item" command cannot be added
- // to the project because the generated items will override an existing item,
- // the item must not be deleted here, we must empty the _deleted list so the
- // file isn't later removed.
- //
- public void afterAddExistingItem(string Guid, int ID, object obj, object CustomOut)
- {
- try
- {
- foreach (String path in _deleted)
- {
- ProjectItem item = Util.findItem(path);
- if(item != null)
- {
- item.Remove();
- }
- }
- _deleted.Clear();
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- public void afterBuildCancel(string Guid, int ID, object obj, object CustomOut)
- {
- try
- {
- Util.solutionExplorerRefresh();
- _sliceBuild = false;
- //
- // If a Slice file has changed during the build, we rebuild that project's
- // Slice files now that the build has been canceled.
- //
- List<Project> rebuildProjects = getRebuildProjects();
- foreach(Project p in rebuildProjects)
- {
- buildProject(p, false, vsBuildScope.vsBuildScopeProject, false);
- }
- rebuildProjects.Clear();
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- finally
- {
- _buildProject = null;
- _building = false;
- }
- }
- public void setDebugEnvironmentStartupProject(string Guid, int ID, object obj, object CustomOut, ref bool done)
- {
- setDebugEnvironment(getStartupProject());
- }
- public void setDebugEnvironmentActiveProject(string Guid, int ID, object obj, object CustomOut, ref bool done)
- {
- setDebugEnvironment(getActiveProject());
- }
- public void setDebugEnvironment(Project project)
- {
- try
- {
- if(project != null && Util.isSliceBuilderEnabled(project))
- {
- if(Util.isCppProject(project))
- {
- VCProject vcProject = (VCProject)project.Object;
- IVCCollection configurations = (IVCCollection)vcProject.Configurations;
- foreach(VCConfiguration conf in configurations)
- {
- Util.addIceCppEnvironment((VCDebugSettings)conf.DebugSettings, project);
- }
- }
- else if(Util.isCSharpProject(project) || Util.isVBProject(project))
- {
- setDotNetDebugEnvironment(project);
- }
- }
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- //
- // Set DEVPATH if .NET development mode is enabled and project type is C# or VB,
- // otherwise do nothing.
- //
- // NOTE: for Silverlight projects we don't need to set DEVPATH.
- //
- private void setDotNetDebugEnvironment(Project project)
- {
- //
- // If development mode isn't enabled then don't set DEVPATH.
- //
- if(!Util.developmentMode(project))
- {
- return;
- }
- //
- // Check if vshosting process is enabled, if so disable it before updating
- // environment variables. If it is running it will be stopped.
- //
- bool vsHosting = false;
- if(Util.useVSHostingProcess(project))
- {
- Util.setVsHostingProcess(project, false);
- vsHosting = true;
- }
- setDotNetDevPath(Util.getCsBinDir(project));
- //
- // Re-enable the vshosting process if it was previously enabled,
- // so it reads the new environment when it is started by Visual Studio.
- //
- if(vsHosting)
- {
- Util.setVsHostingProcess(project, true);
- }
- }
- private static void setDotNetDevPath(string csBinPath)
- {
- string devPath = Environment.GetEnvironmentVariable("DEVPATH");
- if(String.IsNullOrEmpty(devPath))
- {
- Environment.SetEnvironmentVariable("DEVPATH", csBinPath);
- return;
- }
- if(devPath.Contains(csBinPath))
- {
- ComponentList list = new ComponentList(csBinPath.Split(Path.PathSeparator));
- list.Remove(csBinPath);
- devPath = list.ToString(Path.PathSeparator);
- }
- devPath = csBinPath + Path.PathSeparator + devPath;
- devPath = devPath.Trim(Path.PathSeparator);
- Environment.SetEnvironmentVariable("DEVPATH", devPath);
- }
-
- public void disconnect()
- {
- if(_iceConfigurationCmd != null)
- {
- _iceConfigurationCmd.Delete();
- }
-
- if(_connectMode != ext_ConnectMode.ext_cm_CommandLine)
- {
- _solutionEvents.Opened -= new _dispSolutionEvents_OpenedEventHandler(solutionOpened);
- _solutionEvents.AfterClosing -= new _dispSolutionEvents_AfterClosingEventHandler(afterClosing);
- _solutionEvents.ProjectAdded -= new _dispSolutionEvents_ProjectAddedEventHandler(projectAdded);
- _solutionEvents.ProjectRemoved -= new _dispSolutionEvents_ProjectRemovedEventHandler(projectRemoved);
- _solutionEvents.ProjectRenamed -= new _dispSolutionEvents_ProjectRenamedEventHandler(projectRenamed);
- _solutionEvents = null;
- }
- _buildEvents.OnBuildBegin -= new _dispBuildEvents_OnBuildBeginEventHandler(buildBegin);
- _buildEvents.OnBuildDone -= new _dispBuildEvents_OnBuildDoneEventHandler(buildDone);
- _buildEvents = null;
- if(_connectMode != ext_ConnectMode.ext_cm_CommandLine)
- {
- endTrackDocumentEvents();
- }
- if(_dependenciesMap != null)
- {
- _dependenciesMap.Clear();
- _dependenciesMap = null;
- }
- if(_rebuildProjects != null)
- {
- _rebuildProjects.Clear();
- _rebuildProjects = null;
- }
-
- _errorCount = 0;
- if(_errors != null)
- {
- _errors.Clear();
- _errors = null;
- }
- if(_fileTracker != null)
- {
- _fileTracker.clear();
- _fileTracker = null;
- }
- }
- private void setupCommandBars()
- {
- _iceConfigurationCmd = null;
- try
- {
- _iceConfigurationCmd =
- _applicationObject.Commands.Item(_addInInstance.ProgID + ".IceConfiguration", -1);
- }
- catch(ArgumentException)
- {
- object[] contextGUIDS = new object[] { };
- _iceConfigurationCmd =
- ((Commands2)_applicationObject.Commands).AddNamedCommand2(_addInInstance,
- "IceConfiguration",
- "Ice Configuration...",
- "Ice Configuration...",
- true, -1, ref contextGUIDS,
- (int)vsCommandStatus.vsCommandStatusSupported +
- (int)vsCommandStatus.vsCommandStatusEnabled,
- (int)vsCommandStyle.vsCommandStylePictAndText,
- vsCommandControlType.vsCommandControlTypeButton);
- }
- if(_iceConfigurationCmd == null)
- {
- MessageBox.Show("Error initializing Ice Visual Studio Add-in.\n" +
- "Cannot create required commands",
- "Ice Visual Studio Add-in",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error,
- MessageBoxDefaultButton.Button1,
- (MessageBoxOptions)0);
- return;
- }
- CommandBar toolsCmdBar = ((CommandBars)_applicationObject.CommandBars)["Tools"];
- _iceConfigurationCmd.AddControl(toolsCmdBar, toolsCmdBar.Controls.Count + 1);
- CommandBar projectCmdBar = projectCommandBar();
- _iceConfigurationCmd.AddControl(projectCmdBar, projectCmdBar.Controls.Count + 1);
- }
- public void afterClosing()
- {
- try
- {
- clearErrors();
- removeDocumentEvents();
- if(_dependenciesMap != null)
- {
- _dependenciesMap.Clear();
- _dependenciesMap = null;
- }
- if(_rebuildProjects != null)
- {
- _rebuildProjects.Clear();
- _rebuildProjects = null;
- }
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- finally
- {
- _opened = false;
- }
- }
- public void solutionOpened()
- {
- try
- {
- _opening = true;
- DependenciesMap dependenciesMap = getDependenciesMap();
- initDocumentEvents();
- }
- catch(Exception ex)
- {
- _opening = false;
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- Util.getCurrentDTE().StatusBar.Text = "Ready";
- _opening = false;
- _opened = false;
- }
-
- //
- // Enable slice builder for the project with default components.
- //
- public void addBuilderToProject(Project project)
- {
- addBuilderToProject(project, new ComponentList());
- }
- //
- // Enable Slice builder for the project, and enable the components that are
- // in components. If components list is empty, the default set of components
- // are added to the project.
- //
- // Note: Components in this context is the list of Ice libraries or assemblies
- // that will be added to the project.
- //
- public void addBuilderToProject(Project project, ComponentList components)
- {
- if(Util.isCppProject(project))
- {
- Util.addIceCppConfigurations(project);
- if(components.Count == 0)
- {
- components =
- new ComponentList(Util.getProjectProperty(project, Util.PropertyIceComponents));
- }
- if(!components.Contains("Ice"))
- {
- components.Add("Ice");
- }
- if(!Util.isWinRTProject(project))
- {
- if(!components.Contains("IceUtil"))
- {
- components.Add("IceUtil");
- }
- }
- Util.addIceCppLibs(project, components);
- }
- else
- {
- if(Util.isCSharpProject(project))
- {
- bool development = Util.developmentMode(project);
- if(components.Count == 0)
- {
- components =
- new ComponentList(Util.getProjectProperty(project, Util.PropertyIceComponents));
- }
- if(!components.Contains("Ice"))
- {
- components.Add("Ice");
- }
- string iceHome = Util.getIceHome();
- foreach(string component in components)
- {
- Util.addDotNetReference(project, component, development);
- }
- }
- else if(Util.isVBProject(project))
- {
- string iceHome = Util.getIceHome();
- bool development = Util.developmentMode(project);
- if(components.Count == 0)
- {
- components =
- new ComponentList(Util.getProjectProperty(project, Util.PropertyIceComponents));
- }
- if(!components.Contains("Ice"))
- {
- components.Add("Ice");
- }
- foreach(string component in components)
- {
- Util.addDotNetReference(project, component, development);
- }
- }
- }
- Util.setProjectProperty(project, Util.PropertyIceComponents, "");
- Util.setProjectProperty(project, Util.PropertyIce, true.ToString());
- if(hasErrors(project))
- {
- bringErrorsToFront();
- }
- }
- public void removeBuilderFromProject(Project project, ComponentList components)
- {
- cleanProject(project, true);
- if(Util.isCppProject(project))
- {
- Util.removeIceCppConfigurations(project);
- Util.setProjectProperty(project, Util.PropertyIceComponents, components.ToString());
- }
- else if(Util.isCSharpProject(project))
- {
- Util.removeDotNetReference(project, "Ice");
- }
- Util.setProjectProperty(project, Util.PropertyIceComponents, components.ToString());
- Util.setProjectProperty(project, Util.PropertyIce, false.ToString());
- }
- //
- // Ensure that generated items are opened in read only mode.
- //
- private void documentOpened(Document document)
- {
- try
- {
- if(document == null || document.ProjectItem == null || document.ProjectItem.ContainingProject == null)
- {
- return;
- }
- if(!Util.isSliceBuilderEnabled(document.ProjectItem.ContainingProject))
- {
- return;
- }
- if(fileTracker().hasGeneratedFile(document.ProjectItem.ContainingProject, document.FullName))
- {
- if(!document.ReadOnly)
- {
- document.ReadOnly = true;
- }
- }
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- public void documentSaved(Document document)
- {
- try
- {
- Project project = null;
- try
- {
- project = document.ProjectItem.ContainingProject;
- }
- catch(Exception)
- {
- //
- // Expected when documents are created during project initialization
- // and the ProjectItem is not yet available.
- //
- return;
- }
- if(!Util.isSliceBuilderEnabled(project))
- {
- return;
- }
- if(!Util.isSliceFilename(document.Name))
- {
- return;
- }
- //
- // If build is in proccess, we don't run the slice compiler now, we append the document
- // to a list of projects that have changes and return. The projects on this list
- // will be rebuilt when the current build process is done or canceled, see
- // "buildDone" and "afterBuildCancel" methods in this class.
- //
- if(isBuilding(project))
- {
- List<Project> rebuildProjects = getRebuildProjects();
- if(!rebuildProjects.Contains(project))
- {
- rebuildProjects.Add(project);
- }
- return;
- }
- clearErrors(project);
- buildProject(project, false, vsBuildScope.vsBuildScopeProject, false);
- Util.solutionExplorerRefresh();
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
-
- public void projectAdded(Project project)
- {
- if(!_opened)
- {
- return;
- }
- try
- {
- if(Util.isSliceBuilderEnabled(project))
- {
- Util.verifyProjectSettings(project);
- updateDependencies(project);
- Util.solutionExplorerRefresh();
- }
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- public void projectRemoved(Project project)
- {
- try
- {
- DependenciesMap dependenciesMap = getDependenciesMap();
- if(dependenciesMap.ContainsKey(project.FullName))
- {
- dependenciesMap.Remove(project.FullName);
- }
- List<Project> rebuildProjects = getRebuildProjects();
- foreach(Project p in rebuildProjects)
- {
- if(project == p)
- {
- rebuildProjects.Remove(p);
- break;
- }
- }
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- public void projectRenamed(Project project, string oldName)
- {
- try
- {
- DependenciesMap dependenciesMap = getDependenciesMap();
- String oldPath = Path.Combine(Path.GetDirectoryName(project.FullName), oldName);
- if(dependenciesMap.ContainsKey(oldPath))
- {
- dependenciesMap.Remove(oldPath);
- }
- updateDependencies(project);
- }
- catch(Exception ex)
- {
- Util.unexpectedExceptionWarning(ex);
- throw;
- }
- }
- public void cleanProject(Project project, bool remove)
- {
- DTE dte = Util.getCurrentDTE();
- if(!_opening)
- {
- dte.StatusBar.Text = "Ice Add-in: cleaning project '" + project.FullName + "'";
- }
- if(project == null)
- {
- return;
- }
- if(!Util.isSliceBuilderEnabled(project))
- {
- return;
- }
- clearErrors(project);
- if(Util.isCSharpProject(project))
- {
- removeCSharpGeneratedItems(project, project.ProjectItems, remove);
- }
- else if(Util.isCppProject(project))
- {
- removeCppGeneratedItems(project.ProjectItems, remove);
- }
- if(!_opening)
- {
- dte.StatusBar.Text = "Ready";
- }
- }
- public void removeCSharpGeneratedItems(Project project, ProjectItems items, bool remove)
- {
- if(project == null)
- {
- return;
- }
- if(items == null)
- {
- return;
- }
- List<ProjectItem> tmpItems = Util.clone(items);
- foreach(ProjectItem i in tmpItems)
- {
- if(i == null)
- {
- continue;
- }
- if(Util.isProjectItemFolder(i))
- {
- removeCSharpGeneratedItems(project, i.ProjectItems, remove);
- }
- else if(Util.isProjectItemFile(i))
- {
- removeCSharpGeneratedItems(i, remove);
- }
- }
- }
- public void buildProject(Project project, bool force, vsBuildScope scope, bool buildDependencies)
- {
- List<Project> builded = new List<Project>();
- buildProject(project, force, null, scope, buildDependencies, ref builded);
- }
- public void buildProject(Project project, bool force, vsBuildScope scope, bool buildDependencies, ref List<Project> builded)
- {
- buildProject(project, force, null, scope, buildDependencies, ref builded);
- }
- public void buildProject(Project project, bool force, ProjectItem excludeItem, vsBuildScope scope, bool buildDependencies)
- {
- List<Project> builded = new List<Project>();
- buildProject(project, force, excludeItem, scope, buildDependencies, ref builded);
- }
- public void buildProject(Project project, bool force, ProjectItem excludeItem, vsBuildScope scope, bool buildDependencies,
- ref List<Project> builded)
- {
- if(project == null)
- {
- return;
- }
- if(!Util.isSliceBuilderEnabled(project))
- {
- return;
- }
- if(builded.Contains(project))
- {
- return;
- }
- if(_deleted.Count > 0)
- {
- return;
- }
- initializeProject(project);
- builded.Add(project);
- List<ProjectItem> buildItems = new List<ProjectItem>();
- //
- // When building a single project, we must first build projects
- // that this project depends on.
- //
- if(vsBuildScope.vsBuildScopeProject == scope && buildDependencies)
- {
- BuildDependencies dependencies = _applicationObject.Solution.SolutionBuild.BuildDependencies;
- for(int i = 0; i < dependencies.Count; ++i)
- {
- BuildDependency dp = dependencies.Item(i + 1);
- if(dp == null)
- {
- continue;
- }
- if(dp.Project.Equals(project))
- {
- System.Array projects = dp.RequiredProjects as System.Array;
- if(projects != null)
- {
- foreach(Project p in projects)
- {
- buildProject(p, force, vsBuildScope.vsBuildScopeProject, buildDependencies, ref builded);
- }
- }
- }
- }
- }
- if(Util.isVBProject(project))
- {
- //
- // For VB projects we just build dependencies.
- //
- return;
- }
- DTE dte = Util.getCurrentDTE();
- if(!_opening)
- {
- dte.StatusBar.Text = "Ice Add-in: building project '" + project.FullName + "'";
- }
- string msg = "------ Slice compilation started " + "Project: " + Util.getTraceProjectName(project) + " ------\n";
- Util.write(project, Util.msgLevel.msgInfo, msg);
- int verboseLevel = Util.getVerboseLevel(project);
- DateTime now = DateTime.Now;
- if(verboseLevel >= (int)Util.msgLevel.msgDebug)
- {
- Util.write(project, Util.msgLevel.msgDebug, "DEBUG Start Time: " + now.ToShortDateString() + " " +
- now.ToLongTimeString() + "\n");
- }
- if(Util.isCSharpProject(project))
- {
- buildCSharpProject(project, force, excludeItem);
- }
- else if(Util.isCppProject(project))
- {
- buildCppProject(project, force, ref buildItems);
- }
- if(verboseLevel >= (int)Util.msgLevel.msgDebug)
- {
- System.TimeSpan t = System.DateTime.Now - now;
- Util.write(project, Util.msgLevel.msgDebug, "DEBUG Output:\n");
- Util.write(project, Util.msgLevel.msgDebug, "DEBUG Time Elapsed: " + t.ToString() + "\n");
- }
- if(hasErrors(project))
- {
- Util.write(project, Util.msgLevel.msgError,
- "------ Slice compilation failed: Project: " + Util.getTraceProjectName(project) +" ------\n\n");
- }
- else
- {
- Util.write(project, Util.msgLevel.msgInfo,
- "------ Slice compilation succeeded: Project: " + Util.getTraceProjectName(project) + " ------\n\n");
- }
- if(!_opening)
- {
- dte.StatusBar.Text = "Ready";
- }
- }
- public bool buildCppProject(Project project, bool force, ref List<ProjectItem> buildedItems)
- {
- VCConfiguration conf = Util.getActiveVCConfiguration(project);
- if(conf.ConfigurationType == ConfigurationTypes.typeGeneric ||
- conf.ConfigurationType == ConfigurationTypes.typeUnknown)
- {
- string err = "Configuration Type: '" + conf.ConfigurationType.ToString() + "' not supported by Ice Visual Studio Add-in";
- Util.write(project, Util.msgLevel.msgError,
- "------ Slice compilation failed: Project: " + Util.getTraceProjectName(project) + " ------\n\n" +
- err);
- MessageBox.Show(err, "Ice Visual Studio Add-in", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
- (MessageBoxOptions)0);
- Connect.getBuilder().addError(project, "", TaskErrorCategory.Error, 0, 0, err);
- return false;
- }
- VCCLCompilerTool compilerTool =
- (VCCLCompilerTool)(((IVCCollection)conf.Tools).Item("VCCLCompilerTool"));
- bool staticLib = conf.ConfigurationType == Microsoft.VisualStudio.VCProjectEngine.ConfigurationTypes.typeStaticLibrary;
- LinkerAdapter linkerAdapter;
- if(staticLib)
- {
- linkerAdapter = new StaticLinkerAdapter((VCLibrarianTool)(((IVCCollection)conf.Tools).Item("VCLibrarianTool")));
- }
- else
- {
- linkerAdapter = new DynamicLinkerAdapter((VCLinkerTool)(((IVCCollection)conf.Tools).Item("VCLinkerTool")));
- }
- if(!_opening)
- {
- Util.checkCppRunTimeLibrary(this, project, compilerTool, linkerAdapter);
- }
- string sliceCompiler = getSliceCompilerPath(project);
- return buildCppProject(project, project.ProjectItems, sliceCompiler, force, ref buildedItems);
- }
- public bool buildCppProject(Project project, ProjectItems items, string sliceCompiler, bool force,
- ref List<ProjectItem> buildedItems)
- {
- bool success = true;
- List<ProjectItem> tmpItems = Util.clone(items);
- foreach(ProjectItem i in tmpItems)
- {
- if(i == null)
- {
- continue;
- }
- if(Util.isProjectItemFilter(i))
- {
- if(!buildCppProject(project, i.ProjectItems, sliceCompiler, force, ref buildedItems))
- {
- success = false;
- }
- }
- else if(Util.isProjectItemFile(i))
- {
- if(!buildCppProjectItem(project, i, sliceCompiler, force, ref buildedItems))
- {
- success = false;
- }
- }
- }
- return success;
- }
- public bool buildCppProjectItem(Project project, ProjectItem item, string sliceCompiler, bool force,
- ref List<ProjectItem> buildedItems)
- {
- if(project == null)
- {
- return true;
- }
- if(item == null)
- {
- return true;
- }
- if(item.Name == null)
- {
- return true;
- }
- if(!Util.isSliceFilename(item.Name))
- {
- return true;
- }
- FileInfo iceFileInfo = new FileInfo(item.Properties.Item("FullPath").Value.ToString());
- FileInfo hFileInfo = new FileInfo(getCppGeneratedFileName(project,
- iceFileInfo.FullName, Util.getHeaderExt(project)));
- FileInfo cppFileInfo = new FileInfo(Path.ChangeExtension(hFileInfo.FullName, Util.getSourceExt(project)));
- string output = Path.GetDirectoryName(cppFileInfo.FullName);
- return buildCppProjectItem(project, output, iceFileInfo, cppFileInfo, hFileInfo, sliceCompiler, force,
- ref buildedItems);
- }
- public bool buildCppProjectItem(Project project, String output, FileSystemInfo ice, FileSystemInfo cpp,
- FileSystemInfo h, string sliceCompiler, bool force,
- ref List<ProjectItem> buildedItems)
- {
- bool updated = false;
- bool success = false;
-
- if(!h.Exists || !cpp.Exists)
- {
- updated = true;
- }
- else if(Util.findItem(h.FullName, project.ProjectItems) == null ||
- Util.findItem(cpp.FullName, project.ProjectItems) == null)
- {
- updated = true;
- }
- else if(ice.LastWriteTime > h.LastWriteTime || ice.LastWriteTime > cpp.LastWriteTime)
- {
- if(!Directory.Exists(output))
- {
- Directory.CreateDirectory(output);
- }
- updated = true;
- }
- else
- {
- //
- // Now check if any of the dependencies have changed.
- //
- DependenciesMap solutionDependenciesMap = getDependenciesMap();
- if(solutionDependenciesMap.ContainsKey(project.FullName))
- {
- Dictionary<string, List<string>> dependenciesMap = solutionDependenciesMap[project.FullName];
- if(dependenciesMap.ContainsKey(ice.FullName))
- {
- List<string> fileDependencies = dependenciesMap[ice.FullName];
- foreach(string name in fileDependencies)
- {
- FileInfo dependency = new FileInfo(Util.absolutePath(project, name));
- if(!dependency.Exists)
- {
- updated = true;
- break;
- }
-
- if(dependency.LastWriteTime > cpp.LastWriteTime ||
- …
Large files files are truncated, but you can click here to view the full file