comparison mxtool/mx.py @ 15060:858d2b91c1f8

Add a prototype for mx intellijinit
author Gilles Duboscq <duboscq@ssw.jku.at>
date Thu, 10 Apr 2014 17:58:16 +0200
parents e1ce6c66f56e
children f3e74d317e83
comparison
equal deleted inserted replaced
15059:4df6d7c966a2 15060:858d2b91c1f8
3552 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)') 3552 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)')
3553 3553
3554 _zip_files(files, suite.dir, configZip.path) 3554 _zip_files(files, suite.dir, configZip.path)
3555 _zip_files(libFiles, suite.dir, configLibsZip) 3555 _zip_files(libFiles, suite.dir, configLibsZip)
3556 3556
3557 def intellijinit(args, refreshOnly=False):
3558 """(re)generate Intellij project configurations"""
3559
3560 for suite in suites(True):
3561 _intellij_suite(args, suite, refreshOnly)
3562
3563 def _intellij_suite(args, suite, refreshOnly=False):
3564
3565 libraries = set()
3566
3567 ideaProjectDirectory = join(suite.dir, '.idea')
3568
3569 if not exists(ideaProjectDirectory):
3570 os.mkdir(ideaProjectDirectory)
3571 nameFile = join(ideaProjectDirectory, '.name')
3572 update_file(nameFile, "Graal")
3573 modulesXml = XMLDoc()
3574 modulesXml.open('project', attributes={'version': '4'})
3575 modulesXml.open('component', attributes={'name': 'ProjectModuleManager'})
3576 modulesXml.open('modules')
3577
3578
3579 def _intellij_exclude_if_exists(xml, p, name):
3580 path = join(p.dir, name)
3581 if exists(path):
3582 xml.element('excludeFolder', attributes={'url':'file://$MODULE_DIR$/' + name})
3583
3584 annotationProcessorProfiles = {}
3585
3586 def _complianceToIntellijLanguageLevel(compliance):
3587 return 'JDK_1_' + str(compliance.value)
3588
3589 # create the modules (1 module = 1 Intellij project)
3590 for p in suite.projects:
3591 if p.native:
3592 continue
3593
3594 if not java(p.javaCompliance):
3595 log('Excluding {0} (JDK with compliance level {1} not available)'.format(p.name, p.javaCompliance))
3596 continue
3597
3598 if not exists(p.dir):
3599 os.makedirs(p.dir)
3600
3601 annotationProcessorProfileKey = tuple(p.annotation_processors())
3602
3603 if not annotationProcessorProfileKey in annotationProcessorProfiles:
3604 annotationProcessorProfiles[annotationProcessorProfileKey] = [p]
3605 else:
3606 annotationProcessorProfiles[annotationProcessorProfileKey].append(p)
3607
3608 intellijLanguageLevel = _complianceToIntellijLanguageLevel(p.javaCompliance)
3609
3610 moduleXml = XMLDoc()
3611 moduleXml.open('module', attributes={'type': 'JAVA_MODULE', 'version': '4'})
3612
3613 moduleXml.open('component', attributes={'name': 'NewModuleRootManager', 'LANGUAGE_LEVEL': intellijLanguageLevel, 'inherit-compiler-output': 'false'})
3614 moduleXml.element('output', attributes={'url': 'file://$MODULE_DIR$/bin'}) # TODO use p.output_dir() ?
3615 moduleXml.element('exclude-output')
3616
3617 moduleXml.open('content', attributes={'url': 'file://$MODULE_DIR$'})
3618 for src in p.srcDirs:
3619 srcDir = join(p.dir, src)
3620 if not exists(srcDir):
3621 os.mkdir(srcDir)
3622 moduleXml.element('sourceFolder', attributes={'url':'file://$MODULE_DIR$/' + src, 'isTestSource': 'false'})
3623
3624 if len(p.annotation_processors()) > 0:
3625 genDir = p.source_gen_dir()
3626 if not exists(genDir):
3627 os.mkdir(genDir)
3628 moduleXml.element('sourceFolder', attributes={'url':'file://$MODULE_DIR$/' + os.path.relpath(genDir, p.dir), 'isTestSource': 'false'})
3629
3630 for name in ['.externalToolBuilders', '.settings', 'nbproject']:
3631 _intellij_exclude_if_exists(moduleXml, p, name)
3632 moduleXml.close('content')
3633
3634 moduleXml.element('orderEntry', attributes={'type': 'jdk', 'jdkType': 'JavaSDK', 'jdkName': str(p.javaCompliance)})
3635 moduleXml.element('orderEntry', attributes={'type': 'sourceFolder', 'forTests': 'false'})
3636
3637 deps = p.all_deps([], True, includeAnnotationProcessors=True)
3638 for dep in deps:
3639 if dep == p:
3640 continue
3641
3642 if dep.isLibrary():
3643 if dep.mustExist:
3644 libraries.add(dep)
3645 moduleXml.element('orderEntry', attributes={'type': 'library', 'name': dep.name, 'level': 'project'})
3646 else:
3647 moduleXml.element('orderEntry', attributes={'type': 'module', 'module-name': dep.name})
3648
3649 moduleXml.close('component')
3650 moduleXml.close('module')
3651 moduleFile = join(p.dir, p.name + '.iml')
3652 update_file(moduleFile, moduleXml.xml(indent=' ', newl='\n'))
3653
3654 moduleFilePath = "$PROJECT_DIR$/" + os.path.relpath(moduleFile, suite.dir)
3655 modulesXml.element('module', attributes={'fileurl': 'file://' + moduleFilePath, 'filepath': moduleFilePath})
3656
3657 modulesXml.close('modules')
3658 modulesXml.close('component')
3659 modulesXml.close('project')
3660 moduleXmlFile = join(ideaProjectDirectory, 'modules.xml')
3661 update_file(moduleXmlFile, modulesXml.xml(indent=' ', newl='\n'))
3662
3663 # TODO What about cross-suite dependencies?
3664
3665 librariesDirectory = join(ideaProjectDirectory, 'libraries')
3666
3667 if not exists(librariesDirectory):
3668 os.mkdir(librariesDirectory)
3669
3670 # Setup the libraries that were used above
3671 # TODO: setup all the libraries from the suite regardless of usage?
3672 for library in libraries:
3673 libraryXml = XMLDoc()
3674
3675 libraryXml.open('component', attributes={'name': 'libraryTable'})
3676 libraryXml.open('library', attributes={'name': library.name})
3677 libraryXml.open('CLASSES')
3678 libraryXml.element('root', attributes={'url': 'jar://$PROJECT_DIR$/' + os.path.relpath(library.path, suite.dir) + '!/'})
3679 libraryXml.close('CLASSES')
3680 libraryXml.element('JAVADOC')
3681 if library.sourcePath:
3682 libraryXml.open('SOURCES')
3683 libraryXml.element('root', attributes={'url': 'jar://$PROJECT_DIR$/' + os.path.relpath(library.sourcePath, suite.dir) + '!/'})
3684 libraryXml.close('SOURCES')
3685 else:
3686 libraryXml.element('SOURCES')
3687 libraryXml.close('library')
3688 libraryXml.close('component')
3689
3690 libraryFile = join(librariesDirectory, library.name + '.xml')
3691 update_file(libraryFile, libraryXml.xml(indent=' ', newl='\n'))
3692
3693
3694
3695 # Set annotation processor profiles up, and link them to modules in compiler.xml
3696 compilerXml = XMLDoc()
3697 compilerXml.open('project', attributes={'version': '4'})
3698 compilerXml.open('component', attributes={'name': 'CompilerConfiguration'})
3699
3700 compilerXml.element('option', attributes={'name': "DEFAULT_COMPILER", 'value': 'Javac'})
3701 compilerXml.element('resourceExtensions')
3702 compilerXml.open('wildcardResourcePatterns')
3703 compilerXml.element('entry', attributes={'name': '!?*.java'})
3704 compilerXml.close('wildcardResourcePatterns')
3705
3706 if annotationProcessorProfiles:
3707 compilerXml.open('annotationProcessing')
3708 for processors, modules in annotationProcessorProfiles.items():
3709 compilerXml.open('profile', attributes={'default': 'false', 'name': '-'.join(processors), 'enabled': 'true'})
3710 compilerXml.element('sourceOutputDir', attributes={'name': 'src_gen'}) # TODO use p.source_gen_dir() ?
3711 compilerXml.element('outputRelativeToContentRoot', attributes={'value': 'true'})
3712 compilerXml.open('processorPath', attributes={'useClasspath': 'false'})
3713 for apName in processors:
3714 pDep = dependency(apName)
3715 for entry in pDep.all_deps([], True):
3716 if entry.isLibrary():
3717 compilerXml.element('entry', attributes={'name': '$PROJECT_DIR$/' + os.path.relpath(entry.path, suite.dir)})
3718 else:
3719 assert entry.isProject()
3720 compilerXml.element('entry', attributes={'name': '$PROJECT_DIR$/' + os.path.relpath(entry.output_dir(), suite.dir)})
3721 compilerXml.close('processorPath')
3722 for module in modules:
3723 compilerXml.element('module', attributes={'name': module.name})
3724 compilerXml.close('profile')
3725 compilerXml.close('annotationProcessing')
3726
3727 compilerXml.close('component')
3728 compilerXml.close('project')
3729 compilerFile = join(ideaProjectDirectory, 'compiler.xml')
3730 update_file(compilerFile, compilerXml.xml(indent=' ', newl='\n'))
3731
3732 # Wite misc.xml for global JDK config
3733 miscXml = XMLDoc()
3734 miscXml.open('project', attributes={'version': '4'})
3735 miscXml.element('component', attributes={'name': 'ProjectRootManager', 'version': '2', 'languagelevel': _complianceToIntellijLanguageLevel(java().javaCompliance), 'project-jdk-name': str(java().javaCompliance), 'project-jdk-type': 'JavaSDK'})
3736 miscXml.close('project')
3737 miscFile = join(ideaProjectDirectory, 'misc.xml')
3738 update_file(miscFile, miscXml.xml(indent=' ', newl='\n'))
3739
3740
3741 # TODO look into copyright settings
3742 # TODO should add vcs.xml support
3743
3557 def ideclean(args): 3744 def ideclean(args):
3558 """remove all Eclipse and NetBeans project configurations""" 3745 """remove all Eclipse and NetBeans project configurations"""
3559 def rm(path): 3746 def rm(path):
3560 if exists(path): 3747 if exists(path):
3561 os.remove(path) 3748 os.remove(path)
3562 3749
3563 for s in suites(): 3750 for s in suites():
3564 rm(join(s.mxDir, 'eclipse-config.zip')) 3751 rm(join(s.mxDir, 'eclipse-config.zip'))
3565 rm(join(s.mxDir, 'netbeans-config.zip')) 3752 rm(join(s.mxDir, 'netbeans-config.zip'))
3753 shutil.rmtree(join(s.dir, '.idea'), ignore_errors=True)
3566 3754
3567 for p in projects(): 3755 for p in projects():
3568 if p.native: 3756 if p.native:
3569 continue 3757 continue
3570 3758
3573 shutil.rmtree(join(p.dir, 'nbproject'), ignore_errors=True) 3761 shutil.rmtree(join(p.dir, 'nbproject'), ignore_errors=True)
3574 rm(join(p.dir, '.classpath')) 3762 rm(join(p.dir, '.classpath'))
3575 rm(join(p.dir, '.checkstyle')) 3763 rm(join(p.dir, '.checkstyle'))
3576 rm(join(p.dir, '.project')) 3764 rm(join(p.dir, '.project'))
3577 rm(join(p.dir, '.factorypath')) 3765 rm(join(p.dir, '.factorypath'))
3766 rm(join(p.dir, p.name + '.iml'))
3578 rm(join(p.dir, 'build.xml')) 3767 rm(join(p.dir, 'build.xml'))
3579 rm(join(p.dir, 'eclipse-build.xml')) 3768 rm(join(p.dir, 'eclipse-build.xml'))
3580 try: 3769 try:
3581 rm(join(p.dir, p.name + '.jar')) 3770 rm(join(p.dir, p.name + '.jar'))
3582 except: 3771 except:
3585 3774
3586 def ideinit(args, refreshOnly=False, buildProcessorJars=True): 3775 def ideinit(args, refreshOnly=False, buildProcessorJars=True):
3587 """(re)generate Eclipse and NetBeans project configurations""" 3776 """(re)generate Eclipse and NetBeans project configurations"""
3588 eclipseinit(args, refreshOnly=refreshOnly, buildProcessorJars=buildProcessorJars) 3777 eclipseinit(args, refreshOnly=refreshOnly, buildProcessorJars=buildProcessorJars)
3589 netbeansinit(args, refreshOnly=refreshOnly, buildProcessorJars=buildProcessorJars) 3778 netbeansinit(args, refreshOnly=refreshOnly, buildProcessorJars=buildProcessorJars)
3779 intellijinit(args, refreshOnly=refreshOnly)
3590 if not refreshOnly: 3780 if not refreshOnly:
3591 fsckprojects([]) 3781 fsckprojects([])
3592 3782
3593 def fsckprojects(args): 3783 def fsckprojects(args):
3594 """find directories corresponding to deleted Java projects and delete them""" 3784 """find directories corresponding to deleted Java projects and delete them"""
4151 'findclass': [findclass, ''], 4341 'findclass': [findclass, ''],
4152 'fsckprojects': [fsckprojects, ''], 4342 'fsckprojects': [fsckprojects, ''],
4153 'help': [help_, '[command]'], 4343 'help': [help_, '[command]'],
4154 'ideclean': [ideclean, ''], 4344 'ideclean': [ideclean, ''],
4155 'ideinit': [ideinit, ''], 4345 'ideinit': [ideinit, ''],
4346 'intellijinit': [intellijinit, ''],
4156 'archive': [archive, '[options]'], 4347 'archive': [archive, '[options]'],
4157 'projectgraph': [projectgraph, ''], 4348 'projectgraph': [projectgraph, ''],
4158 'pylint': [pylint, ''], 4349 'pylint': [pylint, ''],
4159 'javap': [javap, '<class name patterns>'], 4350 'javap': [javap, '<class name patterns>'],
4160 'javadoc': [javadoc, '[options]'], 4351 'javadoc': [javadoc, '[options]'],