Skip to content

Commit

Permalink
Merge pull request #46 from nmiyake/ideaJUnitDefaultDirFix
Browse files Browse the repository at this point in the history
Set IDEA settings on iws instead of ipr
  • Loading branch information
uschi2000 committed Mar 22, 2016
2 parents 8f65c11 + 0cdc532 commit 8e4e9a0
Showing 1 changed file with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class BaselineIdea extends AbstractBaselinePlugin {
addCopyright(node)
addCheckstyle(node)
addGit(node)
addJUnitWorkingDirectory(node)
}

ideaRootModel.workspace.iws.withXml { provider ->
def node = provider.asNode()
setRunManagerWorkingDirectory(node)
}
}

Expand Down Expand Up @@ -133,19 +137,30 @@ class BaselineIdea extends AbstractBaselinePlugin {
}

/**
* Configure the default working directory of JUnit tests to be the module directory.
* Configure the default working directory of RunManager configurations to be the module directory.
*/
private void addJUnitWorkingDirectory(node) {
node.append(new XmlParser().parseText('''
<component name="RunManager">
<configuration default="true" type="Application" factoryName="Application">
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit">
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
</configuration>
</component>
'''.stripIndent()))
private void setRunManagerWorkingDirectory(node) {
def runManager = node.component.find { it.'@name' == 'RunManager' }

if (runManager) {
// if RunManager configuration exists, set all WORKING_DIRECTORY options to module
def items = runManager.configuration.option.findAll { it.'@name' == 'WORKING_DIRECTORY' }
items.each { item ->
item.'@value' = 'file://$MODULE_DIR$'
}
} else {
// if RunManager configuration does not exist, add it
node.append(new XmlParser().parseText('''
<component name="RunManager">
<configuration default="true" type="Application" factoryName="Application">
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit">
<option name="WORKING_DIRECTORY" value="file://$MODULE_DIR$" />
</configuration>
</component>
'''.stripIndent()))
}
}

/**
Expand Down

0 comments on commit 8e4e9a0

Please sign in to comment.