Examples of GoToolWindow


Examples of ro.redeul.google.go.ide.ui.GoToolWindow

        }

        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);

        try {
            GoToolWindow toolWindow = this.getGoToolWindow(project);
            toolWindow.showAndCreate(project);
            toolWindow.clearConsoleView();

            String[] goEnv = GoSdkUtil.getExtendedGoEnv(sdkData, projectDir, "");

            String command = String.format(
                    "%s env",
                    goExecName
            );


            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(command, goEnv);
            OSProcessHandler handler = new OSProcessHandler(proc, null);
            toolWindow.attachConsoleViewToProcess(handler);
            toolWindow.printNormalMessage(String.format("%s -> %s%n", "Project dir", projectDir));
            toolWindow.printNormalMessage(String.format("%s%n", command));
            handler.startNotify();
        } catch (Exception e) {
            e.printStackTrace();
            Messages.showErrorDialog("Error while processing go env command.", "Error on go env");
        }
View Full Code Here

Examples of ro.redeul.google.go.ide.ui.GoToolWindow

        }

        GoProjectSettings.GoProjectSettingsBean settings = GoProjectSettings.getInstance(m_project).getState();
        Map<String,String> sysEnv = GoSdkUtil.getExtendedSysEnv(sdkData, projectDir, m_configuration.envVars, settings.prependGoPath, settings.useGoPath);

        GoToolWindow toolWindow = GoToolWindow.getInstance(m_project);
        toolWindow.setTitle(TITLE);

        if (!m_configuration.goBuildBeforeRun && !m_configuration.runPackage) {
            // Just run
            GeneralCommandLine commandLine = new GeneralCommandLine();

            commandLine.setExePath(goExecName);
            commandLine.addParameter("run");
            if (m_configuration.runBuilderArguments != null && m_configuration.runBuilderArguments.trim().length() > 0) {
                commandLine.getParametersList().addParametersString(m_configuration.runBuilderArguments);
            }

            commandLine.addParameter(m_configuration.scriptName);
            if (m_configuration.scriptArguments != null && m_configuration.scriptArguments.trim().length() > 0) {
                commandLine.getParametersList().addParametersString(m_configuration.scriptArguments);
            }

            commandLine.getEnvironment().putAll(sysEnv);
            commandLine.withWorkDirectory(m_configuration.workingDir);

            return GoApplicationProcessHandler.runCommandLine(commandLine);
        }

        // 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()) {
            if (!execName.endsWith(".exe")) {
                execName = execName.concat(".exe");
            }
        }

        (new File(execName)).delete();

        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.runBuilderArguments, 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(m_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 CantRunException(String.format("Error while processing %s build command.", goExecName));
            }
        } catch (Exception e) {
            throw new CantRunException(String.format("Error while processing %s build command.", goExecName));
        }
View Full Code Here

