1
/*******************************************************************************
2
* Copyright (c) 2006 IBM Corporation.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
10
*******************************************************************************/
12
package org.eclipse.linuxtools.systemtap.ui.ide.structures;
16
import org.eclipse.jface.dialogs.InputDialog;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin;
19
import org.eclipse.linuxtools.internal.systemtap.ui.ide.Localization;
20
import org.eclipse.linuxtools.internal.systemtap.ui.ide.preferences.IDEPreferenceConstants;
21
import org.eclipse.linuxtools.systemtap.ui.ide.IDESessionSettings;
22
import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode;
23
import org.eclipse.linuxtools.systemtap.ui.structures.listeners.IUpdateListener;
24
import org.eclipse.linuxtools.systemtap.ui.systemtapgui.preferences.PreferenceConstants;
25
import org.eclipse.ui.PlatformUI;
30
* This class is used for obtaining all probes and functions from the tapsets.
31
* It will initially try to obtain the list from the TreeSettings.xml file, but
32
* if there is a problem doing that it will run the TapsetParser in order to
33
* obtain everything that way.
36
public final class TapsetLibrary {
37
public static TreeNode getProbes() {
41
public static TreeNode getFunctions() {
46
* This mthod will attempt to get the most up-to-date information.
47
* However, if the TapsetParser is running already it will quit,
48
* assuming that new information will be avilable soon. By registering
49
* a listener at that point the class can be notified when an update is
52
public static void init() {
53
if(null != stpp && stpp.isRunning())
56
if(IDEPlugin.getDefault().getPreferenceStore()
57
.getBoolean(IDEPreferenceConstants.P_STORED_TREE) &&
65
* This method will create a new instance of the TapsetParser in order
66
* to get the information directly from the files.
68
private static void runStapParser() {
69
String[] tapsets = IDEPlugin.getDefault().getPreferenceStore()
70
.getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator);
72
stpp = new TapsetParser(tapsets);
74
stpp.addListener(completionListener);
75
functionTree = stpp.getFunctions();
76
probeTree = stpp.getProbes();
80
* This method will get all of the tree information from
81
* the TreeSettings xml file.
83
private static void readTreeFile() {
84
functionTree = TreeSettings.getFunctionTree();
85
probeTree = TreeSettings.getProbeTree();
89
* This method checks to see if the tapsets have changed
90
* at all since the TreeSettings.xml file was created.
91
* @return boolean indecating whether or not the TreeSettings.xml file has the most up-to-date version
93
private static boolean isTreeFileCurrent() {
94
long treesDate = TreeSettings.getTreeFileDate();
96
IPreferenceStore p = IDEPlugin.getDefault().getPreferenceStore();
97
String[] tapsets = p.getString(IDEPreferenceConstants.P_TAPSETS).split(File.pathSeparator);
99
File f = getTapsetLocation(p);
101
if(!checkIsCurrentFolder(treesDate, f))
104
if(null != tapsets) {
105
for(int i=0; i<tapsets.length; i++) {
106
f = new File(tapsets[i]);
107
if(f.lastModified() > treesDate)
109
if(f.canRead() && !checkIsCurrentFolder(treesDate, f))
117
* This method attempts to locate the default tapset directory.
118
* @param p Preference store where the tapset location might be stored
119
* @return File representing the default tapset location.
121
public static File getTapsetLocation(IPreferenceStore p) {
123
String path = p.getString(PreferenceConstants.P_ENV[2][0]);
124
if(path.trim().equals("")) {
125
f = new File("/usr/share/systemtap/tapset");
127
f = new File("/usr/local/share/systemtap/tapset");
129
InputDialog i = new InputDialog(
130
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
131
Localization.getString("TapsetBrowserView.TapsetLocation"), Localization.getString("TapsetBrowserView.WhereDefaultTapset"), "", null);
133
p.setValue(PreferenceConstants.P_ENV[2][0], i.getValue());
134
f = new File( i.getValue() );
138
f = new File( p.getString(path) );
140
IDESessionSettings.tapsetLocation = f.getAbsolutePath();
145
* This method checks the provided time stap against the folders
146
* time stamp. This is to see if the folder may have new data in it
147
* @param time The current time stamp
148
* @param folder The folder to check if it is newer the then time stamp
149
* @return boolean indicating whther the time stamp is newer then the folder
151
private static boolean checkIsCurrentFolder(long time, File folder) {
152
File[] fs = folder.listFiles();
154
for(int i=0; i<fs.length; i++) {
155
if(fs[i].lastModified() > time)
158
if(fs[i].isDirectory() && fs[i].canRead())
159
if(!checkIsCurrentFolder(time, fs[i]))
166
* Adds a new listener to the TapsetParser
167
* @param listener the listener to be added
168
* @return boolean indacating whether or not the listener was added
170
public static boolean addListener(IUpdateListener listener) {
174
stpp.addListener(listener);
179
* Removes the provided listener from the tapsetParser.
180
* @param listener The listener to be removed from the tapsetParser
182
public static void removeUpdateListener(IUpdateListener listener) {
183
stpp.removeListener(listener);
187
* This class handles saving the results of the TapsetParser to
188
* the TreeSettings.xml file.
190
private static final IUpdateListener completionListener = new IUpdateListener() {
191
public void handleUpdateEvent() {
192
functionTree = stpp.getFunctions();
193
probeTree = stpp.getProbes();
194
if(stpp.isFinishSuccessful())
195
TreeSettings.setTrees(functionTree, probeTree);
199
private static TreeNode functionTree = null;
200
private static TreeNode probeTree = null;
201
private static TapsetParser stpp = null;