def _get_jvm_connector_jar(self):
     for jar_file in self._get_jars_from_classpath():
         if not os.path.exists(jar_file):
             continue
         try:
             manifest = JarFile(jar_file).getManifest()
             if not manifest:
                 continue
             main_attributes = manifest.getMainAttributes()
             premain_class = main_attributes.getValue('Premain-Class')
         except (ZipException, IOException, FileNotFoundException):
             continue
         if premain_class == 'org.robotframework.remoteapplications.agent.RmiServiceAgent':
             print "*TRACE* Found jvm_connector jar '%s'" % jar_file
             return os.path.abspath(jar_file)
     raise RuntimeError("Could not find remoteapplications jarfile from CLASSPATH")
    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
Example #3
0
    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 _get_jvm_connector_jar(self):
     for jar_file in self._get_jars_from_classpath():
         if not os.path.exists(jar_file):
             continue
         try:
             manifest = JarFile(jar_file).getManifest()
             if not manifest:
                 continue
             main_attributes = manifest.getMainAttributes()
             premain_class = main_attributes.getValue('Premain-Class')
         except (ZipException, IOException, FileNotFoundException):
             continue
         if premain_class == 'org.robotframework.jvmconnector.agent.RmiServiceAgent':
             print "*TRACE* Found jvm_connector jar '%s'" % jar_file
             return jar_file
     raise RuntimeError(
         "Could not find jvmconnector jarfile from CLASSPATH")
Example #5
0
  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()
Example #6
0
 def extract_tools_data_from_jar_files(self):
     """Create tools directories from JAR files with tools data
        Read directories from tools/data and create jar files in tools/jar
     """
     jarDir = File(self.jarDir)
     for jarFileName in jarDir.list():
         toolDir = File.separator.join([self.toolsDir, jarFileName[:-4]])
         self.delete_old_tool_directory(File(toolDir))
         jar = JarFile(File(self.jarDir, jarFileName))
         for entry in jar.entries():
             f = File(File.separator.join([self.toolsDir, entry.getName()]))
             if entry.isDirectory():
                 f.mkdir()
                 continue
             inputStream = jar.getInputStream(entry)
             fos = FileOutputStream(f)
             while inputStream.available() > 0:
                 fos.write(inputStream.read())
             fos.close()
             inputStream.close()
Example #7
0
 def extract_tools_data_from_jar_files(self):
     """Create tools directories from JAR files with tools data
        Read directories from tools/data and create jar files in tools/jar
     """
     jarDir = File(self.jarDir)
     for jarFileName in jarDir.list():
         toolDir = File.separator.join([self.toolsDir, jarFileName[:-4]])
         self.delete_old_tool_directory(File(toolDir))
         jar = JarFile(File(self.jarDir, jarFileName))
         for entry in jar.entries():
             f = File(File.separator.join([self.toolsDir, entry.getName()]))
             if entry.isDirectory():
                 f.mkdir()
                 continue
             inputStream = jar.getInputStream(entry)
             fos = FileOutputStream(f)
             while inputStream.available() > 0:
                 fos.write(inputStream.read())
             fos.close()
             inputStream.close()
Example #8
0
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
Example #9
0
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
Example #10
0
# JAR info tool
# priting out Manifest File informatin
# Kota Miura ([email protected])
# 20120417

from java.util.jar import JarFile
#from java.util.jar import Manifest
def printClasses(jf):
	for e in jf.entries():
		print e.getName()

def printManifest(jf):
	mf = jf.getManifest()
	if mf is not None:
		mainatt = mf.getMainAttributes()
		keys = mainatt.keySet()
		for i in keys:
			print i, mainatt.getValue(i)
	else:
		print 'pity, No Manifest File found!'

# main
filepath = 'C:\\ImageJ2\\plugins\\CLI_.jar'
filepath = 'C:\\ImageJ2\\plugins\\AutoThresholdAdjuster3D_.jar'
filepath = 'D:\\gitrepo\\CorrectBleach\\CorrectBleach_.jar'
jf = JarFile(filepath)
printManifest(jf)
jf.close()