Examples of ro.redeul.google.go.ide.ui.GoToolWindow

            }
            final String projectDir = module.getProject().getBasePath();
            if (projectDir == null) {
                throw new CantRunException("Could not retrieve the project directory");
            }
            final GoToolWindow toolWindow = GoToolWindow.getInstance(module.getProject());
            toolWindow.setTitle(TITLE);
            toolWindow.showAndCreate(module.getProject());

            final String packageDir;

            if (isNew) {
                //Create folders bin and pkg and add main.go to src folder:
                PsiDirectory srcDir = PsiManager.getInstance(module.getProject()).findDirectory(sourceRoots[0]);
                PsiDirectory baseDir = srcDir.getParentDirectory();
                baseDir.createSubdirectory("bin");
                baseDir.createSubdirectory("pkg");

                String packageNameLeafTemp = packageName;
                PsiDirectory currentDir = srcDir;
                if (packageName.contains("/") || packageName.contains("\\")) {
                    String[] parts = packageName.split("[\\\\/]");
                    for (int i = 0; i < parts.length-1; ++i) {
                        currentDir = currentDir.createSubdirectory(parts[i]);
                    }
                    packageNameLeafTemp = parts[parts.length-1];
                }

                final String packageNameLeaf = packageNameLeafTemp;
                final PsiDirectory mainPackage = currentDir.createSubdirectory(packageNameLeaf);
                packageDir = mainPackage.getVirtualFile().getPath();

                ApplicationManager.getApplication().runWriteAction(new Runnable() {
                    @Override
                    public void run() {
                        String mainFileName = projectName.concat(".go");
                        mainPackage.checkCreateFile(mainFileName);
                        GoTemplatesFactory.createFromTemplate(mainPackage, "main", "main", mainFileName, GoTemplatesFactory.Template.GoAppMain);
                        toolWindow.printNormalMessage(String.format("%nFinished creating package %s from template.%n", packageName));
                        sourceRoots[0].refresh(true, true);
                    }
                });

            } else {
                packageDir = sourceRoots[0].getCanonicalPath() + File.separatorChar + packageURL;

                Runnable r = new Runnable() {
                    public void run() {

                        try {
                            //Download a go package and the dependencies from URL:
                            Map<String, String> projectEnv = GoSdkUtil.getExtendedSysEnv(sdkData, projectDir, "", false, false);
                            String[] goEnv = GoSdkUtil.convertEnvMapToArray(projectEnv);
                            String[] command = GoSdkUtil.computeGoGetCommand(goExecName, "-u -v", packageURL);
                            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.show();
                            handler.startNotify();
                            if (proc.waitFor() == 0) {
                                toolWindow.printNormalMessage(String.format("%nFinished go get package %s%n", packageURL));
                            } else {
                                toolWindow.printErrorMessage(String.format("%nCould't go get package %s%n", packageURL));
                            }
                            sourceRoots[0].refresh(true, true);

                        } catch (Exception e) {
                            e.printStackTrace();
                            Messages.showErrorDialog(String.format("Error while processing go get command: %s.", e.getMessage()), "Error on Google Go Plugin");
                            LOG.error(e.getMessage());
                        }
                    }
                };
                new Thread(r).start();

            }

            final String configName = (new File(packageDir)).getName();

            // Now add a new run configuration:
            RunManager runManager = RunManager.getInstance(module.getProject());
            GoApplicationConfigurationType goAppConfigType = new GoApplicationConfigurationType();
            GoApplicationConfigurationType.GoFactory goConfigFactory = new GoApplicationConfigurationType.GoFactory(new GoApplicationConfigurationType());
            GoApplicationConfiguration configuration = new GoApplicationConfiguration("name", module.getProject(), goAppConfigType);
            configuration.runPackage = true;
            configuration.packageDir = packageDir;
            configuration.workingDir = module.getProject().getBasePath();
            configuration.goOutputDir = module.getProject().getBasePath() + File.separatorChar + "bin";
            configuration.goBuildBeforeRun = true;
            configuration.runBuilderArguments = "";
            configuration.runExecutableName = configName;
            configuration.scriptName = "";
            configuration.scriptArguments = "";
            configuration.autoStartGdb = true;
            configuration.GDB_PATH = "gdb";
            configuration.debugBuilderArguments = "-gcflags \"-N -l\"";
            configuration.setModule(module);
            configuration.setName(configName);
            RunnerAndConfigurationSettings runAndConfig = runManager.createConfiguration(configuration, goConfigFactory);
            runManager.addConfiguration(runAndConfig, false);
            runManager.setSelectedConfiguration(runAndConfig);

            toolWindow.showAndCreate(module.getProject());


        } catch (CantRunException e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of ro.redeul.google.go.ide.ui.GoToolWindow

    @Override
    public void run(@NotNull ProgressIndicator indicator) {
        LOG.assertTrue(!ApplicationManager.getApplication().isReadAccessAllowed());

        GoToolWindow toolWindow = GoToolWindow.getInstance(myProject);

        indicator.setText(this.myTitle);
        indicator.setFraction(0);

        Sdk sdk = GoSdkUtil.getGoogleGoSdkForProject(myProject);
        if ( sdk == null ) {
            LOG.error("No Go Sdk defined for this project");
        }

        final GoSdkData sdkData = (GoSdkData)sdk.getSdkAdditionalData();
        if ( sdkData == null ) {
            LOG.error("No Go Sdk defined for this project");
        }

        String goExecName = GoSdkUtil.getGoExecName(sdk);
        if (goExecName == null) {
            return;
        }

        String projectDir = myProject.getBasePath();

        try {
            GoProjectSettings.GoProjectSettingsBean settings = GoProjectSettings.getInstance(myProject).getState();
            Map<String,String> sysEnv = GoSdkUtil.getExtendedSysEnv(sdkData, projectDir, goConfig.envVars, settings.prependGoPath, settings.useGoPath);
            String[] goEnv = GoSdkUtil.convertEnvMapToArray(sysEnv);

            String command = String.format(
                    "%s vet ./...%n",
                    goExecName
            );

            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", command));
            toolWindow.showAndCreate(myProject);
            handler.startNotify();

            if (proc.waitFor() == 0) {
                ApplicationManager.getApplication().invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        VirtualFileManager.getInstance().syncRefresh();
                    }
                });
                toolWindow.printNormalMessage(String.format("%nFinished running go vet on project %s%n", projectDir));
            } else {
                toolWindow.printErrorMessage(String.format("%nCouldn't vet project %s%n", projectDir));
            }
        } catch (Exception e) {
            toolWindow.printErrorMessage(String.format("Error while processing %s vet command.%n", goExecName));

            //An Exception shouldn't happen, so print a log-error
            LOG.error(String.format("Error while processing %s vet command.%n", goExecName));
        }
        finally {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.