Commit aa226113 authored by Adam Knapp's avatar Adam Knapp
Browse files

Comments added



Change-Id: Ib57075bcec79d7f936aa8583fc7b08b725d14504
Signed-off-by: default avatarAdam Knapp <adam.knapp@sigmatechnology.se>
parent 9756d17c
......@@ -22,7 +22,12 @@ import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.internal.core.groups.GroupLaunchConfigurationDelegate;
import org.eclipse.debug.internal.core.groups.GroupLaunchElement;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.parsers.cfg.ConfigFileHandler;
......@@ -31,6 +36,7 @@ import org.eclipse.titan.executor.designerconnection.DynamicLinkingHelper;
import org.eclipse.titan.executor.views.executormonitor.ExecutorMonitorView;
/**
* Utility class for different operations related to launch configurations
* @author Adam Knapp
* */
@SuppressWarnings("restriction")
......@@ -41,6 +47,15 @@ public final class LaunchConfigurationUtil {
private static final String GROUP_LAUNCH_CONFIGURATION_ID = "org.eclipse.debug.core.groups.GroupLaunchConfigurationType";
private static final String LAUNCH_CONFIGURATION_LIST_ATTR = PLUGIN_ID + ".linkedLaunchConfigurations";
/**
* Creates a new or overwrites the existing launch group configuration for Titan Native Java launcher.
* If the Main Controller has a linked launch group configuration, then it will be overwritten.
* @param configMC Launch configuration of the Main Controller
* @param configHC Launch configuration of the Host Controller
* @return The newly created or the overwritten launch group configuration. It returns {@code null},
* if the configuration of the Main Controller is {@code null} or not properly filled.
* @throws CoreException
*/
public static ILaunchConfiguration createGroupLaunchConfiguration(
final ILaunchConfiguration configMC, final ILaunchConfiguration configHC) throws CoreException {
if (configMC == null || configHC == null) {
......@@ -77,6 +92,14 @@ public final class LaunchConfigurationUtil {
return config;
}
/**
* Creates a new or overwrites the existing Java app launch configuration for Titan Native Java launcher.
* If the Main Controller has a linked Java app launch configuration, then it will be overwritten.
* @param configuration Launch configuration of the Main Controller
* @return The newly created or the overwritten Java app launch configuration. It returns {@code null},
* if the configuration of the Main Controller is {@code null} or not properly filled.
* @throws CoreException
*/
public static ILaunchConfiguration createJavaAppLaunchConfiguration(
final ILaunchConfiguration configuration) throws CoreException {
if (configuration == null) {
......@@ -141,6 +164,14 @@ public final class LaunchConfigurationUtil {
return config;
}
/**
* Overwrites the existing linked launch group configuration and disables the Host Controller.
* It might be necessary, if the Main Controller is set to single mode.
* Thus running the launch group will only start the Main Controller.
* @param configuration Launch configuration of the Main Controller
* @return Returns whether the operation was successful or not
* @throws CoreException
*/
public static boolean disableHCinGroupLaunchConfiguration(final ILaunchConfigurationWorkingCopy configuration) throws CoreException {
if (configuration == null) {
return false;
......@@ -160,18 +191,47 @@ public final class LaunchConfigurationUtil {
return true;
}
/**
* Looks for the launch group configuration with the given name in the workspace.
* @param configurationName Name of the launch group configuration
* @return Launch group configuration. It returns {@code null} if the {@code configurationName}
* is {@code null} or empty or no launch group configuration was found with this name in the workspace.
* @throws CoreException
*/
public static ILaunchConfiguration findGroupLaunchConfigurationByName(final String configurationName) throws CoreException {
return findLaunchConfigurationByName(configurationName, getGroupLaunchConfigurationType());
}
/**
* Looks for the Java app launch configuration with the given name in the workspace.
* @param configurationName Name of the Java app launch configuration
* @return Java app launch configuration. It returns {@code null} if the {@code configurationName}
* is {@code null} or empty or no Java app launch configuration was found with this name in the workspace.
* @throws CoreException
*/
public static ILaunchConfiguration findJavaAppLaunchConfigurationByName(final String configurationName) throws CoreException {
return findLaunchConfigurationByName(configurationName, getJavaAppLaunchConfigurationType());
}
/**
* Looks for any type of launch configuration with the given name in the workspace.
* @param configurationName Name of the launch configuration
* @return Launch configuration. It returns {@code null} if the {@code configurationName}
* is {@code null} or empty or no launch configuration was found with this name in the workspace.
* @throws CoreException
*/
public static ILaunchConfiguration findLaunchConfigurationByName(final String configurationName) throws CoreException {
return findLaunchConfigurationByName(configurationName, null);
}
/**
* Looks for the launch configuration of the specified type with the given name in the workspace.
* @param configurationName Name of the launch configuration
* @param type Type of the launch configuration. Might be {@code null}
* @return Launch configuration. It returns {@code null} if the {@code configurationName}
* is {@code null} or empty or no launch configuration was found with this name in the workspace.
* @throws CoreException
*/
public static ILaunchConfiguration findLaunchConfigurationByName(final String configurationName,
final ILaunchConfigurationType type) throws CoreException {
if (configurationName == null || configurationName.isEmpty()) {
......@@ -194,6 +254,13 @@ public final class LaunchConfigurationUtil {
return null;
}
/**
* Extracts the {@code localAddress} and {@code tcpPort} from the specified Titan configuration file.
* @param file Titan configuration file
* @return Return the the {@code localAddress} and {@code tcpPort} parameters as a concatenated string.
* It returns an empty string if the file is {@code null} or not exist or the {@code tcpPort} parameter is not valid.
* Never returns {@code null}
*/
public static String getArgsForParallelLaunch(final IFile file) {
if (file == null || !file.exists()) {
return "";
......@@ -214,6 +281,10 @@ public final class LaunchConfigurationUtil {
if (tcpPort == 0) {
ErrorReporter.logError("\"TCPPort\" parameter is missing from configuration file: "
+ configFileName);
ErrorReporter.parallelErrorDisplayInMessageDialog(
"Error while launching the project " + file.getProject().getName(),
"\"TCPPort\" parameter is missing from configuration file: " + file.getFullPath().toOSString() +
"\nCannot continue");
TITANConsole.println("\"TCPPort\" parameter is missing from configuration file: "
+ configFileName);
TITANConsole.println("Cannot continue");
......@@ -223,18 +294,41 @@ public final class LaunchConfigurationUtil {
return MessageFormat.format("{0} {1,number,#}", localAddress, tcpPort);
}
/**
* Extracts the {@code localAddress} and {@code tcpPort} from the specified Titan project and file.
* @param project Titan project
* @param configFileName Name of the Titan configuration file
* @return Return the the {@code localAddress} and {@code tcpPort} parameters as a concatenated string.
* It returns an empty string if the file is {@code null} or not exist or the {@code tcpPort} parameter is not valid.
* Never returns {@code null}
*/
public static String getArgsForParallelLaunch(final IProject project, final String configFileName) {
return getArgsForParallelLaunch(project.getFile(configFileName));
}
/**
* Returns the launch configuration type extension for launch group configurations.
* @return The launch configuration type extension for launch group configurations
* @see org.eclipse.debug.core.ILaunchManager#getLaunchConfigurationType
*/
public static ILaunchConfigurationType getGroupLaunchConfigurationType() {
return getLaunchManager().getLaunchConfigurationType(GROUP_LAUNCH_CONFIGURATION_ID);
}
/**
* Returns the launch configuration type extension for Java app launch configurations.
* @return The launch configuration type extension for Java app launch configurations
* @see org.eclipse.debug.core.ILaunchManager#getLaunchConfigurationType
*/
public static ILaunchConfigurationType getJavaAppLaunchConfigurationType() {
return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
}
/**
* Returns the launch configuration type extension for Java Main Controller launch configurations.
* @return The launch configuration type extension for Java Main Controller launch configurations
* @see org.eclipse.debug.core.ILaunchManager#getLaunchConfigurationType
*/
public static ILaunchConfigurationType getJavaMctrLaunchConfigurationType() {
return getLaunchManager().getLaunchConfigurationType(ExecutorMonitorView.NATIVE_JAVA_LAUNCHCONFIGURATION_ID);
}
......@@ -248,6 +342,12 @@ public final class LaunchConfigurationUtil {
return DebugPlugin.getDefault().getLaunchManager();
}
/**
* Returns the name of the linked launch group configuration.
* @param configuration Launch configuration of the Main Controller
* @return The name of the linked launch group configuration or {@code null} if no launch group configuration is linked
* @throws CoreException
*/
public static String getLinkedGroupLaunchConfigurationName(final ILaunchConfiguration configuration) throws CoreException {
List<String> list = getLinkedLaunchConfigurations(configuration);
if (list != null && list.size() == 2) {
......@@ -256,6 +356,12 @@ public final class LaunchConfigurationUtil {
return null;
}
/**
* Returns the name of the linked java app launch configuration.
* @param configuration Launch configuration of the Main Controller
* @return The name of the linked java app launch configuration or {@code null} if no java app launch configuration is linked
* @throws CoreException
*/
public static String getLinkedJavaAppLaunchConfigurationName(final ILaunchConfiguration configuration) throws CoreException {
List<String> list = getLinkedLaunchConfigurations(configuration);
if (list != null && !list.isEmpty()) {
......@@ -264,17 +370,38 @@ public final class LaunchConfigurationUtil {
return null;
}
/**
* Returns the list of the linked launch configurations.
* @param configuration Launch configuration of the Main Controller
* @return The list of the linked launch configurations or an empty list if no launch configuration is linked.
* Never returns {@code null}
* @throws CoreException
*/
public static List<String> getLinkedLaunchConfigurations(final ILaunchConfiguration configuration) throws CoreException {
return configuration.getAttribute(LAUNCH_CONFIGURATION_LIST_ATTR, new ArrayList<String>(0));
}
/**
* Stores the specified list of launch configurations as linked launch configurations
* in the specified launch configuration of the Main Controller.
* @param configuration Launch configuration of the Main Controller
* @param list List of names of linked launch configurations
*/
public static void setLinkedLaunchConfigurations(ILaunchConfigurationWorkingCopy configuration, List<String> list) {
if (list == null || list.isEmpty()) {
return;
}
configuration.setAttribute(LAUNCH_CONFIGURATION_LIST_ATTR, list);
}
/**
* Creates the list of {@code GroupLaunchElements} for launch group configurations.
* @param MCName Name of launch configuration related to the Main Controller
* @param HCName Name of launch configuration related to the Host Controller
* @param enableHC If {@code true}, the Host Controller is enabled in launch group configuration, disabled otherwise
* @return The list of {@code GroupLaunchElements} for launch group configurations
* @see org.eclipse.debug.internal.core.groups.GroupLaunchElement
*/
private static List<GroupLaunchElement> createGroupLaunchElements(final String MCName, final String HCName, final boolean enableHC) {
List<GroupLaunchElement> configList = new ArrayList<GroupLaunchElement>(2);
if (MCName == null || MCName.isEmpty() || HCName == null || HCName.isEmpty()) {
......@@ -294,6 +421,13 @@ public final class LaunchConfigurationUtil {
return configList;
}
/**
* Extracts the module name from the specified type. Originates from
* org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut#getModuleName
* @param type Type from which the module name is extracted
* @return The extracted module name
* @see org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut#getModuleName
*/
private static String getModuleName(IType type) {
IJavaElement javaElement = type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (javaElement instanceof IPackageFragmentRoot) {
......@@ -302,7 +436,7 @@ public final class LaunchConfigurationUtil {
return moduleDescription.getElementName();
}
}
return ""; //$NON-NLS-1$
return "";
}
}
......@@ -151,7 +151,13 @@ public abstract class LaunchShortcut implements ILaunchShortcut {
return null;
}
}
/**
* Launches the given configuration in the specified mode
* @param configuration launch configuration to start
* @param mode one of the launch modes defined by the launchmanager
* @throws CoreException
*/
protected void performLaunch(ILaunchConfiguration configuration, final String mode) throws CoreException {
if (configuration.isWorkingCopy()) {
configuration = ((ILaunchConfigurationWorkingCopy)configuration).doSave();
......
......@@ -149,7 +149,13 @@ public abstract class LaunchShortcutConfig implements ILaunchShortcut {
return null;
}
}
/**
* Launches the given configuration in the specified mode
* @param configuration launch configuration to start
* @param mode one of the launch modes defined by the launchmanager
* @throws CoreException
*/
protected void performLaunch(ILaunchConfiguration configuration, final String mode) throws CoreException {
if (configuration.isWorkingCopy()) {
configuration = ((ILaunchConfigurationWorkingCopy)configuration).doSave();
......
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