OptionalPkgDependencypublic class OptionalPkgDependency extends Object This class resolves the dependencies between optional packages and also between
apps/stand-alone modules that depend on optional packages |
Fields Summary |
---|
private static Hashtable | optionalPackageStore | private static Set | extDirJars | private static Logger | logger |
Constructors Summary |
---|
public OptionalPkgDependency()
|
Methods Summary |
---|
public static java.lang.String | getExtDirFilesAsClasspath()Adds all the jar files in all of the ext dirs into a single string
in classpath format. Returns the empty string if there are no
jar files in any ext dirs.
StringBuffer classpath = new StringBuffer();
for(Iterator iter = extDirJars.iterator(); iter.hasNext();) {
String next = (String) iter.next();
if( classpath.length() > 0 ) {
classpath.append(File.pathSeparator);
}
classpath.append(next);
}
return classpath.toString();
| public static boolean | optionalPkgDependencyLogic(java.util.jar.Manifest manifest, java.lang.String archiveUri)
boolean dependencySatisfied = true;
String extensionList = null;
try {
extensionList = manifest.getMainAttributes().
getValue(Attributes.Name.EXTENSION_LIST);
logger.fine("extensionList..." + extensionList);
} catch (Exception npe) {
//ignore this exception
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"OptionalPkgDependency : exception occurred ==> " + npe.toString());
}
}
if (extensionList == null)
return dependencySatisfied;
StringTokenizer st =
new StringTokenizer(extensionList, " ");
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
String extName = manifest.getMainAttributes().
getValue(token + "-" + Attributes.Name.EXTENSION_NAME);
String specVersion = manifest.getMainAttributes().
getValue(token + "-" + Attributes.Name.SPECIFICATION_VERSION);
if (specVersion == null) {
specVersion = new String("");
}
if (!optionalPackageStore.containsKey(extName)) {
logger.log(Level.WARNING,
"enterprise.deployment.backend.optionalpkg.dependency.notexist",
new Object[] {extName, archiveUri});
dependencySatisfied = false;
} else if (!specVersion.equals("") &&
(optionalPackageStore.get(extName).toString().equals("")) ||
!specVersion.equals(optionalPackageStore.get(extName).toString())) {
logger.log(Level.WARNING,
"enterprise.deployment.backend.optionalpkg.dependency.notexist",
new Object[] {extName, archiveUri});
dependencySatisfied = false;
}
}
if (dependencySatisfied == true) {
logger.log(Level.INFO,
"enterprise.deployment.backend.optionalpkg.dependency.satisfied",
new Object[] {archiveUri});
}
return dependencySatisfied;
| public static void | satisfyOptionalPackageDependencies()check whether the optional packages have all their
internal dependencies resolved
String ext_dirStr = new String(
System.getProperty("java.ext.dirs"));
logger.fine("ext_dirStr..." + ext_dirStr);
Vector ext_dirs = new Vector();
StringTokenizer st = new StringTokenizer(ext_dirStr, File.pathSeparator);
while (st.hasMoreTokens()) {
String next = st.nextToken();
logger.log(Level.FINE,"string tokens..." + next);
ext_dirs.addElement(next);
}
/*
*Records the files that are legitimate JARs.
*/
ArrayList<File> validOptionalPackageFiles = new ArrayList<File>();
for (int v = 0; v < ext_dirs.size(); v++) {
File ext_dir = new File((String)ext_dirs.elementAt(v));
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,"extension dir..." + ext_dir);
}
File[] optionalPackages = ext_dir.listFiles();
if (optionalPackages != null) {
try {
for (int i = 0; i < optionalPackages.length; i++) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,"optional package..." + optionalPackages[i]);
}
/*
*Skip any candidate that does not end with .jar or is a
*directory.
*/
if (optionalPackages[i].isDirectory()) {
logger.log(Level.FINE,
"Skipping optional package processing on " +
optionalPackages[i].getAbsolutePath() +
"; it is a directory");
continue;
} else if ( ! optionalPackages[i].getName().toLowerCase().endsWith(".jar")) {
logger.log(Level.FINE,
"Skipping optional package processing on " +
optionalPackages[i].getAbsolutePath() +
"; it does not appear to be a JAR file based on its file type");
continue;
}
JarFile jarFile = null;
try {
jarFile = new JarFile(optionalPackages[i]);
Manifest manifest = jarFile.getManifest();
validOptionalPackageFiles.add(optionalPackages[i]);
extDirJars.add(optionalPackages[i].toString());
//Extension-Name of optional package
if (manifest!=null) {
String extNameOfOptionalPkg = manifest.getMainAttributes().
getValue(Attributes.Name.EXTENSION_NAME);
String specVersion = manifest.getMainAttributes().
getValue(Attributes.Name.SPECIFICATION_VERSION);
logger.fine("Extension " + optionalPackages[i].getAbsolutePath() +
", extNameOfOPtionalPkg..." + extNameOfOptionalPkg +
", specVersion..." + specVersion);
if (extNameOfOptionalPkg != null) {
if (specVersion == null) {
logger.log(Level.WARNING,
"enterprise.tools.deployment.backend.optionalpkg.dependency.specversion.null",
new Object[] {extNameOfOptionalPkg});
specVersion = new String("");
}
optionalPackageStore.put(extNameOfOptionalPkg,
specVersion);
}
}
} catch (Throwable thr) {
/*
*Log a warning, with stack trace if logging is FINE.
*/
String msg = logger.getResourceBundle().getString("enterprise.deployment.backend.optionalpkg.dependency.error");
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, MessageFormat.format(msg, optionalPackages[i].getAbsolutePath(), thr.getMessage()), thr);
} else {
logger.log(Level.INFO, MessageFormat.format(msg, optionalPackages[i].getAbsolutePath(), thr.getMessage()));
}
} finally {
if (jarFile != null) {
jarFile.close();
}
}
}
for (File file : validOptionalPackageFiles) {
JarFile jarFile = null;
try {
jarFile = new JarFile(file);
Manifest m = jarFile.getManifest();
if (m!=null) {
optionalPkgDependencyLogic(m, file.getAbsolutePath());
}
} catch (IOException ioe) {
logger.log(Level.WARNING,
"enterprise.deployment.backend.optionalpkg.invalid.zip", new Object[] {file.getAbsolutePath(), ioe.getMessage()});
}finally {
if (jarFile!=null)
jarFile.close();
}
}
} catch (IOException e) {
logger.log(Level.WARNING,
"enterprise.deployment.backend.optionalpkg.dependency.exception", new Object[] {e.getMessage()});
}
}
}
|
|