Mercurial > hg > truffle
comparison mxtool/mx.py @ 8633:c4bca84d86d7
ensure generated Jar.launch files have the same format as that produced when refreshing in Eclipse
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 04 Apr 2013 15:05:48 +0200 |
parents | c7672a325faf |
children | 51a8368d0231 |
comparison
equal
deleted
inserted
replaced
8632:c50bfedfb704 | 8633:c4bca84d86d7 |
---|---|
661 return self | 661 return self |
662 | 662 |
663 def element(self, tag, attributes={}, data=None): | 663 def element(self, tag, attributes={}, data=None): |
664 return self.open(tag, attributes, data).close(tag) | 664 return self.open(tag, attributes, data).close(tag) |
665 | 665 |
666 def xml(self, indent='', newl='', escape=False): | 666 def xml(self, indent='', newl='', escape=False, standalone=None): |
667 assert self.current == self | 667 assert self.current == self |
668 result = self.toprettyxml(indent, newl, encoding="UTF-8") | 668 result = self.toprettyxml(indent, newl, encoding="UTF-8") |
669 if escape: | 669 if escape: |
670 entities = { '"': """, "'": "'", '\n': ' ' } | 670 entities = { '"': """, "'": "'", '\n': ' ' } |
671 result = xml.sax.saxutils.escape(result, entities) | 671 result = xml.sax.saxutils.escape(result, entities) |
672 if standalone is not None: | |
673 result = result.replace('encoding="UTF-8"?>', 'encoding="UTF-8" standalone="' + str(standalone) + '"?>') | |
672 return result | 674 return result |
673 | 675 |
674 def get_os(): | 676 def get_os(): |
675 """ | 677 """ |
676 Get a canonical form of sys.platform. | 678 Get a canonical form of sys.platform. |
1975 slm = XMLDoc() | 1977 slm = XMLDoc() |
1976 slm.open('sourceLookupDirector') | 1978 slm.open('sourceLookupDirector') |
1977 slm.open('sourceContainers', {'duplicates' : 'false'}) | 1979 slm.open('sourceContainers', {'duplicates' : 'false'}) |
1978 | 1980 |
1979 # Every Java program depends on the JRE | 1981 # Every Java program depends on the JRE |
1980 memento = XMLDoc().element('classpathContainer', {'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'}).xml() | 1982 memento = XMLDoc().element('classpathContainer', {'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'}).xml(standalone='no') |
1981 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) | 1983 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) |
1982 | 1984 |
1983 for dep in deps: | 1985 for dep in deps: |
1984 if dep.isLibrary(): | 1986 if dep.isLibrary(): |
1985 if hasattr(dep, 'eclipse.container'): | 1987 if hasattr(dep, 'eclipse.container'): |
1986 memento = XMLDoc().element('classpathContainer', {'path' : getattr(dep, 'eclipse.container')}).xml() | 1988 memento = XMLDoc().element('classpathContainer', {'path' : getattr(dep, 'eclipse.container')}).xml(standalone='no') |
1987 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) | 1989 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) |
1988 else: | 1990 else: |
1989 memento = XMLDoc().element('javaProject', {'name' : dep.name}).xml() | 1991 memento = XMLDoc().element('javaProject', {'name' : dep.name}).xml(standalone='no') |
1990 slm.element('container', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.javaProject'}) | 1992 slm.element('container', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.javaProject'}) |
1991 | 1993 |
1992 slm.close('sourceContainers') | 1994 slm.close('sourceContainers') |
1993 slm.close('sourceLookupDirector') | 1995 slm.close('sourceLookupDirector') |
1994 return slm | 1996 return slm |
2008 launch.element('mapEntry', {'key' : 'port', 'value' : port}) | 2010 launch.element('mapEntry', {'key' : 'port', 'value' : port}) |
2009 launch.close('mapAttribute') | 2011 launch.close('mapAttribute') |
2010 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) | 2012 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) |
2011 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_CONNECTOR_ID', 'value' : 'org.eclipse.jdt.launching.socketAttachConnector'}) | 2013 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_CONNECTOR_ID', 'value' : 'org.eclipse.jdt.launching.socketAttachConnector'}) |
2012 launch.close('launchConfiguration') | 2014 launch.close('launchConfiguration') |
2013 launch = launch.xml(newl='\n') % slm.xml(escape=True) | 2015 launch = launch.xml(newl='\n', standalone='no') % slm.xml(escape=True, standalone='no') |
2014 | 2016 |
2015 if name is None: | 2017 if name is None: |
2016 name = 'attach-' + hostname + '-' + port | 2018 name = 'attach-' + hostname + '-' + port |
2017 eclipseLaunches = join('mx', 'eclipse-launches') | 2019 eclipseLaunches = join('mx', 'eclipse-launches') |
2018 if not exists(eclipseLaunches): | 2020 if not exists(eclipseLaunches): |
2075 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.MAIN_TYPE', 'value' : mainClass}) | 2077 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.MAIN_TYPE', 'value' : mainClass}) |
2076 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROGRAM_ARGUMENTS', 'value' : ' '.join(appArgs)}) | 2078 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROGRAM_ARGUMENTS', 'value' : ' '.join(appArgs)}) |
2077 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) | 2079 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) |
2078 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_ARGUMENTS', 'value' : ' '.join(vmArgs)}) | 2080 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_ARGUMENTS', 'value' : ' '.join(vmArgs)}) |
2079 launch.close('launchConfiguration') | 2081 launch.close('launchConfiguration') |
2080 launch = launch.xml(newl='\n') % slm.xml(escape=True) | 2082 launch = launch.xml(newl='\n', standalone='no') % slm.xml(escape=True, standalone='no') |
2081 | 2083 |
2082 eclipseLaunches = join('mx', 'eclipse-launches') | 2084 eclipseLaunches = join('mx', 'eclipse-launches') |
2083 if not exists(eclipseLaunches): | 2085 if not exists(eclipseLaunches): |
2084 os.makedirs(eclipseLaunches) | 2086 os.makedirs(eclipseLaunches) |
2085 return update_file(join(eclipseLaunches, name + '.launch'), launch) | 2087 return update_file(join(eclipseLaunches, name + '.launch'), launch) |
2212 out.element('name', data=buildCommand) | 2214 out.element('name', data=buildCommand) |
2213 out.element('arguments', data='') | 2215 out.element('arguments', data='') |
2214 out.close('buildCommand') | 2216 out.close('buildCommand') |
2215 | 2217 |
2216 if _isAnnotationProcessorDependency(p): | 2218 if _isAnnotationProcessorDependency(p): |
2217 _genEclipseBuilder(out, p, 'Jar.launch', 'archive ' + p.name, refresh = False, async = False) | 2219 _genEclipseBuilder(out, p, 'Jar.launch', 'archive ' + p.name, refresh = False, async = False, xmlIndent='', xmlStandalone='no') |
2218 _genEclipseBuilder(out, p, 'Refresh.launch', '', refresh = True, async = True) | 2220 _genEclipseBuilder(out, p, 'Refresh.launch', '', refresh = True, async = True) |
2219 | 2221 |
2220 if projToDist.has_key(p.name): | 2222 if projToDist.has_key(p.name): |
2221 dist, distDeps = projToDist[p.name] | 2223 dist, distDeps = projToDist[p.name] |
2222 _genEclipseBuilder(out, p, 'Create' + dist.name + 'Dist.launch', 'archive @' + dist.name, refresh=False, async=True) | 2224 _genEclipseBuilder(out, p, 'Create' + dist.name + 'Dist.launch', 'archive @' + dist.name, refresh=False, async=True) |
2294 if p in deps: | 2296 if p in deps: |
2295 return True | 2297 return True |
2296 | 2298 |
2297 return False | 2299 return False |
2298 | 2300 |
2299 def _genEclipseBuilder(dotProjectDoc, p, name, mxCommand, refresh=True, async=False, logToConsole=False): | 2301 def _genEclipseBuilder(dotProjectDoc, p, name, mxCommand, refresh=True, async=False, logToConsole=False, xmlIndent='\t', xmlStandalone=None): |
2300 launchOut = XMLDoc(); | 2302 launchOut = XMLDoc(); |
2301 consoleOn = 'true' if logToConsole else 'false' | 2303 consoleOn = 'true' if logToConsole else 'false' |
2302 launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'}) | 2304 launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'}) |
2305 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.capture_output', 'value': consoleOn}) | |
2303 launchOut.open('mapAttribute', {'key' : 'org.eclipse.debug.core.environmentVariables'}) | 2306 launchOut.open('mapAttribute', {'key' : 'org.eclipse.debug.core.environmentVariables'}) |
2304 launchOut.element('mapEntry', {'key' : 'JAVA_HOME', 'value' : java().jdk}) | 2307 launchOut.element('mapEntry', {'key' : 'JAVA_HOME', 'value' : java().jdk}) |
2305 launchOut.close('mapAttribute') | 2308 launchOut.close('mapAttribute') |
2306 | 2309 |
2307 if refresh: | 2310 if refresh: |
2308 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_SCOPE', 'value': '${project}'}) | 2311 launchOut.element('stringAttribute', {'key' : 'org.eclipse.debug.core.ATTR_REFRESH_SCOPE', 'value': '${project}'}) |
2309 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON', 'value': consoleOn}) | 2312 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON', 'value': consoleOn}) |
2310 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.capture_output', 'value': consoleOn}) | 2313 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND', 'value': 'true' if async else 'false'}) |
2311 if async: | |
2312 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND', 'value': 'true'}) | |
2313 | 2314 |
2314 baseDir = dirname(dirname(os.path.abspath(__file__))) | 2315 baseDir = dirname(dirname(os.path.abspath(__file__))) |
2315 | 2316 |
2316 cmd = 'mx.sh' | 2317 cmd = 'mx.sh' |
2317 if get_os() == 'windows': | 2318 if get_os() == 'windows': |
2327 | 2328 |
2328 externalToolDir = join(p.dir, '.externalToolBuilders') | 2329 externalToolDir = join(p.dir, '.externalToolBuilders') |
2329 | 2330 |
2330 if not exists(externalToolDir): | 2331 if not exists(externalToolDir): |
2331 os.makedirs(externalToolDir) | 2332 os.makedirs(externalToolDir) |
2332 update_file(join(externalToolDir, name), launchOut.xml(indent='\t', newl='\n')) | 2333 update_file(join(externalToolDir, name), launchOut.xml(indent=xmlIndent, standalone=xmlStandalone, newl='\n')) |
2333 | 2334 |
2334 dotProjectDoc.open('buildCommand') | 2335 dotProjectDoc.open('buildCommand') |
2335 dotProjectDoc.element('name', data='org.eclipse.ui.externaltools.ExternalToolBuilder') | 2336 dotProjectDoc.element('name', data='org.eclipse.ui.externaltools.ExternalToolBuilder') |
2336 dotProjectDoc.element('triggers', data='auto,full,incremental,') | 2337 dotProjectDoc.element('triggers', data='auto,full,incremental,') |
2337 dotProjectDoc.open('arguments') | 2338 dotProjectDoc.open('arguments') |