This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run configuration gneration and some minor ui feedback.
- Loading branch information
1 parent
23909ac
commit 1a6664e
Showing
8 changed files
with
534 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/main/java/covers1624/ccintelli/workspace/RunConfigGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package covers1624.ccintelli.workspace; | ||
|
||
import covers1624.ccintelli.gui.GuiFields; | ||
import covers1624.ccintelli.launch.Launch; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.transform.OutputKeys; | ||
import javax.xml.transform.Transformer; | ||
import javax.xml.transform.TransformerFactory; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static covers1624.util.XMLUtils.createAndAdd; | ||
import static covers1624.util.XMLUtils.getFirstElementNode; | ||
|
||
/** | ||
* Created by covers1624 on 20/02/2017. | ||
*/ | ||
public class RunConfigGenerator { | ||
|
||
public static void generateRunConfigs(String projectName) { | ||
File workspaceIWS = new File(Launch.WORKSPACE, projectName + ".iws"); | ||
try { | ||
List<String> vmArgs = new ArrayList<>(); | ||
|
||
vmArgs.addAll(GuiFields.vmArgs); | ||
|
||
if (!GuiFields.fmlCorePlugins.isEmpty()) { | ||
StringBuilder builder = new StringBuilder("-Dfml.coreMods.load="); | ||
boolean hasFirst = false; | ||
for (String corePlugin : GuiFields.fmlCorePlugins) { | ||
if (hasFirst) { | ||
builder.append(","); | ||
} | ||
hasFirst = true; | ||
builder.append(corePlugin); | ||
} | ||
vmArgs.add(builder.toString()); | ||
} | ||
|
||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder builder = factory.newDocumentBuilder(); | ||
Document document = builder.parse(RunConfigGenerator.class.getResourceAsStream("/iwsTemplate.xml")); | ||
document.getDocumentElement().normalize(); | ||
|
||
Element documentElement = document.getDocumentElement(); | ||
Element componentElement = getFirstElementNode(documentElement, "component"); | ||
{ | ||
Element clientRun = createAndAdd(document, componentElement, "configuration"); | ||
clientRun.setAttribute("factoryName", "Application"); | ||
clientRun.setAttribute("type", "Application"); | ||
clientRun.setAttribute("name", "Minecraft Client"); | ||
clientRun.setAttribute("default", "false"); | ||
Element extension = createAndAdd(document, clientRun, "extension"); | ||
extension.setAttribute("runner", "idea"); | ||
extension.setAttribute("merge", "false"); | ||
extension.setAttribute("enabled", "false"); | ||
extension.setAttribute("name", "coverage"); | ||
Element mainClassOpt = createAndAdd(document, clientRun, "option"); | ||
mainClassOpt.setAttribute("value", "GradleStart"); | ||
mainClassOpt.setAttribute("name", "MAIN_CLASS_NAME"); | ||
StringBuilder argBuilder = new StringBuilder(); | ||
boolean hasFirst = false; | ||
for (String arg : vmArgs) { | ||
if (hasFirst) { | ||
argBuilder.append(" "); | ||
} | ||
hasFirst = true; | ||
argBuilder.append(arg); | ||
} | ||
Element vmArgsOpt = createAndAdd(document, clientRun, "option"); | ||
vmArgsOpt.setAttribute("value", argBuilder.toString()); | ||
vmArgsOpt.setAttribute("name", "VM_PARAMETERS"); | ||
Element progArgsOpt = createAndAdd(document, clientRun, "option"); | ||
progArgsOpt.setAttribute("value", ""); | ||
progArgsOpt.setAttribute("name", "PROGRAM_PARAMETERS"); | ||
Element workingDirOpt = createAndAdd(document, clientRun, "option"); | ||
workingDirOpt.setAttribute("value", "file://" + Launch.PROJECT_RUN.getAbsoluteFile().getPath()); | ||
workingDirOpt.setAttribute("name", "WORKING_DIRECTORY"); | ||
Element altJERpathEnableOpt = createAndAdd(document, clientRun, "option"); | ||
altJERpathEnableOpt.setAttribute("value", "false"); | ||
altJERpathEnableOpt.setAttribute("name", "ALTERNATIVE_JRE_PATH_ENABLED"); | ||
Element aldJrePathOpt = createAndAdd(document, clientRun, "option"); | ||
aldJrePathOpt.setAttribute("name", "ALTERNATIVE_JRE_PATH"); | ||
Element swingInspecOpt = createAndAdd(document, clientRun, "option"); | ||
swingInspecOpt.setAttribute("value", "false"); | ||
swingInspecOpt.setAttribute("name", "ENABLE_SWING_INSPECTOR"); | ||
Element envVarsOpt = createAndAdd(document, clientRun, "option"); | ||
envVarsOpt.setAttribute("name", "ENV_VARIABLES"); | ||
Element passParentEnvsOpt = createAndAdd(document, clientRun, "option"); | ||
passParentEnvsOpt.setAttribute("value", "true"); | ||
passParentEnvsOpt.setAttribute("name", "PASS_PARENT_ENVS"); | ||
|
||
Element moduleClassPathElement = createAndAdd(document, clientRun, "module"); | ||
moduleClassPathElement.setAttribute("name", GuiFields.forgeModule.NAME); | ||
createAndAdd(document, clientRun, "envs"); | ||
createAndAdd(document, clientRun, "method"); | ||
} | ||
{ | ||
Element serverRun = createAndAdd(document, componentElement, "configuration"); | ||
serverRun.setAttribute("factoryName", "Application"); | ||
serverRun.setAttribute("type", "Application"); | ||
serverRun.setAttribute("name", "Minecraft Server"); | ||
serverRun.setAttribute("default", "false"); | ||
Element extension = createAndAdd(document, serverRun, "extension"); | ||
extension.setAttribute("runner", "idea"); | ||
extension.setAttribute("merge", "false"); | ||
extension.setAttribute("enabled", "false"); | ||
extension.setAttribute("name", "coverage"); | ||
Element mainClassOpt = createAndAdd(document, serverRun, "option"); | ||
mainClassOpt.setAttribute("value", "GradleStartServer"); | ||
mainClassOpt.setAttribute("name", "MAIN_CLASS_NAME"); | ||
StringBuilder argBuilder = new StringBuilder(); | ||
boolean hasFirst = false; | ||
for (String arg : vmArgs) { | ||
if (hasFirst) { | ||
argBuilder.append(" "); | ||
} | ||
hasFirst = true; | ||
argBuilder.append(arg); | ||
} | ||
Element vmArgsOpt = createAndAdd(document, serverRun, "option"); | ||
vmArgsOpt.setAttribute("value", argBuilder.toString()); | ||
vmArgsOpt.setAttribute("name", "VM_PARAMETERS"); | ||
Element progArgsOpt = createAndAdd(document, serverRun, "option"); | ||
progArgsOpt.setAttribute("value", ""); | ||
progArgsOpt.setAttribute("name", "PROGRAM_PARAMETERS"); | ||
Element workingDirOpt = createAndAdd(document, serverRun, "option"); | ||
workingDirOpt.setAttribute("value", "file://" + Launch.PROJECT_RUN.getAbsoluteFile().getPath()); | ||
workingDirOpt.setAttribute("name", "WORKING_DIRECTORY"); | ||
Element altJERpathEnableOpt = createAndAdd(document, serverRun, "option"); | ||
altJERpathEnableOpt.setAttribute("value", "false"); | ||
altJERpathEnableOpt.setAttribute("name", "ALTERNATIVE_JRE_PATH_ENABLED"); | ||
Element aldJrePathOpt = createAndAdd(document, serverRun, "option"); | ||
aldJrePathOpt.setAttribute("name", "ALTERNATIVE_JRE_PATH"); | ||
Element swingInspecOpt = createAndAdd(document, serverRun, "option"); | ||
swingInspecOpt.setAttribute("value", "false"); | ||
swingInspecOpt.setAttribute("name", "ENABLE_SWING_INSPECTOR"); | ||
Element envVarsOpt = createAndAdd(document, serverRun, "option"); | ||
envVarsOpt.setAttribute("name", "ENV_VARIABLES"); | ||
Element passParentEnvsOpt = createAndAdd(document, serverRun, "option"); | ||
passParentEnvsOpt.setAttribute("value", "true"); | ||
passParentEnvsOpt.setAttribute("name", "PASS_PARENT_ENVS"); | ||
|
||
Element moduleClassPathElement = createAndAdd(document, serverRun, "module"); | ||
moduleClassPathElement.setAttribute("name", GuiFields.forgeModule.NAME); | ||
createAndAdd(document, serverRun, "envs"); | ||
createAndAdd(document, serverRun, "method"); | ||
} | ||
|
||
Element listElement = getFirstElementNode(componentElement, "list"); | ||
listElement.setAttribute("size", "2"); | ||
Element clientChild = createAndAdd(document, listElement, "item"); | ||
clientChild.setAttribute("itemvalue", "Application.Minecraft Client"); | ||
clientChild.setAttribute("class", "java.lang.String"); | ||
clientChild.setAttribute("index", "0"); | ||
|
||
Element serverChild = createAndAdd(document, listElement, "item"); | ||
serverChild.setAttribute("itemvalue", "Application.Minecraft Server"); | ||
serverChild.setAttribute("class", "java.lang.String"); | ||
serverChild.setAttribute("index", "1"); | ||
|
||
TransformerFactory transformerFactory = TransformerFactory.newInstance(); | ||
Transformer transformer = transformerFactory.newTransformer(); | ||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); | ||
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); | ||
DOMSource source = new DOMSource(document); | ||
StreamResult result = new StreamResult(workspaceIWS); | ||
transformer.transform(source, result); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
//throw new RuntimeException("Exception thrown whilst generating run configs.", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package covers1624.util; | ||
|
||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
||
import java.util.Iterator; | ||
|
||
/** | ||
* Created by covers1624 on 28/02/2017. | ||
*/ | ||
public class NodeListIterator implements Iterator<Node>, Iterable<Node> { | ||
|
||
private final NodeList list; | ||
private int index; | ||
|
||
public NodeListIterator(NodeList list) { | ||
this.list = list; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return list != null && index < list.getLength(); | ||
} | ||
|
||
@Override | ||
public Node next() { | ||
Node object = list.item(index); | ||
if (object != null) { | ||
index++; | ||
} | ||
return object; | ||
} | ||
|
||
@Override | ||
public Iterator<Node> iterator() { | ||
return this; | ||
} | ||
} |
Oops, something went wrong.