Search in sources :

Example 1 with RuntimeConfigurationProducer

use of com.intellij.execution.junit.RuntimeConfigurationProducer in project intellij-community by JetBrains.

the class PreferredProducerFind method getConfigurationsFromContext.

@Nullable
public static List<ConfigurationFromContext> getConfigurationsFromContext(final Location location, final ConfigurationContext context, final boolean strict) {
    if (location == null) {
        return null;
    }
    final ArrayList<ConfigurationFromContext> configurationsFromContext = new ArrayList<>();
    for (RuntimeConfigurationProducer producer : findAllProducers(location, context)) {
        configurationsFromContext.add(new ConfigurationFromContextWrapper(producer));
    }
    for (RunConfigurationProducer producer : RunConfigurationProducer.getProducers(context.getProject())) {
        ConfigurationFromContext fromContext = producer.findOrCreateConfigurationFromContext(context);
        if (fromContext != null) {
            configurationsFromContext.add(fromContext);
        }
    }
    if (configurationsFromContext.isEmpty())
        return null;
    Collections.sort(configurationsFromContext, ConfigurationFromContext.COMPARATOR);
    if (strict) {
        final ConfigurationFromContext first = configurationsFromContext.get(0);
        for (Iterator<ConfigurationFromContext> it = configurationsFromContext.iterator(); it.hasNext(); ) {
            ConfigurationFromContext producer = it.next();
            if (producer != first && ConfigurationFromContext.COMPARATOR.compare(producer, first) > 0) {
                it.remove();
            }
        }
    }
    return configurationsFromContext;
}
Also used : RuntimeConfigurationProducer(com.intellij.execution.junit.RuntimeConfigurationProducer) ArrayList(java.util.ArrayList) ConfigurationFromContextWrapper(com.intellij.execution.impl.ConfigurationFromContextWrapper) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with RuntimeConfigurationProducer

use of com.intellij.execution.junit.RuntimeConfigurationProducer in project intellij-community by JetBrains.

the class ConfigurationContext method findExisting.

/**
   * Finds an existing run configuration matching the context.
   *
   * @return an existing configuration, or null if none was found.
   */
@Nullable
public RunnerAndConfigurationSettings findExisting() {
    if (myExistingConfiguration != null)
        return myExistingConfiguration.get();
    myExistingConfiguration = new Ref<>();
    if (myLocation == null) {
        return null;
    }
    final PsiElement psiElement = myLocation.getPsiElement();
    if (!psiElement.isValid()) {
        return null;
    }
    final List<RuntimeConfigurationProducer> producers = findPreferredProducers();
    if (myRuntimeConfiguration != null) {
        if (producers != null) {
            for (RuntimeConfigurationProducer producer : producers) {
                final RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(myLocation, this);
                if (configuration != null && configuration.getConfiguration() == myRuntimeConfiguration) {
                    myExistingConfiguration.set(configuration);
                }
            }
        }
        for (RunConfigurationProducer producer : RunConfigurationProducer.getProducers(getProject())) {
            RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(this);
            if (configuration != null && configuration.getConfiguration() == myRuntimeConfiguration) {
                myExistingConfiguration.set(configuration);
            }
        }
    }
    if (producers != null) {
        for (RuntimeConfigurationProducer producer : producers) {
            final RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(myLocation, this);
            if (configuration != null) {
                myExistingConfiguration.set(configuration);
            }
        }
    }
    for (RunConfigurationProducer producer : RunConfigurationProducer.getProducers(getProject())) {
        RunnerAndConfigurationSettings configuration = producer.findExistingConfiguration(this);
        if (configuration != null) {
            myExistingConfiguration.set(configuration);
        }
    }
    return myExistingConfiguration.get();
}
Also used : RuntimeConfigurationProducer(com.intellij.execution.junit.RuntimeConfigurationProducer) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with RuntimeConfigurationProducer

use of com.intellij.execution.junit.RuntimeConfigurationProducer in project intellij-community by JetBrains.

the class PreferredProducerFind method findAllProducers.

private static List<RuntimeConfigurationProducer> findAllProducers(Location location, ConfigurationContext context) {
    //todo load configuration types if not already loaded
    Extensions.getExtensions(ConfigurationType.CONFIGURATION_TYPE_EP);
    final RuntimeConfigurationProducer[] configurationProducers = ApplicationManager.getApplication().getExtensions(RuntimeConfigurationProducer.RUNTIME_CONFIGURATION_PRODUCER);
    final ArrayList<RuntimeConfigurationProducer> producers = new ArrayList<>();
    for (final RuntimeConfigurationProducer prototype : configurationProducers) {
        final RuntimeConfigurationProducer producer;
        try {
            producer = prototype.createProducer(location, context);
        } catch (AbstractMethodError e) {
            LOG.error(new ExtensionException(prototype.getClass()));
            continue;
        }
        if (producer.getConfiguration() != null) {
            LOG.assertTrue(producer.getSourceElement() != null, producer);
            producers.add(producer);
        }
    }
    return producers;
}
Also used : RuntimeConfigurationProducer(com.intellij.execution.junit.RuntimeConfigurationProducer) ArrayList(java.util.ArrayList) ExtensionException(com.intellij.openapi.extensions.ExtensionException)

Example 4 with RuntimeConfigurationProducer

use of com.intellij.execution.junit.RuntimeConfigurationProducer in project intellij-community by JetBrains.

the class PreferredProducerFind method findPreferredProducers.

@Nullable
@Deprecated
public static List<RuntimeConfigurationProducer> findPreferredProducers(final Location location, final ConfigurationContext context, final boolean strict) {
    if (location == null) {
        return null;
    }
    final List<RuntimeConfigurationProducer> producers = findAllProducers(location, context);
    if (producers.isEmpty())
        return null;
    Collections.sort(producers, RuntimeConfigurationProducer.COMPARATOR);
    if (strict) {
        final RuntimeConfigurationProducer first = producers.get(0);
        for (Iterator<RuntimeConfigurationProducer> it = producers.iterator(); it.hasNext(); ) {
            RuntimeConfigurationProducer producer = it.next();
            if (producer != first && RuntimeConfigurationProducer.COMPARATOR.compare(producer, first) >= 0) {
                it.remove();
            }
        }
    }
    return producers;
}
Also used : RuntimeConfigurationProducer(com.intellij.execution.junit.RuntimeConfigurationProducer) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RuntimeConfigurationProducer (com.intellij.execution.junit.RuntimeConfigurationProducer)4 Nullable (org.jetbrains.annotations.Nullable)3 ArrayList (java.util.ArrayList)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFromContextWrapper (com.intellij.execution.impl.ConfigurationFromContextWrapper)1 ExtensionException (com.intellij.openapi.extensions.ExtensionException)1 PsiElement (com.intellij.psi.PsiElement)1