/eclipse/plugins/com.android.ide.eclipse.pdt/src/com/android/ide/eclipse/pdt/PdtPlugin.java

https://github.com/CyanogenMod/android_sdk · Java · 146 lines · 78 code · 27 blank · 41 comment · 20 complexity · ea62db0d1283f71a68d308749502d112 MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
  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. package com.android.ide.eclipse.pdt;
  17. import com.android.ide.eclipse.ddms.DdmsPlugin;
  18. import com.android.ide.eclipse.pdt.internal.preferences.PrefPage;
  19. import org.eclipse.jface.preference.IPreferenceStore;
  20. import org.eclipse.jface.util.IPropertyChangeListener;
  21. import org.eclipse.jface.util.PropertyChangeEvent;
  22. import org.eclipse.ui.plugin.AbstractUIPlugin;
  23. import org.osgi.framework.BundleContext;
  24. public class PdtPlugin extends AbstractUIPlugin {
  25. public final static String PLUGIN_ID = "com.android.ide.eclipse.pdt"; //$NON-NLS-1$
  26. private static PdtPlugin sPlugin;
  27. public PdtPlugin() {
  28. sPlugin = this;
  29. }
  30. /**
  31. * Returns the shared instance
  32. *
  33. * @return the shared instance
  34. */
  35. public static synchronized PdtPlugin getDefault() {
  36. return sPlugin;
  37. }
  38. @Override
  39. public void start(BundleContext context) throws Exception {
  40. super.start(context);
  41. // set the listener for the preference change
  42. getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
  43. @Override
  44. public void propertyChange(PropertyChangeEvent event) {
  45. // if the SDK changed, we have to do some extra work
  46. if (PrefPage.PREFS_DEVTREE_DIR.equals(event.getProperty())) {
  47. // restart adb, in case it's a different version
  48. DdmsPlugin.setToolsLocation(getAdbLocation(), true /* startAdb */,
  49. getHprofConvLocation(), getTraceViewLocation());
  50. }
  51. }
  52. });
  53. }
  54. /**
  55. * Returns the location of the dev tree or <code>null</code> if unknown.
  56. */
  57. public static String getDevTree() {
  58. // this always return a store, even a temp one if an error occurred.
  59. IPreferenceStore store = sPlugin.getPreferenceStore();
  60. // returns an empty, non-null, string if the preference is not found.
  61. String devTree = store.getString(PrefPage.PREFS_DEVTREE_DIR);
  62. if (devTree.length() == 0) {
  63. devTree = System.getenv("ANDROID_BUILD_TOP"); //$NON-NLS-1$
  64. }
  65. return devTree;
  66. }
  67. /**
  68. * Returns the location of adb or <code>null</code> if unknown.
  69. */
  70. public static String getAdbLocation() {
  71. String devTreeBin = getDevTreeOutBin();
  72. if (devTreeBin != null && devTreeBin.length() > 0) {
  73. return devTreeBin + "adb"; //$NON-NLS-1$
  74. }
  75. return null;
  76. }
  77. /**
  78. * Returns the location of hprof-conv or <code>null</code> if unknown.
  79. */
  80. public static String getHprofConvLocation() {
  81. String devTreeBin = getDevTreeOutBin();
  82. if (devTreeBin != null && devTreeBin.length() > 0) {
  83. return devTreeBin + "hprof-conv"; //$NON-NLS-1$
  84. }
  85. return null;
  86. }
  87. /**
  88. * Returns the location of traceview or <code>null</code> if unknown.
  89. */
  90. public static String getTraceViewLocation() {
  91. String devTreeBin = getDevTreeOutBin();
  92. if (devTreeBin != null && devTreeBin.length() > 0) {
  93. return devTreeBin + "traceview"; //$NON-NLS-1$
  94. }
  95. return null;
  96. }
  97. private static String getDevTreeOutBin() {
  98. String devTree = getDevTree();
  99. if (devTree != null && devTree.length() > 0) {
  100. return devTree + "/out/host/" + currentPlatform() + "/bin/"; //$NON-NLS-1$ //$NON-NLS-2$
  101. }
  102. return null;
  103. }
  104. /**
  105. * Returns the current platform name as used by the Android build system
  106. *
  107. */
  108. private static String currentPlatform() {
  109. String os = System.getProperty("os.name"); //$NON-NLS-1$
  110. if (os.startsWith("Mac OS")) { //$NON-NLS-1$
  111. return "darwin-x86"; //$NON-NLS-1$
  112. } else if (os.startsWith("Windows")) { //$NON-NLS-1$
  113. return "windows"; //$NON-NLS-1$
  114. } else if (os.startsWith("Linux")) { //$NON-NLS-1$
  115. return "linux-x86"; //$NON-NLS-1$
  116. }
  117. return ""; //$NON-NLS-1$
  118. }
  119. }