001: /**
002: * $Id: PortalVersion.java,v 1.5 2007/01/26 03:48:33 portalbld Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.fabric.tasks;
014:
015: import java.io.File;
016: import java.io.FileNotFoundException;
017: import java.io.IOException;
018:
019: import java.util.logging.Level;
020: import java.util.logging.Logger;
021:
022: //PS Admin Common
023: import com.sun.portal.fabric.util.FileUtil;
024: import com.sun.portal.fabric.util.os.OSTasksFactory;
025: import com.sun.portal.fabric.util.os.OSTasks;
026:
027: import com.sun.portal.admin.common.PSMBeanException;
028: import com.sun.portal.admin.common.PSConfigConstants;
029: import com.sun.portal.admin.common.context.PSConfigContext;
030: import com.sun.portal.log.common.PortalLogger;
031:
032: import com.sun.portal.util.Platform;
033:
034: /**
035: * This class implements the psadmin version mbean operations.
036: */
037:
038: public class PortalVersion {
039: static final String fs = Platform.fs;
040: private PSConfigContext cc;
041: private OSTasks osTasks;
042: private static Logger logger = PortalLogger
043: .getLogger(PortalVersion.class);
044:
045: public PortalVersion(PSConfigContext cc) {
046: OSTasksFactory osTasksFactory = OSTasksFactory.getInstance();
047: this .cc = cc;
048: this .osTasks = osTasksFactory.getOSTasks(cc);
049: }
050:
051: public String getVersion() throws PSMBeanException {
052: String psBaseDir = cc.getPSBaseDir();
053: String psVersionPath = psBaseDir + fs + "lib" + fs
054: + "PSversion.properties";
055: File psVersionFile = new File(psVersionPath);
056: StringBuffer sb = new StringBuffer(256);
057:
058: if (psVersionFile.exists()) {
059: String build = FileUtil.findTextInFile(psVersionFile,
060: "build=");
061: String productName = FileUtil.findTextInFile(psVersionFile,
062: "productname=");
063: String productVersion = FileUtil.findTextInFile(
064: psVersionFile, "productversion=");
065: sb.append(build.substring(6)).append(" ").append(
066: productName.substring(12)).append(" ").append(
067: productVersion.substring(15));
068: } else {
069: Object tokens[] = { psVersionFile };
070: throw new PSMBeanException("error.psadmin.file.not.found",
071: tokens);
072: }
073: return sb.toString();
074: }
075:
076: public String getVersionFromJar(String jarFilePath)
077: throws PSMBeanException {
078: StringBuffer sb = new StringBuffer(256);
079: String versionFilePath = null;
080:
081: try {
082: versionFilePath = "META-INF" + fs + "MANIFEST.MF";
083: File versionFile = FileUtil.extractFileFromJar(jarFilePath,
084: versionFilePath, false);
085: if (versionFile.exists()) {
086: String build = FileUtil.findTextInFile(versionFile,
087: "Created-At:");
088: String productName = FileUtil.findTextInFile(
089: versionFile, "Product:");
090: String productVersion = FileUtil.findTextInFile(
091: versionFile, "Version:");
092: while (productVersion != null
093: && productVersion.length() >= 7
094: && !productVersion.substring(0, 7).equals(
095: "Version")) {
096: FileUtil.deleteLineInFile(versionFile,
097: productVersion.substring(0, 6));
098: productVersion = FileUtil.findTextInFile(
099: versionFile, "Version:");
100: }
101:
102: if (build != null && build.length() >= 12) {
103: sb.append(build.substring(12)).append(" ");
104: }
105: if (productName != null && build.length() >= 9) {
106: sb.append(productName.substring(9)).append(" ");
107: }
108: if (productVersion != null
109: && productVersion.length() >= 9) {
110: sb.append(productVersion.substring(9));
111: }
112: if (sb.toString().length() <= 0) {
113: Object tokens[] = { jarFilePath };
114: throw new PSMBeanException(
115: "admin.error.version.info.not.found",
116: tokens);
117: }
118:
119: } else {
120: Object tokens[] = { jarFilePath };
121: throw new PSMBeanException(
122: "admin.error.version.info.not.found", tokens);
123: }
124: } catch (FileNotFoundException fe) {
125: Object tokens[] = { versionFilePath };
126: logger.log(Level.SEVERE, "PSFB_CSPFT0285", fe);
127: throw new PSMBeanException(
128: "admin.error.version.file.not.found", tokens);
129: } catch (IOException ie) {
130: Object tokens[] = { jarFilePath };
131: logger.log(Level.SEVERE, "PSFB_CSPFT0285", ie);
132: throw new PSMBeanException(
133: "admin.error.version.info.not.found", tokens);
134: }
135: return sb.toString();
136: }
137:
138: public String getPatchInfo() throws PSMBeanException {
139: String patchInfo = osTasks.getPatchInfo();
140: if (patchInfo != null && patchInfo.length() != 0) {
141: return patchInfo;
142: }
143: throw new PSMBeanException("admin.error.patch.info.not.found");
144: }
145:
146: public String getPatchVerbose() throws PSMBeanException {
147: String patchInfo = osTasks.getPatchVerbose();
148: if (patchInfo != null && patchInfo.length() != 0) {
149: return patchInfo;
150: }
151: throw new PSMBeanException("admin.error.patch.info.not.found");
152: }
153:
154: }
|