blob: e8a2d3fbd41294fbadcc0035b18a3091e304a3c9 [file] [log] [blame]
/*
* Copyright 2017 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.blaze.python.run;
import com.google.idea.blaze.base.command.BlazeCommandName;
import com.google.idea.blaze.base.run.BlazeCommandRunConfiguration;
import com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder;
import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandler;
import com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationRunner;
import com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.Blaze.BuildSystem;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.runners.ExecutionEnvironment;
import javax.annotation.Nullable;
import javax.swing.Icon;
/** Python-specific handler for {@link BlazeCommandRunConfiguration}s. */
public final class BlazePyRunConfigurationHandler implements BlazeCommandRunConfigurationHandler {
private final String buildSystemName;
private final BlazeCommandRunConfigurationCommonState state;
public BlazePyRunConfigurationHandler(BlazeCommandRunConfiguration configuration) {
BuildSystem buildSystem = Blaze.getBuildSystem(configuration.getProject());
this.buildSystemName = buildSystem.getName();
this.state = new BlazeCommandRunConfigurationCommonState(buildSystem);
}
@Override
public BlazeCommandRunConfigurationCommonState getState() {
return state;
}
@Override
public BlazeCommandRunConfigurationRunner createRunner(
Executor executor, ExecutionEnvironment environment) {
return new BlazePyRunConfigurationRunner();
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
state.validate(buildSystemName);
}
@Override
@Nullable
public String suggestedName(BlazeCommandRunConfiguration configuration) {
if (configuration.getTarget() == null) {
return null;
}
return new BlazeConfigurationNameBuilder(configuration).build();
}
@Override
@Nullable
public String getCommandName() {
BlazeCommandName command = state.getCommandState().getCommand();
return command != null ? command.toString() : null;
}
@Override
public String getHandlerName() {
return "Python Handler";
}
@Override
@Nullable
public Icon getExecutorIcon(RunConfiguration configuration, Executor executor) {
return null;
}
}