/// <summary> /// Recursively search if this project reference guid is in cycle. /// </summary> private bool IsReferenceInCycle(Guid projectGuid) { // TODO: This has got to be wrong, it doesn't work w/ other project types. IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(this.ProjectMgr.Site, projectGuid); IReferenceContainerProvider provider = hierarchy.GetProject().GetCommonProject() as IReferenceContainerProvider; if (provider != null) { IReferenceContainer referenceContainer = provider.GetReferenceContainer(); Utilities.CheckNotNull(referenceContainer, "Could not found the References virtual node"); foreach (ReferenceNode refNode in referenceContainer.EnumReferences()) { ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode; if (projRefNode != null) { if (projRefNode.ReferencedProjectGuid == this.ProjectMgr.ProjectIDGuid) { return(true); } if (this.IsReferenceInCycle(projRefNode.ReferencedProjectGuid)) { return(true); } } } } return(false); }
/// <summary> /// Recursively search if this project reference guid is in cycle. /// </summary> private bool IsReferenceInCycle(Guid projectGuid) { IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(this.ProjectMgr.Site, projectGuid); IReferenceContainerProvider provider = hierarchy as IReferenceContainerProvider; if (provider != null) { IReferenceContainer referenceContainer = provider.GetReferenceContainer(); Debug.Assert(referenceContainer != null, "Could not found the References virtual node"); foreach (ReferenceNode refNode in referenceContainer.EnumReferences()) { ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode; if (projRefNode != null) { if (projRefNode.ReferencedProjectGuid == this.ProjectMgr.ProjectIDGuid) { return(true); } if (this.IsReferenceInCycle(projRefNode.ReferencedProjectGuid)) { return(true); } } } } return(false); }
/// <summary> /// Refreshes references and redraws them correctly. /// </summary> private void RefreshReferences() { // Refresh the reference container node for assemblies that could be resolved. IReferenceContainer referenceContainer = this.config.ProjectMgr.GetReferenceContainer(); foreach (ReferenceNode referenceNode in referenceContainer.EnumReferences()) { referenceNode.RefreshReference(); } }
/// <summary> /// Refreshes references and redraws them correctly. /// </summary> protected virtual void RefreshReferences() { // Refresh the reference container node for assemblies that could be resolved. IReferenceContainer referenceContainer = this.config.ProjectManager.GetReferenceContainer(); if (referenceContainer == null) { return; } foreach (ReferenceNode referenceNode in referenceContainer.EnumReferences()) { referenceNode.RefreshReference(); } }
private List <ProjectReferenceNode> GetProjectReferencesContainingThisProject(IVsHierarchy inputHierarchy) { List <ProjectReferenceNode> projectReferences = new List <ProjectReferenceNode>(); if (this.Solution == null || inputHierarchy == null) { return(projectReferences); } uint flags = (uint)(__VSENUMPROJFLAGS.EPF_ALLPROJECTS | __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION); Guid enumOnlyThisType = Guid.Empty; IEnumHierarchies enumHierarchies = null; ThreadHelper.ThrowIfNotOnUIThread(); ErrorHandler.ThrowOnFailure(this.Solution.GetProjectEnum(flags, ref enumOnlyThisType, out enumHierarchies)); Debug.Assert(enumHierarchies != null, "Could not get list of hierarchies in solution"); IVsHierarchy[] hierarchies = new IVsHierarchy[1]; uint fetched; int returnValue = VSConstants.S_OK; do { returnValue = enumHierarchies.Next(1, hierarchies, out fetched); Debug.Assert(fetched <= 1, "We asked one project to be fetched VSCore gave more than one. We cannot handle that"); if (returnValue == VSConstants.S_OK && fetched == 1) { IVsHierarchy hierarchy = hierarchies[0]; Debug.Assert(hierarchy != null, "Could not retrieve a hierarchy"); IReferenceContainerProvider provider = hierarchy as IReferenceContainerProvider; if (provider != null) { IReferenceContainer referenceContainer = provider.GetReferenceContainer(); Debug.Assert(referenceContainer != null, "Could not found the References virtual node"); ProjectReferenceNode projectReferenceNode = GetProjectReferenceOnNodeForHierarchy(referenceContainer.EnumReferences(), inputHierarchy); if (projectReferenceNode != null) { projectReferences.Add(projectReferenceNode); } } } } while(returnValue == VSConstants.S_OK && fetched == 1); return(projectReferences); }
private void Build(uint options, IVsOutputWindowPane output, string target) { bool shouldRepaintReferences = false; if (!this.config.ProjectMgr.HasPassedSecurityChecks) { // From a security perspective, if there was something truly malicious about the project, // the user is about to toast himself by requesting a build. Any further attempts at // preventing damage by avoiding MSBuild targets/tasks are futile. So, from this point // forward, we might as well pretend that this project has passed all security checks, // and we're free to run any targets we like. this.config.ProjectMgr.HasPassedSecurityChecks = true; shouldRepaintReferences = true; } int shouldContinue = 1; foreach (IVsBuildStatusCallback cb in callbacks) { try { ErrorHandler.ThrowOnFailure(cb.BuildBegin(ref shouldContinue)); if (shouldContinue == 0) { return; } } catch (Exception e) { // If those who ask for status have bugs in their code it should not prevent the build/notification from happening Debug.Fail(String.Format("Exception was thrown during BuildBegin event\n{0}", e.Message)); } } MSBuildResult result = MSBuildResult.Failed; try { result = config.ProjectMgr.Build(options, this.config.ConfigName, output, target); } catch (Exception e) { Trace.WriteLine("Exception : " + e.Message); ErrorHandler.ThrowOnFailure(output.OutputStringThreadSafe("Unhandled Exception:" + e.Message + "\n")); throw e; } finally { int success = ((result == MSBuildResult.Sucessful) ? 1 : 0); foreach (IVsBuildStatusCallback cb in callbacks) { try { ErrorHandler.ThrowOnFailure(cb.BuildEnd(success)); } catch (Exception e) { // If those who ask for status have bugs in their code it should not prevent the build/notification from happening Debug.Fail(String.Format("Exception was thrown during BuildEnd event\n{0}", e.Message)); } } ErrorHandler.ThrowOnFailure(output.FlushToTaskList()); // Now repaint references if that is needed. // We hardly rely here on the fact the ResolveAssemblyReferences target has been run as part of the build. if (shouldRepaintReferences) { // Repaint references IReferenceContainer referenceContainer = this.config.ProjectMgr.GetReferenceContainer(); foreach (ReferenceNode node in referenceContainer.EnumReferences()) { node.RefreshReference(); } } } }
public override int DebugLaunch(uint grfLaunch) { DebugTargetInfo info = new DebugTargetInfo(); CommandLineBuilder commandLine = new CommandLineBuilder(); bool x64 = Platform.EndsWith("X64", StringComparison.OrdinalIgnoreCase) || (Platform.EndsWith("Any CPU", StringComparison.OrdinalIgnoreCase) && Environment.Is64BitOperatingSystem); string agentBaseFileName = "Tvl.Java.DebugHostWrapper"; if (x64) { agentBaseFileName += "X64"; } bool useDevelopmentEnvironment = (grfLaunch & (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_NoDebug) == 0; string debugAgentName = GetConfigurationProperty(JavaConfigConstants.DebugAgent, _PersistStorageType.PST_USER_FILE, false); bool useJdwp = string.Equals(DebugAgent.Jdwp.ToString(), debugAgentName, StringComparison.OrdinalIgnoreCase); if (useJdwp) { commandLine.AppendSwitch("-Xdebug"); string serverValue = useDevelopmentEnvironment ? "y" : "n"; commandLine.AppendSwitch("-Xrunjdwp:transport=dt_socket,server=" + serverValue + ",address=6777"); } else { string agentFolder = Path.GetDirectoryName(typeof(JavaProjectConfig).Assembly.Location); string agentFileName = agentBaseFileName + ".dll"; string agentPath = Path.GetFullPath(Path.Combine(agentFolder, agentFileName)); commandLine.AppendSwitchIfNotNull("-agentpath:", agentPath); string agentArguments = GetConfigurationProperty(JavaConfigConstants.DebugAgentArguments, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(agentArguments)) { commandLine.AppendTextUnquoted("=" + agentArguments); } } switch (GetConfigurationProperty(JavaConfigConstants.DebugStartAction, _PersistStorageType.PST_USER_FILE, false)) { case "Class": string jvmArguments = GetConfigurationProperty(JavaConfigConstants.DebugJvmArguments, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(jvmArguments)) { commandLine.AppendTextUnquoted(" " + jvmArguments); } commandLine.AppendSwitch("-cp"); commandLine.AppendFileNameIfNotNull(GetConfigurationProperty("TargetPath", _PersistStorageType.PST_PROJECT_FILE, false)); string startupObject = GetConfigurationProperty(JavaConfigConstants.DebugStartClass, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(startupObject)) { commandLine.AppendFileNameIfNotNull(startupObject); } break; default: throw new NotImplementedException("This preview version of the Java debugger only supports starting execution in a named class; the class name may be configured in the project properties on the Debug tab."); } string debugArgs = GetConfigurationProperty(JavaConfigConstants.DebugExtraArgs, _PersistStorageType.PST_USER_FILE, false); if (!string.IsNullOrEmpty(debugArgs)) { commandLine.AppendTextUnquoted(" " + debugArgs); } string workingDirectory = GetConfigurationProperty(JavaConfigConstants.DebugWorkingDirectory, _PersistStorageType.PST_USER_FILE, false); if (string.IsNullOrEmpty(workingDirectory)) { workingDirectory = GetConfigurationProperty(JavaConfigConstants.OutputPath, _PersistStorageType.PST_PROJECT_FILE, false); } if (!Path.IsPathRooted(workingDirectory)) { workingDirectory = Path.GetFullPath(Path.Combine(this.ProjectManager.ProjectFolder, workingDirectory)); } // Pass the project references via the CLASSPATH environment variable List <string> classPathEntries = new List <string>(); IReferenceContainer referenceContainer = ProjectManager.GetReferenceContainer(); IList <ReferenceNode> references = referenceContainer.EnumReferences(); foreach (var referenceNode in references) { JarReferenceNode jarReferenceNode = referenceNode as JarReferenceNode; if (jarReferenceNode != null) { if (File.Exists(jarReferenceNode.InstalledFilePath) || Directory.Exists(jarReferenceNode.InstalledFilePath)) { classPathEntries.Add(jarReferenceNode.InstalledFilePath); } } } if (classPathEntries != null) { string classPath = string.Join(";", classPathEntries); info.Environment.Add("CLASSPATH", classPath); } //List<string> arguments = new List<string>(); //arguments.Add(@"-agentpath:C:\dev\SimpleC\Tvl.Java.DebugHost\bin\Debug\Tvl.Java.DebugHostWrapper.dll"); ////arguments.Add(@"-verbose:jni"); ////arguments.Add(@"-cp"); ////arguments.Add(@"C:\dev\JavaProjectTest\JavaProject\out\Debug"); //arguments.Add("tvl.school.ee382v.a3.problem1.program1"); ////arguments.Add(GetConfigurationProperty("OutputPath", true)); ////arguments.Add(GetConfigurationProperty(JavaConfigConstants.DebugStartClass, false, _PersistStorageType.PST_USER_FILE)); ////arguments.Add(GetConfigurationProperty(JavaConfigConstants.DebugExtraArgs, false, _PersistStorageType.PST_USER_FILE)); //info.Arguments = string.Join(" ", arguments); info.Arguments = commandLine.ToString(); info.Executable = FindJavaBinary("java.exe", useDevelopmentEnvironment); //info.CurrentDirectory = GetConfigurationProperty("WorkingDirectory", false, _PersistStorageType.PST_USER_FILE); info.CurrentDirectory = workingDirectory; info.SendToOutputWindow = false; info.DebugEngines = new Guid[] { typeof(JavaDebugEngine).GUID, //VSConstants.DebugEnginesGuids.ManagedOnly_guid, //VSConstants.DebugEnginesGuids.NativeOnly_guid, }; Guid localPortSupplier = new Guid("{708C1ECA-FF48-11D2-904F-00C04FA302A1}"); info.PortSupplier = localPortSupplier; info.LaunchOperation = DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; info.LaunchFlags = (__VSDBGLAUNCHFLAGS)grfLaunch | (__VSDBGLAUNCHFLAGS)__VSDBGLAUNCHFLAGS2.DBGLAUNCH_MergeEnv; var debugger = (IVsDebugger2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsShellDebugger)); int result = debugger.LaunchDebugTargets(info); if (result != VSConstants.S_OK) { IVsUIShell uishell = (IVsUIShell)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsUIShell)); string message = uishell.GetErrorInfo(); } return(result); }