diff options
author | Camilo Bernal | 2013-06-14 14:27:37 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2013-06-17 12:20:13 +0000 |
commit | ed87d6026e38993a4dc5a922eabd5a2e0187a557 (patch) | |
tree | 17a2ed45f5d4b4e1ed4fc58205e18a98e73742bc /systemtap | |
parent | bdf8a3b817f8d5ffbc64a49454040451a3fecd7a (diff) | |
download | org.eclipse.linuxtools-ed87d6026e38993a4dc5a922eabd5a2e0187a557.tar.gz org.eclipse.linuxtools-ed87d6026e38993a4dc5a922eabd5a2e0187a557.tar.xz org.eclipse.linuxtools-ed87d6026e38993a4dc5a922eabd5a2e0187a557.zip |
Callgraph: Fix various warnings.
* Log exceptions.
* Close resources.
* Internalize non-message strings.
* Remove unused code.
Change-Id: Ib95d2e6e375fbcb2d5277f216a113633159d8a9f
Reviewed-on: https://git.eclipse.org/r/13419
Tested-by: Hudson CI
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
IP-Clean: Alexander Kurtakov <akurtako@redhat.com>
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'systemtap')
6 files changed, 68 insertions, 46 deletions
diff --git a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/CallgraphCorePlugin.java b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/CallgraphCorePlugin.java index c7c4c93fc3..8afa20db7d 100644 --- a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/CallgraphCorePlugin.java +++ b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/CallgraphCorePlugin.java @@ -15,8 +15,10 @@ import java.io.IOException; import java.net.URL; import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -90,4 +92,14 @@ public class CallgraphCorePlugin extends AbstractUIPlugin { return fileUrl.getFile(); } + /** + * Log specified exception. + * @param e Exception to log. + */ + public static void logException(Exception e) { + Status status = new Status(IStatus.ERROR, CallgraphCorePlugin.PLUGIN_ID, + e.getMessage()); + CallgraphCorePlugin.getDefault().getLog().log(status); + } + } diff --git a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapView.java b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapView.java index 585927921c..4943b2f531 100644 --- a/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapView.java +++ b/systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapView.java @@ -306,46 +306,54 @@ public abstract class SystemTapView extends ViewPart { * @param sourcePath */ public void saveData(String targetFile) { - try { - File file = new File(targetFile); - file.delete(); - file.createNewFile(); - - File sFile = new File(sourcePath); - if (!sFile.exists()) { - return; - } - - FileChannel in = null; - FileChannel out = null; - - try { - in = new FileInputStream(sFile).getChannel(); - out = new FileOutputStream(file).getChannel(); - - if (in == null || out == null) { - return; - } - - long size = in.size(); - MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size); - - out.write(buf); - - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); - } - } - - - } catch (IOException e) { - e.printStackTrace(); - } - } + try { + File file = new File(targetFile); + file.delete(); + file.createNewFile(); + + File sFile = new File(sourcePath); + if (!sFile.exists()) { + return; + } + + FileInputStream fileIn = null; + FileOutputStream fileOut = null; + FileChannel channelIn = null; + FileChannel channelOut = null; + try { + fileIn = new FileInputStream(sFile); + fileOut = new FileOutputStream(file); + channelIn = fileIn.getChannel(); + channelOut = fileOut.getChannel(); + + if (channelIn == null || channelOut == null) { + return; + } + + long size = channelIn.size(); + MappedByteBuffer buf = channelIn.map( + FileChannel.MapMode.READ_ONLY, 0, size); + + channelOut.write(buf); + + } finally { + if (channelIn != null) { + channelIn.close(); + } + if (channelOut != null) { + channelOut.close(); + } + if (fileIn != null) { + fileIn.close(); + } + if (fileOut != null) { + fileOut.close(); + } + } + } catch (IOException e) { + CallgraphCorePlugin.logException(e); + } + } public void setSourcePath(String file) { sourcePath = file; diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandTest.java b/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandTest.java index 8af9ff6e5a..56f4df9976 100644 --- a/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandTest.java +++ b/systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandTest.java @@ -38,9 +38,11 @@ public class SystemTapCommandTest { File temporaryScript = new File(tempLocation); FileOutputStream output = new FileOutputStream(temporaryScript); - new PrintStream(output).println("probe begin { printf(\"" + testText + "\") exit() }"); + PrintStream printer = new PrintStream(output); + printer.println("probe begin { printf(\"" + testText + "\") exit() }"); //Cleanup + printer.close(); temporaryScript.delete(); } } diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/ListTreeContentProvider.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/ListTreeContentProvider.java index 81d77c1a74..8d2ba73727 100644 --- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/ListTreeContentProvider.java +++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/ListTreeContentProvider.java @@ -60,7 +60,7 @@ public class ListTreeContentProvider implements ITreeContentProvider { try { for (ICElement child : cont.getChildren()) { - if ((child instanceof ICElement) + if ((child != null) && SystemTapLaunchShortcut.validElement(child)) return true; if ((child instanceof ICContainer) diff --git a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java index 9a890be58a..d4f50f6016 100644 --- a/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java +++ b/systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java @@ -109,6 +109,7 @@ public abstract class SystemTapLaunchShortcut extends ProfileLaunchShortcut { protected ILaunchConfiguration config; private static final String USER_SELECTED_ALL = "ALL"; //$NON-NLS-1$ + private static final String MAIN_FUNC_NAME = "main"; //$NON-NLS-1$ protected String name; protected String binaryPath; @@ -635,7 +636,7 @@ public abstract class SystemTapLaunchShortcut extends ProfileLaunchShortcut { if (!(validElement(c))) { continue; } - if (c.getElementName().contains("main") && !output.contains(c)) { //$NON-NLS-1$ + if (c.getElementName().contains(MAIN_FUNC_NAME) && !output.contains(c)) { output.add(c); } } @@ -799,6 +800,7 @@ public abstract class SystemTapLaunchShortcut extends ProfileLaunchShortcut { * * @throws IOException */ + @SuppressWarnings("unused") public String generateScript() throws IOException { return null; } diff --git a/systemtap/org.eclipse.linuxtools.callgraph.tests/src/org/eclipse/linuxtools/callgraph/tests/SystemTapGraphTest.java b/systemtap/org.eclipse.linuxtools.callgraph.tests/src/org/eclipse/linuxtools/callgraph/tests/SystemTapGraphTest.java index 9fe855e660..03ffaaa2c0 100644 --- a/systemtap/org.eclipse.linuxtools.callgraph.tests/src/org/eclipse/linuxtools/callgraph/tests/SystemTapGraphTest.java +++ b/systemtap/org.eclipse.linuxtools.callgraph.tests/src/org/eclipse/linuxtools/callgraph/tests/SystemTapGraphTest.java @@ -61,10 +61,8 @@ public class SystemTapGraphTest { tasks.add("Reload file"); tasks.add("Maximize"); + for (int taskNumber = 0; taskNumber < tasks.size(); taskNumber++) { - int taskNumber = 0; - for (String task : tasks) { - taskNumber++; Action act = null; switch (taskNumber) { case 1: |