/*
 * Copyright 2019 The Bazel Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.idea.sdkcompat.util;

import com.intellij.openapi.diagnostic.Logger;
import java.io.File;
import java.lang.reflect.Method;
import javax.annotation.Nullable;

/**
 * Compat for {@link com.intellij.ide.actions.CreateDesktopEntryAction}. Remove when #api192 is no
 * longer supported.
 */
public class CreateDesktopEntryActionCompat {
  private static final Logger logger = Logger.getInstance(CreateDesktopEntryActionCompat.class);

  private CreateDesktopEntryActionCompat() {}

  @Nullable
  public static String getLauncherScript() {
    // TODO (arakesh): Remove hack once IJ gets updated to use new plugin api.
    // Hack for IJ2019.3 which uses an older api193 which doesn't contain the Restarter class.
    try {
      // Should raise ClassNotFoundException if Class not found.
      Class<?> cls = Class.forName("com.intellij.ide.actions.CreateDesktopEntryAction");
      // Should throw NoSuchMethodException in new PluginSDK.
      Method method = cls.getMethod("getLauncherScript");
      return (String) method.invoke(null);
    } catch (ReflectiveOperationException e) {
      // Ignore exceptions. We default to using the new Class.
      logger.info(
          "Error Calling `CreateDesktopEntryAction.getLauncherScript()`. Using default"
              + " `Restarter.getIdeStarter()`",
          e);
    }

    try {
      Class<?> cls = Class.forName("com.intellij.util.Restarter");
      Method method = cls.getMethod("getIdeStarter");
      File startFile = (File) method.invoke(null);
      if (startFile == null) {
        return null;
      }

      return startFile.getPath();
    } catch (ReflectiveOperationException e) {
      logger.error("Error calling `Restarter.getIdeStarter()`", e);
    }
    return null;
  }
}

@@ -680,87 +680,43 @@
 lij.
-openapi.diagnostic.Logger;%0Aimport java.io.File;%0Aimport java.lang.reflect.Method
+util.Restarter;%0Aimport java.io.File
 ;%0Aim
@@ -926,106 +926,8 @@
 t %7B%0A
-  private static final Logger logger = Logger.getInstance(CreateDesktopEntryActionCompat.class);%0A%0A
   pr
@@ -1034,1204 +1034,109 @@
     
-// TODO (arakesh): Remove hack once IJ gets updated to use new plugin api.%0A    // Hack for IJ2019.3 which uses an older api193 which doesn't contain the Restarter class.%0A    try %7B%0A      // Should raise ClassNotFoundException if Class not found.%0A      Class%3C?%3E cls = Class.forName(%22com.intellij.ide.actions.CreateDesktopEntryAction%22);%0A      // Should throw NoSuchMethodException in new PluginSDK.%0A      Method method = cls.getMethod(%22getLauncherScript%22);%0A      return (String) method.invoke(null);%0A    %7D catch (ReflectiveOperationException e) %7B%0A      // Ignore exceptions. We default to using the new Class.%0A      logger.info(%0A          %22Error Calling %60CreateDesktopEntryAction.getLauncherScript()%60. Using default%22%0A              + %22 %60Restarter.getIdeStarter()%60%22,%0A          e);%0A    %7D%0A%0A    try %7B%0A      Class%3C?%3E cls = Class.forName(%22com.intellij.util.Restarter%22);%0A      Method method = cls.getMethod(%22getIdeStarter%22);%0A      File startFile = (File) method.invoke(null);%0A      if (startFile == null) %7B%0A        return null;%0A      %7D%0A%0A      return startFile.getPath();%0A    %7D catch (ReflectiveOperationException e) %7B%0A      logger.error(%22Error calling %60Restarter.getIdeStarter()%60%22, e);%0A    %7D%0A    return null
+File startFile = Restarter.getIdeStarter();%0A    return startFile == null ? null : startFile.getPath()
 ;%0A  

Remove reflection to get starter script