comparison mxtool/mx.py @ 5853:767312416f6a

added support to mx for specifying library sources
author Doug Simon <doug.simon@oracle.com>
date Wed, 18 Jul 2012 12:17:38 +0200
parents b1dc8fbebb48
children 2c00c51357d8
comparison
equal deleted inserted replaced
5852:76191410c88d 5853:767312416f6a
84 be downloaded and saved in the location specified by 'path'. 84 be downloaded and saved in the location specified by 'path'.
85 85
86 optional 86 optional
87 If "true" then this library will be omitted from a class path 87 If "true" then this library will be omitted from a class path
88 if it doesn't exist on the file system and no URLs are specified. 88 if it doesn't exist on the file system and no URLs are specified.
89
90 sourcePath
91 The file system path for a jar file containing the library sources.
92
93 sourceUrls
94 A comma separated list of URLs from which the library source jar can
95 be downloaded and saved in the location specified by 'sourcePath'.
89 96
90 Project specification format: 97 Project specification format:
91 98
92 project@<name>@<prop>=<value> 99 project@<name>@<prop>=<value>
93 100
305 classes.append(pkg + '.' + basename) 312 classes.append(pkg + '.' + basename)
306 return classes 313 return classes
307 314
308 315
309 class Library(Dependency): 316 class Library(Dependency):
310 def __init__(self, suite, name, path, mustExist, urls): 317 def __init__(self, suite, name, path, mustExist, urls, sourcePath, sourceUrls):
311 Dependency.__init__(self, suite, name) 318 Dependency.__init__(self, suite, name)
312 self.path = path.replace('/', os.sep) 319 self.path = path.replace('/', os.sep)
313 self.urls = urls 320 self.urls = urls
314 self.mustExist = mustExist 321 self.mustExist = mustExist
322 self.sourcePath = sourcePath
323 self.sourceUrls = sourceUrls
315 324
316 def get_path(self, resolve): 325 def get_path(self, resolve):
317 path = self.path 326 path = self.path
318 if not isabs(path): 327 if not isabs(path):
319 path = join(self.suite.dir, path) 328 path = join(self.suite.dir, path)
320 if resolve and self.mustExist and not exists(path): 329 if resolve and self.mustExist and not exists(path):
321 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + " " + path; 330 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + ' ' + path;
322 print('Downloading ' + self.name + ' from ' + str(self.urls)) 331 print('Downloading ' + self.name + ' from ' + str(self.urls))
323 download(path, self.urls) 332 download(path, self.urls)
324 333 return path
334
335 def get_source_path(self, resolve):
336 path = self.sourcePath
337 if path is None:
338 return None
339 if not isabs(path):
340 path = join(self.suite.dir, path)
341 if resolve and len(self.sourceUrls) != 0 and not exists(path):
342 print('Downloading sources for ' + self.name + ' from ' + str(self.sourceUrls))
343 download(path, self.sourceUrls)
325 return path 344 return path
326 345
327 def append_to_classpath(self, cp, resolve): 346 def append_to_classpath(self, cp, resolve):
328 path = self.get_path(resolve) 347 path = self.get_path(resolve)
329 if exists(path) or not resolve: 348 if exists(path) or not resolve:
400 419
401 for name, attrs in libsMap.iteritems(): 420 for name, attrs in libsMap.iteritems():
402 path = attrs.pop('path') 421 path = attrs.pop('path')
403 mustExist = attrs.pop('optional', 'false') != 'true' 422 mustExist = attrs.pop('optional', 'false') != 'true'
404 urls = pop_list(attrs, 'urls') 423 urls = pop_list(attrs, 'urls')
405 l = Library(self, name, path, mustExist, urls) 424 sourcePath = attrs.pop('sourcePath', None)
425 sourceUrls = pop_list(attrs, 'sourceUrls')
426 l = Library(self, name, path, mustExist, urls, sourcePath, sourceUrls)
406 l.__dict__.update(attrs) 427 l.__dict__.update(attrs)
407 self.libs.append(l) 428 self.libs.append(l)
408 429
409 def _load_commands(self, mxDir): 430 def _load_commands(self, mxDir):
410 commands = join(mxDir, 'commands.py') 431 commands = join(mxDir, 'commands.py')
1204 built.add(p.name) 1225 built.add(p.name)
1205 continue 1226 continue
1206 else: 1227 else:
1207 if not args.java: 1228 if not args.java:
1208 continue 1229 continue
1230 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
1231 continue
1209 1232
1210 # skip building this Java project if its Java compliance level is "higher" than the configured JDK 1233 # skip building this Java project if its Java compliance level is "higher" than the configured JDK
1211 if javaCompliance < p.javaCompliance: 1234 if javaCompliance < p.javaCompliance:
1212 log('Excluding {0} from build (Java compliance level {1} required)'.format(p.name, p.javaCompliance)) 1235 log('Excluding {0} from build (Java compliance level {1} required)'.format(p.name, p.javaCompliance))
1213 continue 1236 continue
1690 out.element('classpathentry', {'kind' : 'src', 'path' : src}) 1713 out.element('classpathentry', {'kind' : 'src', 'path' : src})
1691 1714
1692 # Every Java program depends on the JRE 1715 # Every Java program depends on the JRE
1693 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'}) 1716 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'})
1694 1717
1718 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
1719 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.pde.core.requiredPlugins'})
1720
1695 for dep in p.all_deps([], True): 1721 for dep in p.all_deps([], True):
1696 if dep == p: 1722 if dep == p:
1697 continue; 1723 continue;
1698 1724
1699 if dep.isLibrary(): 1725 if dep.isLibrary():
1703 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + getattr(dep, 'eclipse.project')}) 1729 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + getattr(dep, 'eclipse.project')})
1704 else: 1730 else:
1705 path = dep.path 1731 path = dep.path
1706 if dep.mustExist: 1732 if dep.mustExist:
1707 dep.get_path(resolve=True) 1733 dep.get_path(resolve=True)
1708 if isabs(path): 1734 if not isabs(path):
1709 out.element('classpathentry', {'exported' : 'true', 'kind' : 'lib', 'path' : path})
1710 else:
1711 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse 1735 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse
1712 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's 1736 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's
1713 # safest to simply use absolute paths. 1737 # safest to simply use absolute paths.
1714 out.element('classpathentry', {'exported' : 'true', 'kind' : 'lib', 'path' : join(suite.dir, path)}) 1738 path = join(suite.dir, path)
1739
1740 attributes = {'exported' : 'true', 'kind' : 'lib', 'path' : path}
1741
1742 sourcePath = dep.get_source_path(resolve=True)
1743 if sourcePath is not None:
1744 attributes['sourcepath'] = sourcePath
1745 out.element('classpathentry', attributes)
1715 else: 1746 else:
1716 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name}) 1747 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name})
1717 1748
1718 out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')}) 1749 out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')})
1719 out.close('classpath') 1750 out.close('classpath')
1764 if exists(csConfig): 1795 if exists(csConfig):
1765 out.open('buildCommand') 1796 out.open('buildCommand')
1766 out.element('name', data='net.sf.eclipsecs.core.CheckstyleBuilder') 1797 out.element('name', data='net.sf.eclipsecs.core.CheckstyleBuilder')
1767 out.element('arguments', data='') 1798 out.element('arguments', data='')
1768 out.close('buildCommand') 1799 out.close('buildCommand')
1800 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
1801 for buildCommand in ['org.eclipse.pde.ManifestBuilder', 'org.eclipse.pde.SchemaBuilder']:
1802 out.open('buildCommand')
1803 out.element('name', data=buildCommand)
1804 out.element('arguments', data='')
1805 out.close('buildCommand')
1769 out.close('buildSpec') 1806 out.close('buildSpec')
1770 out.open('natures') 1807 out.open('natures')
1771 out.element('nature', data='org.eclipse.jdt.core.javanature') 1808 out.element('nature', data='org.eclipse.jdt.core.javanature')
1772 if exists(csConfig): 1809 if exists(csConfig):
1773 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature') 1810 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature')
1811 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
1812 out.element('nature', data='org.eclipse.pde.PluginNature')
1774 out.close('natures') 1813 out.close('natures')
1775 out.close('projectDescription') 1814 out.close('projectDescription')
1776 update_file(join(p.dir, '.project'), out.xml(indent='\t', newl='\n')) 1815 update_file(join(p.dir, '.project'), out.xml(indent='\t', newl='\n'))
1777 1816
1778 settingsDir = join(p.dir, ".settings") 1817 settingsDir = join(p.dir, ".settings")
1801 out.write(str(obj) + '\n') 1840 out.write(str(obj) + '\n')
1802 1841
1803 updated = False 1842 updated = False
1804 for p in projects(): 1843 for p in projects():
1805 if p.native: 1844 if p.native:
1845 continue
1846
1847 if exists(join(p.dir, 'plugin.xml')): # eclipse plugin project
1806 continue 1848 continue
1807 1849
1808 if not exists(join(p.dir, 'nbproject')): 1850 if not exists(join(p.dir, 'nbproject')):
1809 os.makedirs(join(p.dir, 'nbproject')) 1851 os.makedirs(join(p.dir, 'nbproject'))
1810 1852