Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / lttng / TraceHelper.java
CommitLineData
a3767fd9
FC
1/*******************************************************************************
2 * Copyright (c) 2011 MontaVista Software
3 *
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
8 *
9 * Contributors:
10 * Yufen Kuo (ykuo@mvista.com) - Initial API and implementation
11 *******************************************************************************/
12c155f5
FC
12
13package org.eclipse.linuxtools.lttng;
a3767fd9
FC
14
15import org.eclipse.core.resources.IProject;
16import org.eclipse.core.resources.ProjectScope;
17import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18
19public class TraceHelper {
12c155f5
FC
20
21 // ------------------------------------------------------------------------
22 // Constants
23 // ------------------------------------------------------------------------
24
25 private static String TRACE_LIB_PATH = "traceLibraryPath"; //$NON-NLS-1$
26 private static String QUALIFIER = "org.eclipse.linuxtools.lttng.jni"; //$NON-NLS-1$
27
28 // ------------------------------------------------------------------------
29 // Methods
30 // ------------------------------------------------------------------------
31
a3767fd9
FC
32 /**
33 * Get Trace Library Directory from Project Preference.
34 *
35 * @param project
36 * The <b>project</b> in the workspace.
37 * @return The <b>directory</b> of the trace libraries. null if not defined
38 */
39 public static String getTraceLibDirFromProject(IProject project) {
40 if (project != null && project.exists()) {
12c155f5 41 return getProjectPreference(project, TRACE_LIB_PATH);
a3767fd9
FC
42 }
43 return null;
44 }
12c155f5 45
a3767fd9
FC
46 /**
47 * Get the project preference with the specified name
48 *
49 * @param project
50 * The <b>project</b> in the workspace.
51 * @param preferenceName
52 * name of the preference.
53 * @return The project preference value.
54 */
12c155f5 55 public static String getProjectPreference(IProject project, String preferenceName) {
a3767fd9 56 if (project.exists()) {
12c155f5 57 IEclipsePreferences prefs = new ProjectScope(project).getNode(QUALIFIER);
a3767fd9
FC
58
59 return prefs.get(preferenceName, null);
60 }
61 return null;
62 }
12c155f5 63
a3767fd9
FC
64 /**
65 * Set the project preference with the specified value
66 *
67 * @param project
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.
74 */
12c155f5 75 public static boolean setProjectPreference(IProject project, String preferenceName, String preferenceValue) {
a3767fd9 76 if (project.exists()) {
12c155f5 77 IEclipsePreferences prefs = new ProjectScope(project).getNode(QUALIFIER);
a3767fd9
FC
78
79 prefs.put(preferenceName, preferenceValue);
80 try {
81 prefs.flush();
82 return true;
83 } catch (org.osgi.service.prefs.BackingStoreException e) {
84 e.printStackTrace();
85 }
86
87 }
88 return false;
89 }
12c155f5 90
a3767fd9
FC
91 /**
92 * Remove the project preference with the specified name
93 *
94 * @param project
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.
99 */
12c155f5 100 public static boolean removeProjectPreference(IProject project, String preferenceName) {
a3767fd9 101 if (project.exists()) {
12c155f5 102 IEclipsePreferences prefs = new ProjectScope(project).getNode(QUALIFIER);
a3767fd9
FC
103
104 prefs.remove(preferenceName);
105 try {
106 prefs.flush();
107 return true;
108 } catch (org.osgi.service.prefs.BackingStoreException e) {
109 e.printStackTrace();
110 }
111
112 }
113 return false;
114 }
115
116}
This page took 0.028585 seconds and 5 git commands to generate.