Commit 95a0c8b4 authored by balaskoa's avatar balaskoa
Browse files

launchShortcut impovement for cfg file handling, see [bug 492566] in bugzilla


Signed-off-by: default avatarbalaskoa <jeno.balasko@ericsson.com>
parent d37a7a8b
......@@ -59,6 +59,11 @@ public final class PathConverter {
* @return the path in cygwin style or the value of the path parameter.
* */
public static String convert(final String path, final boolean reportDebugInformation, final MessageConsole outputConsole) {
if("".equals(path)){
return path;
}
if (!Platform.OS_WIN32.equals(Platform.getOS())) {
return path;
}
......
......@@ -150,6 +150,58 @@ public final class ProjectFileHandler {
}
}
/**
* Gets all the files of the project
*
* @param project
* @return Map of the projects
*/
public static Map<String, IFile> getFiles(final IProject project) {
final IContainer[] workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(false);
final ResourceVisitor saveVisitor = new ResourceVisitor(workingDirectories);
// collect the resources
try {
project.accept(saveVisitor);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While collecting resources of `" + project.getName() + "'", e);
}
final Map<String, IFile> files = saveVisitor.getFiles();
return files;
}
public static List<IFile> getCfgFiles(final IProject project) {
Map<String, IFile> files = getFiles(project);
List<IFile> cfgFiles = new ArrayList<IFile>();
for( IFile file : files.values()) {
if("cfg".equals(file.getFileExtension())) {
cfgFiles.add(file);
}
}
return cfgFiles;
}
/**
* Gets all the folders of the project
*
* @param project
* @return
*/
public static Map<String, IFolder> getFoldersOfProject(final IProject project) {
final IContainer[] workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(false);
final ResourceVisitor saveVisitor = new ResourceVisitor(workingDirectories);
// collect the resources
try {
project.accept(saveVisitor);
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace("While collecting resources of `" + project.getName() + "'", e);
}
final Map<String, IFolder> folders = saveVisitor.getFolders();
return folders;
}
/**
* Constructs the object, saves the project to work on, and initializes
* the needed structures.
......
......@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.variables,
org.eclipse.debug.ui,
org.eclipse.core.expressions,
org.eclipse.titan.common;bundle-version="5.5.0"
org.eclipse.titan.common;bundle-version="5.5.0",
org.eclipse.titan.designer;bundle-version="5.5.0"
Bundle-ActivationPolicy: lazy
Eclipse-LazyStart: true
Bundle-Vendor: Eclipse Titan Project
......
......@@ -8,10 +8,12 @@
package org.eclipse.titan.executor.executors;
import static org.eclipse.titan.executor.GeneralConstants.EXECUTECONFIGFILEONLAUNCH;
import org.eclipse.titan.designer.properties.data.ProjectFileHandler;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
......@@ -48,32 +50,19 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
public abstract boolean initLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration,
final IProject project, final String configFilePath);
protected ILaunchConfigurationWorkingCopy getWorkingCopy(final ISelection selection, final String mode) {
if (!(selection instanceof IStructuredSelection)) {
return null;
}
final Object[] selections = ((IStructuredSelection) selection).toArray();
if (1 != selections.length) {
return null;
}
protected ILaunchConfigurationWorkingCopy getWorkingCopy(final IProject project, IFile file, final String mode) {
if (!(selections[0] instanceof IProject)) {
return null;
}
final IProject project = (IProject) selections[0];
try {
final ILaunchConfigurationType configurationType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getConfigurationId());
final ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configurationType);
final String configurationName = "new configuration (" + project.getName() + ")";
final List<ILaunchConfiguration> candidateConfigurations = new ArrayList<ILaunchConfiguration>();
for (ILaunchConfiguration configuration : configurations) {
IResource[] resources = configuration.getMappedResources();
if (null != resources) {
boolean found = false;
for (IResource resource : resources) {
if (project.equals(resource)) {
if (file.equals(resource)) {
found = true;
}
}
......@@ -90,19 +79,19 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
dialog.setTitle(getDialogTitle());
dialog.setMessage("Select existing configuration.");
dialog.setMessage("Select existing configuration:");
dialog.setElements(candidateConfigurations.toArray(new ILaunchConfiguration[candidateConfigurations.size()]));
if (dialog.open() == Window.OK) {
ILaunchConfiguration result = (ILaunchConfiguration) dialog.getFirstResult();
result.launch(mode, null);
labelProvider.dispose();
return null ;
}
labelProvider.dispose();
}
//old: final String configurationName = "new configuration (" + project.getName() + ")";
final String configurationName = "new configuration (" + file.getFullPath().toString().replace("/", "__") + ")";
ILaunchConfigurationWorkingCopy wc = configurationType.newInstance(null, configurationName);
wc.setMappedResources(new IResource[] {project});
wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true);
......@@ -129,22 +118,50 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
return;
}
if (!(selections[0] instanceof IProject)) {
return;
}
final IProject project = (IProject) selections[0];
try {
final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(selection, mode);
if (wc == null) {
IFile cfgFile = null;
IProject project = null;
if ((selections[0] instanceof IProject)) {
// try to find the cfg file:
project = (IProject) selections[0];
List<IFile> cfgFiles = ProjectFileHandler.getCfgFiles(project);
if (cfgFiles.size() == 1) {
cfgFile = cfgFiles.get(0);
} else if (cfgFiles.size() > 1) {
final ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
final ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
dialog.setTitle("Config File Selection");
dialog.setMessage("Select existing cfg file:");
dialog.setElements(cfgFiles.toArray(new IFile[cfgFiles.size()]));
if (dialog.open() == Window.OK) {
cfgFile = (IFile) dialog.getFirstResult();
}
} else {
ErrorReporter.logError("Config file not found");
ErrorReporter.parallelErrorDisplayInMessageDialog(
"An error was found while creating the default launch configuration for project "
+ project.getName(),
"Config file not found in project " + project.getName());
return;
}
} else {
return;
}
boolean result = initLaunchConfiguration(wc, project, "");
if (result) {
result = HostControllersTab.initLaunchConfiguration(wc);
}
if (project == null || cfgFile == null) {
return;
}
final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(project, cfgFile, mode);
if (wc == null) {
return; // successful launch happened
}
boolean result = initLaunchConfiguration(wc, project, cfgFile.getLocation().toOSString());
if (result) {
result = HostControllersTab.initLaunchConfiguration(wc);
}
try {
if (result) {
ILaunchConfiguration conf = wc.doSave();
conf.launch(mode, null);
......
......@@ -48,27 +48,11 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
public abstract boolean initLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration,
final IProject project, final String configFilePath);
protected ILaunchConfigurationWorkingCopy getWorkingCopy(final ISelection selection, final String mode) {
if (!(selection instanceof IStructuredSelection)) {
return null;
}
final Object[] selections = ((IStructuredSelection) selection).toArray();
if (1 != selections.length) {
return null;
}
if (!(selections[0] instanceof IFile)) {
return null;
}
final IFile file = (IFile) selections[0];
final IProject project = file.getProject();
protected ILaunchConfigurationWorkingCopy getWorkingCopy(final IProject project, IFile file, final String mode) {
try {
final ILaunchConfigurationType configurationType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getConfigurationId());
final ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configurationType);
final String configurationName = "new configuration (" + file.getFullPath().toString().replace("/", "__") + ")";
final List<ILaunchConfiguration> candidateConfigurations = new ArrayList<ILaunchConfiguration>();
for (ILaunchConfiguration configuration : configurations) {
IResource[] resources = configuration.getMappedResources();
......@@ -98,13 +82,13 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
final ILaunchConfiguration result = (ILaunchConfiguration) dialog.getFirstResult();
result.launch(mode, null);
labelProvider.dispose();
return null;
}
labelProvider.dispose();
}
// size() == 0 case: create new configuration
final String configurationName = "new configuration (" + file.getFullPath().toString().replace("/", "__") + ")";
final ILaunchConfigurationWorkingCopy wc = configurationType.newInstance(null, configurationName);
wc.setMappedResources(new IResource[] {project, file});
wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true);
......@@ -133,16 +117,21 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
}
if (!(selections[0] instanceof IFile)) {
ErrorReporter.logError("Config file not found"); // Is it necessary???
return;
}
final IFile file = (IFile) selections[0];
final IProject project = file.getProject();
if( project == null ) {
ErrorReporter.logError("Project file not found");
return;
}
try {
final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(selection, mode);
final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(project,file, mode);
if (wc == null) {
return;
return; //successful launch
}
boolean result = initLaunchConfiguration(wc, project, file.getLocation().toOSString());
......
......@@ -23,7 +23,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L
@Override
protected String getDialogTitle() {
return "Select jni mode execution";
return "Select (parallel) jni mode execution configuration";
}
@Override
......
......@@ -379,7 +379,11 @@ public final class CliExecutor extends BaseExecutor {
//TODO: implement
if ( !CREATE_TEMP_CFG || logFileNameDefined ) {
command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(configFilePath, true, TITANDebugConsole.getConsole()) + "'");
if (!StringUtils.isNullOrEmpty(configFilePath)) {
command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(configFilePath, true, TITANDebugConsole.getConsole()) + "'");
} else {
command.add(" sleep 1; " + mctrCliPath);
}
} else {
generateTemporalCfgFile(generateCfgString());
command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(temporalConfigFile.getName(), true, TITANDebugConsole.getConsole()) + "'");
......
......@@ -21,8 +21,8 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L
}
@Override
protected String getDialogTitle() {
return "Select mctr_cli mode execution";
protected String getDialogTitle() {
return "Select (parallel) mctr_cli mode execution configuration";
}
@Override
......
......@@ -23,7 +23,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L
@Override
protected String getDialogTitle() {
return "Select single mode execution";
return "Select single mode execution configuration";
}
@Override
......
......@@ -653,6 +653,7 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
}
}
configurationFileIsValid = false;
exceptions.clear();
exceptions.add(new Exception("The path `" + path + "' does not seem to be correct."));
automaticExecuteSectionExecution.setEnabled(false);
}
......@@ -726,13 +727,14 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
}
if(EMPTY.equals(configurationFileText.getStringValue())) {
setErrorMessage("The configuration file must be set.");
return false;
setErrorMessage("The configuration file must be set."); //<<<<== This should be set to "setErrorMessage(null);"
//if the cfg file is not mandatory !
return false; // <<<<== This can be set to true if the cfg file is not mandatory !
} else if (!configurationFileIsValid) {
if (null != exceptions && !exceptions.isEmpty()) {
setErrorMessage("Problem in config file: " + exceptions.get(0).toString());
setErrorMessage("Problem in config file: " + exceptions.get(0).getMessage());
} else {
setErrorMessage("The configurationfile is not valid.");
setErrorMessage("The configuration file is not valid.");
}
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment