Package ch.ethz.prose.eclipse.internal.launcher

Source Code of ch.ethz.prose.eclipse.internal.launcher.ProseLaunchConfiguration

//
//  This file is part of the Prose Development Tools for Eclipse package.
//
//  The contents of this file are subject to the Mozilla Public License
//  Version 1.1 (the "License"); you may not use this file except in
//  compliance with the License. You may obtain a copy of the License at
//  http://www.mozilla.org/MPL/
//
//  Software distributed under the License is distributed on an "AS IS" basis,
//  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
//  for the specific language governing rights and limitations under the
//  License.
//
//  The Original Code is Prose Development Tools for Eclipse.
//
//  The Initial Developer of the Original Code is Angela Nicoara. Portions
//  created by Angela Nicoara are Copyright (C) 2006 Angela Nicoara.
//  All Rights Reserved.
//
//  Contributor(s):
//  $Id: ProseLaunchConfiguration.java,v 1.1 2008/11/18 12:18:41 anicoara Exp $
//  ==============================================================================
//

package ch.ethz.prose.eclipse.internal.launcher;

import java.io.File;
import java.text.MessageFormat;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate;
import org.eclipse.jdt.launching.ExecutionArguments;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMRunner;
import org.eclipse.jdt.launching.SocketUtil;
import org.eclipse.jdt.launching.VMRunnerConfiguration;

import ch.ethz.prose.eclipse.internal.core.ProsePlugin;
import ch.ethz.prose.eclipse.internal.run.ProseRunNode;

/**
* Launch configuration delegate for Prose applications.
*
* @author Angela Nicoara
* @version $Id: ProseLaunchConfiguration.java,v 1.1 2008/11/18 12:18:41 anicoara Exp $
*/
public class ProseLaunchConfiguration extends AbstractJavaLaunchConfigurationDelegate {

    /** Launch configuration identifier. */
    public static final String ID_PROSE_APPLICATION = "ch.ethz.prose.eclipse.launchconfig"; //$NON-NLS-1$

    /** Attribute identifier for Prose server launch option. */
    public static final String ATTR_LAUNCH_PROSE_SERVER = ProsePlugin.PLUGIN_ID + ".LAUNCH_PROSE_SERVER"; //$NON-NLS-1$

    protected int port;

    /* (non-Javadoc)
     * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
     */
    public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
            throws CoreException {
        if (monitor == null) {
            monitor = new NullProgressMonitor();
        }

        monitor.beginTask(MessageFormat.format("{0}...", new String[] { configuration.getName()}), 3); //$NON-NLS-1$
        // check for cancellation
        if (monitor.isCanceled()) { return; }

        monitor.subTask("Verifying launch attributes..");

        String mainTypeName = verifyMainTypeName(configuration);

        IVMInstall vm = verifyVMInstall(configuration);

        IVMRunner runner = vm.getVMRunner(ILaunchManager.DEBUG_MODE); // we always run in debug mode
        if (runner == null) {
            abort(MessageFormat.format("JRE {0} does not support debug mode.", new String[] { vm.getName()}), null,
                    IJavaLaunchConfigurationConstants.ERR_VM_RUNNER_DOES_NOT_EXIST);
        }

        File workingDir = verifyWorkingDirectory(configuration);
        String workingDirName = null;
        if (workingDir != null) {
            workingDirName = workingDir.getAbsolutePath();
        }

        // Environment variables
        String[] envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);

        // Program & VM args (and set Prose path property)
        String pgmArgs = getProgramArguments(configuration);
        String vmArgs = getVMArguments(configuration);
        ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);

        // VM-specific attributes
        Map vmAttributesMap = getVMSpecificAttributesMap(configuration);

        // Classpath
        String[] classpath = getClasspath(configuration);

        // Create VM config
        VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
        runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
        runConfig.setEnvironment(envp);
        runConfig.setVMArguments(execArgs.getVMArgumentsArray());
        runConfig.setWorkingDirectory(workingDirName);
        runConfig.setVMSpecificAttributesMap(vmAttributesMap);

        // Bootpath
        runConfig.setBootClassPath(getBootpath(configuration));

        // check for cancellation
        if (monitor.isCanceled()) { return; }

        // stop in main
        prepareStopInMain(configuration);

        // done the verification phase
        monitor.worked(1);

        monitor.subTask("Creating source locator...");
        // set the default source locator if required
        setDefaultSourceLocator(launch, configuration);
        monitor.worked(1);

        // Launch the configuration - 1 unit of work
        runner.run(runConfig, launch, monitor);

        // check for cancellation
        if (monitor.isCanceled()) { return; }

        if (configuration.getAttribute(ProseLaunchConfiguration.ATTR_LAUNCH_PROSE_SERVER, true))
            ProsePlugin.getDefault().addRun(new ProseRunNode(mainTypeName, "localhost", port, launch));
        monitor.done();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate#getVMArguments(org.eclipse.debug.core.ILaunchConfiguration)
     */
    public String getVMArguments(ILaunchConfiguration config) throws CoreException {
        String args = super.getVMArguments(config);
        String path = ProsePlugin.getDefault().getProsePath();

        // Set Prose home property.
        args = "-Dch.ethz.inf.project.home=" + path + " " + args;

        // Set security policy property.
        args = "-Djava.security.policy=" + path + "testpolicy " + args;

        // Set Prose server port property if server component is enabled.
        if (config.getAttribute(ProseLaunchConfiguration.ATTR_LAUNCH_PROSE_SERVER, true)) {
            port = SocketUtil.findFreePort();
            args = "-Dprose.port=" + port + " " + args;
        }
       
        args = " -Dch.ethz.prose.EXManager=ch.ethz.prose.LocalHotSwapAspectManager " + args;

        args = " -Dch.ethz.prose.JVMAIProvider=ch.ethz.inf.iks.jvmai.jvmdi.HotSwapProvider " + args;

        args = " -Dprose.library.path=" + path + "lib/i386/ " + args;
       
        args = " -Xnoclassgc " + args;
       
        //args = " -agentlib:prosevm=noBreakpoints " + args;
        args = " -agentpath:" + path + "lib/i386/libprosevm.so=noBreakpoints " + args;
       
        return args;
    }

}
TOP

Related Classes of ch.ethz.prose.eclipse.internal.launcher.ProseLaunchConfiguration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.