plugins/org.symbian.tools.tmw.debug/src/org/symbian/tools/wrttools/debug/internal/launch/DebugUtil.java
changeset 471 06589bf52fa7
parent 470 d4809db37847
child 472 bd9f2d7c64a6
equal deleted inserted replaced
470:d4809db37847 471:06589bf52fa7
     1 /**
       
     2  * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Symbian Foundation - initial contribution.
       
    11  * Contributors:
       
    12  * Description:
       
    13  * Overview:
       
    14  * Details:
       
    15  * Platforms/Drives/Compatibility:
       
    16  * Assumptions/Requirement/Pre-requisites:
       
    17  * Failures and causes:
       
    18  */
       
    19 package org.symbian.tools.wrttools.debug.internal.launch;
       
    20 
       
    21 import java.text.MessageFormat;
       
    22 
       
    23 import org.eclipse.core.resources.IProject;
       
    24 import org.eclipse.core.resources.ResourcesPlugin;
       
    25 import org.eclipse.core.runtime.CoreException;
       
    26 import org.eclipse.core.runtime.IStatus;
       
    27 import org.eclipse.core.runtime.Status;
       
    28 import org.eclipse.debug.core.ILaunch;
       
    29 import org.eclipse.debug.core.ILaunchConfiguration;
       
    30 import org.eclipse.debug.core.ILaunchManager;
       
    31 import org.symbian.tools.wrttools.debug.internal.Activator;
       
    32 import org.symbian.tools.wrttools.debug.internal.IConstants;
       
    33 
       
    34 public class DebugUtil {
       
    35     public static CoreException createCoreException(String message, Throwable exeption) {
       
    36         return new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, exeption));
       
    37     }
       
    38 
       
    39     public static IProject getProject(ILaunch configuration) {
       
    40         try {
       
    41             if (WidgetLaunchDelegate.ID.equals(configuration.getLaunchConfiguration().getType().getIdentifier())) {
       
    42                 String projectName = configuration.getLaunchConfiguration().getAttribute(IConstants.PROP_PROJECT_NAME,
       
    43                         (String) null);
       
    44                 if (projectName != null) {
       
    45                     IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
       
    46                     if (project.isAccessible()) {
       
    47                         return project;
       
    48                     }
       
    49                 }
       
    50             }
       
    51         } catch (CoreException e) {
       
    52             Activator.log(e);
       
    53         }
       
    54         return null;
       
    55     }
       
    56 
       
    57     public static IProject getProject(ILaunchConfiguration configuration) throws CoreException {
       
    58         if (!WidgetLaunchDelegate.ID.equals(configuration.getType().getIdentifier())) {
       
    59             return null;
       
    60         }
       
    61         String projectName = configuration.getAttribute(IConstants.PROP_PROJECT_NAME, (String) null);
       
    62         if (projectName == null) {
       
    63             throw createCoreException("Project is not selected", null);
       
    64         }
       
    65 
       
    66         IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
       
    67         if (!project.isAccessible()) {
       
    68             throw createCoreException(MessageFormat.format("Project {0} is not opened", projectName), null);
       
    69         }
       
    70         return project;
       
    71     }
       
    72 
       
    73     public static boolean isProjectDebugged(IProject project, ILaunchManager launchManager, ILaunch l)
       
    74             throws CoreException {
       
    75         ILaunch[] launches = launchManager.getLaunches();
       
    76         for (ILaunch launch : launches) {
       
    77             ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
       
    78             if ((l == null || !l.equals(launch)) && !launch.isTerminated()
       
    79                     && WidgetLaunchDelegate.ID.equals(launchConfiguration.getType().getIdentifier())) {
       
    80                 IProject p2 = getProject(launchConfiguration);
       
    81                 if (project.equals(p2)) {
       
    82                     return true;
       
    83                 }
       
    84             }
       
    85         }
       
    86         return false;
       
    87     }
       
    88 
       
    89 }