// Path: tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/runners/RunProject.java
// public class RunProject {
// 
//     private static final Logger logger = LoggerFactory.getLogger(RunProject.class);
// 
//     private final RunConfigurationFactory factory;
// 
//     public RunProject(RunManager runManager, Module module, String configurationType) {
//         logger.info("Creating RunConfigurationFactory.");
//         factory = new RunConfigurationFactory(runManager, module, configurationType);
//         if (makeSureConfigurationIsCorrectType(runManager)) {
//             return;
//         }
//         factory.createRunner();
//     }
// 
//     private boolean makeSureConfigurationIsCorrectType(RunManager runManager) {
//         if (runManager.getSelectedConfiguration() == null || factory.checkConfigurationType()) {
//             logger.info("Prompting user to choose main class with Chooser.");
//             TreeClassChooser chooser = factory.chooseMainClassForProject();
//             if (chooser.getSelected() == null) {
//                 logger.warn("Choosing main class returned null and running is cancelled.");
//                 return true;
//             }
//             logger.info("Creating configurations.");
//             factory.createConfiguration();
//             factory.configApplicationConfiguration(chooser);
//         }
//         return false;
//     }
// }


import fi.helsinki.cs.tmc.intellij.runners.RunProject;
import com.intellij.execution.RunManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package fi.helsinki.cs.tmc.intellij.actions.buttonactions;





public class RunProjectAction extends AnAction {

    private static final Logger logger = LoggerFactory.getLogger(RunProjectAction.class);

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        runProject(anActionEvent.getProject());
    }

    /**
     * Main run method, readies project module for running. First it finds current module, then
     * checks, whether it has a valid runconfiguration or not. If it does not, it creates one,
     * otherwise current configuration is run as is as long as it has a main class.
     */
    private void runProject(Project project) {
        logger.info("Run project action called.");
        logger.info("Getting RunManager.");
        RunManager runManager = RunManager.getInstance(project);
        Module module = getModule(project);
        String configurationType = getConfigurationType();
        logger.info("Creating RunProject object.");
// Path: tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/runners/RunProject.java
// public class RunProject {
// 
//     private static final Logger logger = LoggerFactory.getLogger(RunProject.class);
// 
//     private final RunConfigurationFactory factory;
// 
//     public RunProject(RunManager runManager, Module module, String configurationType) {
//         logger.info("Creating RunConfigurationFactory.");
//         factory = new RunConfigurationFactory(runManager, module, configurationType);
//         if (makeSureConfigurationIsCorrectType(runManager)) {
//             return;
//         }
//         factory.createRunner();
//     }
// 
//     private boolean makeSureConfigurationIsCorrectType(RunManager runManager) {
//         if (runManager.getSelectedConfiguration() == null || factory.checkConfigurationType()) {
//             logger.info("Prompting user to choose main class with Chooser.");
//             TreeClassChooser chooser = factory.chooseMainClassForProject();
//             if (chooser.getSelected() == null) {
//                 logger.warn("Choosing main class returned null and running is cancelled.");
//                 return true;
//             }
//             logger.info("Creating configurations.");
//             factory.createConfiguration();
//             factory.configApplicationConfiguration(chooser);
//         }
//         return false;
//     }
// }


// Path: tmc-plugin-intellij/src/main/java/fi/helsinki/cs/tmc/intellij/actions/buttonactions/RunProjectAction.java
import fi.helsinki.cs.tmc.intellij.runners.RunProject;
import com.intellij.execution.RunManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package fi.helsinki.cs.tmc.intellij.actions.buttonactions;





public class RunProjectAction extends AnAction {

    private static final Logger logger = LoggerFactory.getLogger(RunProjectAction.class);

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        runProject(anActionEvent.getProject());
    }

    /**
     * Main run method, readies project module for running. First it finds current module, then
     * checks, whether it has a valid runconfiguration or not. If it does not, it creates one,
     * otherwise current configuration is run as is as long as it has a main class.
     */
    private void runProject(Project project) {
        logger.info("Run project action called.");
        logger.info("Getting RunManager.");
        RunManager runManager = RunManager.getInstance(project);
        Module module = getModule(project);
        String configurationType = getConfigurationType();
        logger.info("Creating RunProject object.");
        new RunProject(runManager, module, configurationType);