}
@SuppressWarnings("serial")
protected void configureIntellij()
{
IdeaModel ideaConv = (IdeaModel) project.getExtensions().getByName("idea");
ideaConv.getModule().getExcludeDirs().addAll(project.files(".gradle", "build", ".idea").getFiles());
ideaConv.getModule().setDownloadJavadoc(true);
ideaConv.getModule().setDownloadSources(true);
Task task = makeTask("genIntellijRuns", DefaultTask.class);
task.doLast(new Action<Task>() {
@Override
public void execute(Task task)
{
try
{
String module = task.getProject().getProjectDir().getCanonicalPath();
File file = project.file(".idea/workspace.xml");
if (!file.exists())
throw new RuntimeException("Only run this task after importing a build.gradle file into intellij!");
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(file);
injectIntellijRuns(doc, module);
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(file);
//StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
if (ideaConv.getWorkspace().getIws() == null)
return;
ideaConv.getWorkspace().getIws().withXml(new Closure<Object>(this, null)
{
public Object call(Object... obj)
{
Element root = ((XmlProvider) this.getDelegate()).asElement();
Document doc = root.getOwnerDocument();