/*
-* Inhouse
-*
-* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
-*
-* Contact:
-* Taejun Ha <taejun.ha@samsung.com>
-* Jiil Hyoun <jiil.hyoun@samsung.com>
-* Donghyuk Yang <donghyuk.yang@samsung.com>
-* Hoon Kang <h245.kang@samsung.com>
-* DongHee Yang <donghee.yang@samsung.com>
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-* Contributors:
-* - S-Core Co., Ltd
-*
-*/
+ * Inhouse
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Taejun Ha <taejun.ha@samsung.com>
+ * Jiil Hyoun <jiil.hyoun@samsung.com>
+ * Donghyuk Yang <donghyuk.yang@samsung.com>
+ * Hoon Kang <h245.kang@samsung.com>
+ * DongHee Yang <donghee.yang@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
package org.tizen.nativeplatform.pkgmgr;
import java.io.File;
import org.tizen.nativeplatform.pkgmgr.model.Package;
import org.tizen.nativeplatform.util.CommandLauncher;
import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.IShellOutputReceiver;
+import org.tizen.sdblib.SdbCommandRejectedException;
+import org.tizen.sdblib.ShellCommandUnresponsiveException;
import org.tizen.sdblib.SyncService;
import org.tizen.sdblib.SyncService.SyncResult;
+import org.tizen.sdblib.TimeoutException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class RPMPackageCommander {
private final static int MAX_TIMEOUT = 10000;
- private static String http_proxy = "";
+ private static String http_proxy = "";
private static final String REMOVE_PKGS = "rpm-x86-arm";
-
- private static final String BUNDLE_NAME = RPMPackageCommander.class.getPackage().getName() + ".RPMPackageCommands";
- private static ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_NAME);
-
- public RPMPackageCommander() {
- }
-
+
+ private static final String BUNDLE_NAME = RPMPackageCommander.class
+ .getPackage().getName() + ".RPMPackageCommands";
+ private static ResourceBundle resources = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ public RPMPackageCommander() {
+ }
+
public static void setHttpProxy(String proxy) {
http_proxy = proxy;
- }
+ }
-
public static void DistUpgradeRootstrap(String path,
- IProgressMonitor monitor ) throws InterruptedException {
-
+ IProgressMonitor monitor) throws InterruptedException {
+
actionBeforeUseZypper(path);
- String command = getChrootedCommand(path,
- String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getDistUpgradeCmd()));
-
- CommandLauncher.executeSudo(command, null, "Platform Internal", monitor);
+ String command = getChrootedCommand(path, String.format("%s;%s;%s",
+ getProxyCmd(), getResetDbCmd(), getDistUpgradeCmd()));
+
+ CommandLauncher
+ .executeSudo(command, null, "Platform Internal", monitor);
}
-
-
+
public static void InstallLocalPkgToRootstrap(ArrayList<String> fileList,
String path, IProgressMonitor monitor) throws InterruptedException {
-
+
actionBeforeUseZypper(path);
// copy
ArrayList<String> fileListOnRootstrap = new ArrayList<String>();
- for (String filePath : fileList) {
+ for (String filePath : fileList) {
String filename = new File(filePath).getName();
String pathOnRootstrap = "/tmp/" + filename;
try {
FileUtil.copyTo(filePath, path + pathOnRootstrap);
} catch (IOException e) {
- //do nothing
+ e.printStackTrace();
+ continue;
}
fileListOnRootstrap.add(pathOnRootstrap);
- }
+ }
- // install
- String cmd = String.format("%s;%s", getResetDbCmd(), getInstallLocalPkgCmd(fileListOnRootstrap));
+ // install
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getInstallLocalPkgCmd(fileListOnRootstrap));
String command = getChrootedCommand(path, cmd);
- CommandLauncher.executeSudo(command, null, "Platform Internal", monitor);
+ CommandLauncher
+ .executeSudo(command, null, "Platform Internal", monitor);
}
-
- public static void InstallLocalPkgToDevice(ArrayList<String> fileList, IDevice device) {
+ public static void InstallLocalPkgToDevice(ArrayList<String> fileList,
+ IDevice device) {
actionBeforeUseZypperDevice(device);
- try {
- // copy
- ArrayList<String> fileListOnDevice = new ArrayList<String>();
- for (String filePath : fileList) {
- String filename = new File(filePath).getName();
- String pathOnDevice = "/tmp/" + filename;
- SyncService syncService = device.getSyncService();
- SyncResult syncResult = syncService.pushFile(filePath, pathOnDevice, SyncService.getNullProgressMonitor());
- if (syncResult.getCode() != SyncService.RESULT_OK) {
- continue;
- }
- fileListOnDevice.add(pathOnDevice);
- }
-
- // set update mode
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- rec.cleanLog();
- if (!device.isEmulator()) {
- RPMPackageCommander.changeUpdateModeForDevice(device, rec);
+ // copy
+ ArrayList<String> fileListOnDevice = new ArrayList<String>();
+ for (String filePath : fileList) {
+ String filename = new File(filePath).getName();
+ String pathOnDevice = "/tmp/" + filename;
+ SyncService syncService;
+ try {
+ syncService = device.getSyncService();
+ } catch (TimeoutException e) {
+ e.printStackTrace();
+ continue;
+ } catch (SdbCommandRejectedException e) {
+ e.printStackTrace();
+ continue;
+ } catch (IOException e) {
+ e.printStackTrace();
+ continue;
+ }
+ SyncResult syncResult = syncService.pushFile(filePath,
+ pathOnDevice, SyncService.getNullProgressMonitor());
+ if (syncResult.getCode() != SyncService.RESULT_OK) {
+ continue;
}
+ fileListOnDevice.add(pathOnDevice);
+ }
- // install
- String command = String.format("%s;%s", getResetDbCmd(), getInstallLocalPkgCmdWithRPM(fileListOnDevice));
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e1) {
- e1.printStackTrace();
+ // set update mode
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ rec.cleanLog();
+ if (!device.isEmulator()) {
+ RPMPackageCommander.changeUpdateModeForDevice(device, rec);
}
+
+ // install
+ String command = String.format("%s;%s", getResetDbCmd(),
+ getInstallLocalPkgCmdWithRPM(fileListOnDevice));
+ executeDeviceShellCommand(device, command, rec);
}
-
- public static Document InstallPkgWithZypperXmlOut(String path, String pkgs, boolean refresh, boolean force) {
+
+ private static void executeDeviceShellCommand( IDevice device,
+ String command, IShellOutputReceiver rec ) {
+ try {
+ device.executeShellCommand(command, rec, MAX_TIMEOUT );
+ } catch (TimeoutException e) {
+ e.printStackTrace();
+ } catch (SdbCommandRejectedException e) {
+ e.printStackTrace();
+ } catch (ShellCommandUnresponsiveException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public static Document InstallPkgWithZypperXmlOut(String path, String pkgs,
+ boolean refresh, boolean force) {
String log = "";
if (refresh) {
refreshRepositoryForRootstrap(path);
if (force) {
additionOp = "--force";
}
- String cmd = String.format("%s;%s", getProxyCmd(), getInstallPkgWithZypper(basicOp, additionOp, pkgs));
+ String cmd = String.format("%s;%s", getProxyCmd(),
+ getInstallPkgWithZypper(basicOp, additionOp, pkgs));
String command = getChrootedCommand(path, cmd);
-
- try {
- log = CommandLauncher.executeSudoOutput(command, null, true);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
+
+ log = executeSudoOutputCommand(command, null, true);
+
if (log.contains("<?xml")) {
int index = log.indexOf("<?xml");
log = log.substring(index);
}
-
+
Document doc = null;
StringReader sr = new StringReader(log);
InputSource is = new InputSource(sr);
db = dbf.newDocumentBuilder();
doc = db.parse(is);
} catch (ParserConfigurationException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
return doc;
}
+
+
+ private static String executeSudoOutputCommand( String command ) {
+ try {
+ return CommandLauncher.executeSudoOutput(command, null, false, null);
+ } catch (InterruptedException e1) {
+ return "";
+ }
+ }
- public static void uninstallPkgFromRootstrap(CopyOnWriteArrayList<Package> pkgList,
- String path, IProgressMonitor monitor) throws InterruptedException {
- String cmd = String.format("%s;%s", getResetDbCmd(), getUninstallPkgCmd(pkgList));
- String command = getChrootedCommand(path, cmd);
-
- CommandLauncher.executeSudo(command, null, "Platform Internal", monitor);
+ private static String executeSudoOutputCommand( String command, String workingDir,
+ boolean includeStdErr ) {
+ try {
+ return CommandLauncher.executeSudoOutput(command, workingDir, includeStdErr, null);
+ } catch (InterruptedException e1) {
+ return "";
+ }
}
+
+ public static void uninstallPkgFromRootstrap(
+ CopyOnWriteArrayList<Package> pkgList, String path,
+ IProgressMonitor monitor) throws InterruptedException {
+
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getUninstallPkgCmd(pkgList));
+ String command = getChrootedCommand(path, cmd);
+
+ CommandLauncher
+ .executeSudo(command, null, "Platform Internal", monitor);
+ }
- public static void uninstallPkgFromDevice(CopyOnWriteArrayList<Package> pkgList, IDevice device) {
- try {
+ public static void uninstallPkgFromDevice(
+ CopyOnWriteArrayList<Package> pkgList, IDevice device) {
PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getUninstallPkgCmd(pkgList));
+ String command = String.format("%s;%s;%s", getProxyCmd(),
+ getResetDbCmd(), getUninstallPkgCmd(pkgList));
rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ executeDeviceShellCommand(device, command, rec);
}
-
- public static void UninstallPkgFromRootstrapNoDeps(String fileList, String path) {
+ public static void UninstallPkgFromRootstrapNoDeps(String fileList,
+ String path) {
- String cmd = String.format("%s;%s", getResetDbCmd(), getUninstallPkgCmdNoDeps(fileList));
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getUninstallPkgCmdNoDeps(fileList));
String command = getChrootedCommand(path, cmd);
-
+
try {
- CommandLauncher.executeSudo(command, null, "Platform Internal", null);
- } catch (Exception e) {
- // TODO Auto-generated catch block
+ CommandLauncher.executeSudo(command, null, "Platform Internal",
+ null);
+ } catch (InterruptedException e) {
e.printStackTrace();
- }
+ }
}
-
public static String getArchForFile(String filePath) {
try {
- return CommandLauncher.executeOutput(getQueryInfoCmd("ARCH", filePath));
+ return CommandLauncher.executeOutput(getQueryInfoCmd("ARCH",
+ filePath));
} catch (InterruptedException e) {
return "";
}
}
-
-
+
public static String getPkgNameForFile(String filePath) {
try {
- return CommandLauncher.executeOutput(getQueryInfoCmd("NAME", filePath));
+ return CommandLauncher.executeOutput(getQueryInfoCmd("NAME",
+ filePath));
} catch (InterruptedException e) {
return "";
}
}
-
-
- public static String getPkgVerForFile(String filePath) {
+
+ public static String getPkgVerForFile(String filePath) {
String version;
String release;
try {
- version = CommandLauncher.executeOutput(getQueryInfoCmd("VERSION", filePath));
- release = CommandLauncher.executeOutput(getQueryInfoCmd("RELEASE", filePath));
+ version = CommandLauncher.executeOutput(getQueryInfoCmd("VERSION",
+ filePath));
+ release = CommandLauncher.executeOutput(getQueryInfoCmd("RELEASE",
+ filePath));
} catch (InterruptedException e) {
return "";
- }
-
- return version + "-" + release;
+ }
+
+ return version + "-" + release;
}
-
-
- public static String getPkgInstalledVerForRootstrap(String pkgName, String path) {
+
+ public static String getPkgInstalledVerForRootstrap(String pkgName,
+ String path) {
String retStr = "";
String version = "";
String release = "";
-
+
if (!pkgInstalledSuccessfullyForRootstrap(pkgName, path)) {
return retStr;
- }
-
+ }
+
String result = null;
- String cmd = String.format("%s;%s", getResetDbCmd(), getShowPkgInfoCmd(pkgName));
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getShowPkgInfoCmd(pkgName));
String command = getChrootedCommand(path, cmd);
-
- try {
- result = CommandLauncher.executeSudoOutput(command);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+
+ result = executeSudoOutputCommand(command);
+
String[] splitResult = result.split("\n");
for (String r : splitResult) {
if (r.trim().startsWith("Version")) {
- version = r.split(":")[1].trim();
+ version = r.split(":")[1].trim();
} else if (r.trim().startsWith("Release")) {
- release = r.split(":")[1].trim();
+ release = r.split(":")[1].trim();
}
}
-
- retStr = version + "-" + release;
+
+ retStr = version + "-" + release;
return retStr;
}
-
- public static String getPkgInstalledVerForDevice(String pkgName, IDevice device, PackageManagerOuputReceiver rec) {
+
+ public static String getPkgInstalledVerForDevice(String pkgName,
+ IDevice device, PackageManagerOuputReceiver rec) {
String retStr = "";
String version = "";
String release = "";
-
+
if (device != null) {
if (!pkgInstalledSuccessfullyForDevice(pkgName, device, rec)) {
return retStr;
}
-
- try {
- String command = String.format("%s;%s", getResetDbCmd(), getShowPkgInfoCmd(pkgName));
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- for (String l : rec.getLog()) {
- if (l.trim().startsWith("Version")) {
- version = l.split(":")[1].trim();
- } else if (l.trim().startsWith("Release")) {
- release = l.split(":")[1].trim();
- }
- }
-
- } catch (Exception e1) {
- e1.printStackTrace();
+
+ String command = String.format("%s;%s", getResetDbCmd(),
+ getShowPkgInfoCmd(pkgName));
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
+ for (String l : rec.getLog()) {
+ if (l.trim().startsWith("Version")) {
+ version = l.split(":")[1].trim();
+ } else if (l.trim().startsWith("Release")) {
+ release = l.split(":")[1].trim();
+ }
}
}
-
- retStr = version + "-" + release;
+
+ retStr = version + "-" + release;
return retStr;
}
-
- public static boolean pkgInstalledSuccessfullyForRootstrap(String pkgName, String path) {
-
- boolean ret = false;
- String result = "";
-
- String cmd = String.format("%s;%s", getResetDbCmd(), getShowPkgCmd(pkgName));
+
+ public static boolean pkgInstalledSuccessfullyForRootstrap(String pkgName,
+ String path) {
+
+ boolean ret = false;
+ String result = "";
+
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getShowPkgCmd(pkgName));
String command = getChrootedCommand(path, cmd);
-
- try {
- result = CommandLauncher.executeSudoOutput(command);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+
+ result = executeSudoOutputCommand(command);
+
if (!result.isEmpty() && result.contains(pkgName)) {
ret = true;
}
-
+
return ret;
}
-
- public static boolean pkgInstalledSuccessfullyForDevice(String pkgName, IDevice device, PackageManagerOuputReceiver rec) {
-
+
+ public static boolean pkgInstalledSuccessfullyForDevice(String pkgName,
+ IDevice device, PackageManagerOuputReceiver rec) {
+
boolean ret = false;
-
+
if (device != null) {
- try {
- String command = String.format("%s;%s", getResetDbCmd(), getShowPkgCmd(pkgName));
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e1) {
- e1.printStackTrace();
- }
+ String command = String.format("%s;%s", getResetDbCmd(),
+ getShowPkgCmd(pkgName));
+ executeDeviceShellCommand(device, command, rec);
}
-
+
if (rec.getLog() == null) {
return false;
}
-
+
for (String l : rec.getLog()) {
if (l.contains(pkgName)) {
ret = true;
}
- }
-
- return ret;
+ }
+
+ return ret;
}
-
-
+
public static ArrayList<Package> getPackageListForRootstrap(String path,
- IProgressMonitor monitor ) throws InterruptedException {
-
+ IProgressMonitor monitor) throws InterruptedException {
+
ArrayList<Package> packageList = new ArrayList<Package>();
Hashtable<String, Package> packageHash = new Hashtable<String, Package>();
-
+
// get list using zypper
- String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getRemotePkgListCmd());
+ String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(),
+ getRemotePkgListCmd());
String command = getChrootedCommand(path, cmd);
- String result = CommandLauncher.executeSudoOutput(command, null, false, monitor);
+ String result = CommandLauncher.executeSudoOutput(command, null, false,
+ monitor);
String[] splitStr = result.split("\n");
- for (String s : splitStr ) {
+ for (String s : splitStr) {
s = s.replaceAll(" ", "");
String[] part = s.split("\\|");
- if ( part.length == 5 && !part[0].equals("S")) {
- String name = part[2];
- String version = part[3];
+ if (part.length == 5 && !part[0].equals("S")) {
+ String name = part[2];
+ String version = part[3];
String arch = part[4];
- if ( part[0].equals("i") ) {
- packageHash.put(name, new Package(name,version,version,arch) );
- }
- else if ( part[0].equals("v") ) {
+ if (part[0].equals("i")) {
+ packageHash.put(name, new Package(name, version, version,
+ arch));
+ } else if (part[0].equals("v")) {
Package p = packageHash.get(name);
- if ( p != null ) {
- if ( version.compareTo( p.getNewVersion() ) > 0 ) {
+ if (p != null) {
+ if (version.compareTo(p.getNewVersion()) > 0) {
p.setNewVersion(version);
}
+ } else {
+ packageHash.put(name, new Package(name, version,
+ version, arch));
}
- else {
- packageHash.put(name, new Package(name,version,version,arch) );
- }
- }
- else {
- packageHash.put(name, new Package(name,"",version,arch) );
+ } else {
+ packageHash.put(name, new Package(name, "", version, arch));
}
}
}
for (String s : splitStr) {
s = s.replaceAll(" ", "").trim();
String[] part = s.split(",");
- if ( part.length == 3 ) {
- String name = part[0];
- String version = part[1];
+ if (part.length == 3) {
+ String name = part[0];
+ String version = part[1];
String arch = part[2];
Package pkg = packageHash.get(name);
- if ( pkg == null ) {
- packageHash.put(name, new Package(name,version,"",arch));
- }
- else {
+ if (pkg == null) {
+ packageHash.put(name, new Package(name, version, "", arch));
+ } else {
pkg.setInstalledVersion(version);
}
}
}
-
+
Enumeration<Package> e = packageHash.elements();
- while(e.hasMoreElements()) {
+ while (e.hasMoreElements()) {
packageList.add(e.nextElement());
}
-
+
return packageList;
}
-
-
+
public static ArrayList<Package> getPackageListForDevice(IDevice device) {
actionBeforeUseZypperDevice(device);
Hashtable<String, Package> packageHash = new Hashtable<String, Package>();
PackageManagerOuputReceiver rec = getNewOuputReceiver();
rec.setPrintConsole(false);
- try {
- // get list using zypper
- String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getRemotePkgListCmd());
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- for (String s : rec.getLog() ) {
- s = s.replaceAll(" ", "");
- String[] part = s.split("\\|");
- if ( part.length == 5 && !part[0].equals("S")) {
- String name = part[2];
- String version = part[3];
- String arch = part[4];
- if ( part[0].equals("i") ) {
- packageHash.put(name, new Package(name,version,version,arch) );
- }
- else if ( part[0].equals("v") ) {
- Package p = packageHash.get(name);
- if ( p != null && version.compareTo( p.getNewVersion() ) > 0 ) {
- p.setNewVersion(version);
- }
- else {
- packageHash.put(name, new Package(name,"",version,arch) );
- }
- }
- else {
- packageHash.put(name, new Package(name,"",version,arch) );
+
+ // get list using zypper
+ String command = String.format("%s;%s;%s", getProxyCmd(),
+ getResetDbCmd(), getRemotePkgListCmd());
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
+ for (String s : rec.getLog()) {
+ s = s.replaceAll(" ", "");
+ String[] part = s.split("\\|");
+ if (part.length == 5 && !part[0].equals("S")) {
+ String name = part[2];
+ String version = part[3];
+ String arch = part[4];
+ if (part[0].equals("i")) {
+ packageHash.put(name, new Package(name, version,
+ version, arch));
+ } else if (part[0].equals("v")) {
+ Package p = packageHash.get(name);
+ if (p != null
+ && version.compareTo(p.getNewVersion()) > 0) {
+ p.setNewVersion(version);
+ } else {
+ packageHash.put(name, new Package(name, "",
+ version, arch));
}
+ } else {
+ packageHash.put(name, new Package(name, "", version,
+ arch));
}
}
+ }
- // get installed packages using rpm
- command = String.format("%s;%s", getResetDbCmd(), getInstalledPkgListCmdDevice());
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- for (String s : rec.getLog()) {
- s = s.replaceAll(" ", "").trim();
- String[] part = s.split(",");
- if ( part.length == 3 ) {
- String name = part[0];
- String version = part[1];
- String arch = part[2];
- Package pkg = packageHash.get(name);
- if ( pkg == null ) {
- packageHash.put(name, new Package(name,version,"",arch));
- }
- else {
- pkg.setInstalledVersion(version);
- }
+ // get installed packages using rpm
+ command = String.format("%s;%s", getResetDbCmd(),
+ getInstalledPkgListCmdDevice());
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
+ for (String s : rec.getLog()) {
+ s = s.replaceAll(" ", "").trim();
+ String[] part = s.split(",");
+ if (part.length == 3) {
+ String name = part[0];
+ String version = part[1];
+ String arch = part[2];
+ Package pkg = packageHash.get(name);
+ if (pkg == null) {
+ packageHash.put(name, new Package(name, version, "",
+ arch));
+ } else {
+ pkg.setInstalledVersion(version);
}
}
- } catch (Exception e) {
- // do nothing
- }
-
+ }
+
Enumeration<Package> e = packageHash.elements();
- while(e.hasMoreElements()) {
+ while (e.hasMoreElements()) {
packageList.add(e.nextElement());
}
-
+
return packageList;
}
-
-
+
public static void resetRepositoryForRootstrap(String path) {
- String cmd = String.format("%s", getRepoResetCmd());
+ String cmd = String.format("%s", getRepoResetCmd());
String command = getChrootedCommand(path, cmd);
-
- try {
- CommandLauncher.executeSudoOutput(command);
- } catch (Exception e) {
- // do nothing
- }
+ executeSudoOutputCommand(command);
}
-
- public static Hashtable<String, String> getRepositoryListForDevice(IDevice device) {
+ public static Hashtable<String, String> getRepositoryListForDevice(
+ IDevice device) {
PackageManagerOuputReceiver rec = getNewOuputReceiver();
Hashtable<String, String> reposHash = new Hashtable<String, String>();
-
- try {
- String command = String.format("%s;%s", getResetDbCmd(), getRepoListCmd());
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
+
+ String command = String.format("%s;%s", getResetDbCmd(),
+ getRepoListCmd());
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
+
for (String reposStr : rec.getLog()) {
reposStr = reposStr.replaceAll(" ", "");
String[] part = reposStr.split("\\|");
- if ( part.length == 6 && !part[0].equals("#") ) {
+ if (part.length == 6 && !part[0].equals("#")) {
reposHash.put(part[1], part[5]);
}
}
-
- return reposHash;
+
+ return reposHash;
}
-
public static String refreshRepositoryForRootstrap(String path) {
-
- String result = "";
- String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getRefreshCmd());
+
+ String result = "";
+ String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(),
+ getRefreshCmd());
String command = getChrootedCommand(path, cmd);
-
- try {
- CommandLauncher.executeSudo(command, null, "Platform Internal", null);
- } catch (Exception e) {
+
+ try {
+ CommandLauncher.executeSudo(command, null, "Platform Internal", null);
+ } catch (InterruptedException e) {
e.printStackTrace();
- }
-
+ }
+
return result;
}
-
-
+
public static void refreshRepositoryForDevice(IDevice device) {
- try {
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getRefreshCmd());
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s;%s", getProxyCmd(),
+ getResetDbCmd(), getRefreshCmd());
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
}
-
- public static String addRepositoryForRootstrap(String name, String uri, String path) {
-
+ public static String addRepositoryForRootstrap(String name, String uri,
+ String path) {
+
String result = "";
- String cmd = String.format("%s;%s", getResetDbCmd(), getAddRepoCmd(uri, name));
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getAddRepoCmd(uri, name));
String command = getChrootedCommand(path, cmd);
-
- try {
- result = CommandLauncher.executeSudoOutput(command);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+
+ result = executeSudoOutputCommand(command);
+
return result;
}
-
-
- public static void addRepositoryForDevice(String name, String uri, IDevice device) {
- try {
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String command = String.format("%s;%s", getResetDbCmd(), getAddRepoCmd(uri, name));
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ public static void addRepositoryForDevice(String name, String uri,
+ IDevice device) {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s", getResetDbCmd(),
+ getAddRepoCmd(uri, name));
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
}
-
public static String removeRepositoryForRootstrap(String name, String path) {
-
- String result = "";
- String cmd = String.format("%s;%s", getResetDbCmd(), getRemoveRepoCmd(name));
+
+ String cmd = String.format("%s;%s", getResetDbCmd(),
+ getRemoveRepoCmd(name));
String command = getChrootedCommand(path, cmd);
-
- try {
- result = CommandLauncher.executeSudoOutput(command);
-
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return result;
+
+ return executeSudoOutputCommand(command);
}
-
-
+
public static void removeRepositoryForDevice(String name, IDevice device) {
-
- try {
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String command = String.format("%s;%s", getResetDbCmd(), getRemoveRepoCmd(name));
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s", getResetDbCmd(),
+ getRemoveRepoCmd(name));
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
}
-
-
-
-
- public static void installRemotePkgForRootstrap(CopyOnWriteArrayList<Package> selectedList,
- String path, IProgressMonitor monitor ) throws InterruptedException {
+
+ public static void installRemotePkgForRootstrap(
+ CopyOnWriteArrayList<Package> selectedList, String path,
+ IProgressMonitor monitor) throws InterruptedException {
actionBeforeUseZypper(path);
-
- String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getInstallPkgCmd(selectedList));
+
+ String cmd = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(),
+ getInstallPkgCmd(selectedList));
String command = getChrootedCommand(path, cmd);
-
- CommandLauncher.executeSudo(command, null, "Platform Internal", monitor);
+
+ CommandLauncher
+ .executeSudo(command, null, "Platform Internal", monitor);
}
-
-
- public static void installRemotePkgForDevice(CopyOnWriteArrayList<Package> selectedList, IDevice device) {
-
- try {
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- String command = String.format("%s;%s;%s", getProxyCmd(), getResetDbCmd(), getInstallPkgCmd(selectedList));
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ public static void installRemotePkgForDevice(
+ CopyOnWriteArrayList<Package> selectedList, IDevice device) {
+
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ String command = String.format("%s;%s;%s", getProxyCmd(),
+ getResetDbCmd(), getInstallPkgCmd(selectedList));
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
}
-
-
- private static void changeUpdateModeForDevice(IDevice device, PackageManagerOuputReceiver rec) {
-
- try {
- String command = resources.getString("Command.Change.Updatemode");
- rec.cleanLog();
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ private static void changeUpdateModeForDevice(IDevice device,
+ PackageManagerOuputReceiver rec) {
+
+ String command = resources.getString("Command.Change.Updatemode");
+ rec.cleanLog();
+ executeDeviceShellCommand(device, command, rec);
}
-
-
+
private static void actionBeforeUseZypper(String path) {
if (pkgInstalledSuccessfullyForRootstrap(REMOVE_PKGS, path)) {
UninstallPkgFromRootstrapNoDeps(REMOVE_PKGS, path);
}
}
-
private static void actionBeforeUseZypperDevice(IDevice device) {
- if ( device.isEmulator() ) {
- try {
- PackageManagerOuputReceiver rec = getNewOuputReceiver();
- rec.cleanLog();
- String command = String.format("sed -i \"s/# arch = s390/arch = i686/g\" /etc/zypp/zypp.conf");
- device.executeShellCommand(command, rec, MAX_TIMEOUT);
- return;
- } catch (Exception e) {
- e.printStackTrace();
- }
+ if (device.isEmulator()) {
+ PackageManagerOuputReceiver rec = getNewOuputReceiver();
+ rec.cleanLog();
+ String command = String
+ .format("sed -i \"s/# arch = s390/arch = i686/g\" /etc/zypp/zypp.conf");
+ executeDeviceShellCommand(device, command, rec);
}
}
-
private static String getProxyCmd() {
- return String.format(resources.getString("Command.Export.Proxy"), http_proxy);
+ return String.format(resources.getString("Command.Export.Proxy"),
+ http_proxy);
}
-
-
+
private static String getResetDbCmd() {
return String.format(resources.getString("Command.Reset.Db"));
}
-
-
+
private static String getDistUpgradeCmd() {
return String.format(resources.getString("Command.DistUpgrade"));
}
-
-
+
private static String getInstallPkgCmd(CopyOnWriteArrayList<Package> pkgList) {
String pkgListStr = "";
- for( Package pkg: pkgList) {
- pkgListStr = pkgListStr.isEmpty() ? pkg.getName() : pkgListStr + " " + pkg.getName();
+ for (Package pkg : pkgList) {
+ pkgListStr = pkgListStr.isEmpty() ? pkg.getName() : pkgListStr
+ + " " + pkg.getName();
}
- return String.format(resources.getString("Command.Install.Remote.Pkg"), pkgListStr);
+ return String.format(resources.getString("Command.Install.Remote.Pkg"),
+ pkgListStr);
}
private static String getInstallLocalPkgCmd(ArrayList<String> fileList) {
String pkgListStr = "";
- for( String filePath: fileList) {
- pkgListStr = pkgListStr.isEmpty() ? filePath : pkgListStr + " " + filePath;
+ for (String filePath : fileList) {
+ pkgListStr = pkgListStr.isEmpty() ? filePath : pkgListStr + " "
+ + filePath;
}
- return String.format(resources.getString("Command.Install.Local.Pkg"), pkgListStr);
+ return String.format(resources.getString("Command.Install.Local.Pkg"),
+ pkgListStr);
}
- private static String getInstallLocalPkgCmdWithRPM(ArrayList<String> fileList) {
+ private static String getInstallLocalPkgCmdWithRPM(
+ ArrayList<String> fileList) {
String pkgListStr = "";
- for( String filePath: fileList) {
- pkgListStr = pkgListStr.isEmpty() ? filePath : pkgListStr + " " + filePath;
+ for (String filePath : fileList) {
+ pkgListStr = pkgListStr.isEmpty() ? filePath : pkgListStr + " "
+ + filePath;
}
- return String.format(resources.getString("Command.Install.Local.Pkg.RPM"), pkgListStr);
+ return String.format(
+ resources.getString("Command.Install.Local.Pkg.RPM"),
+ pkgListStr);
}
- private static String getUninstallPkgCmd(CopyOnWriteArrayList<Package> pkgList) {
+ private static String getUninstallPkgCmd(
+ CopyOnWriteArrayList<Package> pkgList) {
String pkgListStr = "";
- for( Package pkg: pkgList) {
- pkgListStr = pkgListStr.isEmpty() ? pkg.getName() : pkgListStr + " " + pkg.getName();
+ for (Package pkg : pkgList) {
+ pkgListStr = pkgListStr.isEmpty() ? pkg.getName() : pkgListStr
+ + " " + pkg.getName();
}
- return String.format(resources.getString("Command.Uninstall.Pkg"), pkgListStr);
+ return String.format(resources.getString("Command.Uninstall.Pkg"),
+ pkgListStr);
}
private static String getUninstallPkgCmdNoDeps(String pkgList) {
- return String.format(resources.getString("Command.Uninstall.Pkg.NoDeps"), pkgList);
+ return String.format(
+ resources.getString("Command.Uninstall.Pkg.NoDeps"), pkgList);
}
-
+
private static String getRemoveRepoCmd(String name) {
return String.format(resources.getString("Command.Remove.Repo"), name);
}
-
+
private static String getAddRepoCmd(String uri, String name) {
- return String.format(resources.getString("Command.Add.Repo"), uri, name);
+ return String
+ .format(resources.getString("Command.Add.Repo"), uri, name);
}
-
+
private static String getRefreshCmd() {
return resources.getString("Command.Refresh.Repo");
}
-
+
private static String getRepoListCmd() {
return resources.getString("Command.List.Repo");
}
private static String getRemotePkgListCmd() {
return resources.getString("Command.List.Remote.Pkg");
}
-
+
private static String getInstalledPkgListCmd() {
return resources.getString("Command.List.Installed.Pkg");
}
-
+
private static String getInstalledPkgListCmdDevice() {
return resources.getString("Command.List.Installed.Pkg.Device");
}
private static String getShowPkgCmd(String name) {
return String.format(resources.getString("Command.Show.Pkg"), name);
}
-
+
private static String getShowPkgInfoCmd(String name) {
- return String.format(resources.getString("Command.Show.Info.Pkg"), name);
+ return String
+ .format(resources.getString("Command.Show.Info.Pkg"), name);
}
-
+
private static String getQueryInfoCmd(String tag, String name) {
- return String.format(resources.getString("Command.Info.Pkg.File"), tag, name);
+ return String.format(resources.getString("Command.Info.Pkg.File"), tag,
+ name);
}
-
- private static String getInstallPkgWithZypper(String basicOp, String additionOp, String pkgs) {
- return String.format(resources.getString("Command.Install.Pkg.WithZypper"),
- basicOp, additionOp, pkgs);
+
+ private static String getInstallPkgWithZypper(String basicOp,
+ String additionOp, String pkgs) {
+ return String.format(
+ resources.getString("Command.Install.Pkg.WithZypper"), basicOp,
+ additionOp, pkgs);
}
-
+
private static String getChrootedCommand(String path, String cmd) {
- return String.format("sudo -S chroot %s sh -c \\\"%s\\\"", path, cmd);
+ return String.format("sudo -S chroot %s sh -c \\\"%s\\\"", path, cmd);
}
-
-
+
public static int compareVersion(String ver1, String ver2) {
ArrayList<String> tokList1 = tokenizeVersionString(ver1);
ArrayList<String> tokList2 = tokenizeVersionString(ver2);
- int maxTokens = tokList1.size() > tokList2.size() ? tokList1.size() : tokList2.size();
-
- for( int i = 0; i < maxTokens; i++ ) {
+ int maxTokens = tokList1.size() > tokList2.size() ? tokList1.size()
+ : tokList2.size();
+
+ for (int i = 0; i < maxTokens; i++) {
// check length
- if ( i == tokList1.size() ) {return -1;}
- if ( i == tokList2.size() ) {return 1;}
-
- String tok1 = tokList1.get(i);
+ if (i == tokList1.size()) {
+ return -1;
+ }
+ if (i == tokList2.size()) {
+ return 1;
+ }
+
+ String tok1 = tokList1.get(i);
String tok2 = tokList2.get(i);
-
+
int value1 = -1, value2 = -1;
try {
value1 = Integer.parseInt(tok1);
- }
- catch ( NumberFormatException e) {
+ } catch (NumberFormatException e) {
// do nothing
+ e.printStackTrace();
}
-
+
try {
value2 = Integer.parseInt(tok2);
- }
- catch ( NumberFormatException e) {
+ } catch (NumberFormatException e) {
// do nothing
+ e.printStackTrace();
}
-
- if ( value1 > value2 ) {
+
+ if (value1 > value2) {
return 1;
- }
- else if ( value1 < value2 ) {
+ } else if (value1 < value2) {
return -1;
- }
- else {
+ } else {
int result = tok1.compareTo(tok2);
- if ( result != 0 ) {
+ if (result != 0) {
return result;
}
}
}
-
+
return 0;
}
-
+
private static ArrayList<String> tokenizeVersionString(String ver) {
ArrayList<String> result = new ArrayList<String>();
final int NUM = 0;
final int ALPHA = 1;
final int NONALPHANUM = 2;
- int oldStatus=NONALPHANUM;
+ int oldStatus = NONALPHANUM;
String buf = "";
- for( int i = 0; i < ver.length(); i++ ) {
+ for (int i = 0; i < ver.length(); i++) {
char c = ver.charAt(i);
int newStatus;
- if ( c >= '0' && c <= '9' ) {
+ if (c >= '0' && c <= '9') {
newStatus = NUM;
- }
- else if ( (c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z') ) {
+ } else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
newStatus = ALPHA;
- }
- else {
+ } else {
newStatus = NONALPHANUM;
}
-
- if ( oldStatus != newStatus ) {
- if ( !buf.isEmpty() ) {
+
+ if (oldStatus != newStatus) {
+ if (!buf.isEmpty()) {
result.add(buf);
}
- if ( newStatus != NONALPHANUM ) {
+ if (newStatus != NONALPHANUM) {
buf = String.valueOf(c);
- }
- else {
+ } else {
buf = "";
}
oldStatus = newStatus;
- }
- else {
- if ( newStatus != NONALPHANUM ) {
+ } else {
+ if (newStatus != NONALPHANUM) {
buf += String.valueOf(c);
}
}
}
- if ( !buf.isEmpty() ) {
+ if (!buf.isEmpty()) {
result.add(buf);
}
-
+
return result;
}
-
+
static private PackageManagerOuputReceiver getNewOuputReceiver() {
ConsoleManager cm = new ConsoleManager("Platform Internal", true);
cm.clear();
- //MessageConsoleStream mcsError = cm.getMessageConsoleStream();
+ // MessageConsoleStream mcsError = cm.getMessageConsoleStream();
MessageConsoleStream mcs = cm.getMessageConsoleStream();
PackageManagerOuputReceiver rec = new PackageManagerOuputReceiver();
rec.setMessageConsoleStream(mcs);