use of com.sun.pkg.client.Image in project Payara by payara.
the class UpdateCenterHandlers method getAuthority.
@Handler(id = "getAuthority", output = { @HandlerOutput(name = "result", type = String.class) })
public static void getAuthority(HandlerContext handlerCtx) {
Image image = getUpdateCenterImage();
handlerCtx.setOutputValue("result", (image == null) ? "" : image.getPreferredAuthorityName());
}
use of com.sun.pkg.client.Image in project Payara by payara.
the class UpdateCenterHandlers method getUpdateDisplayList.
// If countOnly is set to true, return a List that contains only one Integer that specifies the # of updates.
// This is for displaying in the masthead
// If countOnly is set to false, it will go through each package that has update available and return a list
// suitable for displaying as a table row.
private static List getUpdateDisplayList(Image image, boolean countOnly) {
List<Image.FmriState> installed = image.getInventory(null, false);
Map<String, Fmri> updateListMap = new HashMap();
List<String> nameList = new ArrayList();
for (Image.FmriState fs : installed) {
if (fs.upgradable) {
Fmri fmri = fs.fmri;
updateListMap.put(fmri.getName(), fmri);
nameList.add(fmri.getName());
}
}
List result = new ArrayList();
String[] pkgsName = nameList.toArray(new String[nameList.size()]);
try {
Image.ImagePlan ip = image.makeInstallPlan(pkgsName, "list");
Fmri[] proposed = ip.getProposedFmris();
if (countOnly) {
result.add(Integer.valueOf(proposed.length));
return result;
}
for (Fmri newPkg : proposed) {
Map oneRow = new HashMap();
try {
String name = newPkg.getName();
Fmri oldPkg = updateListMap.get(name);
Manifest manifest = image.getManifest(newPkg);
int changedSize = manifest.getPackageSize() - image.getManifest(oldPkg).getPackageSize();
oneRow.put("selected", false);
oneRow.put("fmri", newPkg);
oneRow.put("fmriStr", newPkg.toString());
putInfo(oneRow, "pkgName", name);
putInfo(oneRow, "newVersion", getPkgVersion(newPkg.getVersion()));
putInfo(oneRow, "version", getPkgVersion(oldPkg.getVersion()));
putInfo(oneRow, "category", getCategory(manifest));
putInfo(oneRow, "pkgSize", convertSizeForDispay(changedSize));
oneRow.put("size", Integer.valueOf(changedSize));
putInfo(oneRow, "auth", newPkg.getAuthority());
String tooltip = manifest.getAttribute(PKG_SUMMARY);
if (GuiUtil.isEmpty(tooltip))
tooltip = manifest.getAttribute(DESC);
putInfo(oneRow, "tooltip", tooltip);
result.add(oneRow);
} catch (Exception ex) {
ex.printStackTrace();
}
}
} catch (Exception ex) {
ex.printStackTrace();
if (countOnly) {
List tmpL = new ArrayList();
tmpL.add(Integer.valueOf(-1));
return tmpL;
}
}
GuiUtil.setSessionValue("_updateCountMsg", GuiUtil.getMessage(UpdateCenterHandlers.BUNDLE, "msg.updatesAvailable", new String[] { "" + result.size() }));
return result;
}
use of com.sun.pkg.client.Image in project Payara by payara.
the class UpdateCenterHandlers method setProxyInfo.
@Handler(id = "setProxyInfo", input = { @HandlerInput(name = "connection", type = String.class), @HandlerInput(name = "host", type = String.class), @HandlerInput(name = "port", type = String.class) })
public static void setProxyInfo(HandlerContext handlerCtx) {
String connection = (String) handlerCtx.getInputValue("connection");
String host = (String) handlerCtx.getInputValue("host");
String port = (String) handlerCtx.getInputValue("port");
try {
Image image = getUpdateCenterImage();
if (image == null) {
String ucDir = (String) GuiUtil.getSessionValue("topDir");
GuiUtil.handleError(handlerCtx, GuiUtil.getMessage(BUNDLE, "NoImage", new String[] { ucDir }));
return;
}
if (connection.equals("useProxy")) {
int portNo = Integer.parseInt(port);
SocketAddress address = new InetSocketAddress(host, portNo);
image.setProxy(new Proxy(Proxy.Type.HTTP, address));
String url = "http://" + host + ":" + portNo;
Properties prop = new Properties();
prop.setProperty("proxy.URL", url);
SystemInfo.initUpdateToolProps(prop);
} else {
image.setProxy(null);
Properties prop = new Properties();
prop.setProperty("proxy.URL", "");
SystemInfo.initUpdateToolProps(prop);
}
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
}
use of com.sun.pkg.client.Image in project Payara by payara.
the class UpdateCenterHandlers method getPkgDetailsInfo.
@Handler(id = "getPkgDetailsInfo", input = { @HandlerInput(name = "fmriStr", type = String.class, required = true), @HandlerInput(name = "auth", type = String.class, required = true) }, output = { @HandlerOutput(name = "details", type = java.util.Map.class) })
public static void getPkgDetailsInfo(HandlerContext handlerCtx) {
String fmriStr = (String) handlerCtx.getInputValue("fmriStr");
// Called by the intiPage and don't need to process. When we can use beforeCreate to do this, we can remove this check.
if (fmriStr == null) {
handlerCtx.setOutputValue("details", new HashMap());
return;
}
Fmri fmri = new Fmri(fmriStr);
Map details = new HashMap();
Image img = getUpdateCenterImage();
try {
details.put("pkgName", fmri.getName());
details.put("uid", fmri.toString());
details.put("version", getPkgVersion(fmri.getVersion()));
details.put("date", fmri.getVersion().getPublishDate());
details.put("auth", (String) handlerCtx.getInputValue("auth"));
details.put("url", fmri.getURLPath());
if (img != null) {
Manifest manifest = img.getManifest(fmri);
details.put("category", getCategory(manifest));
details.put("bytes", "" + manifest.getPackageSize());
details.put("pkgSize", getPkgSize(manifest));
// look for description in the following order:
// pkg.description, description_long, pkg.summary, description
// since description_long and description has been deprecated.
String desc = manifest.getAttribute(PKG_DESC);
if (GuiUtil.isEmpty(desc)) {
desc = manifest.getAttribute(DESC_LONG);
if (GuiUtil.isEmpty(desc)) {
desc = manifest.getAttribute(PKG_SUMMARY);
if (GuiUtil.isEmpty(desc))
desc = manifest.getAttribute(DESC);
}
}
details.put("desc", desc);
}
} catch (Exception ex) {
ex.printStackTrace();
}
handlerCtx.setOutputValue("details", details);
}
use of com.sun.pkg.client.Image in project Payara by payara.
the class UpdateCenterHandlers method getAddOnList.
private static List<Fmri> getAddOnList(Image image) {
List<String> installed = new ArrayList<String>();
for (Image.FmriState each : image.getInventory(null, false)) {
installed.add(each.fmri.getName());
}
String pAuth = image.getPreferredAuthorityName();
SortedMap<String, Fmri> addOnMap = new TreeMap();
for (Image.FmriState each : image.getInventory(null, true)) {
Fmri fmri = each.fmri;
// of this package is installed, then skip it.
if (each.installed || installed.contains(fmri.getName())) {
continue;
}
if (addOnMap.containsKey(fmri.getName())) {
// We have seen this package name already. See if this
// version should replace the saved version.
Fmri saved = addOnMap.get(fmri.getName());
if (supersedes(fmri, saved, pAuth)) {
addOnMap.put(fmri.getName(), fmri);
}
} else {
// We haven't seen this package name yet. Save fmri
addOnMap.put(fmri.getName(), fmri);
}
}
List<Fmri> result = new ArrayList();
for (Fmri f : addOnMap.values()) {
result.add(f);
}
return result;
}
Aggregations