/
bootstrap.gradle
187 lines (156 loc) · 4.14 KB
/
bootstrap.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
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* bukkit-bootstrap (c) 2013-2014 Ian Macalinao
*/
import org.yaml.snakeyaml.Yaml
import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'java'
apply plugin: 'maven'
// Plugin information loaded from the YML file
ext.plugin = (new Yaml()).load(new FileInputStream(new File(projectDir, "src/main/resources/plugin.yml")))
// Determine the group/artifact
ext.pkg = plugin.main.substring(0, plugin.main.lastIndexOf('.'))
// Our group/artifact ids. Version is declared in the main file
group = pkg.substring(0, pkg.lastIndexOf('.'))
archivesBaseName = plugin.name.toLowerCase()
version = project.version
// Default parameters
if (!project.hasProperty('ossrhUsername')) {
ext.ossrhUsername = '';
}
if (!project.hasProperty('ossrhPassword')) {
ext.ossrhPassword = '';
}
if (!project.hasProperty('testPluginDir')) {
ext.testPluginDir = '';
}
if (!project.hasProperty('remotePluginDir')) {
ext.remotePluginDir = '';
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'org.yaml:snakeyaml:1.5'
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7.1'
}
}
repositories {
mavenCentral()
maven {
url 'http://repo.md-5.net/content/groups/public/'
}
}
dependencies {
compile 'org.bukkit:bukkit:1.7.9-R0.3-SNAPSHOT'
}
processResources {
from('src/main/resources') {
include '*'
filter { String line ->
line.replace('$version', 'v' + cmd('git describe --always --dirty=-dirty'))
}
}
}
/**
* Executes a command and returns its output.
*/
def cmd(str) {
try {
def output = new ByteArrayOutputStream()
exec {
commandLine str.split(' ')
standardOutput = output
}
return output.toString().trim()
}
catch (ignored) {
return null;
}
}
/**
* Scaffolds the Bukkit project.
*/
task scaffold << {
// Make artifact source directory
def mainClass = plugin.main.substring(plugin.main.lastIndexOf('.') + 1, plugin.main.length())
def artifactPath = new File('src/main/java/' + plugin.main.replace('.', '/')).getAbsolutePath()
def artifactSrcDir = new File(artifactPath.substring(0, artifactPath.lastIndexOf(File.separator)))
artifactSrcDir.mkdirs()
// Copy plugin bootstrap file over
copy {
from 'bootstrap/'
into artifactSrcDir.getPath()
include 'PluginBootstrap.java'
rename '.*', plugin.name + '.java'
filter(ReplaceTokens, tokens: [pkg: pkg, pluginName: mainClass])
}
if ((cmd('git remote -v') =~ /origin.+?bukkit-bootstrap\.git/).find()) {
cmd('git remote rename origin bukkit-bootstrap')
}
delete {
delete 'README.md'
}
}
task testCopy << {
cmd("mkdir -p $testPluginDir")
cmd("cp $projectDir/build/${plugin.name}.jar $testPluginDir")
}
task remoteCopy << {
cmd("scp $projectDir/build/${plugin.name}.jar $remotePluginDir")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
task copyPlugin(type: Copy) {
description 'Copy resulting JAR to a nice plugin name'
dependsOn 'build'
description 'Copies the plugin from the libs/ directory into the main build directory.'
from 'build/libs/'
into 'build/'
include jar.archiveName
rename jar.archiveName, plugin.name + '.jar'
}
// Publishing stuff
javadoc {
failOnError = false
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives javadocJar, sourcesJar
}
if (project.hasProperty('signing.keyId')) {
apply plugin: 'signing'
signing {
sign configurations.archives
}
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name plugin.name
packaging 'jar'
description plugin.description
url plugin.url
}
}
}
}