Search in sources :

Example 1 with JavaRunConfigurationModule

use of com.intellij.execution.configurations.JavaRunConfigurationModule in project intellij-community by JetBrains.

the class ConfigurationModuleSelector method getConfigurationModule.

public JavaRunConfigurationModule getConfigurationModule() {
    final JavaRunConfigurationModule configurationModule = new JavaRunConfigurationModule(getProject(), false);
    configurationModule.setModule(getModule());
    return configurationModule;
}
Also used : JavaRunConfigurationModule(com.intellij.execution.configurations.JavaRunConfigurationModule)

Example 2 with JavaRunConfigurationModule

use of com.intellij.execution.configurations.JavaRunConfigurationModule in project intellij-community by JetBrains.

the class ResetConfigurationModuleAdapter method tryWithAnotherModule.

public static <T extends ModuleBasedConfiguration<JavaRunConfigurationModule> & CommonJavaRunConfigurationParameters> boolean tryWithAnotherModule(T configuration, boolean isDebug) {
    final String packageName = configuration.getPackage();
    if (packageName == null)
        return false;
    final Project project = configuration.getProject();
    final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName);
    if (aPackage == null)
        return false;
    final Module module = configuration.getConfigurationModule().getModule();
    if (module == null)
        return false;
    final Set<Module> modulesWithPackage = new HashSet<>();
    final PsiDirectory[] directories = aPackage.getDirectories();
    for (PsiDirectory directory : directories) {
        final Module currentModule = ModuleUtilCore.findModuleForFile(directory.getVirtualFile(), project);
        if (module != currentModule && currentModule != null) {
            modulesWithPackage.add(currentModule);
        }
    }
    if (!modulesWithPackage.isEmpty()) {
        final String testRunDebugId = isDebug ? ToolWindowId.DEBUG : ToolWindowId.RUN;
        final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        final Function<Module, String> moduleNameRef = module1 -> {
            final String moduleName = module1.getName();
            return "<a href=\"" + moduleName + "\">" + moduleName + "</a>";
        };
        String message = "Tests were not found in module \"" + module.getName() + "\".\n" + "Use ";
        if (modulesWithPackage.size() == 1) {
            message += "module \"" + moduleNameRef.fun(modulesWithPackage.iterator().next()) + "\" ";
        } else {
            message += "one of\n" + StringUtil.join(modulesWithPackage, moduleNameRef, "\n") + "\n";
        }
        message += "instead";
        toolWindowManager.notifyByBalloon(testRunDebugId, MessageType.WARNING, message, null, new ResetConfigurationModuleAdapter(configuration, project, isDebug, toolWindowManager, testRunDebugId));
        return true;
    }
    return false;
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) MessageType(com.intellij.openapi.ui.MessageType) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ExecutionException(com.intellij.execution.ExecutionException) ModuleManager(com.intellij.openapi.module.ModuleManager) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) ModuleBasedConfiguration(com.intellij.execution.configurations.ModuleBasedConfiguration) Balloon(com.intellij.openapi.ui.popup.Balloon) HashSet(java.util.HashSet) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) Executor(com.intellij.execution.Executor) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) JavaRunConfigurationModule(com.intellij.execution.configurations.JavaRunConfigurationModule) CommonJavaRunConfigurationParameters(com.intellij.execution.CommonJavaRunConfigurationParameters) Function(com.intellij.util.Function) PsiDirectory(com.intellij.psi.PsiDirectory) Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module) JavaRunConfigurationModule(com.intellij.execution.configurations.JavaRunConfigurationModule) HashSet(java.util.HashSet)

Example 3 with JavaRunConfigurationModule

use of com.intellij.execution.configurations.JavaRunConfigurationModule in project intellij-community by JetBrains.

the class TestCategory method checkConfiguration.

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
    JavaParametersUtil.checkAlternativeJRE(getConfiguration());
    ProgramParametersUtil.checkWorkingDirectoryExist(getConfiguration(), getConfiguration().getProject(), getConfiguration().getConfigurationModule().getModule());
    final String category = getConfiguration().getPersistentData().getCategory();
    if (category == null || category.isEmpty()) {
        throw new RuntimeConfigurationError("Category is not specified");
    }
    final JavaRunConfigurationModule configurationModule = getConfiguration().getConfigurationModule();
    if (getSourceScope() == null) {
        configurationModule.checkForWarning();
    }
    final Module module = configurationModule.getModule();
    if (module != null) {
        final PsiClass psiClass = JavaExecutionUtil.findMainClass(getConfiguration().getProject(), category, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
        if (psiClass == null) {
            throw new RuntimeConfigurationWarning(ExecutionBundle.message("class.not.found.in.module.error.message", category, configurationModule.getModuleName()));
        }
    }
}
Also used : RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) JavaRunConfigurationModule(com.intellij.execution.configurations.JavaRunConfigurationModule) Module(com.intellij.openapi.module.Module) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) JavaRunConfigurationModule(com.intellij.execution.configurations.JavaRunConfigurationModule)

Aggregations

JavaRunConfigurationModule (com.intellij.execution.configurations.JavaRunConfigurationModule)3 Module (com.intellij.openapi.module.Module)2 CommonJavaRunConfigurationParameters (com.intellij.execution.CommonJavaRunConfigurationParameters)1 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 ModuleBasedConfiguration (com.intellij.execution.configurations.ModuleBasedConfiguration)1 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)1 RuntimeConfigurationWarning (com.intellij.execution.configurations.RuntimeConfigurationWarning)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)1 Project (com.intellij.openapi.project.Project)1 MessageType (com.intellij.openapi.ui.MessageType)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 ToolWindowId (com.intellij.openapi.wm.ToolWindowId)1 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)1