-
Notifications
You must be signed in to change notification settings - Fork 109
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = '''\ | ||
<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()]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. workspase ~> workspace |
||
wsXml = XMLDoc() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't just nuke someones |
||
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' | ||
|
There was a problem hiding this comment.
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-organizeunittest
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.