Mercurial > hg > truffle
comparison mxtool/mx.py @ 5198:887b45f6aa02
improved name of Eclipse launch file created for jar applications
converted IDE configuration generation to use XML class
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 06 Apr 2012 17:24:47 +0200 |
parents | a6eceb5efb0e |
children | 70777e50f1e6 |
comparison
equal
deleted
inserted
replaced
5197:e91f0761c56d | 5198:887b45f6aa02 |
---|---|
399 existing = _libs.get(l.name) | 399 existing = _libs.get(l.name) |
400 if existing is not None: | 400 if existing is not None: |
401 abort('cannot redefine library ' + l.name) | 401 abort('cannot redefine library ' + l.name) |
402 _libs[l.name] = l | 402 _libs[l.name] = l |
403 | 403 |
404 | |
404 class XML(xml.dom.minidom.Document): | 405 class XML(xml.dom.minidom.Document): |
405 | 406 |
406 def __init__(self): | 407 def __init__(self): |
407 xml.dom.minidom.Document.__init__(self) | 408 xml.dom.minidom.Document.__init__(self) |
408 self.current = self | 409 self.current = self |
409 | 410 self.padTextNodeWithoutSiblings = False |
410 def open(self, tag, attributes={}): | 411 |
412 def open(self, tag, attributes={}, data=None): | |
411 element = self.createElement(tag) | 413 element = self.createElement(tag) |
412 for key, value in attributes.items(): | 414 for key, value in attributes.items(): |
413 element.setAttribute(key, value) | 415 element.setAttribute(key, value) |
414 self.current.appendChild(element) | 416 self.current.appendChild(element) |
415 self.current = element | 417 self.current = element |
418 if data is not None: | |
419 element.appendChild(self.createTextNode(data)) | |
416 return self | 420 return self |
417 | 421 |
418 def close(self): | 422 def close(self, tag): |
419 assert self.current != self | 423 assert self.current != self |
424 assert tag == self.current.tagName, str(tag) + ' != ' + self.current.tagName | |
420 self.current = self.current.parentNode | 425 self.current = self.current.parentNode |
421 return self | 426 return self |
422 | 427 |
423 def element(self, tag, attributes={}): | 428 def element(self, tag, attributes={}, data=None): |
424 return self.open(tag, attributes).close() | 429 return self.open(tag, attributes, data).close(tag) |
425 | 430 |
426 def xml(self, indent='', newl='', escape=False): | 431 def xml(self, indent='', newl='', escape=False): |
427 assert self.current == self | 432 assert self.current == self |
428 result = self.toprettyxml(indent, newl, encoding="UTF-8") | 433 result = self.toprettyxml(indent, newl, encoding="UTF-8") |
429 if escape: | 434 if escape: |
430 entities = { '"': """, "'": "'", '\n': ' ' } | 435 entities = { '"': """, "'": "'", '\n': ' ' } |
431 result = xml.sax.saxutils.escape(result, entities) | 436 result = xml.sax.saxutils.escape(result, entities) |
432 return result | 437 return result |
433 | 438 |
439 @staticmethod | |
440 def _Element_writexml(self, writer, indent="", addindent="", newl=""): | |
441 # Monkey patch: if the only child of an Element node is a Text node, then the | |
442 # text is printed without any indentation or new line padding | |
443 writer.write(indent+"<" + self.tagName) | |
444 | |
445 attrs = self._get_attributes() | |
446 a_names = attrs.keys() | |
447 a_names.sort() | |
448 | |
449 for a_name in a_names: | |
450 writer.write(" %s=\"" % a_name) | |
451 xml.dom.minidom._write_data(writer, attrs[a_name].value) | |
452 writer.write("\"") | |
453 if self.childNodes: | |
454 if not self.ownerDocument.padTextNodeWithoutSiblings and len(self.childNodes) == 1 and isinstance(self.childNodes[0], xml.dom.minidom.Text): | |
455 writer.write(">") | |
456 self.childNodes[0].writexml(writer) | |
457 writer.write("</%s>%s" % (self.tagName,newl)) | |
458 else: | |
459 writer.write(">%s"%(newl)) | |
460 for node in self.childNodes: | |
461 node.writexml(writer,indent+addindent,addindent,newl) | |
462 writer.write("%s</%s>%s" % (indent,self.tagName,newl)) | |
463 else: | |
464 writer.write("/>%s"%(newl)) | |
465 | |
466 xml.dom.minidom.Element.writexml = XML._Element_writexml | |
467 | |
434 def get_os(): | 468 def get_os(): |
435 """ | 469 """ |
436 Get a canonical form of sys.platform. | 470 Get a canonical form of sys.platform. |
437 """ | 471 """ |
438 if sys.platform.startswith('darwin'): | 472 if sys.platform.startswith('darwin'): |
1402 for p in projects(): | 1436 for p in projects(): |
1403 for dep in p.canonical_deps(): | 1437 for dep in p.canonical_deps(): |
1404 print '"' + p.name + '"->"' + dep + '"' | 1438 print '"' + p.name + '"->"' + dep + '"' |
1405 print '}' | 1439 print '}' |
1406 | 1440 |
1407 def make_eclipse_launch(args, jre, name=None, deps=[]): | 1441 |
1408 """ | 1442 def _source_locator_memento(deps): |
1409 Creates an Eclipse launch configuration file. | 1443 slm = XML() |
1444 slm.open('sourceLookupDirector') | |
1445 slm.open('sourceContainers', {'duplicates' : 'false'}) | |
1446 | |
1447 for dep in deps: | |
1448 if dep.isLibrary(): | |
1449 if hasattr(dep, 'eclipse.container'): | |
1450 memento = XML().element('classpathContainer', {'path' : getattr(dep, 'eclipse.container')}).xml() | |
1451 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) | |
1452 else: | |
1453 memento = XML().element('javaProject', {'name' : dep.name}).xml() | |
1454 slm.element('container', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.javaProject'}) | |
1455 | |
1456 slm.close('sourceContainers') | |
1457 slm.close('sourceLookupDirector') | |
1458 return slm | |
1459 | |
1460 def make_eclipse_attach(hostname, port, name=None, deps=[]): | |
1461 """ | |
1462 Creates an Eclipse launch configuration file for attaching to a Java process. | |
1463 """ | |
1464 slm = _source_locator_memento(deps) | |
1465 launch = XML() | |
1466 launch.open('launchConfiguration', {'type' : 'org.eclipse.jdt.launching.remoteJavaApplication'}) | |
1467 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_id', 'value' : 'org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector'}) | |
1468 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_memento', 'value' : '%s'}) | |
1469 launch.element('booleanAttribute', {'key' : 'org.eclipse.jdt.launching.ALLOW_TERMINATE', 'value' : 'true'}) | |
1470 launch.open('mapAttribute', {'key' : 'org.eclipse.jdt.launching.CONNECT_MAP'}) | |
1471 launch.element('mapEntry', {'key' : 'hostname', 'value' : hostname}) | |
1472 launch.element('mapEntry', {'key' : 'port', 'value' : port}) | |
1473 launch.close('mapAttribute') | |
1474 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) | |
1475 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_CONNECTOR_ID', 'value' : 'org.eclipse.jdt.launching.socketAttachConnector'}) | |
1476 launch.close('launchConfiguration') | |
1477 launch = launch.xml(newl='\n') % slm.xml(escape=True) | |
1478 | |
1479 if name is None: | |
1480 name = 'attach-' + hostname + '-' + port | |
1481 eclipseLaunches = join('mx', 'eclipse-launches') | |
1482 if not exists(eclipseLaunches): | |
1483 os.makedirs(eclipseLaunches) | |
1484 return update_file(join(eclipseLaunches, name + '.launch'), launch) | |
1485 | |
1486 def make_eclipse_launch(javaArgs, jre, name=None, deps=[]): | |
1487 """ | |
1488 Creates an Eclipse launch configuration file for running/debugging a Java command. | |
1410 """ | 1489 """ |
1411 mainClass = None | 1490 mainClass = None |
1412 vmArgs = [] | 1491 vmArgs = [] |
1413 appArgs = [] | 1492 appArgs = [] |
1414 cp = None | 1493 cp = None |
1415 argsCopy = list(reversed(args)) | 1494 argsCopy = list(reversed(javaArgs)) |
1416 while len(argsCopy) != 0: | 1495 while len(argsCopy) != 0: |
1417 a = argsCopy.pop() | 1496 a = argsCopy.pop() |
1418 if a == '-jar': | 1497 if a == '-jar': |
1419 mainClass = '-jar' | 1498 mainClass = '-jar' |
1420 appArgs = list(reversed(argsCopy)) | 1499 appArgs = list(reversed(argsCopy)) |
1430 mainClass = a | 1509 mainClass = a |
1431 appArgs = list(reversed(argsCopy)) | 1510 appArgs = list(reversed(argsCopy)) |
1432 break | 1511 break |
1433 | 1512 |
1434 if mainClass is None: | 1513 if mainClass is None: |
1435 log('Cannot create Eclipse launch configuration without main class') | 1514 log('Cannot create Eclipse launch configuration without main class or jar file: java ' + ' '.join(javaArgs)) |
1436 return False | 1515 return False |
1437 | 1516 |
1438 if name is None: | 1517 if name is None: |
1439 if mainClass == '-jar': | 1518 if mainClass == '-jar': |
1440 name = basename(appArgs[0]) | 1519 name = basename(appArgs[0]) |
1520 if len(appArgs) > 1 and not appArgs[1].startswith('-'): | |
1521 name = name + '_' + appArgs[1] | |
1441 else: | 1522 else: |
1442 name = mainClass | 1523 name = mainClass |
1443 name = time.strftime('%Y-%m-%d-%H%M%S_' + name) | 1524 name = time.strftime('%Y-%m-%d-%H%M%S_' + name) |
1444 | |
1445 slm = XML() | |
1446 slm.open('sourceLookupDirector') | |
1447 slm.open('sourceContainers', {'duplicates' : 'false'}) | |
1448 | 1525 |
1449 if cp is not None: | 1526 if cp is not None: |
1450 for e in cp.split(os.pathsep): | 1527 for e in cp.split(os.pathsep): |
1451 for s in suites(): | 1528 for s in suites(): |
1452 deps += [p for p in s.projects if e == p.output_dir()] | 1529 deps += [p for p in s.projects if e == p.output_dir()] |
1453 deps += [l for l in s.libs if e == l.get_path(False)] | 1530 deps += [l for l in s.libs if e == l.get_path(False)] |
1454 | 1531 |
1455 for dep in deps: | 1532 slm = _source_locator_memento(deps) |
1456 if dep.isLibrary(): | 1533 |
1457 if hasattr(dep, 'eclipse.container'): | |
1458 memento = XML().element('classpathContainer', {'path' : getattr(dep, 'eclipse.container')}).xml() | |
1459 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'}) | |
1460 else: | |
1461 memento = XML().element('javaProject', {'name' : dep.name}).xml() | |
1462 slm.element('container', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.javaProject'}) | |
1463 | |
1464 slm.close() | |
1465 slm.close() | |
1466 launch = XML() | 1534 launch = XML() |
1467 launch.open('launchConfiguration', {'type' : 'org.eclipse.jdt.launching.localJavaApplication'}) | 1535 launch.open('launchConfiguration', {'type' : 'org.eclipse.jdt.launching.localJavaApplication'}) |
1468 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_id', 'value' : 'org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector'}) | 1536 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_id', 'value' : 'org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector'}) |
1469 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_memento', 'value' : '%s'}) | 1537 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_memento', 'value' : '%s'}) |
1470 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.JRE_CONTAINER', 'value' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jre}) | 1538 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.JRE_CONTAINER', 'value' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jre}) |
1471 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.MAIN_TYPE', 'value' : mainClass}) | 1539 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.MAIN_TYPE', 'value' : mainClass}) |
1472 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROGRAM_ARGUMENTS', 'value' : ' '.join(appArgs)}) | 1540 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROGRAM_ARGUMENTS', 'value' : ' '.join(appArgs)}) |
1473 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) | 1541 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''}) |
1474 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_ARGUMENTS', 'value' : ' '.join(vmArgs)}) | 1542 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_ARGUMENTS', 'value' : ' '.join(vmArgs)}) |
1475 launch.close() | 1543 launch.close('launchConfiguration') |
1476 launch = launch.xml(newl='\n') % slm.xml(escape=True) | 1544 launch = launch.xml(newl='\n') % slm.xml(escape=True) |
1477 | 1545 |
1478 eclipseLaunches = join('mx', 'eclipse-launches') | 1546 eclipseLaunches = join('mx', 'eclipse-launches') |
1479 if not exists(eclipseLaunches): | 1547 if not exists(eclipseLaunches): |
1480 os.makedirs(eclipseLaunches) | 1548 os.makedirs(eclipseLaunches) |
1483 def eclipseinit(args, suite=None): | 1551 def eclipseinit(args, suite=None): |
1484 """(re)generate Eclipse project configurations""" | 1552 """(re)generate Eclipse project configurations""" |
1485 | 1553 |
1486 if suite is None: | 1554 if suite is None: |
1487 suite = _mainSuite | 1555 suite = _mainSuite |
1488 | |
1489 def println(out, obj): | |
1490 out.write(str(obj) + '\n') | |
1491 | |
1492 source_locator_memento = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<sourceLookupDirector><sourceContainers duplicates="false">' | |
1493 entities = { '"': """, "'": "'", '\n': ' ' } | |
1494 | |
1495 sml = XML() | |
1496 | 1556 |
1497 for p in projects(): | 1557 for p in projects(): |
1498 if p.native: | 1558 if p.native: |
1499 continue | 1559 continue |
1500 | 1560 |
1501 if not exists(p.dir): | 1561 if not exists(p.dir): |
1502 os.makedirs(p.dir) | 1562 os.makedirs(p.dir) |
1503 | 1563 |
1504 out = StringIO.StringIO() | 1564 out = XML() |
1505 | 1565 out.open('classpath') |
1506 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 1566 |
1507 println(out, '<classpath>') | |
1508 for src in p.srcDirs: | 1567 for src in p.srcDirs: |
1509 srcDir = join(p.dir, src) | 1568 srcDir = join(p.dir, src) |
1510 if not exists(srcDir): | 1569 if not exists(srcDir): |
1511 os.mkdir(srcDir) | 1570 os.mkdir(srcDir) |
1512 println(out, '\t<classpathentry kind="src" path="' + src + '"/>') | 1571 out.element('classpathentry', {'kind' : 'src', 'path' : src}) |
1513 | 1572 |
1514 # Every Java program depends on the JRE | 1573 # Every Java program depends on the JRE |
1515 println(out, '\t<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>') | 1574 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'}) |
1516 | 1575 |
1517 for dep in p.all_deps([], True): | 1576 for dep in p.all_deps([], True): |
1518 if dep == p: | 1577 if dep == p: |
1519 continue; | 1578 continue; |
1520 | 1579 |
1521 if dep.isLibrary(): | 1580 if dep.isLibrary(): |
1522 if hasattr(dep, 'eclipse.container'): | 1581 if hasattr(dep, 'eclipse.container'): |
1523 println(out, '\t<classpathentry exported="true" kind="con" path="' + getattr(dep, 'eclipse.container') + '"/>') | 1582 out.element('classpathentry', {'exported' : 'true', 'kind' : 'con', 'path' : getattr(dep, 'eclipse.container')}) |
1524 elif hasattr(dep, 'eclipse.project'): | 1583 elif hasattr(dep, 'eclipse.project'): |
1525 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + getattr(dep, 'eclipse.project') + '"/>') | 1584 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + getattr(dep, 'eclipse.project')}) |
1526 else: | 1585 else: |
1527 path = dep.path | 1586 path = dep.path |
1528 if dep.mustExist: | 1587 if dep.mustExist: |
1529 dep.get_path(resolve=True) | 1588 dep.get_path(resolve=True) |
1530 if isabs(path): | 1589 if isabs(path): |
1531 println(out, '\t<classpathentry exported="true" kind="lib" path="' + path + '"/>') | 1590 out.element('classpathentry', {'exported' : 'true', 'kind' : 'lib', 'path' : path}) |
1532 else: | 1591 else: |
1533 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse | 1592 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse |
1534 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's | 1593 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's |
1535 # safest to simply use absolute paths. | 1594 # safest to simply use absolute paths. |
1536 println(out, '\t<classpathentry exported="true" kind="lib" path="' + join(suite.dir, path) + '"/>') | 1595 out.element('classpathentry', {'exported' : 'true', 'kind' : 'lib', 'path' : join(suite.dir, path)}) |
1537 else: | 1596 else: |
1538 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>') | 1597 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name}) |
1539 | 1598 |
1540 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>') | 1599 out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')}) |
1541 println(out, '</classpath>') | 1600 out.close('classpath') |
1542 update_file(join(p.dir, '.classpath'), out.getvalue()) | 1601 update_file(join(p.dir, '.classpath'), out.xml(indent='\t', newl='\n')) |
1543 out.close() | |
1544 | 1602 |
1545 csConfig = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') | 1603 csConfig = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') |
1546 if exists(csConfig): | 1604 if exists(csConfig): |
1547 out = StringIO.StringIO() | 1605 out = XML() |
1548 | 1606 |
1549 dotCheckstyle = join(p.dir, ".checkstyle") | 1607 dotCheckstyle = join(p.dir, ".checkstyle") |
1550 checkstyleConfigPath = '/' + p.checkstyleProj + '/.checkstyle_checks.xml' | 1608 checkstyleConfigPath = '/' + p.checkstyleProj + '/.checkstyle_checks.xml' |
1551 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 1609 out.open('fileset-config', {'file-format-version' : '1.2.0', 'simple-config' : 'true'}) |
1552 println(out, '<fileset-config file-format-version="1.2.0" simple-config="true">') | 1610 out.open('local-check-config', {'name' : 'Checks', 'location' : checkstyleConfigPath, 'type' : 'project', 'description' : ''}) |
1553 println(out, '\t<local-check-config name="Checks" location="' + checkstyleConfigPath + '" type="project" description="">') | 1611 out.element('additional-data', {'name' : 'protect-config-file', 'value' : 'false'}) |
1554 println(out, '\t\t<additional-data name="protect-config-file" value="false"/>') | 1612 out.close('local-check-config') |
1555 println(out, '\t</local-check-config>') | 1613 out.open('fileset', {'name' : 'all', 'enabled' : 'true', 'check-config-name' : 'Checks', 'local' : 'true'}) |
1556 println(out, '\t<fileset name="all" enabled="true" check-config-name="Checks" local="true">') | 1614 out.element('file-match-pattern', {'match-pattern' : '.', 'include-pattern' : 'true'}) |
1557 println(out, '\t\t<file-match-pattern match-pattern="." include-pattern="true"/>') | 1615 out.close('fileset') |
1558 println(out, '\t</fileset>') | 1616 out.open('filter', {'name' : 'all', 'enabled' : 'true', 'check-config-name' : 'Checks', 'local' : 'true'}) |
1559 println(out, '\t<filter name="FileTypesFilter" enabled="true">') | 1617 out.element('filter-data', {'value' : 'java'}) |
1560 println(out, '\t\t<filter-data value="java"/>') | 1618 out.close('filter') |
1561 println(out, '\t</filter>') | |
1562 | 1619 |
1563 exclude = join(p.dir, '.checkstyle.exclude') | 1620 exclude = join(p.dir, '.checkstyle.exclude') |
1564 if exists(exclude): | 1621 if exists(exclude): |
1565 println(out, '\t<filter name="FilesFromPackage" enabled="true">') | 1622 out.open('filter', {'name' : 'FilesFromPackage', 'enabled' : 'true'}) |
1566 with open(exclude) as f: | 1623 with open(exclude) as f: |
1567 for line in f: | 1624 for line in f: |
1568 if not line.startswith('#'): | 1625 if not line.startswith('#'): |
1569 line = line.strip() | 1626 line = line.strip() |
1570 exclDir = join(p.dir, line) | 1627 exclDir = join(p.dir, line) |
1571 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir | 1628 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir |
1572 println(out, '\t\t<filter-data value="' + line + '"/>') | 1629 out.element('filter-data', {'value' : line}) |
1573 println(out, '\t</filter>') | 1630 out.close('filter') |
1574 | 1631 |
1575 println(out, '</fileset-config>') | 1632 out.close('fileset-config') |
1576 update_file(dotCheckstyle, out.getvalue()) | 1633 update_file(dotCheckstyle, out.xml(indent='\t', newl='\n')) |
1577 out.close() | 1634 |
1578 | 1635 out = XML() |
1579 | 1636 out.open('projectDescription') |
1580 out = StringIO.StringIO() | 1637 out.element('name', data=p.name) |
1581 | 1638 out.element('comment', data='') |
1582 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 1639 out.element('projects', data='') |
1583 println(out, '<projectDescription>') | 1640 out.open('buildSpec') |
1584 println(out, '\t<name>' + p.name + '</name>') | 1641 out.open('buildCommand') |
1585 println(out, '\t<comment></comment>') | 1642 out.element('name', data='org.eclipse.jdt.core.javabuilder') |
1586 println(out, '\t<projects>') | 1643 out.element('arguments', data='') |
1587 println(out, '\t</projects>') | 1644 out.close('buildCommand') |
1588 println(out, '\t<buildSpec>') | |
1589 println(out, '\t\t<buildCommand>') | |
1590 println(out, '\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>') | |
1591 println(out, '\t\t\t<arguments>') | |
1592 println(out, '\t\t\t</arguments>') | |
1593 println(out, '\t\t</buildCommand>') | |
1594 if exists(csConfig): | 1645 if exists(csConfig): |
1595 println(out, '\t\t<buildCommand>') | 1646 out.open('buildCommand') |
1596 println(out, '\t\t\t<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>') | 1647 out.element('name', data='net.sf.eclipsecs.core.CheckstyleBuilder') |
1597 println(out, '\t\t\t<arguments>') | 1648 out.element('arguments', data='') |
1598 println(out, '\t\t\t</arguments>') | 1649 out.close('buildCommand') |
1599 println(out, '\t\t</buildCommand>') | 1650 out.close('buildSpec') |
1600 println(out, '\t</buildSpec>') | 1651 out.open('natures') |
1601 println(out, '\t<natures>') | 1652 out.element('nature', data='org.eclipse.jdt.core.javanature') |
1602 println(out, '\t\t<nature>org.eclipse.jdt.core.javanature</nature>') | |
1603 if exists(csConfig): | 1653 if exists(csConfig): |
1604 println(out, '\t\t<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>') | 1654 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature') |
1605 println(out, '\t</natures>') | 1655 out.close('natures') |
1606 println(out, '</projectDescription>') | 1656 out.close('projectDescription') |
1607 update_file(join(p.dir, '.project'), out.getvalue()) | 1657 update_file(join(p.dir, '.project'), out.xml(indent='\t', newl='\n')) |
1608 out.close() | |
1609 | 1658 |
1610 settingsDir = join(p.dir, ".settings") | 1659 settingsDir = join(p.dir, ".settings") |
1611 if not exists(settingsDir): | 1660 if not exists(settingsDir): |
1612 os.mkdir(settingsDir) | 1661 os.mkdir(settingsDir) |
1613 | 1662 |
1618 if isfile(path): | 1667 if isfile(path): |
1619 with open(join(eclipseSettingsDir, name)) as f: | 1668 with open(join(eclipseSettingsDir, name)) as f: |
1620 content = f.read() | 1669 content = f.read() |
1621 content = content.replace('${javaCompliance}', str(p.javaCompliance)) | 1670 content = content.replace('${javaCompliance}', str(p.javaCompliance)) |
1622 update_file(join(settingsDir, name), content) | 1671 update_file(join(settingsDir, name), content) |
1623 | 1672 |
1624 memento = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<javaProject name="' + p.name + '"/>\n' | 1673 make_eclipse_attach('localhost', '8000', deps=projects()) |
1625 source_locator_memento += '\n<container memento="' + xml.sax.saxutils.escape(memento, entities) + '" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/>' | |
1626 | |
1627 source_locator_memento += '</sourceContainers>\n</sourceLookupDirector>' | |
1628 launch = r"""<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
1629 <launchConfiguration type="org.eclipse.jdt.launching.remoteJavaApplication"> | |
1630 <stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/> | |
1631 <stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="{0}"/> | |
1632 <booleanAttribute key="org.eclipse.jdt.launching.ALLOW_TERMINATE" value="true"/> | |
1633 <mapAttribute key="org.eclipse.jdt.launching.CONNECT_MAP"> | |
1634 <mapEntry key="hostname" value="localhost"/> | |
1635 <mapEntry key="port" value="8000"/> | |
1636 </mapAttribute> | |
1637 <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/> | |
1638 <stringAttribute key="org.eclipse.jdt.launching.VM_CONNECTOR_ID" value="org.eclipse.jdt.launching.socketAttachConnector"/> | |
1639 </launchConfiguration>""".format(xml.sax.saxutils.escape(source_locator_memento, entities)) | |
1640 | |
1641 eclipseLaunches = join(suite.dir, 'mx', 'eclipse-launches') | |
1642 if not exists(eclipseLaunches): | |
1643 os.makedirs(eclipseLaunches) | |
1644 update_file(join(eclipseLaunches, 'attach-8000.launch'), launch) | |
1645 | 1674 |
1646 def netbeansinit(args, suite=None): | 1675 def netbeansinit(args, suite=None): |
1647 """(re)generate NetBeans project configurations""" | 1676 """(re)generate NetBeans project configurations""" |
1648 | 1677 |
1649 if suite is None: | 1678 if suite is None: |
1650 suite = _mainSuite | 1679 suite = _mainSuite |
1651 | |
1652 def println(out, obj): | |
1653 out.write(str(obj) + '\n') | |
1654 | 1680 |
1655 updated = False | 1681 updated = False |
1656 for p in projects(): | 1682 for p in projects(): |
1657 if p.native: | 1683 if p.native: |
1658 continue | 1684 continue |
1659 | 1685 |
1660 if not exists(join(p.dir, 'nbproject')): | 1686 if not exists(join(p.dir, 'nbproject')): |
1661 os.makedirs(join(p.dir, 'nbproject')) | 1687 os.makedirs(join(p.dir, 'nbproject')) |
1662 | 1688 |
1663 out = StringIO.StringIO() | 1689 out = XML() |
1664 | 1690 out.open('project', {'name' : p.name, 'default' : 'default', 'basedir' : '.'}) |
1665 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 1691 out.element('description', data='Builds, tests, and runs the project ' + p.name + '.') |
1666 println(out, '<project name="' + p.name + '" default="default" basedir=".">') | 1692 out.element('import', {'file' : 'nbproject/build-impl.xml'}) |
1667 println(out, '\t<description>Builds, tests, and runs the project ' + p.name + '.</description>') | 1693 out.close('project') |
1668 println(out, '\t<import file="nbproject/build-impl.xml"/>') | 1694 updated = update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) or updated |
1669 println(out, '</project>') | 1695 |
1670 updated = update_file(join(p.dir, 'build.xml'), out.getvalue()) or updated | 1696 out = XML() |
1671 out.close() | 1697 out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'}) |
1672 | 1698 out.element('type', data='org.netbeans.modules.java.j2seproject') |
1673 out = StringIO.StringIO() | 1699 out.open('configuration') |
1674 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | 1700 out.open('data', {'xmlns' : 'http://www.netbeans.org/ns/j2se-project/3'}) |
1675 println(out, '<project xmlns="http://www.netbeans.org/ns/project/1">') | 1701 out.element('name', data=p.name) |
1676 println(out, ' <type>org.netbeans.modules.java.j2seproject</type>') | 1702 out.element('explicit-platform', {'explicit-source-supported' : 'true'}) |
1677 println(out, ' <configuration>') | 1703 out.open('source-roots') |
1678 println(out, ' <data xmlns="http://www.netbeans.org/ns/j2se-project/3">') | 1704 out.element('root', {'id' : 'src.dir'}) |
1679 println(out, ' <name>' + p.name+ '</name>') | 1705 out.close('source-roots') |
1680 println(out, ' <explicit-platform explicit-source-supported="true"/>') | 1706 out.open('test-roots') |
1681 println(out, ' <source-roots>') | 1707 out.element('root', {'id' : 'test.src.dir'}) |
1682 println(out, ' <root id="src.dir"/>') | 1708 out.close('test-roots') |
1683 println(out, ' </source-roots>') | 1709 out.close('data') |
1684 println(out, ' <test-roots>') | 1710 |
1685 println(out, ' <root id="test.src.dir"/>') | |
1686 println(out, ' </test-roots>') | |
1687 println(out, ' </data>') | |
1688 | |
1689 firstDep = True | 1711 firstDep = True |
1690 for dep in p.all_deps([], True): | 1712 for dep in p.all_deps([], True): |
1691 if dep == p: | 1713 if dep == p: |
1692 continue; | 1714 continue; |
1693 | 1715 |
1694 if not dep.isLibrary(): | 1716 if not dep.isLibrary(): |
1695 n = dep.name.replace('.', '_') | 1717 n = dep.name.replace('.', '_') |
1696 if firstDep: | 1718 if firstDep: |
1697 println(out, ' <references xmlns="http://www.netbeans.org/ns/ant-project-references/1">') | 1719 out.open('references', {'xmlns' : 'http://www.netbeans.org/ns/ant-project-references/1'}) |
1698 firstDep = False | 1720 firstDep = False |
1699 | 1721 |
1700 println(out, ' <reference>') | 1722 out.open('reference') |
1701 println(out, ' <foreign-project>' + n + '</foreign-project>') | 1723 out.element('foreign-project', data=n) |
1702 println(out, ' <artifact-type>jar</artifact-type>') | 1724 out.element('artifact-type', data='jar') |
1703 println(out, ' <script>build.xml</script>') | 1725 out.element('script', data='build.xml') |
1704 println(out, ' <target>jar</target>') | 1726 out.element('target', data='jar') |
1705 println(out, ' <clean-target>clean</clean-target>') | 1727 out.element('clean-target', data='clean') |
1706 println(out, ' <id>jar</id>') | 1728 out.element('id', data='jar') |
1707 println(out, ' </reference>') | 1729 out.close('reference') |
1708 | 1730 |
1709 if not firstDep: | 1731 if not firstDep: |
1710 println(out, ' </references>') | 1732 out.close('references') |
1711 | 1733 |
1712 println(out, ' </configuration>') | 1734 out.close('configuration') |
1713 println(out, '</project>') | 1735 out.close('project') |
1714 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.getvalue()) or updated | 1736 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated |
1715 out.close() | |
1716 | 1737 |
1717 out = StringIO.StringIO() | 1738 out = StringIO.StringIO() |
1718 | |
1719 jdkPlatform = 'JDK_' + java().version | 1739 jdkPlatform = 'JDK_' + java().version |
1720 | 1740 |
1721 content = """ | 1741 content = """ |
1722 annotation.processing.enabled=false | 1742 annotation.processing.enabled=false |
1723 annotation.processing.enabled.in.editor=false | 1743 annotation.processing.enabled.in.editor=false |
1789 run.test.classpath=\\ | 1809 run.test.classpath=\\ |
1790 ${javac.test.classpath}:\\ | 1810 ${javac.test.classpath}:\\ |
1791 ${build.test.classes.dir} | 1811 ${build.test.classes.dir} |
1792 test.src.dir= | 1812 test.src.dir= |
1793 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep) | 1813 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep) |
1794 println(out, content) | 1814 print >> out, content |
1795 | 1815 |
1796 mainSrc = True | 1816 mainSrc = True |
1797 for src in p.srcDirs: | 1817 for src in p.srcDirs: |
1798 srcDir = join(p.dir, src) | 1818 srcDir = join(p.dir, src) |
1799 if not exists(srcDir): | 1819 if not exists(srcDir): |
1800 os.mkdir(srcDir) | 1820 os.mkdir(srcDir) |
1801 ref = 'file.reference.' + p.name + '-' + src | 1821 ref = 'file.reference.' + p.name + '-' + src |
1802 println(out, ref + '=' + src) | 1822 print >> out, ref + '=' + src |
1803 if mainSrc: | 1823 if mainSrc: |
1804 println(out, 'src.dir=${' + ref + '}') | 1824 print >> out, 'src.dir=${' + ref + '}' |
1805 mainSrc = False | 1825 mainSrc = False |
1806 else: | 1826 else: |
1807 println(out, 'src.' + src + '.dir=${' + ref + '}') | 1827 print >> out, 'src.' + src + '.dir=${' + ref + '}' |
1808 | 1828 |
1809 javacClasspath = [] | 1829 javacClasspath = [] |
1810 for dep in p.all_deps([], True): | 1830 for dep in p.all_deps([], True): |
1811 if dep == p: | 1831 if dep == p: |
1812 continue; | 1832 continue; |
1816 continue | 1836 continue |
1817 path = dep.get_path(resolve=True) | 1837 path = dep.get_path(resolve=True) |
1818 if os.sep == '\\': | 1838 if os.sep == '\\': |
1819 path = path.replace('\\', '\\\\') | 1839 path = path.replace('\\', '\\\\') |
1820 ref = 'file.reference.' + dep.name + '-bin' | 1840 ref = 'file.reference.' + dep.name + '-bin' |
1821 println(out, ref + '=' + path) | 1841 print >> out, ref + '=' + path |
1822 | 1842 |
1823 else: | 1843 else: |
1824 n = dep.name.replace('.', '_') | 1844 n = dep.name.replace('.', '_') |
1825 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') | 1845 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/') |
1826 ref = 'reference.' + n + '.jar' | 1846 ref = 'reference.' + n + '.jar' |
1827 println(out, 'project.' + n + '=' + relDepPath) | 1847 print >> out, 'project.' + n + '=' + relDepPath |
1828 println(out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar') | 1848 print >> out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar' |
1829 | 1849 |
1830 javacClasspath.append('${' + ref + '}') | 1850 javacClasspath.append('${' + ref + '}') |
1831 | 1851 |
1832 println(out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath)) | 1852 print >> out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath) |
1833 | 1853 |
1834 | 1854 |
1835 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated | 1855 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated |
1836 out.close() | 1856 out.close() |
1837 | 1857 |