initial implementation of IDEA restarter for Win32
authorDmitry Jemerov <yole@intellij.com>
Mon, 12 Jan 2009 11:56:29 +0000 (14:56 +0300)
committerDmitry Jemerov <yole@intellij.com>
Mon, 12 Jan 2009 11:56:29 +0000 (14:56 +0300)
14 files changed:
bin/restarter.exe [new file with mode: 0644]
idea-tests/src/com/intellij/mock/MockApplication.java
platform-api/src/com/intellij/openapi/application/Application.java
platform-impl/src/com/intellij/internal/RestartInfoAction.java [new file with mode: 0644]
platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java
platform-impl/src/com/intellij/openapi/application/impl/Win32Restarter.java [new file with mode: 0644]
platform-resources/src/idea/PlatformActions.xml
tools/restarter/ReadMe.txt [new file with mode: 0644]
tools/restarter/restarter.cpp [new file with mode: 0644]
tools/restarter/restarter.sln [new file with mode: 0644]
tools/restarter/restarter.vcproj [new file with mode: 0644]
tools/restarter/stdafx.cpp [new file with mode: 0644]
tools/restarter/stdafx.h [new file with mode: 0644]
tools/restarter/targetver.h [new file with mode: 0644]

diff --git a/bin/restarter.exe b/bin/restarter.exe
new file mode 100644 (file)
index 0000000..013a915
Binary files /dev/null and b/bin/restarter.exe differ
index 35e106095d4762bb67834100e586f3609b566734..ef42273161c52e45623c20a4b0bafaea1b148a45 100644 (file)
@@ -103,6 +103,12 @@ public class MockApplication extends MockComponentManager implements Application
     return false;
   }
 
+  public boolean isRestartCapable() {
+    return false;
+  }
+
+  public void restart() {
+  }
 
   public void runReadAction(Runnable action) {
     action.run();
index 173ccb32b7cc33411bbb3dda265ee11f5145362d..ad9c8b6774e7d092a8aaa0d93a56dc540d15ff78 100644 (file)
@@ -281,4 +281,15 @@ public interface Application extends ComponentManager {
    */
   boolean isDisposeInProgress();
 
+  /**
+   * Checks if IDEA is capable of restarting itself on the current platform and with the current execution mode.
+   *
+   * @return true if IDEA can restart itself, false otherwise.
+   */
+  boolean isRestartCapable();
+
+  /**
+   * Exits and restarts IDEA. If the current platform is not restart capable, only exits.
+   */
+  void restart();
 }
diff --git a/platform-impl/src/com/intellij/internal/RestartInfoAction.java b/platform-impl/src/com/intellij/internal/RestartInfoAction.java
new file mode 100644 (file)
index 0000000..34ed84b
--- /dev/null
@@ -0,0 +1,18 @@
+package com.intellij.internal;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.application.Application;
+import com.intellij.openapi.application.ApplicationManager;
+
+/**
+ * @author yole
+ */
+public class RestartInfoAction extends AnAction {
+  public void actionPerformed(AnActionEvent e) {
+    final Application app = ApplicationManager.getApplication();
+    if (app.isRestartCapable()) {
+      app.restart();
+    }
+  }
+}
index 7f4e21f7f6f3f31301046a579c87bea8dbbd1f6a..a9131a4dfbe01821004bc0635fdedb1f9cd9ffca 100644 (file)
@@ -35,7 +35,6 @@ import com.intellij.openapi.project.ProjectManager;
 import com.intellij.openapi.project.ex.ProjectEx;
 import com.intellij.openapi.project.ex.ProjectManagerEx;
 import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.ui.ex.MessagesEx;
 import com.intellij.openapi.util.*;
 import com.intellij.openapi.wm.ex.ProgressIndicatorEx;
 import com.intellij.psi.PsiLock;
@@ -972,6 +971,16 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
     return myDisposeInProgress;
   }
 
