-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.gradle
85 lines (76 loc) · 3.1 KB
/
build.gradle
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
import java.nio.file.Files
class Globals {
private static final def ARCHIVE_NAME = "generator-fabric-1.20.1" // The name of the exported file
// You can change the root folder of your OS if you have a custom installation
public static final def MCREATOR_ROOT_FOLDER_WINDOWS = "C://Program Files/Pylo/MCreator/" // Default path on Windows
public static def MCREATOR_ROOT_FOLDER_MAC_LINUX = "/Applications/MCreator.app/Contents/MacOS/mcreator" // Default path on macOS and Linux
static def getArchiveName() {
return ARCHIVE_NAME + ".zip"
}
static String getOSName() {
return System.getProperty("os.name").toLowerCase()
}
}
// workaround for IDEA-265203
System.setProperty("user.dir", projectDir.toString())
tasks.register('exportPlugin', Zip) {
group("mcreator_plugins")
from 'src'
archiveFileName = Globals.getArchiveName()
destinationDirectory = file('build/')
}
tasks.register('install') {
dependsOn exportPlugin
group("mcreator_plugins")
doLast {
System.out.println("Installing plugin...")
if (Globals.getOSName().contains('mac') || Globals.getOSName().contains('OS X') || Globals.getOSName().contains('linux')) {
installPlugin((String) ("/Users/" + System.getProperty("user.name") + "/.mcreator/plugins/"), (String) '/')
} else if (Globals.getOSName().contains('windows')) {
installPlugin((String) ("C:\\Users\\" + System.getProperty("user.name") + "\\.mcreator\\plugins\\"), (String) '\\')
}
}
}
tasks.register('runMCreator') {
dependsOn install
group("mcreator_plugins")
doLast {
System.out.println("Launching MCreator...")
if (Globals.getOSName().contains('windows')) {
try {
exec {
workingDir Globals.MCREATOR_ROOT_FOLDER_WINDOWS
commandLine 'cmd', '/c', 'mcreator.bat'
}
} catch (IOException e) {
//noinspection GroovyAssignabilityCheck
throw new RuntimeException("Could not launch MCreator! Please make sure you have installed it to " + Globals.MCREATOR_ROOT_FOLDER_WINDOWS, e)
}
} else if (Globals.getOSName().contains('mac') || Globals.getOSName().contains('OS X') || Globals.getOSName().contains('linux')) {
try {
ProcessBuilder builder = new ProcessBuilder(Globals.MCREATOR_ROOT_FOLDER_MAC_LINUX)
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT)
builder.redirectError(ProcessBuilder.Redirect.INHERIT)
builder.start()
} catch (IOException e) {
//noinspection GroovyAssignabilityCheck
throw new RuntimeException("Could not launch MCreator! Please make sure you have installed it to " + Globals.MCREATOR_ROOT_FOLDER_MAC_LINUX, e)
}
}
}
}
static def installPlugin(String path, String separator) {
File des = new File((String) (path + Globals.getArchiveName()))
File original = new File(String.format("%s%s%s%s%s", System.getProperty("user.dir"), separator, "build", separator, Globals.getArchiveName()))
if (des.exists()) {
des.delete()
}
try {
FileOutputStream os = new FileOutputStream(des)
Files.copy(original.toPath(), os)
System.out.println(String.format("Plugin successfully installed to %s ", path))
} catch (IOException e) {
e.printStackTrace()
throw new RuntimeException("Could not install plugin!")
}
}