1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| import javax.xml.parsers.DocumentBuilder import javax.xml.parsers.DocumentBuilderFactory import javax.xml.transform.TransformerException import javax.xml.transform.TransformerFactory import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult
static void createOption(document, parent, String name, String value) { final var option = document.createElement("option");
option.setAttribute("name", name); option.setAttribute("value", value);
parent.appendChild(option) }
tasks.register('createRunConfigurations') { def runConfigurationsDir = new File(".idea/runConfigurations")
final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
final var javaDocument = docBuilder.newDocument(); { final var rootElement = javaDocument.createElement("component"); { final var configuration = javaDocument.createElement("configuration"); { configuration.setAttribute("default", "false"); configuration.setAttribute("name", "runServer"); configuration.setAttribute("type", "JarApplication")
createOption(javaDocument, configuration, "JAR_PATH", "${targetServerPath}/${targetServerJarName}") createOption(javaDocument, configuration, "WORKING_DIRECTORY", targetServerPath)
var method = javaDocument.createElement("method"); { method.setAttribute("v", "1")
var o1 = javaDocument.createElement("option");
o1.setAttribute("name", "Gradle.BeforeRunTask") o1.setAttribute("enabled", "true") o1.setAttribute("tasks", "build") o1.setAttribute("externalProjectPath", "\$PROJECT_DIR\$") o1.setAttribute("vmOptions", "") o1.setAttribute("scriptParameters", "")
method.appendChild(o1)
var o2 = javaDocument.createElement("option");
o2.setAttribute("name", "Gradle.BeforeRunTask") o2.setAttribute("enabled", "true") o2.setAttribute("tasks", "copyArtifacts") o2.setAttribute("externalProjectPath", "\$PROJECT_DIR\$") o2.setAttribute("vmOptions", "") o2.setAttribute("scriptParameters", "")
method.appendChild(o2) } configuration.appendChild(method) } rootElement.appendChild(configuration) } javaDocument.appendChild(rootElement); }
final TransformerFactory transformerFactory = TransformerFactory.newInstance(); final var transformer = transformerFactory.newTransformer();
final DOMSource source = new DOMSource(javaDocument); final File location = new File(runConfigurationsDir, "runServer.xml"); if (!location.getParentFile().exists()) location.getParentFile().mkdirs(); final StreamResult result = new StreamResult(location);
try { transformer.transform(source, result); } catch (TransformerException e) { e.printStackTrace(); } }
|