cdt/cdt_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java
author ryall
Mon, 10 Aug 2009 13:37:15 -0500
changeset 62 c400a1d2216a
parent 54 89a4ce4b37f5
permissions -rw-r--r--
Sync with changes in public CDT.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     1
/*******************************************************************************
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     2
 * Copyright (c) 2005, 2008 QNX Software Systems and others.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     7
 *
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     8
 * Contributors:
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
     9
 *     QNX Software Systems - initial API and implementation
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    10
 *     Andrew Ferguson (andrew.ferguson@arm.com) - bug 123997
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    11
 *     Ken Ryall (Nokia) - bug 178731
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    12
 *     Anton Leherbauer (Wind River Systems) - bug 224187
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    13
 *******************************************************************************/
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    14
package org.eclipse.cdt.launch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    15
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    16
import java.io.File;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    17
import java.io.FileNotFoundException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    18
import java.util.ArrayList;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    19
import java.util.Arrays;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    20
import java.util.Date;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    21
import java.util.HashMap;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    22
import java.util.HashSet;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    23
import java.util.Iterator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    24
import java.util.List;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    25
import java.util.Map;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    26
import java.util.Properties;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    27
import java.util.Map.Entry;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    28
import java.util.concurrent.atomic.AtomicBoolean;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    29
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    30
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    31
import org.eclipse.cdt.core.model.ICModelMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    32
import org.eclipse.cdt.core.model.ICProject;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    33
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    34
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    35
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    36
import org.eclipse.cdt.debug.core.CDebugUtils;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    37
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    38
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    39
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    40
import org.eclipse.cdt.launch.internal.ui.LaunchMessages;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    41
import org.eclipse.cdt.launch.internal.ui.LaunchUIPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    42
import org.eclipse.cdt.ui.newui.CDTPropertyManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    43
import org.eclipse.core.resources.IContainer;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    44
import org.eclipse.core.resources.IFile;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    45
import org.eclipse.core.resources.IMarker;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    46
import org.eclipse.core.resources.IProject;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    47
import org.eclipse.core.resources.IResource;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    48
import org.eclipse.core.resources.IWorkspace;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    49
import org.eclipse.core.resources.IncrementalProjectBuilder;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    50
import org.eclipse.core.resources.ResourcesPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    51
import org.eclipse.core.runtime.CoreException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    52
import org.eclipse.core.runtime.IPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    53
import org.eclipse.core.runtime.IProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    54
import org.eclipse.core.runtime.IStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    55
import org.eclipse.core.runtime.MultiStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    56
import org.eclipse.core.runtime.NullProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    57
import org.eclipse.core.runtime.Path;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    58
import org.eclipse.core.runtime.Status;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    59
import org.eclipse.core.runtime.SubProgressMonitor;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    60
import org.eclipse.core.runtime.jobs.Job;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    61
import org.eclipse.debug.core.DebugPlugin;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    62
import org.eclipse.debug.core.ILaunch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    63
import org.eclipse.debug.core.ILaunchConfiguration;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    64
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    65
import org.eclipse.debug.core.ILaunchManager;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    66
import org.eclipse.debug.core.IStatusHandler;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    67
import org.eclipse.debug.core.Launch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    68
import org.eclipse.debug.core.model.IPersistableSourceLocator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    69
import org.eclipse.debug.core.model.IProcess;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    70
import org.eclipse.debug.core.model.ISourceLocator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    71
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    72
import org.eclipse.debug.ui.RefreshTab;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    73
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    74
import com.ibm.icu.text.DateFormat;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    75
import com.ibm.icu.text.MessageFormat;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    76
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    77
abstract public class AbstractCLaunchDelegate extends LaunchConfigurationDelegate {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    78
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    79
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    80
	 * @since 6.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    81
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    82
    public class CLaunch extends Launch {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    83
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    84
        private final AtomicBoolean fRefreshDone;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    85
        
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    86
        public CLaunch(ILaunchConfiguration launchConfiguration, String mode, ISourceLocator locator) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    87
            super(launchConfiguration, mode, locator);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    88
            fRefreshDone = new AtomicBoolean(false);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    89
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    90
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    91
        public void refresh() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    92
            if (fRefreshDone.compareAndSet(false, true)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    93
                final ILaunchConfiguration config = getLaunchConfiguration();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    94
                try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    95
                    if (RefreshTab.getRefreshScope(config) != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    96
                        Job refreshJob = new Job("Refresh"){
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    97
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    98
                            /* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
    99
                             * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   100
                             */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   101
                            @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   102
                            protected IStatus run(IProgressMonitor monitor) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   103
                                try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   104
                                    RefreshTab.refreshResources(config, monitor);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   105
                                } catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   106
                                    return new Status(IStatus.ERROR, LaunchUIPlugin.PLUGIN_ID, 1, e.getLocalizedMessage(), e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   107
                                }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   108
                                return Status.OK_STATUS;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   109
                            }};
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   110
                        refreshJob.setSystem(true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   111
                        refreshJob.schedule();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   112
                    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   113
                }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   114
                catch(CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   115
                    LaunchUIPlugin.log( e.getStatus() );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   116
                }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   117
            }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   118
        }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   119
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   120
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   121
    /* (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   122
     * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   123
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   124
    @Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   125
    public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   126
        return new CLaunch(configuration, mode, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   127
    }
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   128
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   129
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   130
	 * The project containing the programs file being launched
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   131
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   132
	private IProject project;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   133
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   134
	 * A list of prequisite projects ordered by their build order.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   135
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   136
	private List orderedProjects;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   137
	private String preLaunchBuildConfiguration;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   138
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   139
	/**
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   140
	 * Used in conjunction with build before launch settings in the main tab.
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   141
	 */
