~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to gcov/org.eclipse.linuxtools.gcov.launch/src/org/eclipse/linuxtools/internal/gcov/launch/GcovLaunchConfigurationDelegate.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2004, 2008, 2009, 2012 Red Hat, Inc. and others
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
 
10
 *    Keith Seitz <keiths@redhat.com> - setup code in launch the method, initially 
 
11
 *        written in the now-defunct OprofileSession class
 
12
 *    QNX Software Systems and others - the section of code marked in the launch 
 
13
 *        method, and the exec method
 
14
 *    Red Hat Inc. - modification of OProfileLaunchConfigurationDelegate to here
 
15
 *******************************************************************************/ 
 
16
package org.eclipse.linuxtools.internal.gcov.launch;
 
17
 
 
18
import java.net.URI;
 
19
import java.util.List;
 
20
 
 
21
import org.eclipse.cdt.debug.core.CDebugUtils;
 
22
import org.eclipse.core.resources.IProject;
 
23
import org.eclipse.core.runtime.CoreException;
 
24
import org.eclipse.core.runtime.IPath;
 
25
import org.eclipse.core.runtime.IProgressMonitor;
 
26
import org.eclipse.core.runtime.Path;
 
27
import org.eclipse.debug.core.DebugPlugin;
 
28
import org.eclipse.debug.core.ILaunch;
 
29
import org.eclipse.debug.core.ILaunchConfiguration;
 
30
import org.eclipse.debug.core.ILaunchManager;
 
31
import org.eclipse.debug.core.ILaunchesListener2;
 
32
import org.eclipse.jface.dialogs.MessageDialog;
 
33
import org.eclipse.linuxtools.gcov.launch.GcovLaunchPlugin;
 
34
import org.eclipse.linuxtools.internal.gcov.parser.CovManager;
 
35
import org.eclipse.linuxtools.internal.gcov.view.CovView;
 
36
import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
 
37
import org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationDelegate;
 
38
import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
 
39
import org.eclipse.swt.widgets.Display;
 
40
import org.eclipse.swt.widgets.Shell;
 
41
import org.eclipse.ui.PlatformUI;
 
42
 
 
43
public class GcovLaunchConfigurationDelegate extends ProfileLaunchConfigurationDelegate {
 
44
        protected ILaunchConfiguration config;
 
45
        
 
46
        @Override
 
47
        public void launch(ILaunchConfiguration config, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
 
48
                this.config = config;
 
49
                IPath exePath = getExePath(config);
 
50
 
 
51
                /* 
 
52
                 * this code written by QNX Software Systems and others and was 
 
53
                 * originally in the CDT under LocalCDILaunchDelegate::RunLocalApplication
 
54
                 */
 
55
                //set up and launch the local c/c++ program
 
56
                IRemoteCommandLauncher launcher = RemoteProxyManager.getInstance().getLauncher(getProject());
 
57
 
 
58
                URI workingDirURI = getProject().getLocationURI();
 
59
                IPath workingDirPath = new Path(workingDirURI.getPath());
 
60
                String arguments[] = getProgramArgumentsArray( config );
 
61
                
 
62
                //add a listener for termination of the launch
 
63
                ILaunchManager lmgr = DebugPlugin.getDefault().getLaunchManager();
 
64
                lmgr.addLaunchListener(new LaunchTerminationWatcher(launch, exePath));
 
65
                
 
66
                Process process = launcher.execute(exePath, arguments, getEnvironment(config), workingDirPath, monitor);
 
67
 
 
68
                DebugPlugin.newProcess( launch, process, renderProcessLabel( exePath.toOSString() ) );
 
69
 
 
70
        }
 
71
        
 
72
        //A class used to listen for the termination of the current launch, and 
 
73
        // run some functions when it is finished. 
 
74
        class LaunchTerminationWatcher implements ILaunchesListener2 {
 
75
                private ILaunch launch;
 
76
                private IPath exePath;
 
77
                public LaunchTerminationWatcher(ILaunch il, IPath exePath) {
 
78
                        launch = il;
 
79
                        this.exePath = exePath;
 
80
                }
 
81
                public void launchesTerminated(ILaunch[] launches) {
 
82
 
 
83
                        for (ILaunch l : launches) {
 
84
                                /**
 
85
                                 * Dump samples from the daemon,
 
86
                                 * shut down the daemon,
 
87
                                 * activate the OProfile view (open it if it isn't already),
 
88
                                 * refresh the view (which parses the data/ui model and displays it).
 
89
                                 */
 
90
                                if (l.equals(launch)) {
 
91
                                        //need to run this in the ui thread otherwise get SWT Exceptions
 
92
                                        // based on concurrency issues
 
93
                                        Display.getDefault().syncExec(new Runnable() {
 
94
                                                public void run() {
 
95
                                                        String s = exePath.toOSString();                        
 
96
                                                        CovManager cvrgeMnger = new CovManager(s, getProject());
 
97
 
 
98
                                                        try {
 
99
                                                                List<String> gcdaPaths = cvrgeMnger.getGCDALocations();
 
100
                                                                if (gcdaPaths.size() == 0) {
 
101
                                                                        String title = GcovLaunchMessages.GcovCompilerOptions_msg;
 
102
                                                                        String message = GcovLaunchMessages.GcovCompileAgain_msg;
 
103
                                                                        Shell parent = PlatformUI.getWorkbench().getDisplay().getActiveShell();
 
104
                                                                        MessageDialog.openWarning(parent, title, message);
 
105
                                                                }
 
106
                                                                CovView.displayCovResults(s, null);
 
107
                                                        } catch (InterruptedException e) {
 
108
                                                                // Do nothing
 
109
                                                        }
 
110
                                                }
 
111
                                        });
 
112
                                }
 
113
                        }
 
114
 
 
115
                }
 
116
                public void launchesAdded(ILaunch[] launches) { /* dont care */}
 
117
                public void launchesChanged(ILaunch[] launches) { /* dont care */ }
 
118
                public void launchesRemoved(ILaunch[] launches) { /* dont care */ }
 
119
 
 
120
        }
 
121
        
 
122
        @Override
 
123
        protected String getPluginID() {
 
124
                return GcovLaunchPlugin.getUniqueIdentifier();
 
125
        }
 
126
        
 
127
        /* all these functions exist to be overridden by the test class in order to allow launch testing */
 
128
        
 
129
        protected IProject getProject(){
 
130
                try{
 
131
                        IProject project = CDebugUtils.verifyCProject(config).getProject();
 
132
                        return project;
 
133
                } catch (CoreException e) {
 
134
                        e.printStackTrace();
 
135
                }
 
136
                return null;
 
137
        }
 
138
         /**
 
139
          *
 
140
          * Return the exe path of the binary to be profiled.
 
141
          * @param config
 
142
          * @return the exe path of the binary stored in the configuration
 
143
          * @throws CoreException
 
144
          * @since 1.1
 
145
          */
 
146
        protected IPath getExePath(ILaunchConfiguration config) throws CoreException{
 
147
                IPath exePath = CDebugUtils.verifyProgramPath( config );
 
148
 
 
149
                return exePath;
 
150
        }
 
151
 
 
152
        @Override
 
153
        public String generateCommand(ILaunchConfiguration config) {
 
154
                return "";
 
155
        }
 
156
}