[Title] revert ondemand install path
authorYoonKi Park <yoonki.park@samsung.com>
Tue, 27 Dec 2011 11:38:12 +0000 (20:38 +0900)
committerYoonKi Park <yoonki.park@samsung.com>
Tue, 27 Dec 2011 11:38:12 +0000 (20:38 +0900)
com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/DebugTool.java
com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/Messages.java [deleted file]
com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstall.java
com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstallMessages.java [new file with mode: 0644]
com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstallMessages.properties [new file with mode: 0644]
com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/messages.properties [deleted file]

index 79bf28c..a89badb 100644 (file)
 */
 package com.samsung.tizen.common.connection.debugtools;
 
+import com.samsung.tizen.common.properties.InstallPathConfig;
+
 public class DebugTool {
        final public static String CONTROL_EXTENSION = ".control";
+       final public static String TOOLS_TARGET_PATH = "/home/developer/sdk_tools";
+       final public static String TOOLS_HOST_PATH = InstallPathConfig.getSDKPath();
+       
        private String binaryname; 
        private String packagename;
        private String sourcepath; 
diff --git a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/Messages.java b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/Messages.java
deleted file mode 100644 (file)
index 395c2f7..0000000
+++ /dev/null
@@ -1,133 +0,0 @@
-/*\r
-*  Common\r
-*\r
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
-*\r
-* Contact: \r
-* Hoon Kang <h245.kang@samsung.com>\r
-* YoonKi Park <yoonki.park@samsung.com>\r
-* \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
-* you may not use this file except in compliance with the License.\r
-* You may obtain a copy of the License at\r
-*\r
-* http://www.apache.org/licenses/LICENSE-2.0\r
-*\r
-* Unless required by applicable law or agreed to in writing, software\r
-* distributed under the License is distributed on an "AS IS" BASIS,\r
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-* See the License for the specific language governing permissions and\r
-* limitations under the License.\r
-*\r
-* Contributors:\r
-* - S-Core Co., Ltd\r
-*\r
-*/\r
-package com.samsung.tizen.common.connection.debugtools;\r
-\r
-import java.util.MissingResourceException;\r
-import java.util.ResourceBundle;\r
-\r
-public class Messages {\r
-       private static final String BUNDLE_NAME = "com.samsung.tizen.common.connection.debugtools.messages"; //$NON-NLS-1$\r
-\r
-       private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle\r
-                       .getBundle(BUNDLE_NAME);\r
-\r
-       private Messages() {\r
-       }\r
-       \r
-       public static String getString(String key) {\r
-               // TODO Auto-generated method stub\r
-               try {\r
-                       return RESOURCE_BUNDLE.getString(key);\r
-               } catch (MissingResourceException e) {\r
-                       return '!' + key + '!';\r
-               }\r
-       }\r
-       \r
-       public static String getString(String key, Object binding) {\r
-               // TODO Auto-generated method stub\r
-               try {\r
-                       return RESOURCE_BUNDLE.getString(key);\r
-               } catch (MissingResourceException e) {\r
-                       return '!' + key + '!';\r
-               }\r
-       }\r
-       private static String messageBind(String message, Object[] args, String argZero, String argOne) {\r
-               int length = message.length();\r
-               //estimate correct size of string buffer to avoid growth\r
-               int bufLen = length + (args.length * 5);\r
-               if (argZero != null)\r
-                       bufLen += argZero.length() - 3;\r
-               if (argOne != null)\r
-                       bufLen += argOne.length() - 3;\r
-               StringBuffer buffer = new StringBuffer(bufLen < 0 ? 0 : bufLen);\r
-               for (int i = 0; i < length; i++) {\r
-                       char c = message.charAt(i);\r
-                       switch (c) {\r
-                               case '{' :\r
-                                       int index = message.indexOf('}', i);\r
-                                       // if we don't have a matching closing brace then...\r
-                                       if (index == -1) {\r
-                                               buffer.append(c);\r
-                                               break;\r
-                                       }\r
-                                       i++;\r
-                                       if (i >= length) {\r
-                                               buffer.append(c);\r
-                                               break;\r
-                                       }\r
-                                       // look for a substitution\r
-                                       int number = -1;\r
-                                       try {\r
-                                               number = Integer.parseInt(message.substring(i, index));\r
-                                       } catch (NumberFormatException e) {\r
-                                               throw (IllegalArgumentException) new IllegalArgumentException().initCause(e);\r
-                                       }\r
-                                       if (number == 0 && argZero != null)\r
-                                               buffer.append(argZero);\r
-                                       else if (number == 1 && argOne != null)\r
-                                               buffer.append(argOne);\r
-                                       else {\r
-                                               if (number >= args.length || number < 0) {\r
-                                                       buffer.append("<missing argument>"); //$NON-NLS-1$\r
-                                                       i = index;\r
-                                                       break;\r
-                                               }\r
-                                               buffer.append(args[number]);\r
-                                       }\r
-                                       i = index;\r
-                                       break;\r
-                               case '\'' :\r
-                                       // if a single quote is the last char on the line then skip it\r
-                                       int nextIndex = i + 1;\r
-                                       if (nextIndex >= length) {\r
-                                               buffer.append(c);\r
-                                               break;\r
-                                       }\r
-                                       char next = message.charAt(nextIndex);\r
-                                       // if the next char is another single quote then write out one\r
-                                       if (next == '\'') {\r
-                                               i++;\r
-                                               buffer.append(c);\r
-                                               break;\r
-                                       }\r
-                                       // otherwise we want to read until we get to the next single quote\r
-                                       index = message.indexOf('\'', nextIndex);\r
-                                       // if there are no more in the string, then skip it\r
-                                       if (index == -1) {\r
-                                               buffer.append(c);\r
-                                               break;\r
-                                       }\r
-                                       // otherwise write out the chars inside the quotes\r
-                                       buffer.append(message.substring(nextIndex, index));\r
-                                       i = index;\r
-                                       break;\r
-                               default :\r
-                                       buffer.append(c);\r
-                       }\r
-               }\r
-               return buffer.toString();\r
-       }\r
-}\r
index f609665..7387000 100644 (file)
@@ -33,7 +33,9 @@ import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 import java.util.regex.Pattern;
 
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.swt.SWT;
@@ -41,7 +43,6 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 
 import com.samsung.tizen.common.connection.ConnectionPlugin;
-import com.samsung.tizen.common.properties.InstallPathConfig;
 import com.samsung.tizen.sdblib.IDevice;
 import com.samsung.tizen.sdblib.SdbCommandRejectedException;
 import com.samsung.tizen.sdblib.SdbShellProcess;
@@ -60,15 +61,13 @@ class PackageInstallMonitorDialog extends ProgressMonitorDialog {
 
 class InstallProgress implements IRunnableWithProgress {
 
-       final private String TOOLS_TARGET_PATH = "/home/root/sdk_tools";
-       final private String TOOLS_HOST_PATH = InstallPathConfig.getSDKPath();
        final private String CMD_RESULT_CHECK = "; echo $?";
 
        private IDevice device = null;
 
        IProgressMonitor monitor = null;
 
-       private boolean checkDirectory(String dir) {
+       private boolean checkDirectory(String dir) throws CoreException {
                boolean checkResult = false;
                SdbShellProcess lsProc;
                try {
@@ -84,12 +83,12 @@ class InstallProgress implements IRunnableWithProgress {
                                checkResult = true;
                        }
                } catch (IOException e) {
-                       return false;
+                       installCoreException(ToolsInstallMessages.CANNOT_CHECK_DIRECTORY, e);
                }
                return checkResult;
        }
 
-       private boolean makeDirectory(String dir) {
+       private void makeDirectory(String dir) throws CoreException {
                boolean makeResult = false;
                SdbShellProcess lsProc;
                try {
@@ -107,18 +106,19 @@ class InstallProgress implements IRunnableWithProgress {
                        }
                        br.close();
                } catch (IOException e) {
-                       return false;
+                       installCoreException(ToolsInstallMessages.CANNOT_CREATE_DIRECTORY, e);
                }
-               return makeResult;
+               if (makeResult == false)
+                       installCoreException(ToolsInstallMessages.CANNOT_CREATE_DIRECTORY, null);                       
        }
 
-       private boolean isInstalled(DebugTool dt) {
+       private boolean isInstalled(DebugTool dt) throws CoreException {
                boolean ret = false;
                try {
                        
                        SdbShellProcess echoProc = device
                                        .executeShellCommand("cat "
-                                                       + TOOLS_TARGET_PATH + "/" + dt.getControlFile() + CMD_RESULT_CHECK);
+                                                       + DebugTool.TOOLS_TARGET_PATH + "/" + dt.getControlFile() + CMD_RESULT_CHECK);
                        BufferedReader br = new BufferedReader(new InputStreamReader(
                                        echoProc.getInputStream()));
                        
@@ -149,7 +149,7 @@ class InstallProgress implements IRunnableWithProgress {
                                ret = false;            
                        br.close();
                } catch (IOException e) {
-                       return true;
+                       installCoreException(ToolsInstallMessages.CANNOT_CHECK_INSTALLED, e);
                }
                return ret;
 
@@ -164,7 +164,7 @@ class InstallProgress implements IRunnableWithProgress {
        }
        private void removeOldPackage(String packagename) {
                try {
-                       SdbShellProcess echoProc = device.executeShellCommand("rm -rf " + TOOLS_TARGET_PATH + "/" + packagename);
+                       SdbShellProcess echoProc = device.executeShellCommand("rm -rf " + DebugTool.TOOLS_TARGET_PATH + "/" + packagename);
                        BufferedReader br = new BufferedReader(new InputStreamReader(echoProc.getInputStream()));
                        while (null != br.readLine()){
                                
@@ -197,7 +197,7 @@ class InstallProgress implements IRunnableWithProgress {
        private void unzipPackage(String packageFile) {
                try {
                        SdbShellProcess tarProc = device.executeShellCommand("cd "
-                                       + TOOLS_TARGET_PATH + " && tar -xzf " + packageFile);
+                                       + DebugTool.TOOLS_TARGET_PATH + " && tar -xzf " + packageFile);
                        BufferedReader br = new BufferedReader(new InputStreamReader(
                                        tarProc.getInputStream()));
                        while (null != br.readLine()) {
@@ -212,7 +212,7 @@ class InstallProgress implements IRunnableWithProgress {
                try {
                        SdbShellProcess echoProc = device
                                        .executeShellCommand("echo 'version:"+version+ "' >"
-                                                       + TOOLS_TARGET_PATH + "/" + controlFile );
+                                                       + DebugTool.TOOLS_TARGET_PATH + "/" + controlFile );
                        BufferedReader br = new BufferedReader(new InputStreamReader(
                                        echoProc.getInputStream()));
                        while (null != br.readLine()) {
@@ -226,7 +226,7 @@ class InstallProgress implements IRunnableWithProgress {
        private void removeTar(String packageFile) {
                try {
                        SdbShellProcess echoProc = device.executeShellCommand("cd "
-                                       + TOOLS_TARGET_PATH + " && rm " + packageFile);
+                                       + DebugTool.TOOLS_TARGET_PATH + " && rm " + packageFile);
                        
                        BufferedReader br = new BufferedReader(new InputStreamReader(
                                        echoProc.getInputStream()));
@@ -237,17 +237,17 @@ class InstallProgress implements IRunnableWithProgress {
                }
        }
 
-       final private void installPackage(DebugTool tool) {
-               String local = TOOLS_HOST_PATH+"/"+tool.getSourcepath() + "/" + tool.getBinaryname();
-               String remote = TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
+       final private void installPackage(DebugTool tool) throws CoreException {
+               String local = DebugTool.TOOLS_HOST_PATH+"/"+tool.getSourcepath() + "/" + tool.getBinaryname();
+               String remote = DebugTool.TOOLS_TARGET_PATH + "/" + tool.getBinaryname();
                
                // delete old version
                try {
                        SdbShellProcess echoProc = device.executeShellCommand("cd "
-                                       + TOOLS_TARGET_PATH + " && rm " + tool.getControlFile());
+                                       + DebugTool.TOOLS_TARGET_PATH + " && rm " + tool.getControlFile());
                } catch (IOException e) {
                        // TODO Auto-generated catch block
-                       e.printStackTrace();
+                       installCoreException(ToolsInstallMessages.CANNOT_REMOVE_CONTROLFILE, e);
                }
                
                
@@ -265,8 +265,7 @@ class InstallProgress implements IRunnableWithProgress {
        }
 
        @Override
-       public void run(IProgressMonitor monitor) throws InvocationTargetException,
-                       InterruptedException {
+       public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                final List<DebugTool>  debugTools = ConnectionPlugin.getDebugTools(device);
                
                if (debugTools == null || debugTools.size() ==0)
@@ -274,7 +273,12 @@ class InstallProgress implements IRunnableWithProgress {
                boolean isInstalled = false;
                for (int i=0 ; i<debugTools.size(); i++) {
                        DebugTool dt = (DebugTool)debugTools.get(i);
-                       isInstalled = isInstalled(dt);
+                       try {
+                               isInstalled = isInstalled(dt);
+                       } catch (CoreException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
                        if (isInstalled == false)
                                break;
                }
@@ -284,12 +288,17 @@ class InstallProgress implements IRunnableWithProgress {
                final IProgressMonitor fmonitor = monitor;
                this.monitor = monitor;
                
-               monitor.beginTask(Messages.getString("debugtools.initilize"), 100);
+               monitor.beginTask(ToolsInstallMessages.DIALOG_INITILIZE, 100);
                //monitor.subTask("Prepare install");
                
                // check directory exist
-               if (!checkDirectory(TOOLS_TARGET_PATH)) 
-                       makeDirectory(TOOLS_TARGET_PATH);
+               try {
+                       if (!checkDirectory(DebugTool.TOOLS_TARGET_PATH)) 
+                               makeDirectory(DebugTool.TOOLS_TARGET_PATH);
+               } catch (CoreException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
 
                monitor.worked(10);
 
@@ -313,7 +322,12 @@ class InstallProgress implements IRunnableWithProgress {
 
                                @Override
                                public void run() {
-                                               installPackage(dt);
+                                               try {
+                                                       installPackage(dt);
+                                               } catch (CoreException e) {
+                                                       // TODO Auto-generated catch block
+                                                       e.printStackTrace();
+                                               }
                                }
                        }, "package check and install");
                        thread.start();
@@ -324,7 +338,11 @@ class InstallProgress implements IRunnableWithProgress {
        public void setDevice(IDevice device) {
                this.device = device;
        }
-
+       
+       private void installCoreException(String message, Throwable exception) throws CoreException {
+        Status status = new Status(Status.ERROR, ConnectionPlugin.PLUGIN_ID, message, exception);
+        throw new CoreException(status);
+    }
 }
 
 public class ToolsInstall {
diff --git a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstallMessages.java b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstallMessages.java
new file mode 100644 (file)
index 0000000..d151bf6
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+*  Common\r
+*\r
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+*\r
+* Contact: \r
+* Hoon Kang <h245.kang@samsung.com>\r
+* YoonKi Park <yoonki.park@samsung.com>\r
+* \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*\r
+* Contributors:\r
+* - S-Core Co., Ltd\r
+*\r
+*/\r
+package com.samsung.tizen.common.connection.debugtools;\r
+\r
+import org.eclipse.osgi.util.NLS;\r
+\r
+public class ToolsInstallMessages extends NLS {\r
+\r
+       static {\r
+               NLS.initializeMessages(ToolsInstallMessages.class.getName(), ToolsInstallMessages.class);\r
+       }\r
+       \r
+       public static String DIALOG_INITILIZE;\r
+       public static String CANNOT_CREATE_DIRECTORY;\r
+       public static String CANNOT_CHECK_DIRECTORY;\r
+       public static String CANNOT_CHECK_INSTALLED;\r
+       public static String CANNOT_COPY_FILE;\r
+       public static String CANNOT_REMOVE_CONTROLFILE;\r
+       \r
+}\r
diff --git a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstallMessages.properties b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/ToolsInstallMessages.properties
new file mode 100644 (file)
index 0000000..5d83979
--- /dev/null
@@ -0,0 +1,8 @@
+\r
+DIALOG_INITILIZE=Connection Explorer is initializing now. It might take few minutes.\r
+CANNOT_CREATE_DIRECTORY=Cannot create sdk tools directory\r
+CANNOT_CHECK_DIRECTORY=Cannot check sdk tools directory\r
+CANNOT_CHECK_INSTALLED=Cannot check installed tools\r
+CANNOT_COPY_FILE=Cannot copy file\r
+CANNOT_REMOVE_CONTROLFILE=Cannot copy file\r
\r
diff --git a/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/messages.properties b/com.samsung.tizen.common.connection/src/com/samsung/tizen/common/connection/debugtools/messages.properties
deleted file mode 100644 (file)
index 982fa4b..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-\r
-debugtools.initilize=Connection Explorer is initializing now. It might take few minutes. \r