Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JUnit config to intellijinit #133

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -13166,6 +13169,58 @@ def artifactFileName(dist):
artifactFile = join(artifactsDir, artifactFileName(dist))
update_file(artifactFile, artifactXML.xml(indent=' ', newl='\n'))

# Default JUnit run 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):
self.run = run
globals()['run'] = self # replace mx.run

def __exit__(self, exc_type, exc_val, exc_tb):
globals()['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)

# 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.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'))

def intellij_scm_name(vc_kind):
if vc_kind == 'git':
return 'Git'
Expand Down Expand Up @@ -13197,10 +13252,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():
Expand Down