aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-06-14 10:27:37 (EDT)
committerAlexander Kurtakov2013-06-17 08:20:13 (EDT)
commited87d6026e38993a4dc5a922eabd5a2e0187a557 (patch)
tree17a2ed45f5d4b4e1ed4fc58205e18a98e73742bc
parentbdf8a3b817f8d5ffbc64a49454040451a3fecd7a (diff)
downloadorg.eclipse.linuxtools-ed87d6026e38993a4dc5a922eabd5a2e0187a557.zip
org.eclipse.linuxtools-ed87d6026e38993a4dc5a922eabd5a2e0187a557.tar.gz
org.eclipse.linuxtools-ed87d6026e38993a4dc5a922eabd5a2e0187a557.tar.bz2
Callgraph: Fix various warnings.refs/changes/19/13419/4
* 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>
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/CallgraphCorePlugin.java12
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.core/src/org/eclipse/linuxtools/internal/callgraph/core/SystemTapView.java88
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.launch.tests/src/org/eclipse/linuxtools/callgraph/launch/tests/SystemTapCommandTest.java4
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/ListTreeContentProvider.java2
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.launch/src/org/eclipse/linuxtools/internal/callgraph/launch/SystemTapLaunchShortcut.java4
-rw-r--r--systemtap/org.eclipse.linuxtools.callgraph.tests/src/org/eclipse/linuxtools/callgraph/tests/SystemTapGraphTest.java4
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 c7c4c93..8afa20d 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 5859279..4943b2f 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 8af9ff6..56f4df9 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 81d77c1..8d2ba73 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 9a890be..d4f50f6 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 9fe855e..03ffaaa 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: