forked from MinecraftForge/ForgeGradle
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskGenIdeaRun.java
More file actions
158 lines (131 loc) · 4.82 KB
/
TaskGenIdeaRun.java
File metadata and controls
158 lines (131 loc) · 4.82 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* A Gradle plugin for the creation of Minecraft mods and MinecraftForge plugins.
* Copyright (C) 2013-2019 Minecraft Forge
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
package net.minecraftforge.gradle.patcher;
import static net.minecraftforge.gradle.common.Constants.addXml;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import net.minecraftforge.gradle.common.Constants;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
class TaskGenIdeaRun extends DefaultTask
{
//@formatter:off
@Input private Object configName;
@Input private Object projectName;
@Input private Object mainClass;
@Input private Object runDir;
@Input @Optional private Object arguments;
@OutputFile private Object outputFile;
//@formatter:on
//@formatter:off
public TaskGenIdeaRun() { super(); }
//@formatter:on
@TaskAction
public void doTask() throws IOException, ParserConfigurationException, TransformerException
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root element
Document doc = docBuilder.newDocument();
Element root = addXml(doc, "component", ImmutableMap.of("name", "ProjectRunConfigurationManager"));
root = addXml(root, "configuration", ImmutableMap.of(
"default", "false",
"name", getConfigName(),
"type", "Application",
"factoryName", "Application"));
addXml(root, "module", ImmutableMap.of("name", getProjectName()));
addXml(root, "option", ImmutableMap.of("name", "MAIN_CLASS_NAME", "value", getMainClass()));
addXml(root, "option", ImmutableMap.of("name", "WORKING_DIRECTORY", "value", getRunDir()));
if (!Strings.isNullOrEmpty(getArguments()))
{
addXml(root, "option", ImmutableMap.of("name", "PROGRAM_PARAMETERS", "value", getArguments()));
}
File outFile = getOutputFile();
outFile.getParentFile().mkdirs();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(outFile);
transformer.transform(source, result);
}
public String getProjectName()
{
return Constants.resolveString(projectName);
}
public void setProjectName(Object projectName)
{
this.projectName = projectName;
}
public String getConfigName()
{
return Constants.resolveString(configName);
}
public void setConfigName(Object configName)
{
this.configName = configName;
}
public String getArguments()
{
return Constants.resolveString(arguments);
}
public void setArguments(Object arguments)
{
this.arguments = arguments;
}
public String getRunDir()
{
return Constants.resolveString(runDir);
}
public void setRunDir(Object runDir)
{
this.runDir = runDir;
}
public File getOutputFile()
{
return getProject().file(outputFile);
}
public void setOutputFile(Object outputFile)
{
this.outputFile = outputFile;
}
public String getMainClass()
{
return Constants.resolveString(mainClass);
}
public void setMainClass(Object mainClass)
{
this.mainClass = mainClass;
}
}