Java Code Examples for com.intellij.execution.actions.ConfigurationContext#getModule()

The following examples show how to use com.intellij.execution.actions.ConfigurationContext#getModule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatRunConfigurationProducer.java    From SmartTomcat with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isConfigurationFromContext(@NotNull TomcatRunConfiguration configuration, @NotNull ConfigurationContext context) {
    boolean result = false;

    VirtualFile vf = context.getLocation().getVirtualFile();
    if (vf != null && vf.isDirectory()) {
        Module module = context.getModule();
        Optional<VirtualFile> webModule = getWebModule(module);
        boolean isWebModule = webModule.isPresent();
        if (isWebModule) {
            VirtualFile virtualFile = webModule.get();
            if (vf.getCanonicalPath().equals(virtualFile.getCanonicalPath())) {
                result = true;
            }
        }
    }
    return result;
}
 
Example 2
Source File: MuleApplicationConfigurationProducer.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(MuleConfiguration muleConfiguration, ConfigurationContext configurationContext, Ref<PsiElement> ref)
{
    final Location location = configurationContext.getLocation();
    if (location != null)
    {
        final boolean muleFile = MuleConfigUtils.isMuleFile(location.getPsiElement().getContainingFile());
        final Module module = configurationContext.getModule();
        if (muleFile && module != null)
        {
            muleConfiguration.setModule(module);
            muleConfiguration.setName(StringUtils.capitalize(module.getName()));
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: WeaveConfigurationProducer.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isConfigurationFromContext(WeaveConfiguration muleConfiguration, ConfigurationContext configurationContext)
{
    final Module module = configurationContext.getModule();
    final PsiFile containingFile = configurationContext.getPsiLocation().getContainingFile();
    if (containingFile == null)
    {
        return false;
    }
    final String canonicalPath = containingFile.getVirtualFile().getCanonicalPath();
    final String weaveFile = muleConfiguration.getWeaveFile();
    if (weaveFile == null)
    {
        return false;
    }
    return module != null && module.equals(muleConfiguration.getModule()) && weaveFile.equals(canonicalPath);
}
 
Example 4
Source File: MultipleJavaClassesTestContextProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public RunConfigurationContext getTestContext(ConfigurationContext context) {
  boolean outsideProject = context.getModule() == null;
  if (outsideProject) {
    // TODO(brendandouglas): resolve PSI asynchronously for files outside the project
    return null;
  }
  PsiElement location = context.getPsiLocation();
  if (location instanceof PsiDirectory) {
    PsiDirectory dir = (PsiDirectory) location;
    ListenableFuture<TargetInfo> future = getTargetContext(dir);
    return futureEmpty(future) ? null : fromDirectory(future, dir);
  }
  Set<PsiClass> testClasses = selectedTestClasses(context);
  if (testClasses.size() <= 1) {
    return null;
  }
  ListenableFuture<TargetInfo> target = getTestTargetIfUnique(context.getProject(), testClasses);
  if (futureEmpty(target)) {
    return null;
  }
  testClasses = ProducerUtils.includeInnerTestClasses(testClasses);
  return fromClasses(target, testClasses);
}
 
Example 5
Source File: GaugeExecutionProducer.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(RunConfiguration configuration, ConfigurationContext context, Ref sourceElement) {
    VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context.getDataContext());
    if (selectedFiles == null || selectedFiles.length > 1) return false;
    Module module = context.getModule();
    if (context.getPsiLocation() == null || module == null) return false;
    PsiFile file = context.getPsiLocation().getContainingFile();
    if (!isSpecFile(file) || !isInSpecScope(context.getPsiLocation())) return false;
    try {
        VirtualFile virtualFile = file.getVirtualFile();
        if (virtualFile == null) return false;
        String name = virtualFile.getCanonicalPath();
        configuration.setName(file.getName());
        ((GaugeRunConfiguration) configuration).setSpecsToExecute(name);
        ((GaugeRunConfiguration) configuration).setModule(module);
        return true;
    } catch (Exception ex) {
        LOG.debug(ex);
        ex.printStackTrace();
    }
    return true;
}
 
Example 6
Source File: SpecsExecutionProducer.java    From Intellij-Plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(RunConfiguration configuration, ConfigurationContext configurationContext, Ref ref) {
    VirtualFile[] selectedFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(configurationContext.getDataContext());
    Module module = configurationContext.getModule();
    if (selectedFiles == null || module == null)
        return false;
    if (selectedFiles.length == 1) {
        if (!selectedFiles[0].isDirectory()) {
            return false;
        } else if (selectedFiles[0].getPath().equals(configurationContext.getProject().getBasePath())) {
            configuration.setName(DEFAULT_CONFIGURATION_NAME);
            ((GaugeRunConfiguration) configuration).setModule(module);
            return true;
        }
    }

    List<String> specsToExecute = getSpecs(selectedFiles);
    if (specsToExecute.size() == 0) {
        return false;
    }
    configuration.setName(DEFAULT_CONFIGURATION_NAME);
    ((GaugeRunConfiguration) configuration).setModule(module);
    ((GaugeRunConfiguration) configuration).setSpecsArrayToExecute(specsToExecute);
    return true;
}
 
Example 7
Source File: TomcatRunConfigurationProducer.java    From SmartTomcat with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(@NotNull TomcatRunConfiguration configuration, @NotNull ConfigurationContext context, @NotNull Ref<PsiElement> sourceElement) {

    boolean result = isConfigurationFromContext(configuration, context);

    if (result) {
        List<TomcatInfo> tomcatInfos = TomcatInfoConfigs.getInstance().getTomcatInfos();
        if (tomcatInfos != null && tomcatInfos.size() > 0) {
            TomcatInfo tomcatInfo = tomcatInfos.get(0);
            configuration.setTomcatInfo(tomcatInfo);
        } else  {
            throw new RuntimeException("Not found any Tomcat Server, please add Tomcat Server first.");
        }

        VirtualFile virtualFile = context.getLocation().getVirtualFile();
        Module module = context.getModule();
        configuration.setName(module.getName());
        configuration.setDocBase(virtualFile.getCanonicalPath());
        configuration.setContextPath("/" + module.getName());
        configuration.setModuleName(module.getName());

        final RunnerAndConfigurationSettings settings =
                RunManager.getInstance(context.getProject()).createConfiguration(configuration, getConfigurationFactory());
        settings.setName(module.getName() + " in SmartTomcat");
    }
    return result;
}
 
Example 8
Source File: MuleApplicationConfigurationProducer.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isConfigurationFromContext(MuleConfiguration muleConfiguration, ConfigurationContext configurationContext)
{
    final Module module = configurationContext.getModule();
    if (module != null) {
        Module[] modules = muleConfiguration.getModules();
        for (Module m : modules) {
            if (module.equals(m))
                return true;
        }
    }
    return false;
}
 
Example 9
Source File: BlazeRunConfigurationProducer.java    From intellij with Apache License 2.0 5 votes vote down vote up
private boolean validContext(ConfigurationContext context) {
  if (restrictedToProjectFiles() && context.getModule() == null) {
    return false;
  }
  if (!isBlazeContext(context)) {
    return false;
  }
  return true;
}
 
Example 10
Source File: PantsConfigurationContext.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static Optional<PantsConfigurationContext> validatesAndCreate(ConfigurationContext context) {
  final Module module = context.getModule();
  if (module == null) return Optional.empty();

  final Optional<VirtualFile> buildRoot = PantsUtil.findBuildRoot(module);
  if (!buildRoot.isPresent()) return Optional.empty();

  final List<String> targets = PantsUtil.getNonGenTargetAddresses(module);
  if (targets.isEmpty()) return Optional.empty();

  final PsiElement psiLocation = context.getPsiLocation();
  if (psiLocation == null) return Optional.empty();

  return Optional.of(new PantsConfigurationContext(module, buildRoot.get(), targets, psiLocation));
}
 
Example 11
Source File: BashRunConfigProducer.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean setupConfigurationFromContext(BashRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Location location = context.getLocation();
    if (location == null) {
        return false;
    }

    PsiElement psiElement = location.getPsiElement();
    if (!psiElement.isValid()) {
        return false;
    }

    PsiFile psiFile = psiElement.getContainingFile();
    if (!(psiFile instanceof BashFile)) {
        return false;
    }
    sourceElement.set(psiFile);

    VirtualFile file = location.getVirtualFile();
    if (file == null) {
        return false;
    }

    configuration.setName(file.getPresentableName());
    configuration.setScriptName(VfsUtilCore.virtualToIoFile(file).getAbsolutePath());

    if (file.getParent() != null) {
        configuration.setWorkingDirectory(VfsUtilCore.virtualToIoFile(file.getParent()).getAbsolutePath());
    }

    Module module = context.getModule();
    if (module != null) {
        configuration.setModule(module);
    }

    // check the location given by the shebang line
    // do this only if the project interpreter isn't used because we don't want to add the options
    // because it would mess up the execution when the project interpreter was used.
    // options might be added by a shebang like "/usr/bin/env bash".
    // also, we don't want to override the defaults of the template run configuration
    if (!configuration.isUseProjectInterpreter() && configuration.getInterpreterPath().isEmpty()) {
        BashFile bashFile = (BashFile) psiFile;
        BashShebang shebang = bashFile.findShebang();
        if (shebang != null) {
            String shebandShell = shebang.shellCommand(false);

            if ((BashInterpreterDetection.instance().isSuitable(shebandShell))) {
                configuration.setInterpreterPath(shebandShell);
                configuration.setInterpreterOptions(shebang.shellCommandParams());
            }
        }
    }

    return true;
}
 
Example 12
Source File: XQueryRunConfigurationProducer.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
private Module getModuleForLocation(ConfigurationContext context, ModuleBasedConfiguration configuration) {
    final Module contextModule = context.getModule();
    return findModule(configuration, contextModule);
}