Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #167 add "Custom Start..." option to choose from in the available Run configurations. #529

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import io.openliberty.tools.intellij.LibertyModule;
import io.openliberty.tools.intellij.LibertyPluginIcons;
import io.openliberty.tools.intellij.runConfiguration.LibertyRunConfiguration;
import io.openliberty.tools.intellij.runConfiguration.LibertyRunConfigurationType;
import io.openliberty.tools.intellij.util.LocalizedResourceUtil;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -43,7 +45,6 @@ protected String getActionCommandName() {
@Override
protected void executeLibertyAction(LibertyModule libertyModule) {
Project project = libertyModule.getProject();
VirtualFile buildFile = libertyModule.getBuildFile();

// open run config
RunManager runManager = RunManager.getInstance(project);
Expand All @@ -63,23 +64,32 @@ protected void executeLibertyAction(LibertyModule libertyModule) {
// create new run config
selectedLibertyConfig = createNewLibertyRunConfig(runManager, libertyModule);
} else {
// TODO if 1+ run configs, prompt user to select the one they want see https://github.com/OpenLiberty/liberty-tools-intellij/issues/167

// 1+ run configs found for the given project
RunnerAndConfigurationSettings selectedConfig = runManager.getSelectedConfiguration();
/*RunnerAndConfigurationSettings selectedConfig = runManager.getSelectedConfiguration();
if (libertyModuleSettings.contains(selectedConfig)) {
// if the selected config is for the Liberty module, use that run config
selectedLibertyConfig = selectedConfig;
// if the selected config is for the Liberty module, use that run config*/
// selectedLibertyConfig = selectedConfig;
final String[] runConfigNames = toRunConfigNames(libertyModuleSettings);

//it will display the dialog box with the run configurations with the selected project
LibertyProjectChooserDialog libertyChooserDiag = new LibertyProjectChooserDialog(project,
LocalizedResourceUtil.getMessage("run.config.file.selection.dialog.message", libertyModule.getName()),
LocalizedResourceUtil.getMessage("run.config.file.selection.dialog.title"),
LibertyPluginIcons.libertyIcon_40, runConfigNames, runConfigNames,
runConfigNames[0]);
libertyChooserDiag.show();

final int ret = libertyChooserDiag.getSelectedIndex();
if (ret >= 0 && ret < libertyModuleSettings.size()) {
selectedLibertyConfig = libertyModuleSettings.get(ret);
} else {
// pick first in list run config in list
selectedLibertyConfig = libertyModuleSettings.get(0);
// The user pressed cancel on the dialog. No need to show an error message.
return;
}
}
// opens run config dialog
selectedLibertyConfig.setEditBeforeRun(true);
ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(DefaultRunExecutor.getRunExecutorInstance(), selectedLibertyConfig);
if (builder != null) {
ExecutionManager.getInstance(project).restartRunProfile(builder.build());
}

openRunConfigDialog(selectedLibertyConfig, project);
}

/**
Expand All @@ -95,4 +105,36 @@ protected RunnerAndConfigurationSettings createNewLibertyRunConfig(RunManager ru
libertyRunConfiguration.setBuildFile(libertyModule.getBuildFile().toNioPath().toString());
return runConfigSettings;
}
}

/**
* To get the run config names.
*
* @param list
* @return array of run config names.
*/
protected final String[] toRunConfigNames(@NotNull List<RunnerAndConfigurationSettings> list) {
final int size = list.size();
final String[] runConfigNames = new String[size];

for (int i = 0; i < size; ++i) {
runConfigNames[i] = list.get(i).getConfiguration().getName();
}
return runConfigNames;
}

/**
* Display selectedLibertyConfig
*
* @param selectedLibertyConfig
* @param project
*/
private void openRunConfigDialog(@NotNull RunnerAndConfigurationSettings selectedLibertyConfig, Project project) {
// opens run config dialog
selectedLibertyConfig.setEditBeforeRun(true);
ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.createOrNull(
DefaultRunExecutor.getRunExecutorInstance(), selectedLibertyConfig);
if (builder != null) {
ExecutionManager.getInstance(project).restartRunProfile(builder.build());
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages/LibertyBundles.properties
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ run.config.liberty.project.tool.tip=Select the build file for your Liberty proje
run.config.start.parameters=Start Parameters
run.config.start.parameters.tool.tip=eg. -DhotTests=true (Maven) --hotTests=true (Gradle)
specify.custom.parameters.for.the.mvn.liberty.dev.command=Specify custom parameters for the mvn liberty:dev command
run.config.file.selection.dialog.message=Select Run Configuration for {0}
run.config.file.selection.dialog.title=Run Configurations

# Maven and Gradle exceptions
maven.wrapper.does.not.exist=A Maven wrapper for the project could not be found. Make sure to configure a valid Maven wrapper or change the build preferences for Maven inside IntelliJ Maven preferences.
Expand Down
Loading