Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@
<extensions defaultExtensionNs="com.intellij">
<toolWindow id="Go" anchor="bottom" icon="/icons/go_13x13.png" factoryClass="ro.redeul.google.go.ide.ui.GoToolWindowFactory" />

<stepsBeforeRunProvider implementation="ro.redeul.google.go.runner.beforeRunTasks.GoVetTaskProvider" />

<applicationService
serviceInterface="ro.redeul.google.go.ide.GoGlobalSettings"
serviceImplementation="ro.redeul.google.go.ide.GoGlobalSettings"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class GoApplicationConfiguration extends ModuleBasedConfiguration<GoAppli
public String goOutputDir = "";
public String workingDir = "";
public String envVars = "";
public Boolean goVetEnabled = false;

public GoApplicationConfiguration(String name, Project project, GoApplicationConfigurationType configurationType) {
super(name, new GoApplicationModuleBasedConfiguration(project), configurationType.getConfigurationFactories()[0]);
Expand Down
28 changes: 0 additions & 28 deletions src/ro/redeul/google/go/runner/GoRunProfileState.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,6 @@ protected ProcessHandler startProcess() throws ExecutionException {
GoToolWindow toolWindow = GoToolWindow.getInstance(m_project);
toolWindow.setTitle(TITLE);

if (m_configuration.goVetEnabled) {
try {
String[] goEnv = GoSdkUtil.convertEnvMapToArray(sysEnv);

String command = String.format(
"%s vet ./...",
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));
handler.startNotify();

if (proc.waitFor() == 0) {
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));
throw new CantRunException(String.format("Error while processing %s vet command.", goExecName));
}
} catch (Exception e) {
throw new CantRunException(String.format("Error while processing %s vet command.", goExecName));
}
}

if (!m_configuration.goBuildBeforeRun) {
// Just run
GeneralCommandLine commandLine = new GeneralCommandLine();
Expand Down
112 changes: 112 additions & 0 deletions src/ro/redeul/google/go/runner/beforeRunTasks/GoVetRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ro.redeul.google.go.runner.beforeRunTasks;

import com.intellij.execution.CantRunException;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ro.redeul.google.go.config.sdk.GoSdkData;
import ro.redeul.google.go.ide.ui.GoToolWindow;
import ro.redeul.google.go.runner.GoApplicationConfiguration;
import ro.redeul.google.go.runner.GoCommonConsoleView;
import ro.redeul.google.go.sdk.GoSdkUtil;

import java.io.File;
import java.util.Map;

/**
* Created by d3xter on 13.03.14.
*/
public class GoVetRunner extends Task.Backgroundable {
private static final Logger LOG = Logger.getInstance(GoVetRunner.class);
private GoApplicationConfiguration goConfig;

public GoVetRunner(@Nullable Project project, @NotNull String title, boolean canBeCancelled, GoApplicationConfiguration goConfig) {
super(project, title, canBeCancelled);

this.goConfig = goConfig;
}

public GoVetRunner(@Nullable Project project, @NotNull String title, GoApplicationConfiguration goConfig) {
this(project, title, false, goConfig);
}

@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 = sdkData.GO_BIN_PATH;
String projectDir = myProject.getBasePath();

try {
Map<String,String> sysEnv = GoSdkUtil.getExtendedSysEnv(sdkData, projectDir, goConfig.envVars);
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));
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 {
indicator.setFraction(100);
}
}
}
24 changes: 24 additions & 0 deletions src/ro/redeul/google/go/runner/beforeRunTasks/GoVetTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ro.redeul.google.go.runner.beforeRunTasks;

import com.intellij.execution.BeforeRunTask;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.NotNull;

