def find_plugins(self, plugin_names): """Returns a map from plugin name to plugin jar.""" plugin_names = set(plugin_names) plugins = {} buildroot = get_buildroot() # plugin_jars is the universe of all possible plugins and their transitive deps. # Here we select the ones to actually use. for jar in self.plugin_jars(): with open_jar(jar, 'r') as jarfile: try: with closing(jarfile.open(_PLUGIN_INFO_FILE, 'r')) as plugin_info_file: plugin_info = ElementTree.parse(plugin_info_file).getroot() if plugin_info.tag != 'plugin': raise TaskError( 'File %s in %s is not a valid scalac plugin descriptor' % (_PLUGIN_INFO_FILE, jar)) name = plugin_info.find('name').text if name in plugin_names: if name in plugins: raise TaskError('Plugin %s defined in %s and in %s' % (name, plugins[name], jar)) # It's important to use relative paths, as the compiler flags get embedded in the zinc # analysis file, and we port those between systems via the artifact cache. plugins[name] = os.path.relpath(jar, buildroot) except KeyError: pass unresolved_plugins = plugin_names - set(plugins.keys()) if unresolved_plugins: raise TaskError('Could not find requested plugins: %s' % list(unresolved_plugins)) return plugins
def find_plugins(plugin_names, plugin_jars): """Returns a map from plugin name to plugin jar.""" plugin_names = set(plugin_names) plugins = {} # plugin_jars is the universe of all possible plugins and their transitive deps. # Here we select the ones to actually use. for jar in plugin_jars: with open_jar(jar, 'r') as jarfile: try: with closing(jarfile.open(_PLUGIN_INFO_FILE, 'r')) as plugin_info_file: plugin_info = ElementTree.parse(plugin_info_file).getroot() if plugin_info.tag != 'plugin': raise TaskError, 'File %s in %s is not a valid scalac plugin descriptor' % (_PLUGIN_INFO_FILE, jar) name = plugin_info.find('name').text if name in plugin_names: if name in plugins: raise TaskError, 'Plugin %s defined in %s and in %s' % (name, plugins[name], jar) plugins[name] = jar except KeyError: pass unresolved_plugins = plugin_names - set(plugins.keys()) if len(unresolved_plugins) > 0: raise TaskError, 'Could not find requested plugins: %s' % list(unresolved_plugins) return plugins
def find_plugins(plugin_names, plugin_jars): """Returns a map from plugin name to plugin jar.""" plugin_names = set(plugin_names) plugins = {} # plugin_jars is the universe of all possible plugins and their transitive deps. # Here we select the ones to actually use. for jar in plugin_jars: with open_jar(jar, 'r') as jarfile: try: with closing(jarfile.open(_PLUGIN_INFO_FILE, 'r')) as plugin_info_file: plugin_info = ElementTree.parse( plugin_info_file).getroot() if plugin_info.tag != 'plugin': raise TaskError, 'File %s in %s is not a valid scalac plugin descriptor' % ( _PLUGIN_INFO_FILE, jar) name = plugin_info.find('name').text if name in plugin_names: if name in plugins: raise TaskError, 'Plugin %s defined in %s and in %s' % ( name, plugins[name], jar) plugins[name] = jar except KeyError: pass unresolved_plugins = plugin_names - set(plugins.keys()) if len(unresolved_plugins) > 0: raise TaskError, 'Could not find requested plugins: %s' % list( unresolved_plugins) return plugins
def create_binary(self, binary): import platform safe_mkdir(self.outdir) jarmap = self.context.products.get('jars') binary_jarname = '%s.jar' % binary.basename binaryjarpath = os.path.join(self.outdir, binary_jarname) self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot())) with open_jar(binaryjarpath, 'w', compression=self.compression) as jar: def add_jars(target): generated = jarmap.get(target) if generated: for basedir, jars in generated.items(): for internaljar in jars: self.dump(os.path.join(basedir, internaljar), jar) binary.walk(add_jars, is_internal) if self.deployjar: for basedir, externaljar in self.list_jar_dependencies(binary): self.dump(os.path.join(basedir, externaljar), jar) manifest = Manifest() manifest.addentry(Manifest.MANIFEST_VERSION, '1.0') manifest.addentry( Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version()) ) main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***' manifest.addentry(Manifest.MAIN_CLASS, main) jar.writestr(Manifest.PATH, manifest.contents()) jarmap.add(binary, self.outdir, [binary_jarname])
def create_jar(self, target, path): existing = self._jars.setdefault(path, target) if target != existing: raise TaskError('Duplicate name: target %s tried to write %s already mapped to target %s' % ( target, path, existing )) self._jars[path] = target with open_jar(path, 'w', compression=self.compression) as jar: yield jar
def dump(self, jarpath, jarfile): self.context.log.debug(' dumping %s' % jarpath) with temporary_dir() as tmpdir: with open_jar(jarpath) as sourcejar: BinaryCreate.safe_extract(sourcejar, tmpdir) for root, dirs, files in os.walk(tmpdir): for file in files: path = os.path.join(root, file) relpath = os.path.relpath(path, tmpdir) if Manifest.PATH != relpath: jarfile.write(path, relpath)
def create_binary(self, binary): import platform safe_mkdir(self.outdir) jarmap = self.context.products.get('jars') binary_jarname = '%s.jar' % binary.basename binaryjarpath = os.path.join(self.outdir, binary_jarname) self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot())) with open_jar(binaryjarpath, 'w', compression=self.compression) as jar: def add_jars(target): generated = jarmap.get(target) if generated: for basedir, jars in generated.items(): for internaljar in jars: self.dump(os.path.join(basedir, internaljar), jar) binary.walk(add_jars, is_internal) if self.deployjar: for basedir, externaljar in self.list_jar_dependencies(binary): self.dump(os.path.join(basedir, externaljar), jar) manifest = Manifest() manifest.addentry(Manifest.MANIFEST_VERSION, '1.0') manifest.addentry( Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version())) main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***' manifest.addentry(Manifest.MAIN_CLASS, main) jar.writestr(Manifest.PATH, manifest.contents()) jarmap.add(binary, self.outdir, [binary_jarname])
def list_jar(self, path): with open_jar(path, 'r') as jar: return jar.namelist()
def create_jar(self, path): with open_jar(path, 'w', compression=self.compression) as jar: yield jar