1 /*******************************************************************************
2 * Copyright (c) 2011 MontaVista Software
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Yufen Kuo (ykuo@mvista.com) - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
;
15 import org
.eclipse
.core
.resources
.IProject
;
16 import org
.eclipse
.core
.resources
.ProjectScope
;
17 import org
.eclipse
.core
.runtime
.preferences
.IEclipsePreferences
;
19 public class TraceHelper
{
21 // ------------------------------------------------------------------------
23 // ------------------------------------------------------------------------
25 private static String TRACE_LIB_PATH
= "traceLibraryPath"; //$NON-NLS-1$
26 private static String QUALIFIER
= "org.eclipse.linuxtools.lttng.jni"; //$NON-NLS-1$
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
33 * Get Trace Library Directory from Project Preference.
36 * The <b>project</b> in the workspace.
37 * @return The <b>directory</b> of the trace libraries. null if not defined
39 public static String
getTraceLibDirFromProject(IProject project
) {
40 if (project
!= null && project
.exists()) {
41 return getProjectPreference(project
, TRACE_LIB_PATH
);
47 * Get the project preference with the specified name
50 * The <b>project</b> in the workspace.
51 * @param preferenceName
52 * name of the preference.
53 * @return The project preference value.
55 public static String
getProjectPreference(IProject project
, String preferenceName
) {
56 if (project
.exists()) {
57 IEclipsePreferences prefs
= new ProjectScope(project
).getNode(QUALIFIER
);
59 return prefs
.get(preferenceName
, null);
65 * Set the project preference with the specified value
68 * The <b>project</b> in the workspace.
69 * @param preferenceName
70 * name of the preference.
71 * @param preferenceValue
72 * value of the preference.
73 * @return true if preference is successfully set, false otherwise.
75 public static boolean setProjectPreference(IProject project
, String preferenceName
, String preferenceValue
) {
76 if (project
.exists()) {
77 IEclipsePreferences prefs
= new ProjectScope(project
).getNode(QUALIFIER
);
79 prefs
.put(preferenceName
, preferenceValue
);
83 } catch (org
.osgi
.service
.prefs
.BackingStoreException e
) {
92 * Remove the project preference with the specified name
95 * The <b>project</b> in the workspace.
96 * @param preferenceName
97 * name of the preference.
98 * @return true if preference name is successfully remove, false otherwise.
100 public static boolean removeProjectPreference(IProject project
, String preferenceName
) {
101 if (project
.exists()) {
102 IEclipsePreferences prefs
= new ProjectScope(project
).getNode(QUALIFIER
);
104 prefs
.remove(preferenceName
);
108 } catch (org
.osgi
.service
.prefs
.BackingStoreException e
) {