/**
* Created by d3xter on 13.03.14.
*/
public class GoVetTask extends BeforeRunTask<GoVetTask> {
private RunConfiguration config;

protected GoVetTask(@NotNull Key<GoVetTask> providerId, RunConfiguration config) {
super(providerId);

this.config = config;
}

public RunConfiguration getConfiguration() {
return this.config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package ro.redeul.google.go.runner.beforeRunTasks;

import com.intellij.execution.BeforeRunTaskProvider;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.Nullable;
import ro.redeul.google.go.GoIcons;
import ro.redeul.google.go.runner.GaeLocalConfiguration;
import ro.redeul.google.go.runner.GoApplicationConfiguration;

import javax.swing.*;

/**
* Created by d3xter on 13.03.14.
*/
public class GoVetTaskProvider extends BeforeRunTaskProvider<GoVetTask> {
private static final Logger LOG = Logger.getInstance(GoVetTaskProvider.class);
private final Key<GoVetTask> TaskID = new Key<GoVetTask>("GoVet");

@Override
public Key<GoVetTask> getId() {
return TaskID;
}

@Override
public String getName() {
return "Go Vet";
}

@Nullable
@Override
public Icon getTaskIcon(GoVetTask task) {
if(task.getConfiguration() instanceof GaeLocalConfiguration) {
return GoIcons.GAE_ICON_13x13;
} else {
return GoIcons.GO_ICON_13x13;
}
}

@Override
public String getDescription(GoVetTask task) {
return "Run Go Vet";
}

@Nullable
@Override
public Icon getIcon() {
return GoIcons.GO_ICON_13x13;
}

@Override
public boolean isConfigurable() {
return false;
}

@Nullable
@Override
public GoVetTask createTask(RunConfiguration runConfiguration) {
return new GoVetTask(TaskID, runConfiguration);
}

@Override
public boolean configureTask(RunConfiguration runConfiguration, GoVetTask task) {
return false;
}

@Override
public boolean canExecuteTask(RunConfiguration configuration, GoVetTask task) {
//Only run Go apps at the moment
return configuration instanceof GoApplicationConfiguration;
}

@Override
public boolean executeTask(DataContext context, final RunConfiguration configuration, final ExecutionEnvironment env, GoVetTask task) {
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {

FileDocumentManager.getInstance().saveAllDocuments();

new GoVetRunner(env.getProject(), "Go Vet", (GoApplicationConfiguration)configuration).queue();
}
}, ModalityState.NON_MODAL);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="38d58" layout-manager="GridLayoutManager" row-count="10" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="38d58" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Run"/>
Expand Down Expand Up @@ -133,14 +133,6 @@
<toolTipText value="You must use &quot;;&quot; in order to separate values. Ex. GOROOT=/usr/lib/go/;GOPATH=/home/Usr/go/"/>
</properties>
</component>
<component id="9f869" class="javax.swing.JCheckBox" binding="runGoVetBeforeCheckBox" default-binding="true">
<constraints>
<grid row="9" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Run go &amp;vet before running anything else"/>
</properties>
</component>
<component id="3465" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class GoApplicationConfigurationEditor extends SettingsEditor<GoApplicati
private RawCommandLineEditor m_debugBuilderArguments;
private TextFieldWithBrowseButton workingDirectoryBrowser;
private RawCommandLineEditor envVars;
private JCheckBox runGoVetBeforeCheckBox;
private JTabbedPane tabbedPane1;
private JLabel gdbVersionWarning;
private TextFieldWithBrowseButton m_gdbPath;
Expand All @@ -54,7 +53,6 @@ protected void resetEditorFrom(GoApplicationConfiguration configuration) {
}

envVars.setText(configuration.envVars);
runGoVetBeforeCheckBox.setSelected(configuration.goVetEnabled);

//Debug stuff
if (configuration.debugBuilderArguments.isEmpty()) {
Expand All @@ -81,7 +79,6 @@ protected void applyEditorTo(GoApplicationConfiguration configuration) throws Co
configuration.goOutputDir = buildDirectoryPathBrowser.getText();
configuration.workingDir = workingDirectoryBrowser.getText();
configuration.envVars = envVars.getText();
configuration.goVetEnabled = runGoVetBeforeCheckBox.isSelected();

//Debug stuff
String gdbPath = m_gdbPath.getText();
Expand Down
34 changes: 0 additions & 34 deletions src/uk/co/cwspencer/ideagdb/run/GoDebugProfileState.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,6 @@ public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner)
GoToolWindow toolWindow = GoToolWindow.getInstance(project);
toolWindow.setTitle(TITLE);

if (m_configuration.goVetEnabled) {
try {
String[] goEnv = GoSdkUtil.convertEnvMapToArray(sysEnv);

String command = String.format(
"%s vet ./...",
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));
handler.startNotify();

if (proc.waitFor() == 0) {
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));
throw new CantRunException(String.format("Error while processing %s vet command.", goExecName));
}


} catch (Exception e) {
e.printStackTrace();
Messages.showErrorDialog(String.format("Error while processing %s vet command.", goExecName), "Error on Google Go Plugin");

throw new CantRunException(String.format("Error while processing %s vet command.", goExecName));
}
}

// Build and run
String execName = m_configuration.goOutputDir.concat("/").concat(project.getName());

Expand Down