comparison mxtool/mx.py @ 21937:3a292e8b9e51

replaced Service marker interface with non-standard META-INF directory names to differentiate JVMCI providers from standard service providers META-INF/services/ files for Options provider are now generated directly from files in META-INF/jvmci.options/
author Doug Simon <doug.simon@oracle.com>
date Fri, 12 Jun 2015 01:19:57 +0200
parents 518052de60d5
children 555f788b964b
comparison
equal deleted inserted replaced
21936:11f241f26c61 21937:3a292e8b9e51
179 179
180 with Archiver(self.path) as arc: 180 with Archiver(self.path) as arc:
181 with Archiver(None if unified else self.sourcesPath) as srcArcRaw: 181 with Archiver(None if unified else self.sourcesPath) as srcArcRaw:
182 srcArc = arc if unified else srcArcRaw 182 srcArc = arc if unified else srcArcRaw
183 services = {} 183 services = {}
184 jvmciServices = {}
184 def overwriteCheck(zf, arcname, source): 185 def overwriteCheck(zf, arcname, source):
185 if os.path.basename(arcname).startswith('.'): 186 if os.path.basename(arcname).startswith('.'):
186 logv('Excluding dotfile: ' + source) 187 logv('Excluding dotfile: ' + source)
187 return True 188 return True
188 if not hasattr(zf, '_provenance'): 189 if not hasattr(zf, '_provenance'):
218 logv('[' + self.path + ': adding library ' + l.name + ']') 219 logv('[' + self.path + ': adding library ' + l.name + ']')
219 lpath = l.get_path(resolve=True) 220 lpath = l.get_path(resolve=True)
220 libSourcePath = l.get_source_path(resolve=True) 221 libSourcePath = l.get_source_path(resolve=True)
221 if lpath: 222 if lpath:
222 with zipfile.ZipFile(lpath, 'r') as lp: 223 with zipfile.ZipFile(lpath, 'r') as lp:
223 for arcname in lp.namelist(): 224 entries = lp.namelist()
225 for arcname in entries:
224 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/': 226 if arcname.startswith('META-INF/services/') and not arcname == 'META-INF/services/':
225 service = arcname[len('META-INF/services/'):] 227 service = arcname[len('META-INF/services/'):]
226 assert '/' not in service 228 assert '/' not in service
227 services.setdefault(service, []).extend(lp.read(arcname).splitlines()) 229 services.setdefault(service, []).extend(lp.read(arcname).splitlines())
228 else: 230 else:
231 assert not arcname.startswith('META-INF/jvmci.services/'), 'did not expect to see jvmci.services in ' + lpath
232 assert not arcname.startswith('META-INF/jvmci.options/'), 'did not expect to see jvmci.options in ' + lpath
229 if not overwriteCheck(arc.zf, arcname, lpath + '!' + arcname): 233 if not overwriteCheck(arc.zf, arcname, lpath + '!' + arcname):
230 arc.zf.writestr(arcname, lp.read(arcname)) 234 arc.zf.writestr(arcname, lp.read(arcname))
231 if srcArc.zf and libSourcePath: 235 if srcArc.zf and libSourcePath:
232 with zipfile.ZipFile(libSourcePath, 'r') as lp: 236 with zipfile.ZipFile(libSourcePath, 'r') as lp:
233 for arcname in lp.namelist(): 237 for arcname in lp.namelist():
246 relpath = root[len(outputDir) + 1:] 250 relpath = root[len(outputDir) + 1:]
247 if relpath == join('META-INF', 'services'): 251 if relpath == join('META-INF', 'services'):
248 for service in files: 252 for service in files:
249 with open(join(root, service), 'r') as fp: 253 with open(join(root, service), 'r') as fp:
250 services.setdefault(service, []).extend([provider.strip() for provider in fp.readlines()]) 254 services.setdefault(service, []).extend([provider.strip() for provider in fp.readlines()])
251 elif relpath == join('META-INF', 'providers'): 255 elif relpath == join('META-INF', 'jvmci.services'):
256 for service in files:
257 with open(join(root, service), 'r') as fp:
258 jvmciServices.setdefault(service, []).extend([provider.strip() for provider in fp.readlines()])
259 elif relpath == join('META-INF', 'jvmci.providers'):
252 for provider in files: 260 for provider in files:
253 with open(join(root, provider), 'r') as fp: 261 with open(join(root, provider), 'r') as fp:
254 for service in fp: 262 for service in fp:
255 services.setdefault(service.strip(), []).append(provider) 263 jvmciServices.setdefault(service.strip(), []).append(provider)
256 else: 264 else:
265 if relpath == join('META-INF', 'jvmci.options'):
266 # Need to create service files for the providers of the
267 # com.oracle.jvmci.options.Options service created by
268 # com.oracle.jvmci.options.processor.OptionProcessor.
269 for optionsOwner in files:
270 provider = optionsOwner + '_Options'
271 providerClassfile = join(outputDir, provider.replace('.', os.sep) + '.class')
272 assert exists(providerClassfile), 'missing generated Options provider ' + providerClassfile
273 services.setdefault('com.oracle.jvmci.options.Options', []).append(provider)
257 for f in files: 274 for f in files:
258 arcname = join(relpath, f).replace(os.sep, '/') 275 arcname = join(relpath, f).replace(os.sep, '/')
259 if not overwriteCheck(arc.zf, arcname, join(root, f)): 276 if not overwriteCheck(arc.zf, arcname, join(root, f)):
260 arc.zf.write(join(root, f), arcname) 277 arc.zf.write(join(root, f), arcname)
261 if srcArc.zf: 278 if srcArc.zf:
272 srcArc.zf.write(join(root, f), arcname) 289 srcArc.zf.write(join(root, f), arcname)
273 290
274 for service, providers in services.iteritems(): 291 for service, providers in services.iteritems():
275 arcname = 'META-INF/services/' + service 292 arcname = 'META-INF/services/' + service
276 arc.zf.writestr(arcname, '\n'.join(providers)) 293 arc.zf.writestr(arcname, '\n'.join(providers))
294 for service, providers in jvmciServices.iteritems():
295 arcname = 'META-INF/jvmci.services/' + service
296 arc.zf.writestr(arcname, '\n'.join(providers))
277 297
278 self.notify_updated() 298 self.notify_updated()
279
280 299
281 def notify_updated(self): 300 def notify_updated(self):
282 for l in self.update_listeners: 301 for l in self.update_listeners:
283 l(self) 302 l(self)
284 303