From b5aee083465989da8854d3938bdef58b299549d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Pejovi=C4=87?= Date: Wed, 26 Apr 2017 03:42:45 +0200 Subject: [PATCH 1/4] Add JUnit config to intellijinit --- mx.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/mx.py b/mx.py index ce6e784a..bf892b71 100755 --- a/mx.py +++ b/mx.py @@ -13166,6 +13166,85 @@ def artifactFileName(dist): artifactFile = join(artifactsDir, artifactFileName(dist)) update_file(artifactFile, artifactXML.xml(indent=' ', newl='\n')) + # JUnit configuration + def get_unittest_args(): + """Gets the VM arguments used for running the unittests by doing a dry run.""" + + class DisabledUnittests(object): + """Context manager that temporarily disables unittests from launching. + + It does this by replacing the mx.run with itself and examining the issued + commands. If it detects the `mx_unittest_main_class` in the command, it + captures the command and reports success without actually doing anything. + """ + + def __enter__(self): + global run + self.run = run + run = self # replace mx.run + + def __exit__(self, exc_type, exc_val, exc_tb): + global run + run = self.run # restore mx.run + + def __call__(self, args, **kwargs): + if mx_unittest_main_class in args: + self.cmd = args + return 0 + return self.run(args, **kwargs) + + mx_unittest_main_class = 'com.oracle.mxtool.junit.MxJUnitWrapper' + + with DisabledUnittests(): + # dry run + mx_unittest.unittest([]) + unittest_args = run.cmd[1:run.cmd.index(mx_unittest_main_class)] + + # remove classpath from args, since IntelliJ will provide one + cp_index = unittest_args.index('-cp') + del unittest_args[cp_index:cp_index + 2] + + return ' '.join(unittest_args) + + # IntelliJ IDEA 2017.1 default JUnit run configuration + default_configuration = '''\ + + + + + + + + + '''.format(vm_params=get_unittest_args()) + + # remove all whitespace between tags, so that we don't end up with excess newlines in xml output + default_configuration = ''.join([line.strip() for line in default_configuration.splitlines()]) + + # until the official solution becomes available (IDEA-65915), use `workspase.xml` + wsXml = XMLDoc() + wsXml.open('project', attributes={'version': '4'}) + wsXml.open('component', attributes={'name': 'RunManager'}) + wsXml.current.appendChild(xml.dom.minidom.parseString(default_configuration).firstChild) + wsXml.close('component') + wsXml.close('project') + + wsFile = join(ideaProjectDirectory, 'workspace.xml') + update_file(wsFile, wsXml.xml(indent=' ', newl='\n')) + def intellij_scm_name(vc_kind): if vc_kind == 'git': return 'Git' From ea21f7e51bb6ec2c54a98abbcb20728aa90bb914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Pejovi=C4=87?= Date: Thu, 27 Apr 2017 09:07:52 +0200 Subject: [PATCH 2/4] Fix pylint complaints --- mx.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mx.py b/mx.py index bf892b71..78ed01f4 100755 --- a/mx.py +++ b/mx.py @@ -13172,20 +13172,18 @@ def get_unittest_args(): class DisabledUnittests(object): """Context manager that temporarily disables unittests from launching. - + It does this by replacing the mx.run with itself and examining the issued commands. If it detects the `mx_unittest_main_class` in the command, it captures the command and reports success without actually doing anything. """ def __enter__(self): - global run self.run = run - run = self # replace mx.run + globals()['run'] = self # replace mx.run def __exit__(self, exc_type, exc_val, exc_tb): - global run - run = self.run # restore mx.run + globals()['run'] = self.run # restore mx.run def __call__(self, args, **kwargs): if mx_unittest_main_class in args: @@ -13234,7 +13232,7 @@ def __call__(self, args, **kwargs): # remove all whitespace between tags, so that we don't end up with excess newlines in xml output default_configuration = ''.join([line.strip() for line in default_configuration.splitlines()]) - # until the official solution becomes available (IDEA-65915), use `workspase.xml` + # until the official solution becomes available (IDEA-65915), use `workspace.xml` wsXml = XMLDoc() wsXml.open('project', attributes={'version': '4'}) wsXml.open('component', attributes={'name': 'RunManager'}) From d8e374c7e492aefe63c26801de038e568ea0a701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Pejovi=C4=87?= Date: Tue, 9 May 2017 04:06:43 +0200 Subject: [PATCH 3/4] Add some tweaks to IntelliJ support - Make IntelliJ builds fail on Ant Exec task error - Pass IntelliJ project's JDK to Ant build tasks, so that they are independent of the environment (i.e., they run even without JAVA_HOME being set) - Make ideclean remove IntelliJ's modules that were created by running intellijinit with --mx-python-modules flag --- mx.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mx.py b/mx.py index 78ed01f4..b12e922f 100755 --- a/mx.py +++ b/mx.py @@ -13108,10 +13108,13 @@ def artifactFileName(dist): # 1) Make an ant file for archiving the distributions. antXml = XMLDoc() antXml.open('project', attributes={'name': s.name, 'default': 'archive'}) + antXml.element('dirname', attributes={'file': '${java.home}', 'property': 'java_home'}) for dist in validDistributions: antXml.open('target', attributes={'name': antTargetName(dist)}) - antXml.open('exec', attributes={'executable': sys.executable}) + antXml.open('exec', attributes={'executable': sys.executable, 'failonerror': 'true'}) antXml.element('arg', attributes={'value': join(_mx_home, 'mx.py')}) + antXml.element('arg', attributes={'value': '--java-home'}) + antXml.element('arg', attributes={'value': '${java_home}'}) antXml.element('arg', attributes={'value': 'archive'}) antXml.element('arg', attributes={'value': '@' + dist.name}) antXml.close('exec') @@ -13274,10 +13277,13 @@ def rm(path): if exists(path): os.remove(path) + rm(join(_mx_suite.dir, basename(_mx_suite.dir) + '.iml')) + for s in suites() + [_mx_suite]: rm(join(s.get_mx_output_dir(), 'eclipse-config.zip')) rm(join(s.get_mx_output_dir(), 'netbeans-config.zip')) shutil.rmtree(join(s.dir, '.idea'), ignore_errors=True) + rm(join(s.mxDir, basename(s.mxDir) + '.iml')) for p in projects() + _mx_suite.projects: if not p.isJavaProject(): From 6bf858057de5a220a1bd91b12ea5786bda7bef76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Pejovi=C4=87?= Date: Sun, 14 May 2017 03:28:50 +0200 Subject: [PATCH 4/4] Generate minimum configuration without template --- mx.py | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/mx.py b/mx.py index b12e922f..c60dc8db 100755 --- a/mx.py +++ b/mx.py @@ -13169,7 +13169,7 @@ def artifactFileName(dist): artifactFile = join(artifactsDir, artifactFileName(dist)) update_file(artifactFile, artifactXML.xml(indent=' ', newl='\n')) - # JUnit configuration + # Default JUnit run configuration def get_unittest_args(): """Gets the VM arguments used for running the unittests by doing a dry run.""" @@ -13207,42 +13207,17 @@ def __call__(self, args, **kwargs): return ' '.join(unittest_args) - # IntelliJ IDEA 2017.1 default JUnit run configuration - default_configuration = '''\ - - - - - - - - - '''.format(vm_params=get_unittest_args()) - - # remove all whitespace between tags, so that we don't end up with excess newlines in xml output - default_configuration = ''.join([line.strip() for line in default_configuration.splitlines()]) - - # until the official solution becomes available (IDEA-65915), use `workspace.xml` + # generate the minimum configuration and let IntelliJ fill in the rest wsXml = XMLDoc() wsXml.open('project', attributes={'version': '4'}) wsXml.open('component', attributes={'name': 'RunManager'}) - wsXml.current.appendChild(xml.dom.minidom.parseString(default_configuration).firstChild) + wsXml.open('configuration', attributes={'default': 'true', 'type': 'JUnit', 'factoryName': 'JUnit'}) + wsXml.element('option', attributes={'name': 'VM_PARAMETERS', 'value': get_unittest_args()}) + wsXml.close('configuration') wsXml.close('component') wsXml.close('project') + # until the official solution becomes available (IDEA-65915), use `workspace.xml` wsFile = join(ideaProjectDirectory, 'workspace.xml') update_file(wsFile, wsXml.xml(indent=' ', newl='\n'))