Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / lttng / TraceHelper.java
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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.lttng;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.ProjectScope;
17 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
18
19 public class TraceHelper {
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
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()) {
41 return getProjectPreference(project, TRACE_LIB_PATH);
42 }
43 return null;
44 }
45
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 */
55 public static String getProjectPreference(IProject project, String preferenceName) {
56 if (project.exists()) {
57 IEclipsePreferences prefs = new ProjectScope(project).getNode(QUALIFIER);
58
59 return prefs.get(preferenceName, null);
60 }
61 return null;
62 }
63
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 */
75 public static boolean setProjectPreference(IProject project, String preferenceName, String preferenceValue) {
76 if (project.exists()) {
77 IEclipsePreferences prefs = new ProjectScope(project).getNode(QUALIFIER);
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 }
90
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 */
100 public static boolean removeProjectPreference(IProject project, String preferenceName) {
101 if (project.exists()) {
102 IEclipsePreferences prefs = new ProjectScope(project).getNode(QUALIFIER);
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.033457 seconds and 6 git commands to generate.