def __get_manifest(self, source_path, from_archive): """ Returns the manifest object for the specified path. The source path may be a jar, or an exploded path. :param source_path: the source path to be checked :param from_archive: if True, use the manifest from the archive, otherwise from the file system :return: the manifest, or None if it is not present :raises: IOException: if there are problems reading an existing manifest """ manifest = None if string_utils.is_empty(source_path): return manifest source_path = self.model_context.replace_token_string(source_path) if from_archive and deployer_utils.is_path_into_archive(source_path): return self.archive_helper.get_manifest(source_path) else: if not os.path.isabs(source_path): # if this was in archive, it has been expanded under domain home. # or it may be a relative file intentionally placed under domain home. source_file = File(File(self.model_context.get_domain_home()), source_path) else: source_file = File(source_path) if source_file.isDirectory(): # read the manifest directly from the file system manifest_file = File(source_file, MANIFEST_NAME) if manifest_file.exists(): stream = None try: stream = FileInputStream(manifest_file) manifest = Manifest(stream) finally: if stream is not None: try: stream.close() except IOException: # nothing to report pass else: # read the manifest from the deployable ear/jar/war on the file system archive = JarFile(source_file.getAbsolutePath()) manifest = archive.getManifest() return manifest
def addJarFile(self, jarFile): __doc__ = """if you want to add a .jar file with a MANIFEST, add it first""" jarJarFile = JarFile(jarFile) self.addManifest(jarJarFile.getManifest()) jarJarFile.close() jarInputStream = JarInputStream(FileInputStream(jarFile)) jarEntry = jarInputStream.getNextJarEntry() while jarEntry: self.getJarOutputStream().putNextEntry(jarEntry) buffer = jarray.zeros(self._bufsize, 'b') read = jarInputStream.read(buffer) while read <> -1: self.getJarOutputStream().write(buffer, 0, read) read = jarInputStream.read(buffer) self.getJarOutputStream().closeEntry() jarEntry = jarInputStream.getNextJarEntry()
def getPluginInfo(jarFilename): if not (os.path.isfile(jarFilename) and jarFilename.endswith(".jar")): raise InvalidPluginError("JES plugins must be .jar files.") jar = JarFile(jarFilename) manifest = jar.getManifest() if manifest is None: raise InvalidPluginError("JES plugins need to have a JAR manifest " "indicating that they are for JES.") attrs = manifest.mainAttributes for attr in REQUIRED_ATTRIBUTES: if attrs.getValue(attr) is None: raise InvalidPluginError("JES plugins need to define a %s " "in their JAR manifest." % attr) entry = jar.getEntry(".JESDescription.txt") if entry is None: raise InvalidPluginError( "JES plugins need to include a description file.") inputStream = jar.getInputStream(entry) scanner = Scanner(inputStream).useDelimiter("\\A") description = scanner.next() if scanner.hasNext( ) else "(No description given.)" inputStream.close() info = { 'filename': jarFilename, 'basename': os.path.basename(jarFilename), 'dirname': os.path.dirname(jarFilename), 'title': attrs.getValue("JES-Plugin-Title"), 'version': attrs.getValue("JES-Plugin-Version"), 'description': description } info['display'] = "%s %s (%s)" % (info['title'], info['version'], info['basename']) info['longDescription'] = info['display'] + '\n' + description jar.close() return info
def getPluginInfo(jarFilename): if not (os.path.isfile(jarFilename) and jarFilename.endswith(".jar")): raise InvalidPluginError("JES plugins must be .jar files.") jar = JarFile(jarFilename) manifest = jar.getManifest() if manifest is None: raise InvalidPluginError("JES plugins need to have a JAR manifest " "indicating that they are for JES.") attrs = manifest.mainAttributes for attr in REQUIRED_ATTRIBUTES: if attrs.getValue(attr) is None: raise InvalidPluginError("JES plugins need to define a %s " "in their JAR manifest." % attr) entry = jar.getEntry(".JESDescription.txt") if entry is None: raise InvalidPluginError("JES plugins need to include a description file.") inputStream = jar.getInputStream(entry) scanner = Scanner(inputStream).useDelimiter("\\A") description = scanner.next() if scanner.hasNext() else "(No description given.)" inputStream.close() info = { 'filename': jarFilename, 'basename': os.path.basename(jarFilename), 'dirname': os.path.dirname(jarFilename), 'title': attrs.getValue("JES-Plugin-Title"), 'version': attrs.getValue("JES-Plugin-Version"), 'description': description } info['display'] = "%s %s (%s)" % (info['title'], info['version'], info['basename']) info['longDescription'] = info['display'] + '\n' + description jar.close() return info