<commit_before>/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * 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.intellij.ide.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.CharsetToolkit;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.swing.*;
import java.io.File;
import java.io.IOException;

/**
 * @author yole
 */
public class CreateLauncherScriptAction extends AnAction {
  private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.CreateLauncherScriptAction");

  @Override
  public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(PlatformDataKeys.PROJECT);
    CreateLauncherScriptDialog dialog = new CreateLauncherScriptDialog(project);
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
      return;
    }
    createLauncherScript(project, dialog.myNameField.getText(), dialog.myPathField.getText());
  }

  public static void createLauncherScript(Project project, String name, String path) {
    try {
      final File scriptFile = createLauncherScriptFile();

      if (SystemInfo.isMac) {
        final ScriptEngine engine = new ScriptEngineManager(null).getEngineByName("AppleScript");
        if (engine == null) {
          throw new IOException("Could not find AppleScript engine");
        }
        engine.eval("do shell script \"mv " + scriptFile + " " + path + "/" + name + "\" with administrator privileges");
      }
      else if (SystemInfo.isUnix) {

      }
    }
    catch (Exception e) {<commit_msg>[yole] run launcher script on Linux<commit_after>/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * 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.intellij.ide.actions;

import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.CharsetToolkit;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.swing.*;
import java.io.File;
import java.io.IOException;

/**
 * @author yole
 */
public class CreateLauncherScriptAction extends AnAction {
  private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.CreateLauncherScriptAction");

  @Override
  public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(PlatformDataKeys.PROJECT);
    CreateLauncherScriptDialog dialog = new CreateLauncherScriptDialog(project);
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
      return;
    }
    createLauncherScript(project, dialog.myNameField.getText(), dialog.myPathField.getText());
  }

  public static void createLauncherScript(Project project, String name, String path) {
    try {
      final File scriptFile = createLauncherScriptFile();

      final String mvCommand = "mv -f " + scriptFile + " " + path + "/" + name;
      if (SystemInfo.isMac) {
        final ScriptEngine engine = new ScriptEngineManager(null).getEngineByName("AppleScript");
        if (engine == null) {
          throw new IOException("Could not find AppleScript engine");
        }
        engine.eval("do shell script \"" + mvCommand + "\" with administrator privileges");
      }
      else if (SystemInfo.isUnix) {
        GeneralCommandLine cmdLine = new GeneralCommandLine();
        if (SystemInfo.isGnome) {
          cmdLine.setExePath("gksudo");
          cmdLine.addParameters("--message",
                                "In order to create a launcher script in " +
                                path +
                                ", please enter your administrator password:");
        }
        else if (SystemInfo.isKDE) {
          cmdLine.setExePath("kdesudo");
        }
        else {
          Messages.showMessageDialog("Unsupported graphical environment. Please execute the following command from the shell:\n" + mvCommand,
                                     "Create Launcher Script",
                                     Messages.getInformationIcon());
          return;
        }
        cmdLine.addParameter(mvCommand);
        cmdLine.createProcess();
      }
    }
    catch (Exception e) {
{'fraction_non_alphanumeric': 0.09666924864446166, 'fraction_numerical': 0.003718048024786987, 'mean_word_length': 3.575478384124734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7154428', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1775, 'n_words': 464}