2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.eclipse.org/org/documents/epl-v10.php
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.
17 package com.android.ide.eclipse.adt.internal.preferences;
19 import com.android.ide.eclipse.adt.AdtPlugin;
20 import com.android.jarutils.DebugKeyProvider;
21 import com.android.jarutils.DebugKeyProvider.KeytoolException;
22 import com.android.prefs.AndroidLocation.AndroidLocationException;
24 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
25 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
26 import org.eclipse.jface.preference.IPreferenceStore;
30 @SuppressWarnings("deprecation")
31 public final class AdtPrefs extends AbstractPreferenceInitializer {
32 public final static String PREFS_SDK_DIR = AdtPlugin.PLUGIN_ID + ".sdk"; //$NON-NLS-1$
34 public final static String PREFS_BUILD_RES_AUTO_REFRESH = AdtPlugin.PLUGIN_ID + ".resAutoRefresh"; //$NON-NLS-1$
36 public final static String PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR = AdtPlugin.PLUGIN_ID + ".forceErrorNativeLibInJar"; //$NON-NLS-1$
38 public final static String PREFS_BUILD_VERBOSITY = AdtPlugin.PLUGIN_ID + ".buildVerbosity"; //$NON-NLS-1$
40 public final static String PREFS_DEFAULT_DEBUG_KEYSTORE = AdtPlugin.PLUGIN_ID + ".defaultDebugKeyStore"; //$NON-NLS-1$
42 public final static String PREFS_CUSTOM_DEBUG_KEYSTORE = AdtPlugin.PLUGIN_ID + ".customDebugKeyStore"; //$NON-NLS-1$
44 public final static String PREFS_HOME_PACKAGE = AdtPlugin.PLUGIN_ID + ".homePackage"; //$NON-NLS-1$
46 public final static String PREFS_EMU_OPTIONS = AdtPlugin.PLUGIN_ID + ".emuOptions"; //$NON-NLS-1$
48 /** singleton instance */
49 private final static AdtPrefs sThis = new AdtPrefs();
51 /** default store, provided by eclipse */
52 private IPreferenceStore mStore;
54 /** cached location for the sdk folder */
55 private String mOsSdkLocation;
57 /** Verbosity of the build */
58 private BuildVerbosity mBuildVerbosity = BuildVerbosity.NORMAL;
60 private boolean mBuildForceResResfresh = false;
61 private boolean mBuildForceErrorOnNativeLibInJar = true;
63 public static enum BuildVerbosity {
64 /** Build verbosity "Always". Those messages are always displayed, even in silent mode */
66 /** Build verbosity level "Normal" */
68 /** Build verbosity level "Verbose". Those messages are only displayed in verbose mode */
73 BuildVerbosity(int level) {
77 public int getLevel() {
82 * Finds and returns a {@link BuildVerbosity} whose {@link #name()} matches a given name.
83 * <p/>This is different from {@link Enum#valueOf(Class, String)} in that it returns null
84 * if no matches are found.
86 * @param name the name to look up.
87 * @return returns the matching enum or null of no match where found.
89 public static BuildVerbosity find(String name) {
90 for (BuildVerbosity v : values()) {
91 if (v.name().equals(name)) {
100 public static void init(IPreferenceStore preferenceStore) {
101 sThis.mStore = preferenceStore;
104 public static AdtPrefs getPrefs() {
108 public synchronized void loadValues(PropertyChangeEvent event) {
109 // get the name of the property that changed, if any
110 String property = event != null ? event.getProperty() : null;
112 if (property == null || PREFS_SDK_DIR.equals(property)) {
113 mOsSdkLocation = mStore.getString(PREFS_SDK_DIR);
115 // make sure it ends with a separator. Normally this is done when the preference
116 // is set. But to make sure older version still work, we fix it here as well.
117 if (mOsSdkLocation.length() > 0 && mOsSdkLocation.endsWith(File.separator) == false) {
118 mOsSdkLocation = mOsSdkLocation + File.separator;
122 if (property == null || PREFS_BUILD_VERBOSITY.equals(property)) {
123 mBuildVerbosity = BuildVerbosity.find(mStore.getString(PREFS_BUILD_VERBOSITY));
124 if (mBuildVerbosity == null) {
125 mBuildVerbosity = BuildVerbosity.NORMAL;
129 if (property == null || PREFS_BUILD_RES_AUTO_REFRESH.equals(property)) {
130 mBuildForceResResfresh = mStore.getBoolean(PREFS_BUILD_RES_AUTO_REFRESH);
133 if (property == null || PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR.equals(property)) {
134 mBuildForceErrorOnNativeLibInJar = mStore.getBoolean(PREFS_BUILD_RES_AUTO_REFRESH);
139 * Returns the SDK folder.
140 * Guaranteed to be terminated by a platform-specific path separator.
142 public synchronized String getOsSdkFolder() {
143 return mOsSdkLocation;
146 public synchronized BuildVerbosity getBuildVerbosity() {
147 return mBuildVerbosity;
150 public boolean getBuildForceResResfresh() {
151 return mBuildForceResResfresh;
154 public boolean getBuildForceErrorOnNativeLibInJar() {
155 return mBuildForceErrorOnNativeLibInJar;
159 public void initializeDefaultPreferences() {
160 IPreferenceStore store = AdtPlugin.getDefault().getPreferenceStore();
162 store.setDefault(PREFS_BUILD_RES_AUTO_REFRESH, true);
163 store.setDefault(PREFS_BUILD_FORCE_ERROR_ON_NATIVELIB_IN_JAR, true);
165 store.setDefault(PREFS_BUILD_VERBOSITY, BuildVerbosity.ALWAYS.name());
167 store.setDefault(PREFS_HOME_PACKAGE, "android.process.acore"); //$NON-NLS-1$
170 store.setDefault(PREFS_DEFAULT_DEBUG_KEYSTORE,
171 DebugKeyProvider.getDefaultKeyStoreOsPath());
172 } catch (KeytoolException e) {
173 AdtPlugin.log(e, "Get default debug keystore path failed"); //$NON-NLS-1$
174 } catch (AndroidLocationException e) {
175 AdtPlugin.log(e, "Get default debug keystore path failed"); //$NON-NLS-1$