Skip to content

Commit

Permalink
Remove SparkJobRun/Debug actions from test sources context
Browse files Browse the repository at this point in the history
  • Loading branch information
wezhang committed Dec 28, 2018
1 parent 1ea7d49 commit e479052
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import java.util.Optional;

import static com.intellij.openapi.roots.TestSourcesFilter.isTestSources;

public class SparkBatchJobLocalRunConfigurationProducer extends JavaRunConfigurationProducerBase<LivySparkBatchJobRunConfiguration> {
private SparkApplicationType applicationType;

Expand All @@ -57,8 +59,10 @@ public boolean setupConfigurationFromContext(LivySparkBatchJobRunConfiguration c
} else {
return Optional.ofNullable(context.getModule())
.map(Module::getProject)
.flatMap(project -> Optional.ofNullable(SparkContextUtilsKt.getSparkMainClassWithElement(context))
.filter(mainClass -> SparkContextUtilsKt.isSparkContext(mainClass.getContainingFile())))
.flatMap(project -> Optional
.ofNullable(SparkContextUtilsKt.getSparkMainClassWithElement(context))
.filter(mainClass -> SparkContextUtilsKt.isSparkContext(mainClass.getContainingFile()) &&
!isTestSources(mainClass.getContainingFile().getVirtualFile(), project)))
.map(mainClass -> {
setupConfiguration(configuration, mainClass, context);

Expand Down Expand Up @@ -101,6 +105,10 @@ public boolean isConfigurationFromContext(LivySparkBatchJobRunConfiguration jobC
return false;
}

if (isTestSources(mainClass.getContainingFile().getVirtualFile(), jobConfiguration.getProject())) {
return false;
}

final Module configurationModule = jobConfiguration.getConfigurationModule().getModule();

if (!Comparing.equal(context.getModule(), configurationModule)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.execution.RunnerRegistry
import com.intellij.execution.runners.ExecutionEnvironmentBuilder
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.roots.TestSourcesFilter.isTestSources
import com.microsoft.azure.hdinsight.common.logger.ILogger
import com.microsoft.azure.hdinsight.spark.run.configuration.LivySparkBatchJobRunConfiguration
import com.microsoft.azure.hdinsight.spark.run.getNormalizedClassNameForSpark
Expand Down Expand Up @@ -58,11 +59,15 @@ abstract class SparkRunConfigurationAction : AzureAnAction, ILogger {
val runManagerEx = RunManagerEx.getInstanceEx(project)
val selectedConfigSettings = runManagerEx.selectedConfiguration

val mainClass = actionEvent.dataContext.getSparkConfigurationContext()?.getSparkMainClassWithElement()
if (mainClass?.containingFile?.let { isTestSources(it.virtualFile, project) } == true) {
return
}

presentation.apply {
when {
actionEvent.isFromActionToolbar -> {
isEnabledAndVisible = canRun(selectedConfigSettings?: return)
}

actionEvent.isFromActionToolbar -> isEnabledAndVisible = canRun(selectedConfigSettings?: return)
else -> {
// From context menu or Line marker action menu
isEnabledAndVisible = actionEvent.dataContext.isSparkContext()
Expand Down

0 comments on commit e479052

Please sign in to comment.