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 { ...@@ -59,6 +59,11 @@ public final class PathConverter {
* @return the path in cygwin style or the value of the path parameter. * @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) { 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())) { if (!Platform.OS_WIN32.equals(Platform.getOS())) {
return path; return path;
} }
......
...@@ -150,6 +150,58 @@ public final class ProjectFileHandler { ...@@ -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 * Constructs the object, saves the project to work on, and initializes
* the needed structures. * the needed structures.
......
...@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui, ...@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.variables, org.eclipse.core.variables,
org.eclipse.debug.ui, org.eclipse.debug.ui,
org.eclipse.core.expressions, 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 Bundle-ActivationPolicy: lazy
Eclipse-LazyStart: true Eclipse-LazyStart: true
Bundle-Vendor: Eclipse Titan Project Bundle-Vendor: Eclipse Titan Project
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
package org.eclipse.titan.executor.executors; package org.eclipse.titan.executor.executors;
import static org.eclipse.titan.executor.GeneralConstants.EXECUTECONFIGFILEONLAUNCH; import static org.eclipse.titan.executor.GeneralConstants.EXECUTECONFIGFILEONLAUNCH;
import org.eclipse.titan.designer.properties.data.ProjectFileHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
...@@ -48,32 +50,19 @@ public abstract class LaunchShortcut implements ILaunchShortcut { ...@@ -48,32 +50,19 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
public abstract boolean initLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration, public abstract boolean initLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration,
final IProject project, final String configFilePath); final IProject project, final String configFilePath);
protected ILaunchConfigurationWorkingCopy getWorkingCopy(final ISelection selection, final String mode) { protected ILaunchConfigurationWorkingCopy getWorkingCopy(final IProject project, IFile file, 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 IProject)) {
return null;
}
final IProject project = (IProject) selections[0];
try { try {
final ILaunchConfigurationType configurationType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getConfigurationId()); final ILaunchConfigurationType configurationType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getConfigurationId());
final ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configurationType); final ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configurationType);
final String configurationName = "new configuration (" + project.getName() + ")";
final List<ILaunchConfiguration> candidateConfigurations = new ArrayList<ILaunchConfiguration>(); final List<ILaunchConfiguration> candidateConfigurations = new ArrayList<ILaunchConfiguration>();
for (ILaunchConfiguration configuration : configurations) { for (ILaunchConfiguration configuration : configurations) {
IResource[] resources = configuration.getMappedResources(); IResource[] resources = configuration.getMappedResources();
if (null != resources) { if (null != resources) {
boolean found = false; boolean found = false;
for (IResource resource : resources) { for (IResource resource : resources) {
if (project.equals(resource)) { if (file.equals(resource)) {
found = true; found = true;
} }
} }
...@@ -90,19 +79,19 @@ public abstract class LaunchShortcut implements ILaunchShortcut { ...@@ -90,19 +79,19 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation(); ILabelProvider labelProvider = DebugUITools.newDebugModelPresentation();
ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider); ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, labelProvider);
dialog.setTitle(getDialogTitle()); dialog.setTitle(getDialogTitle());
dialog.setMessage("Select existing configuration."); dialog.setMessage("Select existing configuration:");
dialog.setElements(candidateConfigurations.toArray(new ILaunchConfiguration[candidateConfigurations.size()])); dialog.setElements(candidateConfigurations.toArray(new ILaunchConfiguration[candidateConfigurations.size()]));
if (dialog.open() == Window.OK) { if (dialog.open() == Window.OK) {
ILaunchConfiguration result = (ILaunchConfiguration) dialog.getFirstResult(); ILaunchConfiguration result = (ILaunchConfiguration) dialog.getFirstResult();
result.launch(mode, null); result.launch(mode, null);
labelProvider.dispose(); labelProvider.dispose();
return null ; return null ;
} }
labelProvider.dispose(); 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); ILaunchConfigurationWorkingCopy wc = configurationType.newInstance(null, configurationName);
wc.setMappedResources(new IResource[] {project}); wc.setMappedResources(new IResource[] {project});
wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true); wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true);
...@@ -129,22 +118,50 @@ public abstract class LaunchShortcut implements ILaunchShortcut { ...@@ -129,22 +118,50 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
return; return;
} }
if (!(selections[0] instanceof IProject)) { 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; return;
} }
final IProject project = (IProject) selections[0]; if (project == null || cfgFile == null) {
try {
final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(selection, mode);
if (wc == null) {
return; return;
} }
boolean result = initLaunchConfiguration(wc, project, ""); final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(project, cfgFile, mode);
if (wc == null) {
return; // successful launch happened
}
boolean result = initLaunchConfiguration(wc, project, cfgFile.getLocation().toOSString());
if (result) { if (result) {
result = HostControllersTab.initLaunchConfiguration(wc); result = HostControllersTab.initLaunchConfiguration(wc);
} }
try {
if (result) { if (result) {
ILaunchConfiguration conf = wc.doSave(); ILaunchConfiguration conf = wc.doSave();
conf.launch(mode, null); conf.launch(mode, null);
......
...@@ -48,27 +48,11 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut { ...@@ -48,27 +48,11 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
public abstract boolean initLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration, public abstract boolean initLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration,
final IProject project, final String configFilePath); final IProject project, final String configFilePath);
protected ILaunchConfigurationWorkingCopy getWorkingCopy(final ISelection selection, final String mode) { protected ILaunchConfigurationWorkingCopy getWorkingCopy(final IProject project, IFile file, 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();
try { try {
final ILaunchConfigurationType configurationType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getConfigurationId()); final ILaunchConfigurationType configurationType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(getConfigurationId());
final ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configurationType); final ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configurationType);
final String configurationName = "new configuration (" + file.getFullPath().toString().replace("/", "__") + ")";
final List<ILaunchConfiguration> candidateConfigurations = new ArrayList<ILaunchConfiguration>(); final List<ILaunchConfiguration> candidateConfigurations = new ArrayList<ILaunchConfiguration>();
for (ILaunchConfiguration configuration : configurations) { for (ILaunchConfiguration configuration : configurations) {
IResource[] resources = configuration.getMappedResources(); IResource[] resources = configuration.getMappedResources();
...@@ -98,13 +82,13 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut { ...@@ -98,13 +82,13 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
final ILaunchConfiguration result = (ILaunchConfiguration) dialog.getFirstResult(); final ILaunchConfiguration result = (ILaunchConfiguration) dialog.getFirstResult();
result.launch(mode, null); result.launch(mode, null);
labelProvider.dispose(); labelProvider.dispose();
return null; return null;
} }
labelProvider.dispose(); labelProvider.dispose();
} }
// size() == 0 case: create new configuration
final String configurationName = "new configuration (" + file.getFullPath().toString().replace("/", "__") + ")";
final ILaunchConfigurationWorkingCopy wc = configurationType.newInstance(null, configurationName); final ILaunchConfigurationWorkingCopy wc = configurationType.newInstance(null, configurationName);
wc.setMappedResources(new IResource[] {project, file}); wc.setMappedResources(new IResource[] {project, file});
wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true); wc.setAttribute(EXECUTECONFIGFILEONLAUNCH, true);
...@@ -133,16 +117,21 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut { ...@@ -133,16 +117,21 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
} }
if (!(selections[0] instanceof IFile)) { if (!(selections[0] instanceof IFile)) {
ErrorReporter.logError("Config file not found"); // Is it necessary???
return; return;
} }
final IFile file = (IFile) selections[0]; final IFile file = (IFile) selections[0];
final IProject project = file.getProject(); final IProject project = file.getProject();
if( project == null ) {
ErrorReporter.logError("Project file not found");
return;
}
try { try {
final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(selection, mode); final ILaunchConfigurationWorkingCopy wc = getWorkingCopy(project,file, mode);
if (wc == null) { if (wc == null) {
return; return; //successful launch
} }
boolean result = initLaunchConfiguration(wc, project, file.getLocation().toOSString()); boolean result = initLaunchConfiguration(wc, project, file.getLocation().toOSString());
......
...@@ -23,7 +23,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L ...@@ -23,7 +23,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L
@Override @Override
protected String getDialogTitle() { protected String getDialogTitle() {
return "Select jni mode execution"; return "Select (parallel) jni mode execution configuration";
} }
@Override @Override
......
...@@ -379,7 +379,11 @@ public final class CliExecutor extends BaseExecutor { ...@@ -379,7 +379,11 @@ public final class CliExecutor extends BaseExecutor {
//TODO: implement //TODO: implement
if ( !CREATE_TEMP_CFG || logFileNameDefined ) { if ( !CREATE_TEMP_CFG || logFileNameDefined ) {
if (!StringUtils.isNullOrEmpty(configFilePath)) {
command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(configFilePath, true, TITANDebugConsole.getConsole()) + "'"); command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(configFilePath, true, TITANDebugConsole.getConsole()) + "'");
} else {
command.add(" sleep 1; " + mctrCliPath);
}
} else { } else {
generateTemporalCfgFile(generateCfgString()); generateTemporalCfgFile(generateCfgString());
command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(temporalConfigFile.getName(), true, TITANDebugConsole.getConsole()) + "'"); command.add(" sleep 1; " + mctrCliPath + " '" + PathConverter.convert(temporalConfigFile.getName(), true, TITANDebugConsole.getConsole()) + "'");
......
...@@ -22,7 +22,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L ...@@ -22,7 +22,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L
@Override @Override
protected String getDialogTitle() { protected String getDialogTitle() {
return "Select mctr_cli mode execution"; return "Select (parallel) mctr_cli mode execution configuration";
} }
@Override @Override
......
...@@ -23,7 +23,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L ...@@ -23,7 +23,7 @@ public final class LaunchShortcut extends org.eclipse.titan.executor.executors.L
@Override @Override
protected String getDialogTitle() { protected String getDialogTitle() {
return "Select single mode execution"; return "Select single mode execution configuration";
} }
@Override @Override
......
...@@ -653,6 +653,7 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT ...@@ -653,6 +653,7 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
} }
} }
configurationFileIsValid = false; configurationFileIsValid = false;
exceptions.clear();
exceptions.add(new Exception("The path `" + path + "' does not seem to be correct.")); exceptions.add(new Exception("The path `" + path + "' does not seem to be correct."));
automaticExecuteSectionExecution.setEnabled(false); automaticExecuteSectionExecution.setEnabled(false);
} }
...@@ -726,13 +727,14 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT ...@@ -726,13 +727,14 @@ public abstract class BaseMainControllerTab extends AbstractLaunchConfigurationT
} }
if(EMPTY.equals(configurationFileText.getStringValue())) { if(EMPTY.equals(configurationFileText.getStringValue())) {
setErrorMessage("The configuration file must be set."); setErrorMessage("The configuration file must be set."); //<<<<== This should be set to "setErrorMessage(null);"
return false; //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) { } else if (!configurationFileIsValid) {
if (null != exceptions && !exceptions.isEmpty()) { if (null != exceptions && !exceptions.isEmpty()) {
setErrorMessage("Problem in config file: " + exceptions.get(0).toString()); setErrorMessage("Problem in config file: " + exceptions.get(0).getMessage());
} else { } else {
setErrorMessage("The configurationfile is not valid."); setErrorMessage("The configuration file is not valid.");
} }
return false; 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