+  public boolean isRestartCapable() {
+    return SystemInfo.isWindows;
+  }
+
+  public void restart() {
+   if (SystemInfo.isWindows) {
+     Win32Restarter.restart();
+    }
+  }
+
   public boolean isSaving() {
     if (getStateStore().isSaving()) return true;
     Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
diff --git a/platform-impl/src/com/intellij/openapi/application/impl/Win32Restarter.java b/platform-impl/src/com/intellij/openapi/application/impl/Win32Restarter.java
new file mode 100644 (file)
index 0000000..3a38ee2
--- /dev/null
@@ -0,0 +1,44 @@
+package com.intellij.openapi.application.impl;
+
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ex.ApplicationEx;
+import com.intellij.openapi.ui.Messages;
+import com.sun.jna.Native;
+import com.sun.jna.WString;
+import com.sun.jna.win32.StdCallLibrary;
+
+import java.io.IOException;
+
+/**
+ * @author yole
+ */
+public class Win32Restarter {
+  private Win32Restarter() {
+  }
+
+  public static void restart() {
+    Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
+    WString cline = kernel32.GetCommandLineW();
+    int pid = kernel32.GetCurrentProcessId();
+
+    try {
+      Runtime.getRuntime().exec("restarter " + Integer.toString(pid) + " " + cline);
+    }
+    catch (IOException ex) {
+      Messages.showMessageDialog("Restart failed: " + ex.getMessage(), "Restart", Messages.getErrorIcon());
+      return;
+    }
+    try {
+      Thread.sleep(500);
+    }
+    catch (InterruptedException e1) {
+      // ignore
+    }
+    ((ApplicationEx)ApplicationManager.getApplication()).exit(true);
+  }
+
+  private interface Kernel32 extends StdCallLibrary {
+    WString GetCommandLineW();
+    int GetCurrentProcessId();
+  }
+}
index dfe4e6ba48cf887c3e81ada77c23714bd629bc58..f30075dbf9c46eb598c2c3e73d7f2340defaa7c6 100644 (file)
       <action id="DropAnOutOfPermGenMemoryError" internal="true" class="com.intellij.diagnostic.DropAnOutOfPermGenMemoryErrorAction"/>
       <separator/>
       <action internal="true" id="ReloadProjectAction" class="com.intellij.internal.ReloadProjectAction"/>
+      <action internal="true" id="RestartInfo" class="com.intellij.internal.RestartInfoAction" text="Restart Info"/>
       <add-to-group group-id="ToolsMenu" anchor="last"/>
     </group>
 
diff --git a/tools/restarter/ReadMe.txt b/tools/restarter/ReadMe.txt
new file mode 100644 (file)
index 0000000..80a9a1c
--- /dev/null
@@ -0,0 +1,33 @@
+========================================================================
+    CONSOLE APPLICATION : restarter Project Overview
+========================================================================
+
+AppWizard has created this restarter application for you.
+
+This file contains a summary of what you will find in each of the files that
+make up your restarter application.
+
+
+restarter.vcproj
+    This is the main project file for VC++ projects generated using an Application Wizard.
+    It contains information about the version of Visual C++ that generated the file, and
+    information about the platforms, configurations, and project features selected with the
+    Application Wizard.
+
+restarter.cpp
+    This is the main application source file.
+
+/////////////////////////////////////////////////////////////////////////////
+Other standard files:
+
+StdAfx.h, StdAfx.cpp
+    These files are used to build a precompiled header (PCH) file
+    named restarter.pch and a precompiled types file named StdAfx.obj.
+
+/////////////////////////////////////////////////////////////////////////////
+Other notes:
+
+AppWizard uses "TODO:" comments to indicate parts of the source code you
+should add to or customize.
+
+/////////////////////////////////////////////////////////////////////////////
diff --git a/tools/restarter/restarter.cpp b/tools/restarter/restarter.cpp
new file mode 100644 (file)
index 0000000..81c4a6a
--- /dev/null
@@ -0,0 +1,24 @@
+// restarter.cpp : Defines the entry point for the console application.
+//
+
+#include "stdafx.h"
+
+
+int _tmain(int argc, _TCHAR* argv[])
+{
+       if (argc < 3) return 0;
+       int ppid = _ttoi(argv [1]);
+       HANDLE parent_process = OpenProcess(SYNCHRONIZE, FALSE, ppid);
+       if (!parent_process) return 0;
+       WaitForSingleObject(parent_process, INFINITE);
+       CloseHandle(parent_process);
+
+       int rc = _texecv(argv [2], argv+3);
+       if (rc == -1)
+       {
+               _tprintf(_T("Error restarting process: errno is %d"), errno);
+       }
+
+       return 0;
+}
+
diff --git a/tools/restarter/restarter.sln b/tools/restarter/restarter.sln
new file mode 100644 (file)
index 0000000..359e70e
--- /dev/null
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "restarter", "restarter.vcproj", "{1B2485B2-CFED-4B2F-8FFD-00F1C9E1BD0C}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {1B2485B2-CFED-4B2F-8FFD-00F1C9E1BD0C}.Debug|Win32.ActiveCfg = Debug|Win32
+               {1B2485B2-CFED-4B2F-8FFD-00F1C9E1BD0C}.Debug|Win32.Build.0 = Debug|Win32
+               {1B2485B2-CFED-4B2F-8FFD-00F1C9E1BD0C}.Release|Win32.ActiveCfg = Release|Win32
+               {1B2485B2-CFED-4B2F-8FFD-00F1C9E1BD0C}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/tools/restarter/restarter.vcproj b/tools/restarter/restarter.vcproj
new file mode 100644 (file)
index 0000000..35a37bc
--- /dev/null
@@ -0,0 +1,225 @@
+<?xml version="1.0" encoding="windows-1251"?>
+<VisualStudioProject
+       ProjectType="Visual C++"
+       Version="9,00"
+       Name="restarter"
+       ProjectGUID="{1B2485B2-CFED-4B2F-8FFD-00F1C9E1BD0C}"
+       RootNamespace="restarter"
+       Keyword="Win32Proj"
+       TargetFrameworkVersion="196613"
+       >
+       <Platforms>
+               <Platform
+                       Name="Win32"
+               />
+       </Platforms>
+       <ToolFiles>
+       </ToolFiles>
+       <Configurations>
+               <Configuration
+                       Name="Debug|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="0"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
+                               UsePrecompiledHeader="2"
+                               WarningLevel="3"
+                               DebugInformationFormat="4"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="2"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+               <Configuration
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
+                       ConfigurationType="1"
+                       CharacterSet="1"
+                       WholeProgramOptimization="1"
+                       >
+                       <Tool
+                               Name="VCPreBuildEventTool"
+                       />
+                       <Tool
+                               Name="VCCustomBuildTool"
+                       />
+                       <Tool
+                               Name="VCXMLDataGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCWebServiceProxyGeneratorTool"
+                       />
+                       <Tool
+                               Name="VCMIDLTool"
+                       />
+                       <Tool
+                               Name="VCCLCompilerTool"
+                               Optimization="2"
+                               EnableIntrinsicFunctions="true"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+                               RuntimeLibrary="2"
+                               EnableFunctionLevelLinking="true"
+                               UsePrecompiledHeader="2"
+                               WarningLevel="3"
+                               DebugInformationFormat="3"
+                       />
+                       <Tool
+                               Name="VCManagedResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCResourceCompilerTool"
+                       />
+                       <Tool
+                               Name="VCPreLinkEventTool"
+                       />
+                       <Tool
+                               Name="VCLinkerTool"
+                               LinkIncremental="1"
+                               GenerateDebugInformation="true"
+                               SubSystem="1"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
+                       />
+                       <Tool
+                               Name="VCALinkTool"
+                       />
+                       <Tool
+                               Name="VCManifestTool"
+                       />
+                       <Tool
+                               Name="VCXDCMakeTool"
+                       />
+                       <Tool
+                               Name="VCBscMakeTool"
+                       />
+                       <Tool
+                               Name="VCFxCopTool"
+                       />
+                       <Tool
+                               Name="VCAppVerifierTool"
+                       />
+                       <Tool
+                               Name="VCPostBuildEventTool"
+                       />
+               </Configuration>
+       </Configurations>
+       <References>
+       </References>
+       <Files>
+               <Filter
+                       Name="Source Files"
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+                       >
+                       <File
+                               RelativePath=".\restarter.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\stdafx.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                               UsePrecompiledHeader="1"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                               UsePrecompiledHeader="1"
+                                       />
+                               </FileConfiguration>
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Header Files"
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+                       >
+                       <File
+                               RelativePath=".\stdafx.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\targetver.h"
+                               >
+                       </File>
+               </Filter>
+               <Filter
+                       Name="Resource Files"
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+                       >
+               </Filter>
+               <File
+                       RelativePath=".\ReadMe.txt"
+                       >
+               </File>
+       </Files>
+       <Globals>
+       </Globals>
+</VisualStudioProject>
diff --git a/tools/restarter/stdafx.cpp b/tools/restarter/stdafx.cpp
new file mode 100644 (file)
index 0000000..ba19d26
--- /dev/null
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// restarter.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file
diff --git a/tools/restarter/stdafx.h b/tools/restarter/stdafx.h
new file mode 100644 (file)
index 0000000..661cb26
--- /dev/null
@@ -0,0 +1,16 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include "targetver.h"
+
+#include <stdio.h>
+#include <tchar.h>
+#include <windows.h>
+
+
+
+// TODO: reference additional headers your program requires here
diff --git a/tools/restarter/targetver.h b/tools/restarter/targetver.h
new file mode 100644 (file)
index 0000000..6fe8eb7
--- /dev/null
@@ -0,0 +1,13 @@
+#pragma once
+
+// The following macros define the minimum required platform.  The minimum required platform
+// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
+// your application.  The macros work by enabling all features available on platform versions up to and 
+// including the version specified.
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
+#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
+#endif
+