From a7e5192a131026ceb7b2f67bc5fc3b366db3556a Mon Sep 17 00:00:00 2001 From: "hyunsik.noh" Date: Mon, 13 Jan 2014 15:09:16 +0900 Subject: [PATCH] CLI: Fix some useless and make better. remove passing null pointer to function. remove dead local store. remove using + to concatenates strings in a loop Change-Id: I353eb5d74c4193c6220da4fcb8ad3522ed5509fa Signed-off-by: hyunsik.noh --- .../ncli/ide/autocomplete/TizenAutoComplete.java | 8 ++++---- .../org/tizen/ncli/ide/shell/BuildNativeCLI.java | 3 +-- .../src/org/tizen/ncli/ide/shell/InstallCLI.java | 3 +-- .../src/org/tizen/ncli/ide/shell/ListAppCLI.java | 3 +-- .../src/org/tizen/ncli/ide/shell/ListTargetCLI.java | 3 +-- .../src/org/tizen/ncli/ide/shell/RunCLI.java | 3 +-- .../src/org/tizen/ncli/ide/shell/SignCLI.java | 3 +-- .../src/org/tizen/ncli/ide/shell/UninstallCLI.java | 3 +-- .../ncli/ide/subcommands/InstallCLICommand.java | 3 +-- .../ncli/ide/subcommands/ListAppCLICommand.java | 2 +- .../ncli/ide/subcommands/ListTargetCLICommand.java | 4 ++-- .../tizen/ncli/ide/subcommands/RunCLICommand.java | 2 +- .../buildnative/BuildNativeCLICommand.java | 21 ++++++++++++--------- 13 files changed, 28 insertions(+), 33 deletions(-) diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java index bdfa6c7..3df05cd 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/autocomplete/TizenAutoComplete.java @@ -230,7 +230,6 @@ public class TizenAutoComplete { return ""; } - String result = ""; boolean needDuplicatedCheck = false; for (String mainCommand : mainCommandsHaveDuplicatedOptions) { @@ -270,20 +269,21 @@ public class TizenAutoComplete { } // make candidate string except duplicated options boolean isFind = false; + StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < candidates.length; i++) { candidate = candidates[i]; isFind = false; for (String duplicatedOption : duplicatedOptionList) { - if (candidate.equals("") || candidate.equals(duplicatedOption)) { + if ("".equals(candidate) || candidate.equals(duplicatedOption)) { isFind = true; break; } } if (!isFind) { - result = result + " " + candidate; + strBuilder.append(" " + candidate); } } - return result.trim(); + return strBuilder.toString().trim(); } private static String findDuplicatedOption(String option) { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java index 46a4b3c..dbaa83e 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/BuildNativeCLI.java @@ -29,7 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; import org.tizen.ncli.ide.subcommands.buildnative.BuildNativeCLICommand; -import org.tizen.ncli.ide.subcommands.buildnative.BuildNativeData; /** * @author Hyunsik Noh{@literal } (S-core) @@ -69,7 +68,7 @@ public class BuildNativeCLI extends AbstractCLI { command.setRequiredOptions(new String[]{architecture, compiler, configuration}); command.setPredefineOption(predefineOption); - BuildNativeData data = command.runCommand(); + command.runCommand(); } public boolean needPrintTime() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java index 315cb4f..4bdc025 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/InstallCLI.java @@ -28,7 +28,6 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; -import org.tizen.ncli.ide.subcommands.Install; import org.tizen.ncli.ide.subcommands.InstallCLICommand; /** * Implemented functions of install CLI options. @@ -52,7 +51,7 @@ public class InstallCLI extends AbstractCLI{ command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); command.setName(name); - Install runCommand = command.runCommand(); + command.runCommand(); } public boolean needPrintTime() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java index 4ece177..5aa4afa 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListAppCLI.java @@ -28,7 +28,6 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; -import org.tizen.ncli.ide.subcommands.ListApp; import org.tizen.ncli.ide.subcommands.ListAppCLICommand; /** * Implemented functions of list app CLI options. @@ -48,7 +47,7 @@ public class ListAppCLI extends AbstractCLI{ ListAppCLICommand command = new ListAppCLICommand(); command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); - ListApp runCommand = command.runCommand(); + command.runCommand(); } } \ No newline at end of file diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java index eba842b..2c4273e 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/ListTargetCLI.java @@ -28,7 +28,6 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; -import org.tizen.ncli.ide.subcommands.ListTarget; import org.tizen.ncli.ide.subcommands.ListTargetCLICommand; @TizenSubCommand(name="target" , usage="Show connected target list") @@ -45,7 +44,7 @@ public class ListTargetCLI extends AbstractCLI{ ListTargetCLICommand command = new ListTargetCLICommand(); command.setWorkingDir(getRealWorkingPath()); command.setDetail(detail); - ListTarget runCommand = command.runCommand(); + command.runCommand(); } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java index ef585af..f0f228a 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/RunCLI.java @@ -28,7 +28,6 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; -import org.tizen.ncli.ide.subcommands.Run; import org.tizen.ncli.ide.subcommands.RunCLICommand; /** * Implemented functions of run CLI options. @@ -51,7 +50,7 @@ public class RunCLI extends AbstractCLI{ command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); command.setPackageId(pkgId); - Run runCommand = command.runCommand(); + command.runCommand(); } } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java index 567192b..1f0abf2 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/SignCLI.java @@ -26,7 +26,6 @@ package org.tizen.ncli.ide.shell; import org.kohsuke.args4j.Option; import org.tizen.ncli.core.TizenSubCommand; -import org.tizen.ncli.ide.subcommands.Sign; import org.tizen.ncli.ide.subcommands.SignCLICommand; @TizenSubCommand(name="sign" , usage="Signing for the tizen project") @@ -46,7 +45,7 @@ public class SignCLI extends AbstractCLI { command.setProfileName(profile); command.setWorkingDir(getRealWorkingPath()); - Sign sign = command.runCommand(); + command.runCommand(); } public boolean needPrintTime() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java index 9ebfab0..d5caf12 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/shell/UninstallCLI.java @@ -28,7 +28,6 @@ import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.tizen.ncli.core.TizenSubCommand; -import org.tizen.ncli.ide.subcommands.Uninstall; import org.tizen.ncli.ide.subcommands.UninstallCLICommand; /** * Implemented functions of uninstall CLI options. @@ -51,7 +50,7 @@ public class UninstallCLI extends AbstractCLI{ command.setWorkingDir(getRealWorkingPath()); command.setTarget(target); command.setPkgId(pkgId); - Uninstall runCommand = command.runCommand(); + command.runCommand(); } public boolean needPrintTime() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java index bc6d28b..9eaf27f 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/InstallCLICommand.java @@ -35,7 +35,6 @@ import org.tizen.common.launch.LaunchMessages; import org.tizen.common.util.FileUtil; import org.tizen.common.util.HostUtil; import org.tizen.common.util.IOUtil; -import org.tizen.common.util.StringUtil; import org.tizen.ncli.ide.CLIConstant; import org.tizen.ncli.ide.messages.TizenCLIMessages; import org.tizen.ncli.ide.util.TargetUtil; @@ -60,7 +59,7 @@ public class InstallCLICommand extends AbstractSubCommand { private String searchPkgCommand = "ls %s"; private String installCommand = TizenPlatformConstants.PKG_TOOL_INSTALL_COMMAND; - private final String SUCCESS= "ok"; + private static final String SUCCESS= "ok"; private final String PKGID = "pkgid["; public InstallCLICommand() { diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java index 01c5c3c..cac3863 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListAppCLICommand.java @@ -43,7 +43,7 @@ public class ListAppCLICommand extends AbstractSubCommand { private IDevice target = null; private String listAppCommand = TizenPlatformConstants.PKG_TOOL + " -l -t %s"; - private final String PKG_TYPE = "pkg_type"; + private static final String PKG_TYPE = "pkg_type"; public ListAppCLICommand() { config = new Configuration(); diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListTargetCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListTargetCLICommand.java index 408caa3..a3f6b2e 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListTargetCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/ListTargetCLICommand.java @@ -31,8 +31,8 @@ import org.tizen.sdblib.IDevice; public class ListTargetCLICommand extends AbstractSubCommand { private boolean detail = false; - private final String EMULATOR = "Emulator"; - private final String DEVICE = "Device"; + private static final String EMULATOR = "Emulator"; + private static final String DEVICE = "Device"; private String detailFormat = "[ID] %s\t[TYPE] %s\t[NAME] %s"; private String defaultFormat = "[ID] %s"; diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java index 52f768d..54d29e4 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/RunCLICommand.java @@ -41,7 +41,7 @@ public class RunCLICommand extends AbstractSubCommand { private String appTypeCommand = "/usr/bin/pkginfo --pkg %s | grep -i Type"; private String runNativeAppCommand = "launch_app %s.%s"; private String runWebAppCommand = "/usr/bin/wrt-launcher --s %s.%s --t 60000"; - private final String SUCCESS= "result: launched"; + private static final String SUCCESS= "result: launched"; public RunCLICommand() { } diff --git a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/buildnative/BuildNativeCLICommand.java b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/buildnative/BuildNativeCLICommand.java index 6e0ea65..12a4ada 100644 --- a/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/buildnative/BuildNativeCLICommand.java +++ b/org.tizen.ncli.ide/src/org/tizen/ncli/ide/subcommands/buildnative/BuildNativeCLICommand.java @@ -91,12 +91,12 @@ public class BuildNativeCLICommand extends AbstractSubCommand { } } if(!isValid) { - String suggestion = ""; + StringBuilder strBuilder = new StringBuilder(); for(int j = 0; j < candidates.length; j++) { - suggestion = suggestion + " \"" + candidates[j] + "\""; + strBuilder.append(" \"" + candidates[j] + "\""); } result = false; - progressLog.info(NLS.bind(TizenCLIMessages.INVALID_ARG, option, suggestion.trim())); + progressLog.info(NLS.bind(TizenCLIMessages.INVALID_ARG, option, strBuilder.toString().trim())); break; } } @@ -162,7 +162,7 @@ public class BuildNativeCLICommand extends AbstractSubCommand { private boolean getBuildTarget() { boolean result = false; - String archKey = null; + String archKey = ""; String platformId = data.getPlatformId(); String targetId = null; String toolchainId = data.getToolchainId(); @@ -206,7 +206,6 @@ public class BuildNativeCLICommand extends AbstractSubCommand { if(toolchainId != null) { targetId = platformId + "_" + toolchainId; - boolean isExist = false; List targets = sbi.getTargetList(); for (String target : targets) { @@ -244,22 +243,26 @@ public class BuildNativeCLICommand extends AbstractSubCommand { File cprojectFile = new File(data.getCprojectPath()); if (cprojectFile.exists()) { - String configurations = ""; + StringBuilder strBuilder = new StringBuilder(); try { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(cprojectFile); NodeList list = doc.getElementsByTagName("configuration"); for (int i = 0; i < list.getLength(); i++) { NamedNodeMap attributeMap = list.item(i).getAttributes(); String value = attributeMap.getNamedItem("name").getNodeValue(); - configurations = configurations + " " + value; + strBuilder.append(" " + value); if (configuration.equals(value)) { result = true; } } if(!result) { - progressLog.info(NLS.bind(TizenCLIMessages.BN_INVALID_CONFIGURATION, configuration, configurations.trim())); + progressLog.info(NLS.bind(TizenCLIMessages.BN_INVALID_CONFIGURATION, configuration, strBuilder.toString().trim())); } - } catch (Exception e) { + } catch (ParserConfigurationException e) { + log.debug(TizenCLIMessages.CANNOT_READ_CPROJECT); + } catch (SAXException e) { + log.debug(TizenCLIMessages.CANNOT_READ_CPROJECT); + } catch (IOException e) { log.debug(TizenCLIMessages.CANNOT_READ_CPROJECT); } } else { -- 2.7.4