diff options
author | Xavier Ducrohet <xav@android.com> | 2010-09-03 17:14:29 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-09-03 17:25:49 -0700 |
commit | 0b21937765ca5307a6a7e244ba4eddd36954b9cf (patch) | |
tree | 0158022cbfffe20f234920a61514c814d1ea59c3 /eclipse | |
parent | d739049a624f4492bf292cde501af39a77b01624 (diff) | |
download | sdk-0b21937765ca5307a6a7e244ba4eddd36954b9cf.zip sdk-0b21937765ca5307a6a7e244ba4eddd36954b9cf.tar.gz sdk-0b21937765ca5307a6a7e244ba4eddd36954b9cf.tar.bz2 |
DDMS now receives the adb location through an extension point.
Previously DDMS received the adb location through a normal Java API
which requires the other plug-in to be actually running (This
was done in the the start method of ADT).
The new change allows DDMS to start a plug-in (by loading
an extension provided by the plug-in) to query for the location
of adb.
This allows us to have plug-ins with no UI able to provide
the location of ADB (ie a "platform" plug-in that has no UI
besides a pref page, that is started by DDMS indirectly).
Also cleaned up how HierarchyViewer use the AndroidDebugBridge.
Change-Id: I8e842a294eea94c06417149144a2ce435e719cfd
Diffstat (limited to 'eclipse')
9 files changed, 229 insertions, 77 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml index bd92a97..bb30ec0 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml +++ b/eclipse/plugins/com.android.ide.eclipse.adt/plugin.xml @@ -765,4 +765,10 @@ id="com.android.ide.eclipse.adt.AndroidJUnitPropertyTester"> </propertyTester> </extension> + <extension + point="com.android.ide.eclipse.ddms.adbLocator"> + <locator + class="com.android.ide.eclipse.adt.AdbLocator"> + </locator> + </extension> </plugin> diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdbLocator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdbLocator.java new file mode 100644 index 0000000..b45b192 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdbLocator.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.eclipse.org/org/documents/epl-v10.php + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.eclipse.adt; + +import com.android.ide.eclipse.ddms.IAdbLocator; + +public class AdbLocator implements IAdbLocator { + + public String getAdbLocation() { + return AdtPlugin.getOsAbsoluteAdb(); + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java index 77ba50e..404fc56 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/AdtPlugin.java @@ -43,7 +43,6 @@ import com.android.ide.eclipse.adt.internal.sdk.Sdk; import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener; import com.android.ide.eclipse.adt.internal.ui.EclipseUiHelper; import com.android.ide.eclipse.ddms.DdmsPlugin; -import com.android.ide.eclipse.hierarchyviewer.HierarchyViewerPlugin; import com.android.sdklib.IAndroidTarget; import com.android.sdklib.SdkConstants; import com.android.sdkstats.SdkStatsService; @@ -232,7 +231,6 @@ public class AdtPlugin extends AbstractUIPlugin { // finally restart adb, in case it's a different version DdmsPlugin.setAdb(getOsAbsoluteAdb(), true /* startAdb */); - HierarchyViewerPlugin.setAdb(getOsAbsoluteAdb(), true /* startAdb */); // get the SDK location and build id. if (checkSdkLocationAndId()) { @@ -250,13 +248,6 @@ public class AdtPlugin extends AbstractUIPlugin { // check the location of SDK final boolean isSdkLocationValid = checkSdkLocationAndId(); - // start the DdmsPlugin by setting the adb location, only if it is set already. - String osSdkLocation = AdtPrefs.getPrefs().getOsSdkFolder(); - if (osSdkLocation.length() > 0) { - DdmsPlugin.setAdb(getOsAbsoluteAdb(), true); - HierarchyViewerPlugin.setAdb(getOsAbsoluteAdb(), true); - } - // and give it the debug launcher for android projects DdmsPlugin.setRunningAppDebugLauncher(new DdmsPlugin.IDebugLauncher() { public boolean debug(String appName, int port) { diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/build.properties b/eclipse/plugins/com.android.ide.eclipse.ddms/build.properties index 4645d2d..a5f5ded 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/build.properties +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/build.properties @@ -4,6 +4,7 @@ bin.includes = META-INF/,\ icons/,\ plugin.xml,\ .,\ - libs/ + libs/,\ + schema/ bin.excludes = libs/.gitignore diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.ddms/plugin.xml index d1b86b7..d0fe8af 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/plugin.xml +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/plugin.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> + <extension-point id="adbLocator" name="ADB Locator" schema="schema/adbLocator.exsd"/> <extension point="org.eclipse.ui.views"> <category diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/schema/adbLocator.exsd b/eclipse/plugins/com.android.ide.eclipse.ddms/schema/adbLocator.exsd new file mode 100644 index 0000000..6292ec1 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/schema/adbLocator.exsd @@ -0,0 +1,104 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="com.android.ide.eclipse.ddms" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="com.android.ide.eclipse.ddms" id="adbLocator" name="ADB Locator"/> + </appInfo> + <documentation> + Extension to provide the location of adb to DDMS. + </documentation> + </annotation> + + <element name="locator"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":com.android.ide.eclipse.ddms.IAdbLocator"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence> + <element ref="locator"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + 8.0.0 + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + <extension point="com.android.ide.eclipse.ddms.adbLocator"> + <locator class="com.android.ide.eclipse.adt.AdbLocator"/> +</extension> + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + The class must implement com.android.ide.ddms.IAdbLocator. + </documentation> + </annotation> + + + <annotation> + <appInfo> + <meta.section type="copyright"/> + </appInfo> + <documentation> + Copyright (C) 2010 The Android Open Source Project + </documentation> + </annotation> + +</schema> diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java index f9b90a0..ebf50d2 100644 --- a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/DdmsPlugin.java @@ -30,9 +30,19 @@ import com.android.ddmuilib.DevicePanel.IUiSelectionListener; import com.android.ide.eclipse.ddms.preferences.PreferenceInitializer; import com.android.ide.eclipse.ddms.views.DeviceView; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWTException; @@ -61,8 +71,6 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL // The plug-in ID public static final String PLUGIN_ID = "com.android.ide.eclipse.ddms"; // $NON-NLS-1$ - private static final String ADB_LOCATION = PLUGIN_ID + ".adb"; // $NON-NLS-1$ - /** The singleton instance */ private static DdmsPlugin sPlugin; @@ -88,8 +96,6 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL private Color mRed; - private boolean mDdmlibInitialized; - /** * Interface to provide debugger launcher for running apps. */ @@ -218,23 +224,47 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL } }); - // read the adb location from the prefs to attempt to start it properly without - // having to wait for ADT to start - final boolean adbValid = setAdbLocation(eclipseStore.getString(ADB_LOCATION)); - // start it in a thread to return from start() asap. - new Thread() { + new Job("ADB location resolution") { @Override - public void run() { - // init ddmlib if needed - getDefault().initDdmlib(); + protected IStatus run(IProgressMonitor monitor) { + // set the preferences. + PreferenceInitializer.setupPreferences(); + + // init the lib + AndroidDebugBridge.init(true /* debugger support */); + + // get the adb location from an implementation of the ADB Locator extension point. + IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint( + "com.android.ide.eclipse.ddms.adbLocator"); //$NON-NLS-1$ + IConfigurationElement[] configElements = extensionPoint.getConfigurationElements(); + if (configElements.length > 0) { + // only use the first one, ignore the others. + IConfigurationElement configElement = configElements[0]; + + // instantiate the clas + try { + Object obj = configElement.createExecutableExtension("class"); //$NON-NLS-1$ + if (obj instanceof IAdbLocator) { + String adbLocation = ((IAdbLocator) obj).getAdbLocation(); + if (adbLocation != null) { + if (setAdbLocation(adbLocation)) { + AndroidDebugBridge.createBridge(sAdbLocation, + true /* forceNewBridge */); + } - // create and start the first bridge - if (adbValid) { - AndroidDebugBridge.createBridge(sAdbLocation, true /* forceNewBridge */); + } + } + } catch (CoreException e) { + return e.getStatus(); + } } + + return Status.OK_STATUS; } - }.start(); + + }.schedule(); } public static Display getDisplay() { @@ -314,17 +344,12 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL public static void setAdb(String adb, boolean startAdb) { if (adb != null) { if (setAdbLocation(adb)) { - // store the location for future ddms only start. - sPlugin.getPreferenceStore().setValue(ADB_LOCATION, sAdbLocation); // starts the server in a thread in case this is blocking. if (startAdb) { new Thread() { @Override public void run() { - // init ddmlib if needed - getDefault().initDdmlib(); - // create and start the bridge AndroidDebugBridge.createBridge(sAdbLocation, false /* forceNewBridge */); @@ -335,18 +360,6 @@ public final class DdmsPlugin extends AbstractUIPlugin implements IDeviceChangeL } } - private synchronized void initDdmlib() { - if (mDdmlibInitialized == false) { - // set the preferences. - PreferenceInitializer.setupPreferences(); - - // init the lib - AndroidDebugBridge.init(true /* debugger support */); - - mDdmlibInitialized = true; - } - } - /** * Sets the launcher responsible for connecting the debugger to running applications. * @param launcher The launcher. diff --git a/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/IAdbLocator.java b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/IAdbLocator.java new file mode 100644 index 0000000..c31dfc4 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.ddms/src/com/android/ide/eclipse/ddms/IAdbLocator.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.ide.eclipse.ddms; + +/** + * Classes which implement this interface provides the location of ADB. + */ +public interface IAdbLocator { + + /** + * Queries the location of ADB + * @return A full OS path to the location of adb. + */ + String getAdbLocation(); +} diff --git a/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java b/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java index 978cfac..9bc3993 100644 --- a/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java +++ b/eclipse/plugins/com.android.ide.eclipse.hierarchyviewer/src/com/android/ide/eclipse/hierarchyviewer/HierarchyViewerPlugin.java @@ -16,7 +16,9 @@ package com.android.ide.eclipse.hierarchyviewer; +import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.Log; +import com.android.ddmlib.AndroidDebugBridge.IDebugBridgeChangeListener; import com.android.ddmlib.Log.ILogOutput; import com.android.ddmlib.Log.LogLevel; import com.android.hierarchyviewerlib.HierarchyViewerDirector; @@ -111,11 +113,23 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin { }); final HierarchyViewerDirector director = HierarchyViewerPluginDirector.createDirector(); + director.startListenForDevices(); + // make the director receive change in ADB. + AndroidDebugBridge.addDebugBridgeChangeListener(new IDebugBridgeChangeListener() { + public void bridgeChanged(AndroidDebugBridge bridge) { + director.acquireBridge(bridge); + } + }); + + // get the current ADB if any + director.acquireBridge(AndroidDebugBridge.getBridge()); + + // populate the UI with current devices (if any) in a thread new Thread() { @Override public void run() { - initDirector(director); + director.populateDeviceSelectionModel(); } }.start(); } @@ -149,39 +163,6 @@ public class HierarchyViewerPlugin extends AbstractUIPlugin { } /** - * Set the location of the adb executable and optionally starts adb - * - * @param adb location of adb - * @param startAdb flag to start adb - */ - public static void setAdb(String adb, boolean startAdb) { - if (adb != null) { - // store the location for future ddms only start. - sPlugin.getPreferenceStore().setValue(ADB_LOCATION, adb); - - // starts the server in a thread in case this is blocking. - if (startAdb) { - new Thread() { - @Override - public void run() { - initDirector(HierarchyViewerDirector.getDirector()); - } - }.start(); - } - } - } - - private static boolean initDirector(HierarchyViewerDirector director) { - if (director.acquireBridge()) { - director.startListenForDevices(); - director.populateDeviceSelectionModel(); - return true; - } - - return false; - } - - /** * Prints a message, associated with a project to the specified stream * * @param stream The stream to write to |