Configuration producer keeps creating new run configurations.


I have configured working custom run configuration type. I can create run configuration from the menu "Edit configurations ... ". It only supports Run option (no debug or coverage)

Now I'm trying to configure to run it from context. I have working RunLineMarkerContributor and my custom icon shows up in the gutter in the right place. When I click on the gutter icon I get popup menu with ability to run or edit the run configuration. Up to here all is fine and expected.

The problem is that it always creates a NEW run configuration and does not find the existing one.

My configuration producer looks like this:

public class ITFRunConfigurationProducer extends LazyRunConfigurationProducer<ITFRunConfiguration> {

private static final Logger log = Logger.getInstance("ITFRunConfigurationProducer");

public ITFRunConfigurationProducer() {
log.warn("Producer constructor, ID "+this.hashCode());

public @NotNull ConfigurationFactory getConfigurationFactory() {
log.warn("Enter getConfigurationFactory, ID "+this.hashCode());
ITFRunConfigurationFactory itfRunConfigurationFactory = new ITFRunConfigurationFactory(new ITFRunConfigurationType());
log.warn("Exit getConfigurationFactory, ID "+this.hashCode());
return itfRunConfigurationFactory;

protected boolean setupConfigurationFromContext(@NotNull ITFRunConfiguration itfRunConfiguration, @NotNull ConfigurationContext context, @NotNull Ref<PsiElement> sourceElement) {
log.warn("Enter setupConfigurationFromContext, ID "+this.hashCode());
PsiElement containingFile = getContainingFile(sourceElement);
boolean isItf = Util.isItfFile(containingFile);
if(isItf) {

RunnerAndConfigurationSettings existingConfigurations = context.findExisting();
if(existingConfigurations != null) {
itfRunConfiguration = (ITFRunConfiguration) existingConfigurations.getConfiguration();
} else {
VirtualFile virtualFile = ((XmlFile) containingFile).getVirtualFile();

log.warn("Exit setupConfigurationFromContext, ID "+this.hashCode());
return isItf;

public boolean isConfigurationFromContext(@NotNull ITFRunConfiguration itfRunConfiguration, @NotNull ConfigurationContext context) {
log.warn("Enter isConfigurationFromContext, ID "+this.hashCode());
boolean isConfigurationFromContext = false;

String configurationScriptName = itfRunConfiguration.getScriptName();
if(configurationScriptName != null && configurationScriptName.equals(context.getLocation().getVirtualFile().getPath())) {
isConfigurationFromContext = true;

log.warn("Exit isConfigurationFromContext with "+isConfigurationFromContext);
return isConfigurationFromContext;

private PsiElement getContainingFile(Ref<PsiElement> sourceElement) {
PsiElement containingFile = null;
if(sourceElement.get() instanceof XmlToken) {
XmlToken xmlToken = (XmlToken) sourceElement.get();
XmlFile xmlFile = (XmlFile) getParent(xmlToken);
if(xmlFile != null) {
containingFile = xmlFile;
return containingFile;

private PsiElement getParent(PsiElement xmlToken) {
PsiElement returnElement = null;
PsiElement parent = xmlToken.getParent();
if(parent instanceof XmlFile) {
returnElement = parent;
} else if(parent != null) {
returnElement = getParent(parent);
return returnElement;

Method isConfigurationFromContext is NEVER called. Which is what I expect so the existing one can be found.

context.FindExisting() always returns null.

What am I missing?

1 comment
Comment actions Permalink

It turns out that my configuration factory was NOT a singleton and it has to be. Once I switched to singleton everything started working as expected.
Thanks to @jansorg


Please sign in to leave a comment.