-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
174 lines (145 loc) · 5.48 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import java.util.jar.JarFile
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.yaml:snakeyaml:2.0")
}
}
plugins {
id 'java'
id 'groovy'
id 'maven-publish'
}
apply from: 'dependencies.gradle'
// Use environment instead of gradle.properties
if ("$System.env.MAVEN_URL" != null) {
ext.MAVEN_URL = "$System.env.MAVEN_URL" + "/tfb"
ext.MAVEN_PASSWORD = "$System.env.MAVEN_PASSWORD"
ext.MAVEN_USERNAME = "$System.env.MAVEN_USERNAME"
}
// Nexus repository configuration
repositories {
mavenCentral()
maven {
url "${MAVEN_URL}"
credentials {
username = "${MAVEN_USERNAME}"
password = "${MAVEN_PASSWORD}"
}
}
}
// Type "gradle plugins" in terminal to update plugins
task plugins(type: Copy) {
doFirst {
delete fileTree(dir: 'plugins/.', include: '/*.jar')
}
from configurations.compileClasspath
exclude '*Paper*', '*Flamecord*', '*Expansion*', 'Purpur*'
into 'plugins'
}
// Type "gradle expansions" in terminal to update PAPI Expansions
task expansions(type: Copy) {
doFirst {
delete fileTree(dir: 'plugins/PlaceholderAPI/expansions/.', include: '/*.jar')
}
from configurations.compileClasspath
include '*Expansion*'
into 'plugins/PlaceholderAPI/expansions'
}
// Type "gradle server" in terminal to update server
task server(type: Copy) {
doFirst {
delete fileTree(dir: '/.', include: 'server.jar')
}
from configurations.compileClasspath
include 'Paper-*', 'Flamecord-*', 'Purpur-*'
rename '.*-(.+)', 'server.jar'
into "."
}
task update(dependsOn: ['server', 'plugins', 'expansions'])
ext.dir = new File("_plugins")
def files = ext.dir.listFiles().findAll { it.isFile() && it.name.endsWith('.jar') }
def allowedPrefixes = ["Paper", "FlameCord", "Purpur", "Expansion"]
def dists = []
files.each { file ->
if (allowedPrefixes.any { prefix -> file.name.startsWith(prefix) } && file.name.endsWith(".jar")) {
def fileName = file.name - '.jar' // Remove the ".jar" extension
if (fileName.startsWith("Expansion-")) {
// Handle Expansion files
def parts = fileName.split('-')
// println(parts)
if (parts.size() >= 1) {
def groupId = "PAPI-Expansion"
def artifactId = "Expansion-" + parts[1]
def version = parts[2]
def path = file
println("Found Expansion JAR: groupId=$groupId, artifactId=$artifactId, version=$version, path=$path")
dists << [groupId: groupId, artifactId: artifactId, version: version, path: path]
}
} else {
// Handle Paper and FlameCord files
def parts = fileName.split('-')
println(parts.toString())
def groupId = "Server"
def artifactId = parts[0]
def version = parts[1]
// Extract the version from the file name
if (parts.size() > 2) {
version += "-" + parts[2]
}
def path = file
println("Found JAR: groupId=$groupId, artifactId=$artifactId, version=$version, path=$path")
dists << [groupId: groupId, artifactId: artifactId, version: version, path: path]
}
} else {
def jarFile = new JarFile(file)
def pluginYml = (jarFile.getEntry("plugin.yml") != null) ? jarFile.getEntry("plugin.yml") : jarFile.getEntry("bungee.yml")
if (pluginYml != null) {
def yaml = new Yaml()
def plugin = yaml.load(jarFile.getInputStream(pluginYml))
def groupId = "Plugin"
def artifactId = plugin.name
//Adds "-Bungee" to artifact name for plugins like LuckPerms that wont rename their plugin when it's a Bungee-plugin.
if(file.name.contains("Bungee") && !artifactId.contains("Bungee") || jarFile.getEntry("bungee.yml") && !jarFile.getEntry("plugin.yml"))
artifactId += "-Bungee"
def version = plugin.version.toString()
if (version.contains(" ") || version.contains(";")) {
version = version.replace(" ", "-").replace(";", "-")
}
// Check for Skript dependency
def dependencies = plugin.depend
if (dependencies != null && dependencies.contains("Skript")) {
groupId = "Skript-Addon"
}
def path = file
println("Found JAR: groupId=$groupId, artifactId=$artifactId, version=$version, path=$path")
dists << [groupId: groupId, artifactId: artifactId, version: version, path: path]
}
}
}
publishing {
publications {
dists.each { dist ->
create(dist.artifactId, MavenPublication) {
groupId = dist.groupId
artifactId = dist.artifactId
version = dist.version
artifact dist.path
}
}
}
repositories {
maven {
url = "${MAVEN_URL}"
credentials {
username = "${MAVEN_USERNAME}"
password = "${MAVEN_PASSWORD}"
}
}
}
}