• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.launch.junit;
18 
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
21 import org.eclipse.jdt.core.IJavaElement;
22 import org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut;
23 
24 /**
25  * Launch shortcut to launch debug/run Android JUnit configuration directly.
26  */
27 public class AndroidJUnitLaunchShortcut extends JUnitLaunchShortcut {
28 
29     @Override
getLaunchConfigurationTypeId()30     protected String getLaunchConfigurationTypeId() {
31         return "com.android.ide.eclipse.adt.junit.launchConfigurationType"; //$NON-NLS-1$
32     }
33 
34     /**
35      * Creates a default Android JUnit launch configuration. Sets the instrumentation runner to the
36      * first instrumentation found in the AndroidManifest.
37      */
38     @Override
createLaunchConfiguration(IJavaElement element)39     protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(IJavaElement element)
40             throws CoreException {
41         ILaunchConfigurationWorkingCopy config = super.createLaunchConfiguration(element);
42         // just get first valid instrumentation runner
43         String instrumentation = new InstrumentationRunnerValidator(element.getJavaProject()).
44                 getValidInstrumentationTestRunner();
45         if (instrumentation != null) {
46             config.setAttribute(AndroidJUnitLaunchConfigDelegate.ATTR_INSTR_NAME,
47                     instrumentation);
48         }
49         // if a valid runner is not found, rely on launch delegate to log error.
50         // This method is called without explicit user action to launch Android JUnit, so avoid
51         // logging an error here.
52 
53         AndroidJUnitLaunchConfigDelegate.setJUnitDefaults(config);
54         return config;
55     }
56 }
57