Search in sources :

Example 1 with HostController

use of org.eclipse.titan.executor.HostController in project titan.EclipsePlug-ins by eclipse.

the class HostControllersTab method performApply.

@Override
public void performApply(final ILaunchConfigurationWorkingCopy configuration) {
    TableItem[] items = hostViewer.getTable().getItems();
    List<String> hostNames = new ArrayList<String>();
    List<String> hostWorkingDirectories = new ArrayList<String>();
    List<String> hostExecutables = new ArrayList<String>();
    List<String> hostLoginCommands = new ArrayList<String>();
    HostController controller;
    for (TableItem item : items) {
        controller = (HostController) item.getData();
        hostNames.add(controller.host());
        hostWorkingDirectories.add(controller.workingdirectory());
        hostExecutables.add(controller.executable());
        hostLoginCommands.add(controller.command());
    }
    if (!hostNames.isEmpty()) {
        configuration.setAttribute(HOSTNAMES, hostNames);
        configuration.setAttribute(HOSTWORKINGDIRECTORIES, hostWorkingDirectories);
        configuration.setAttribute(HOSTEXECUTABLES, hostExecutables);
        configuration.setAttribute(HOSTCOMMANDS, hostLoginCommands);
    } else {
        configuration.setAttribute(HOSTNAMES, (ArrayList<String>) null);
        configuration.setAttribute(HOSTWORKINGDIRECTORIES, (ArrayList<String>) null);
        configuration.setAttribute(HOSTEXECUTABLES, (ArrayList<String>) null);
        configuration.setAttribute(HOSTCOMMANDS, (ArrayList<String>) null);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) HostController(org.eclipse.titan.executor.HostController)

Example 2 with HostController

use of org.eclipse.titan.executor.HostController in project titan.EclipsePlug-ins by eclipse.

the class HostControllersTab method handleInitialization.

private void handleInitialization() {
    MessageConsoleStream stream = TITANDebugConsole.getConsole().newMessageStream();
    stream.println("initializing a host controller");
    IProject project = getProject();
    if (null == project) {
        return;
    }
    stream.println(project.getName());
    try {
        String workingdirectory = project.getPersistentProperty(new QualifiedName(DesignerHelper.PROJECT_BUILD_PROPERTYPAGE_QUALIFIER, DesignerHelper.WORKINGDIR_PROPERTY));
        String executable = project.getPersistentProperty(new QualifiedName(DesignerHelper.PROJECT_BUILD_PROPERTYPAGE_QUALIFIER, DesignerHelper.EXECUTABLE_PROPERTY));
        if (null == executable || 0 == executable.length()) {
            executable = workingdirectory + "/" + project.getName();
            if (Platform.OS_WIN32.equals(Platform.getOS())) {
                executable += ".exe";
            }
        }
        stream.println(workingdirectory);
        stream.println(executable);
        TableItem[] items = hostViewer.getTable().getItems();
        for (TableItem item : items) {
            hostViewer.remove(item.getData());
        }
        hostViewer.add(new HostController("localhost", workingdirectory, executable, "cd %Workingdirectory; %Executable %MCHost %MCPort"));
        updateLaunchConfigurationDialog();
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) TableItem(org.eclipse.swt.widgets.TableItem) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) HostController(org.eclipse.titan.executor.HostController) IProject(org.eclipse.core.resources.IProject)

Example 3 with HostController

use of org.eclipse.titan.executor.HostController in project titan.EclipsePlug-ins by eclipse.

the class HostControllersTab method handleNewButtonSelected.

private void handleNewButtonSelected() {
    HostControllerDialog dialog = new HostControllerDialog(getShell(), getProject(), HOSTCONTROLLER);
    dialog.setHostName("");
    dialog.setWorkingdirectory("");
    dialog.setExecutable("");
    dialog.setCommand("rsh %Host cd %Workingdirectory; %Executable %MCHost %MCPort");
    if (dialog.open() != Window.OK) {
        return;
    }
    hostViewer.add(new HostController(dialog.getHostName(), dialog.getWorkingdirectory(), dialog.getExecutable(), dialog.getCommand()));
    updateLaunchConfigurationDialog();
}
Also used : HostController(org.eclipse.titan.executor.HostController)

Example 4 with HostController

use of org.eclipse.titan.executor.HostController in project titan.EclipsePlug-ins by eclipse.

the class BaseExecutor method startHostControllers.

public final void startHostControllers() {
    if (hostControllers == null || hostControllers.isEmpty()) {
        addNotification(new Notification((new Formatter()).format(PADDEDDATETIMEFORMAT, new Date()).toString(), "", "", NO_HOSTCONTROLLER_SPECIFIED));
        return;
    }
    ProcessBuilder pb = new ProcessBuilder();
    Map<String, String> env = pb.environment();
    if (!appendEnvironmentalVariables) {
        env.clear();
    }
    if (environmentalVariables != null) {
        try {
            EnvironmentHelper.resolveVariables(env, environmentalVariables);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    EnvironmentHelper.setTitanPath(env);
    EnvironmentHelper.set_LICENSE_FILE_PATH(env);
    IProject actualProject = DynamicLinkingHelper.getProject(projectName);
    if (actualProject != null) {
        EnvironmentHelper.set_LD_LIBRARY_PATH(actualProject, env);
    }
    Process proc;
    HostController controller;
    List<String> shellCommand;
    MessageConsoleStream stream = TITANConsole.getConsole().newMessageStream();
    String command;
    for (int i = 0; i < hostControllers.size(); i++) {
        StringBuilder hostControllerLabel = new StringBuilder("Host Controller instance " + (i + 1));
        controller = hostControllers.get(i);
        command = controller.command();
        command = command.replace(REPLACEABLEHOSTNAME, controller.host());
        URI path;
        boolean oldStyleWorkingDir = true;
        if (actualProject == null) {
            path = URIUtil.toURI(controller.workingdirectory());
        } else {
            path = URIUtil.toURI(controller.workingdirectory());
            if (!path.isAbsolute()) {
                oldStyleWorkingDir = false;
                path = TITANPathUtilities.resolvePathURI(controller.workingdirectory(), actualProject.getLocation().toOSString());
            }
        }
        String workingDirResult = PathConverter.convert(oldStyleWorkingDir ? controller.workingdirectory() : URIUtil.toPath(path).toOSString(), true, TITANConsole.getConsole());
        command = command.replace(REPLACEABLEHOSTWORKIGNDIRECTORY, workingDirResult);
        boolean oldStyleExecutable = true;
        if (actualProject == null) {
            path = URIUtil.toURI(controller.executable());
        } else {
            path = URIUtil.toURI(controller.executable());
            if (!path.isAbsolute()) {
                oldStyleExecutable = false;
                path = TITANPathUtilities.resolvePathURI(controller.executable(), actualProject.getLocation().toOSString());
            }
        }
        String executableResult = PathConverter.convert(oldStyleExecutable ? controller.executable() : URIUtil.toPath(path).toOSString(), true, TITANConsole.getConsole());
        String result = PathUtil.getRelativePath(workingDirResult, executableResult);
        if (!result.equals(executableResult)) {
            result = "./" + result;
        }
        command = command.replace(REPLACEABLEHOSTEXECUTABLE, result);
        if ("NULL".equals(mcHost)) {
            command = command.replace(REPLACEABLEMCHOST, "0.0.0.0");
        } else {
            command = command.replace(REPLACEABLEMCHOST, mcHost);
        }
        command = command.replace(REPLACEABLEMCPORT, mcPort);
        shellCommand = new ArrayList<String>();
        shellCommand.add("sh");
        shellCommand.add("-c");
        shellCommand.add(command);
        for (String c : shellCommand) {
            stream.print(c + ' ');
        }
        stream.println();
        pb.command(shellCommand);
        if (workingdirectoryPath != null) {
            pb.directory(new File(workingdirectoryPath));
        }
        try {
            proc = pb.start();
            HostJob job = new HostJob(hostControllerLabel.toString(), proc, this);
            innerHostControllers.add(job);
            job.setPriority(Job.DECORATE);
            job.setUser(true);
            job.schedule();
        } catch (IOException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
}
Also used : Formatter(java.util.Formatter) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) IProcess(org.eclipse.debug.core.model.IProcess) HostController(org.eclipse.titan.executor.HostController) IOException(java.io.IOException) URI(java.net.URI) Notification(org.eclipse.titan.executor.views.notification.Notification) Date(java.util.Date) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 5 with HostController

use of org.eclipse.titan.executor.HostController in project titan.EclipsePlug-ins by eclipse.

the class HostControllerContentProvider method getElements.

@Override
public Object[] getElements(final Object inputElement) {
    HostController[] elements = new HostController[0];
    ILaunchConfiguration config = (ILaunchConfiguration) inputElement;
    List<String> hostNames;
    List<String> hostWorkingDirectories;
    List<String> hostExecutables;
    List<String> hostLoginCommands;
    try {
        hostNames = config.getAttribute(HOSTNAMES, (ArrayList<String>) null);
        hostWorkingDirectories = config.getAttribute(HOSTWORKINGDIRECTORIES, (ArrayList<String>) null);
        hostExecutables = config.getAttribute(HOSTEXECUTABLES, (ArrayList<String>) null);
        hostLoginCommands = config.getAttribute(HOSTCOMMANDS, (ArrayList<String>) null);
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return elements;
    }
    if (null == hostNames || hostNames.isEmpty()) {
        return elements;
    }
    if (null == hostWorkingDirectories || hostWorkingDirectories.size() != hostNames.size()) {
        return elements;
    }
    if (null == hostExecutables || hostExecutables.size() != hostNames.size()) {
        return elements;
    }
    if (null == hostLoginCommands || hostLoginCommands.size() != hostNames.size()) {
        return elements;
    }
    elements = new HostController[hostNames.size()];
    for (int i = 0, size = hostNames.size(); i < size; i++) {
        elements[i] = new HostController(hostNames.get(i), hostWorkingDirectories.get(i), hostExecutables.get(i), hostLoginCommands.get(i));
    }
    return elements;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) HostController(org.eclipse.titan.executor.HostController)

Aggregations

HostController (org.eclipse.titan.executor.HostController)7 CoreException (org.eclipse.core.runtime.CoreException)3 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 TableItem (org.eclipse.swt.widgets.TableItem)2 MessageConsoleStream (org.eclipse.ui.console.MessageConsoleStream)2 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Date (java.util.Date)1 Formatter (java.util.Formatter)1 IFile (org.eclipse.core.resources.IFile)1 QualifiedName (org.eclipse.core.runtime.QualifiedName)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 IProcess (org.eclipse.debug.core.model.IProcess)1 Notification (org.eclipse.titan.executor.views.notification.Notification)1