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 1 commit
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
79 changes: 79 additions & 0 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit invasive: it introduces an invisible dependency between this code and unittest and these eventually fire back. We need to re-organize unittest such that it uses the same function this code will use. This function will simply return all the arguments.

Also, in this way, there will be less code.

"""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 = '''\
<configuration default="true" type="JUnit" factoryName="JUnit">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="PACKAGE_NAME" />
<option name="MAIN_CLASS_NAME" />
<option name="METHOD_NAME" />
<option name="TEST_OBJECT" value="class" />
<option name="VM_PARAMETERS" value="{vm_params}" />
<option name="PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<option name="TEST_SEARCH_SCOPE">
<value defaultName="singleModule" />
</option>
<envs />
<patterns />
<method />
</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()])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good as it breaks indentation. Try some of these that you find the easiest:

http://stackoverflow.com/questions/2504411/proper-indentation-for-python-multiline-strings

Sad that python does not support this. You can also do what Scala does just with a regex here.


# until the official solution becomes available (IDEA-65915), use `workspase.xml`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workspase ~> workspace

wsXml = XMLDoc()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just nuke someones workspace someone might of spent hours on setting it up. We need to find <configuration default="true" type="JUnit" factoryName="JUnit"> and replace it with the new one.

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'
Expand Down