Code Refactorings. Prevented null pointer dereferences.
Change-Id: I6dbf92acf1e0821b8d643e4590a428edc4487719
Signed-off-by: kh5325.kim <kh5325.kim@samsung.com>
import org.tizen.common.ui.view.console.ConsoleManager;
import org.tizen.common.util.ArrayUtil;
import org.tizen.common.util.CollectionUtil;
+import org.tizen.common.util.IOUtil;
import org.tizen.common.util.ViewUtil;
public class GitCommand extends ConsoleCommand {
public void run(final Executor executor, final ExecutionContext context) throws Exception {
+ if (ViewUtil.getWorkbenchWindow() == null)
+ return;
+
ConsoleManager console = new ConsoleManager(CONSOLE_NAME, true);
context.setValue(CONTEXT_CONSOLE, console);
IStructuredSelection selection = (IStructuredSelection) ViewUtil.getWorkbenchWindow().getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer");
//final PrintStream oldOut = System.out;
//final PrintStream oldErr = System.err;
+ PrintStream out = null;
try {
- PrintStream out = new PrintStream(console.getMessageConsoleStream());
+ out = new PrintStream(console.getMessageConsoleStream());
//System.setErr(out);
//System.setOut(out);
} finally {
//System.setErr(oldErr);
//System.setOut(oldOut);
+ IOUtil.tryClose(out);
}
}
// - To prevent System.exit() codes in org.eclipse.jgit.pgm.Main\r
//run(args.toArray(new String[0]));\r
URL fileURL = PluginUtil.getFileURLinBundle(Activator.PLUGIN_ID, "lib/jgit-cli.jar");\r
+ if (fileURL == null)\r
+ throw new Exception("Failed to find lib/jgit-cli.jar");\r
String jarPath = fileURL.getPath();\r
if (OSChecker.isWindows() && jarPath.startsWith("/")) {\r
// /D:/common-eplugin/org.tizen.common.ui/lib/jgit-cli.jar\r
if (revision.length() == 0)\r
throw new IllegalArgumentException("Revision can not be empty");\r
\r
- return parse(repository, resolve(repository, revision));\r
+ ObjectId resolvedId = resolve(repository, revision);\r
+ return (resolvedId != null) ? parse(repository, resolvedId) : null;\r
}\r
\r
private static ObjectId resolve(final Repository repository, final String revision) {\r
// TODO: Not supported\r
// If we call createRenameDetector(), rename can be detected. But compute can be very long running.\r
// cf.)) http://stackoverflow.com/questions/17296278/jgit-detect-rename-in-working-copy/17302068\r
- printStatusMore(String.format("renamed: %s -> %s", one));\r
+ printStatusMore(String.format("renamed: %s -> %s", one, one));\r
break;\r
}\r
printStatusMore("\n");\r
}\r
\r
public String formatVisiting(int answerNumber, String link) {\r
- return String.format(" Visiting... [%d]%n", answerNumber + 1, link);\r
+ return String.format(" Visiting... [%d]%n", answerNumber + 1);\r
}\r
}\r