62
c400a1d2216a Sync with changes in public CDT.
ryall
parents: 54
diff changeset
   142
	private boolean workspaceBuildBeforeLaunch;
c400a1d2216a Sync with changes in public CDT.
ryall
parents: 54
diff changeset
   143
	
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   144
	abstract public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   145
			throws CoreException;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   146
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   147
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   148
	 * Returns the working directory specified by the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   149
	 * configuration, or <code>null</code> if none.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   150
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   151
	 * @deprecated Should use getWorkingDirectory()
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   152
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   153
	 *            launch configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   154
	 * @return the working directory specified by the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   155
	 *         configuration, or <code>null</code> if none
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   156
	 * @exception CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   157
	 *                if unable to retrieve the attribute
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   158
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   159
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   160
	public File getWorkingDir(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   161
		return getWorkingDirectory(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   162
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   163
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   164
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   165
	 * Returns the working directory specified by the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   166
	 * configuration, or <code>null</code> if none.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   167
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   168
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   169
	 *            launch configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   170
	 * @return the working directory specified by the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   171
	 *         configuration, or <code>null</code> if none
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   172
	 * @exception CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   173
	 *                if unable to retrieve the attribute
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   174
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   175
	public File getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   176
		return verifyWorkingDirectory(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   177
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   178
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   179
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   180
	 * Expands and returns the working directory attribute of the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   181
	 * configuration. Returns <code>null</code> if a working directory is not
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   182
	 * specified. If specified, the working is verified to point to an existing
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   183
	 * directory in the local file system.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   184
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   185
	 * @param configuration launch configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   186
	 * @return an absolute path to a directory in the local file system, or
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   187
	 * <code>null</code> if unspecified
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   188
	 * @throws CoreException if unable to retrieve the associated launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   189
	 * configuration attribute, if unable to resolve any variables, or if the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   190
	 * resolved location does not point to an existing directory in the local
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   191
	 * file system
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   192
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   193
	protected IPath getWorkingDirectoryPath(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   194
		String location = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   195
		if (location != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   196
			String expandedLocation = LaunchUtils.getStringVariableManager().performStringSubstitution(location);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   197
			if (expandedLocation.length() > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   198
				return new Path(expandedLocation);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   199
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   200
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   201
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   202
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   203
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   204
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   205
	 * Throws a core exception with an error status object built from the given
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   206
	 * message, lower level exception, and error code.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   207
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   208
	 * @param message
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   209
	 *            the status message
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   210
	 * @param exception
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   211
	 *            lower level exception associated with the error, or
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   212
	 *            <code>null</code> if none
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   213
	 * @param code
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   214
	 *            error code
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   215
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   216
	protected void abort(String message, Throwable exception, int code) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   217
		IStatus status;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   218
		if (exception != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   219
			MultiStatus multiStatus = new MultiStatus(getPluginID(), code, message, exception);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   220
			multiStatus.add(new Status(IStatus.ERROR, getPluginID(), code, exception.getLocalizedMessage(), exception));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   221
			status= multiStatus;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   222
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   223
			status= new Status(IStatus.ERROR, getPluginID(), code, message, null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   224
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   225
		throw new CoreException(status);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   226
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   227
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   228
	protected void cancel(String message, int code) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   229
		throw new CoreException(new Status(IStatus.OK, getPluginID(), code, message, null));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   230
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   231
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   232
	abstract protected String getPluginID();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   233
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   234
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   235
     * @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   236
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   237
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   238
	public static ICProject getCProject(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   239
	    return CDebugUtils.getCProject(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   240
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   241
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   242
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   243
     * @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   244
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   245
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   246
	public static String getProjectName(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   247
        return CDebugUtils.getProjectName(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   248
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   249
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   250
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   251
     * @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   252
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   253
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   254
	public static String getProgramName(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   255
        return CDebugUtils.getProgramName(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   256
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   257
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   258
    /**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   259
     * @deprecated Use {@link org.eclipse.cdt.debug.core.CDebugUtils} instead.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   260
     */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   261
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   262
	public static IPath getProgramPath(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   263
        return CDebugUtils.getProgramPath(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   264
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   265
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   266
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   267
	 * @param launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   268
	 * @param config
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   269
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   270
	 * @deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   271
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   272
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   273
	protected void setSourceLocator(ILaunch launch, ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   274
		setDefaultSourceLocator(launch, config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   275
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   276
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   277
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   278
	 * Assigns a default source locator to the given launch if a source locator
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   279
	 * has not yet been assigned to it, and the associated launch configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   280
	 * does not specify a source locator.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   281
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   282
	 * @param launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   283
	 *            launch object
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   284
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   285
	 *            configuration being launched
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   286
	 * @exception CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   287
	 *                if unable to set the source locator
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   288
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   289
	protected void setDefaultSourceLocator(ILaunch launch, ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   290
		//  set default source locator if none specified
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   291
		if (launch.getSourceLocator() == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   292
			IPersistableSourceLocator sourceLocator;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   293
			String id = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, (String)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   294
			if (id == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   295
				ICProject cProject = CDebugUtils.getCProject(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   296
				if (cProject == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   297
					abort(LaunchMessages.getString("Launch.common.Project_does_not_exist"), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   298
							ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   299
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   300
				sourceLocator = CDebugUIPlugin.createDefaultSourceLocator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   301
				sourceLocator.initializeDefaults(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   302
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   303
				sourceLocator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(id);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   304
				String memento = configuration.getAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, (String)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   305
				if (memento == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   306
					sourceLocator.initializeDefaults(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   307
				} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   308
					sourceLocator.initializeFromMemento(memento);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   309
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   310
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   311
			launch.setSourceLocator(sourceLocator);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   312
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   313
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   314
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   315
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   316
	 * Returns the program arguments as a String.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   317
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   318
	 * @return the program arguments as a String
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   319
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   320
	public String getProgramArguments(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   321
		return LaunchUtils.getProgramArguments(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   322
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   323
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   324
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   325
	 * Returns the program arguments as an array of individual arguments.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   326
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   327
	 * @return the program arguments as an array of individual arguments
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   328
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   329
	public String[] getProgramArgumentsArray(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   330
		return LaunchUtils.getProgramArgumentsArray(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   331
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   332
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   333
	protected ICDebugConfiguration getDebugConfig(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   334
		ICDebugConfiguration dbgCfg = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   335
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   336
			dbgCfg = CDebugCorePlugin.getDefault().getDebugConfiguration(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   337
																			config.getAttribute(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   338
																								ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   339
																								"")); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   340
		} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   341
			IStatus status = new Status(IStatus.ERROR, LaunchUIPlugin.getUniqueIdentifier(),
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   342
					ICDTLaunchConfigurationConstants.ERR_DEBUGGER_NOT_INSTALLED,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   343
					LaunchMessages.getString("AbstractCLaunchDelegate.Debugger_not_installed"), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   344
					e);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   345
			IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   346
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   347
			if (handler != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   348
				Object result = handler.handleStatus(status, this);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   349
				if (result instanceof String) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   350
					// this could return the new debugger id to use?
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   351
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   352
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   353
			throw e;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   354
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   355
		return dbgCfg;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   356
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   357
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   358
	protected String renderTargetLabel(ICDebugConfiguration debugConfig) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   359
		String format = "{0} ({1})"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   360
		String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   361
		return MessageFormat.format(format, new String[]{debugConfig.getName(), timestamp});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   362
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   363
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   364
	protected String renderProcessLabel(String commandLine) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   365
		String format = "{0} ({1})"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   366
		String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   367
		return MessageFormat.format(format, new String[]{commandLine, timestamp});
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   368
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   369
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   370
	// temporary fix for #66015
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   371
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   372
	 * @deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   373
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   374
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   375
	protected String renderDebuggerProcessLabel() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   376
		String format = "{0} ({1})"; //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   377
		String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   378
		return MessageFormat.format(format, new String[]{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   379
				LaunchMessages.getString("AbstractCLaunchDelegate.Debugger_Process"), timestamp}); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   380
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   381
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   382
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   383
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   384
	 * @param config
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   385
	 * @return
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   386
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   387
	 * @deprecated Use <code>verifyProgramFile</code> instead.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   388
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   389
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   390
	protected IFile getProgramFile(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   391
		ICProject cproject = verifyCProject(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   392
		String fileName = CDebugUtils.getProgramName(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   393
		if (fileName == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   394
			abort(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   395
					ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   396
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   397
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   398
		IFile programPath = ((IProject)cproject.getResource()).getFile(fileName);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   399
		if (programPath == null || !programPath.exists() || !programPath.getLocation().toFile().exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   400
			abort(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   401
					LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   402
					new FileNotFoundException(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   403
							LaunchMessages.getFormattedString(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   404
																"AbstractCLaunchDelegate.PROGRAM_PATH_not_found", programPath.getLocation().toOSString())), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   405
					ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   406
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   407
		return programPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   408
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   409
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   410
	protected ICProject verifyCProject(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   411
		String name = CDebugUtils.getProjectName(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   412
		if (name == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   413
			abort(LaunchMessages.getString("AbstractCLaunchDelegate.C_Project_not_specified"), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   414
					ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROJECT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   415
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   416
		ICProject cproject = CDebugUtils.getCProject(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   417
		if (cproject == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   418
			IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   419
			if (!proj.exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   420
				abort(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   421
						LaunchMessages.getFormattedString("AbstractCLaunchDelegate.Project_NAME_does_not_exist", name), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   422
						ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   423
			} else if (!proj.isOpen()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   424
				abort(LaunchMessages.getFormattedString("AbstractCLaunchDelegate.Project_NAME_is_closed", name), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   425
						ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   426
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   427
			abort(LaunchMessages.getString("AbstractCLaunchDelegate.Not_a_C_CPP_project"), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   428
					ICDTLaunchConfigurationConstants.ERR_NOT_A_C_PROJECT);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   429
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   430
		return cproject;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   431
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   432
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   433
	protected IPath verifyProgramPath(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   434
		ICProject cproject = verifyCProject(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   435
		IPath programPath = CDebugUtils.getProgramPath(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   436
		if (programPath == null || programPath.isEmpty()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   437
			abort(LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_not_specified"), null, //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   438
					ICDTLaunchConfigurationConstants.ERR_UNSPECIFIED_PROGRAM);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   439
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   440
		if (!programPath.isAbsolute()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   441
			IPath location = cproject.getProject().getLocation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   442
			if (location != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   443
				programPath = location.append(programPath);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   444
				if (!programPath.toFile().exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   445
					// Try the old way, which is required to support linked resources.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   446
					IFile projFile = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   447
					try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   448
						projFile = project.getFile(CDebugUtils.getProgramPath(config));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   449
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   450
					catch (IllegalArgumentException exc) {}	// thrown if relative path that resolves to a root file (e.g., "..\somefile")
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   451
					if (projFile != null && projFile.exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   452
						programPath = projFile.getLocation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   453
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   454
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   455
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   456
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   457
		if (!programPath.toFile().exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   458
			abort(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   459
					LaunchMessages.getString("AbstractCLaunchDelegate.Program_file_does_not_exist"), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   460
					new FileNotFoundException(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   461
							LaunchMessages.getFormattedString(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   462
																"AbstractCLaunchDelegate.PROGRAM_PATH_not_found", programPath.toOSString())), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   463
					ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_EXIST);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   464
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   465
		return programPath;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   466
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   467
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   468
	protected IPath verifyProgramFile(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   469
		return getProgramFile(config).getLocation();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   470
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   471
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   472
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   473
	 * Verifies the working directory specified by the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   474
	 * configuration exists, and returns the working directory, or
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   475
	 * <code>null</code> if none is specified.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   476
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   477
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   478
	 *            launch configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   479
	 * @return the working directory specified by the given launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   480
	 *         configuration, or <code>null</code> if none
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   481
	 * @exception CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   482
	 *                if unable to retrieve the attribute
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   483
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   484
	public File verifyWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   485
		IPath path = getWorkingDirectoryPath(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   486
		if (path == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   487
			// default working dir is the project if this config has a project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   488
			ICProject cp = CDebugUtils.getCProject(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   489
			if (cp != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   490
				IProject p = cp.getProject();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   491
				return p.getLocation().toFile();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   492
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   493
		} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   494
			if (path.isAbsolute()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   495
				File dir = new File(path.toOSString());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   496
				if (dir.isDirectory()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   497
					return dir;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   498
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   499
				abort(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   500
						LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   501
						new FileNotFoundException(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   502
								LaunchMessages.getFormattedString(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   503
																	"AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found", path.toOSString())), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   504
						ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   505
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   506
				IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   507
				if (res instanceof IContainer && res.exists()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   508
					return res.getLocation().toFile();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   509
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   510
				abort(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   511
						LaunchMessages.getString("AbstractCLaunchDelegate.Working_directory_does_not_exist"), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   512
						new FileNotFoundException(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   513
								LaunchMessages.getFormattedString(
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   514
																	"AbstractCLaunchDelegate.WORKINGDIRECTORY_PATH_not_found", path.toOSString())), //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   515
						ICDTLaunchConfigurationConstants.ERR_WORKING_DIRECTORY_DOES_NOT_EXIST);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   516
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   517
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   518
		return null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   519
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   520
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   521
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   522
	 * Recursively creates a set of projects referenced by the current project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   523
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   524
	 * @param proj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   525
	 *            The current project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   526
	 * @param referencedProjSet
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   527
	 *            A set of referenced projects
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   528
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   529
	 *             if an error occurs while getting referenced projects from the
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   530
	 *             current project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   531
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   532
	private void getReferencedProjectSet(IProject proj, HashSet referencedProjSet) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   533
		IProject[] projects = proj.getReferencedProjects();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   534
		for (int i = 0; i < projects.length; i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   535
			IProject refProject = projects[i];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   536
			if (refProject.exists() && !referencedProjSet.contains(refProject)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   537
				referencedProjSet.add(refProject);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   538
				getReferencedProjectSet(refProject, referencedProjSet);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   539
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   540
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   541
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   542
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   543
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   544
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   545
	 * creates a list of project ordered by their build order from an unordered
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   546
	 * list of projects.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   547
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   548
	 * @param resourceCollection
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   549
	 *            The list of projects to sort.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   550
	 * @return A new list of projects, ordered by build order.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   551
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   552
	private List getBuildOrder(List resourceCollection) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   553
		String[] orderedNames = ResourcesPlugin.getWorkspace().getDescription().getBuildOrder();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   554
		if (orderedNames != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   555
			List orderedProjs = new ArrayList(resourceCollection.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   556
			//Projects may not be in the build order but should be built if
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   557
			// selected
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   558
			List unorderedProjects = new ArrayList(resourceCollection.size());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   559
			unorderedProjects.addAll(resourceCollection);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   560
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   561
			for (int i = 0; i < orderedNames.length; i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   562
				String projectName = orderedNames[i];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   563
				for (int j = 0; j < resourceCollection.size(); j++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   564
					IProject proj = (IProject)resourceCollection.get(j);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   565
					if (proj.getName().equals(projectName)) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   566
						orderedProjs.add(proj);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   567
						unorderedProjects.remove(proj);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   568
						break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   569
					}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   570
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   571
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   572
			//Add anything not specified before we return
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   573
			orderedProjs.addAll(unorderedProjects);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   574
			return orderedProjs;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   575
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   576
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   577
		// Try the project prerequisite order then
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   578
		IProject[] projects = new IProject[resourceCollection.size()];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   579
		projects = (IProject[])resourceCollection.toArray(projects);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   580
		IWorkspace.ProjectOrder po = ResourcesPlugin.getWorkspace().computeProjectOrder(projects);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   581
		ArrayList orderedProjs = new ArrayList();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   582
		orderedProjs.addAll(Arrays.asList(po.projects));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   583
		return orderedProjs;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   584
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   585
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   586
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   587
	 * Builds the current project and all of it's prerequisite projects if
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   588
	 * necessary. Respects specified build order if any exists.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   589
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   590
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   591
	 *            the configuration being launched
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   592
	 * @param mode
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   593
	 *            the mode the configuration is being launched in
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   594
	 * @param monitor
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   595
	 *            progress monitor
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   596
	 * @return whether the debug platform should perform an incremental
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   597
	 *         workspace build before the launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   598
	 * @throws CoreException
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   599
	 *             if an exception occurs while building
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   600
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   601
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   602
	public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   603
62
c400a1d2216a Sync with changes in public CDT.
ryall
parents: 54
diff changeset
   604
		workspaceBuildBeforeLaunch = true;
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   605
		
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   606
		// check the build before launch setting and honor it
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   607
		int buildBeforeLaunchValue = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   608
				ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   609
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   610
		// we shouldn't be getting called if the workspace setting is disabled, so assume we need to
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   611
		// build unless the user explicitly disabled it in the main tab of the launch.
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   612
		if (buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED) {
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   613
			return false;
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   614
		}
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   615
		
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   616
		//This matches the old code, but I don't know that it is the right behavior.
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   617
		//We should be building the local project as well, not just the ordered projects
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   618
		if(orderedProjects == null) {		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   619
			return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   620
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   621
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   622
		if(monitor == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   623
			monitor = new NullProgressMonitor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   624
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   625
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   626
		int scale = 1000;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   627
		int totalWork = (orderedProjects.size() + 1) * scale;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   628
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   629
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   630
			monitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.building_projects"), totalWork); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   631
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   632
			for (Iterator i = orderedProjects.iterator(); i.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   633
				IProject proj = (IProject)i.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   634
				monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.building") + proj.getName()); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   635
				proj.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, scale));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   636
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   637
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   638
			monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.building") + project.getName()); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   639
			setBuildConfiguration(configuration, project);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   640
			project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, scale));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   641
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   642
			monitor.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   643
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   644
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   645
		return false; 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   646
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   647
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   648
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   649
	 * Sets up a project for building by making sure the active configuration is the one used
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   650
	 * when the launch was created.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   651
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   652
	 * @param buildProject
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   653
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   654
	private void setBuildConfiguration(ILaunchConfiguration configuration, IProject buildProject) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   655
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   656
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   657
			String buildConfigID = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   658
			ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(buildProject);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   659
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   660
			if (buildConfigID.length() > 0 && projDes != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   661
			{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   662
				ICConfigurationDescription buildConfiguration = projDes.getConfigurationById(buildConfigID);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   663
				if (buildConfiguration != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   664
					preLaunchBuildConfiguration = projDes.getActiveConfiguration().getId();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   665
					buildConfiguration.setActive();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   666
					CDTPropertyManager.performOk(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   667
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   668
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   669
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   670
		} catch (CoreException e) {}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   671
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   672
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   673
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   674
	 * Searches for compile errors in the current project and any of its
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   675
	 * prerequisite projects. If any compile errors, give the user a chance to
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   676
	 * abort the launch and correct the errors.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   677
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   678
	 * @param configuration
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   679
	 * @param mode
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   680
	 * @param monitor
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   681
	 * @return whether the launch should proceed
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   682
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   683
	 *             if an exception occurs while checking for compile errors.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   684
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   685
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   686
	public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   687
		
62
c400a1d2216a Sync with changes in public CDT.
ryall
parents: 54
diff changeset
   688
		if (!workspaceBuildBeforeLaunch) {
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   689
			// buildForLaunch was not called which means that the workspace pref is disabled.  see if the user enabled the
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   690
			// launch specific setting in the main tab.  if so, we do call buildBeforeLaunch here.
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   691
			if (ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED == configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   692
					ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING)) {
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   693
				
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   694
				IProgressMonitor buildMonitor = new SubProgressMonitor(monitor, 10, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   695
				buildMonitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.BuildBeforeLaunch"), 10); //$NON-NLS-1$	
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   696
				buildMonitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.PerformingBuild")); //$NON-NLS-1$
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   697
				if (buildForLaunch(configuration, mode, new SubProgressMonitor(buildMonitor, 7))) {
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   698
					buildMonitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.PerformingIncrementalBuild")); //$NON-NLS-1$
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   699
					ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(buildMonitor, 3));				
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   700
				}
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   701
				else {
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   702
					buildMonitor.worked(3); /* No incremental build required */
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   703
				}
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   704
			}
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   705
		}
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   706
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   707
		boolean continueLaunch = true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   708
		if(orderedProjects == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   709
			return continueLaunch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   710
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   711
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   712
		if(monitor == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   713
			monitor = new NullProgressMonitor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   714
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   715
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   716
		int scale = 1000;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   717
		int totalWork = (orderedProjects.size() + 1) * scale;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   718
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   719
			monitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.searching_for_errors"), totalWork); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   720
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   721
			boolean compileErrorsInProjs = false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   722
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   723
			//check prerequisite projects for compile errors.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   724
			for (Iterator i = orderedProjects.iterator(); i.hasNext();) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   725
				IProject proj = (IProject)i.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   726
				monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.searching_for_errors_in" + proj.getName())); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   727
				monitor.worked(scale);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   728
				compileErrorsInProjs = existsErrors(proj);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   729
				if (compileErrorsInProjs) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   730
					break;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   731
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   732
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   733
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   734
			//check current project, if prerequite projects were ok
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   735
			if (!compileErrorsInProjs) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   736
				monitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.searching_for_errors_in" + project.getName())); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   737
				monitor.worked(scale);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   738
				compileErrorsInProjs = existsErrors(project);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   739
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   740
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   741
			//if compile errors exist, ask the user before continuing.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   742
			if (compileErrorsInProjs) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   743
				IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(promptStatus);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   744
				if (prompter != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   745
					continueLaunch = ((Boolean)prompter.handleStatus(complileErrorPromptStatus, null)).booleanValue();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   746
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   747
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   748
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   749
			monitor.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   750
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   751
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   752
		if (continueLaunch) // If no problems then restore the previous build configuration. Otherwise leave it so the user can fix the build issues.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   753
			resetBuildConfiguration(project);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   754
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   755
		return continueLaunch;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   756
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   757
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   758
	private void resetBuildConfiguration(IProject buildProject) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   759
		// Restore the active configuration if it was changed for the launch
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   760
		if (preLaunchBuildConfiguration != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   761
			ICProjectDescription projDes = CDTPropertyManager.getProjectDescription(buildProject);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   762
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   763
			if (preLaunchBuildConfiguration.length() > 0 && projDes != null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   764
			{
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   765
				ICConfigurationDescription buildConfiguration = projDes.getConfigurationById(preLaunchBuildConfiguration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   766
				if (buildConfiguration != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   767
					buildConfiguration.setActive();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   768
					CDTPropertyManager.performOk(null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   769
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   770
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   771
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   772
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   773
		preLaunchBuildConfiguration = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   774
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   775
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   776
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   777
	 * Searches for compile errors in the specified project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   778
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   779
	 * @param proj
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   780
	 *            The project to search
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   781
	 * @return true if compile errors exist, otherwise false
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   782
	 * @since 6.0
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   783
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   784
	protected boolean existsErrors(IProject proj) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   785
		IMarker[] markers = proj.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   786
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   787
		if (markers.length > 0) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   788
			for (int j = 0; j < markers.length; j++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   789
				Object severityAttribute = markers[j].getAttribute(IMarker.SEVERITY);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   790
				if (severityAttribute != null && ((Integer) severityAttribute).intValue() == IMarker.SEVERITY_ERROR) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   791
					return true;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   792
				}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   793
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   794
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   795
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   796
		return false;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   797
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   798
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   799
	/*
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   800
	 * (non-Javadoc)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   801
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   802
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate2#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration,
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   803
	 *      java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   804
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   805
	@Override
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   806
	public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   807
		if(monitor == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   808
			monitor = new NullProgressMonitor();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   809
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   810
62
c400a1d2216a Sync with changes in public CDT.
ryall
parents: 54
diff changeset
   811
		workspaceBuildBeforeLaunch = false;
54
89a4ce4b37f5 merge in Ken's previous merges and bug 8513.
timkelly
parents: 51
diff changeset
   812
37
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   813
		int scale = 1000;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   814
		int totalWork = 2 * scale;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   815
		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   816
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   817
			monitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.20"), totalWork); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   818
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   819
			// build project list
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   820
			orderedProjects = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   821
			ICProject cProject = CDebugUtils.getCProject(configuration);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   822
			if (cProject != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   823
				project = cProject.getProject();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   824
				HashSet projectSet = new HashSet();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   825
				getReferencedProjectSet(project, projectSet);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   826
				orderedProjects = getBuildOrder(new ArrayList(projectSet));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   827
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   828
			monitor.worked(scale);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   829
			
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   830
			// do generic launch checks
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   831
			return super.preLaunchCheck(configuration, mode, new SubProgressMonitor(monitor, scale));
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   832
		} finally {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   833
			monitor.done();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   834
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   835
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   836
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   837
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   838
	 * @param project
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   839
	 * @param exePath
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   840
	 * @return
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   841
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   842
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   843
	protected IBinaryObject verifyBinary(ICProject proj, IPath exePath) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   844
		Exception exception;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   845
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   846
			return LaunchUtils.getBinary(proj.getProject(), exePath);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   847
		} catch (ClassCastException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   848
			exception = e;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   849
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   850
		Status status = new Status(IStatus.ERROR,getPluginID(), 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   851
				ICDTLaunchConfigurationConstants.ERR_PROGRAM_NOT_BINARY, 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   852
				LaunchMessages.getString("AbstractCLaunchDelegate.Program_is_not_a_recongnized_executable") + " " + exePath.toOSString(), //$NON-NLS-1$ 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   853
				exception); 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   854
		throw new CoreException(status);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   855
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   856
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   857
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   858
	 * @param config
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   859
	 * @return
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   860
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   861
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   862
	protected Properties getEnvironmentAsProperty(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   863
		String[] envp = getEnvironment(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   864
		Properties p = new Properties( );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   865
		for( int i = 0; i < envp.length; i++ ) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   866
			int idx = envp[i].indexOf('=');
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   867
			if (idx != -1) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   868
				String key = envp[i].substring(0, idx);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   869
				String value = envp[i].substring(idx + 1);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   870
				p.setProperty(key, value);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   871
			} else {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   872
				p.setProperty(envp[i], ""); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   873
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   874
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   875
		return p;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   876
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   877
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   878
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   879
	 * Return the save environment variables in the configuration. The array
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   880
	 * does not include the default environment of the target. array[n] :
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   881
	 * name=value
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   882
	 * @throws CoreException
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   883
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   884
	protected String[] getEnvironment(ILaunchConfiguration config) throws CoreException {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   885
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   886
			// Migrate old env settings to new.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   887
			Map map = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   888
			ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   889
			if (map != null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   890
				wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   891
				wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   892
				config = wc.doSave();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   893
			}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   894
			boolean append = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_INHERIT, true);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   895
			wc.setAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, append);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   896
		} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   897
		}		
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   898
		String[] array = DebugPlugin.getDefault().getLaunchManager().getEnvironment(config);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   899
		if (array == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   900
			return new String[0];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   901
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   902
		return array;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   903
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   904
	
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   905
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   906
	 * Return the save environment variables in the configuration. The array
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   907
	 * does not include the default environment of the target. array[n] :
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   908
	 * name=value
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   909
	 * @deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   910
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   911
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   912
	protected String[] getEnvironmentArray(ILaunchConfiguration config) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   913
		Map env = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   914
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   915
			env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   916
		} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   917
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   918
		if (env == null) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   919
			return new String[0];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   920
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   921
		String[] array = new String[env.size()];
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   922
		Iterator entries = env.entrySet().iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   923
		Entry entry;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   924
		for (int i = 0; entries.hasNext() && i < array.length; i++) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   925
			entry = (Entry)entries.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   926
			array[i] = ((String)entry.getKey()) + "=" + ((String)entry.getValue()); //$NON-NLS-1$
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   927
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   928
		return array;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   929
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   930
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   931
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   932
	 * Return the save environment variables of this configuration. The array
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   933
	 * does not include the default environment of the target.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   934
	 * @deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   935
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   936
	@Deprecated
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   937
	protected Properties getEnvironmentProperty(ILaunchConfiguration config) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   938
		Properties prop = new Properties();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   939
		Map env = null;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   940
		try {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   941
			env = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_ENVIROMENT_MAP, (Map)null);
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   942
		} catch (CoreException e) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   943
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   944
		if (env == null)
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   945
			return prop;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   946
		Iterator entries = env.entrySet().iterator();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   947
		Entry entry;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   948
		while (entries.hasNext()) {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   949
			entry = (Entry)entries.next();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   950
			prop.setProperty((String)entry.getKey(), (String)entry.getValue());
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   951
		}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   952
		return prop;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   953
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   954
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   955
	/**
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   956
	 * Returns the default process attribute map for C/C++ processes.
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   957
	 * 
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   958
	 * @return default process attribute map for C/C++ processes
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   959
	 */
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   960
	protected Map getDefaultProcessMap() {
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   961
		Map map = new HashMap();
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   962
		map.put( IProcess.ATTR_PROCESS_TYPE, ICDTLaunchConfigurationConstants.ID_PROGRAM_PROCESS_TYPE );
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   963
		return map;
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   964
	}
c2bce6dd59e7 add cdt_6_0_x
cawthron
parents:
diff changeset
   965
}