}
GoProjectSettings.GoProjectSettingsBean settings = GoProjectSettings.getInstance(project).getState();
Map<String,String> sysEnv = GoSdkUtil.getExtendedSysEnv(sdkData, projectDir, m_configuration.envVars, settings.prependGoPath, settings.useGoPath);
GoToolWindow toolWindow = GoToolWindow.getInstance(project);
toolWindow.setTitle(TITLE);
// Build and run
String execName;
if (m_configuration.runExecutableName != null && m_configuration.runExecutableName.trim().length() > 0) {
execName = m_configuration.goOutputDir.concat("/").concat(m_configuration.runExecutableName);
}
else {
execName = m_configuration.goOutputDir.concat("/").concat(m_configuration.getName());
}
if (execName.endsWith(".go")) {
execName = execName.substring(0, execName.length() - 3);
}
if (GoSdkUtil.isHostOsWindows()) {
execName = execName.concat(".exe");
}
try {
String[] goEnv = GoSdkUtil.convertEnvMapToArray(sysEnv);
String scriptOrPackage;
if (m_configuration.runPackage) {
scriptOrPackage = new java.io.File(m_configuration.getProject().getBaseDir().getPath().concat("/src")).toURI().relativize(new java.io.File(m_configuration.packageDir).toURI()).getPath();
}
else {
scriptOrPackage = m_configuration.scriptName;
}
String[] command = GoSdkUtil.computeGoBuildCommand(goExecName, m_configuration.debugBuilderArguments, execName, scriptOrPackage);
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(command, goEnv, new File(projectDir));
OSProcessHandler handler = new OSProcessHandler(proc, null);
toolWindow.attachConsoleViewToProcess(handler);
toolWindow.printNormalMessage(String.format("%s%n", StringUtil.join(command, " ")));
toolWindow.showAndCreate(project);
handler.startNotify();
if (proc.waitFor() == 0) {
VirtualFileManager.getInstance().syncRefresh();
toolWindow.printNormalMessage(String.format("%nFinished building project %s%n", execName));
} else {
toolWindow.printErrorMessage(String.format("%nCould't build project %s%n", execName));
throw new Exception("Unable to build executable file");
}
} catch (Exception e) {