public override bool IsAlreadyAdded(out ReferenceNode existingEquivalentNode)
        {
            string fullPath = Path.GetFullPath(InstalledFilePath).Replace('\\', '/');

            ReferenceContainerNode referencesFolder = this.ProjectManager.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;

            for (HierarchyNode node = referencesFolder.FirstChild; node != null; node = node.NextSibling)
            {
                JarReferenceNode referenceNode = node as JarReferenceNode;
                if (referenceNode != null)
                {
                    string otherFullPath = Path.GetFullPath(referenceNode.InstalledFilePath).Replace('\\', '/');
                    if (string.Equals(fullPath, otherFullPath, StringComparison.OrdinalIgnoreCase))
                    {
                        existingEquivalentNode = referenceNode;
                        return(true);
                    }
                }
            }

            existingEquivalentNode = null;
            return(false);
        }
 public JarReferenceProperties(JarReferenceNode node)
     : base(node)
 {
 }
        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);
        }