Commits
md_5 authored 1ef992afbdb
15 15 | import java.io.BufferedWriter; |
16 16 | import java.io.File; |
17 17 | import java.io.FileOutputStream; |
18 18 | import java.io.FileWriter; |
19 19 | import java.io.IOException; |
20 20 | import java.io.InputStream; |
21 21 | import java.io.InputStreamReader; |
22 22 | import java.io.OutputStream; |
23 23 | import java.io.PrintStream; |
24 24 | import java.net.URL; |
25 + | import java.util.Arrays; |
25 26 | import java.util.Date; |
26 27 | import java.util.Enumeration; |
27 28 | import java.util.List; |
28 29 | import java.util.zip.ZipEntry; |
29 30 | import java.util.zip.ZipFile; |
30 31 | import lombok.RequiredArgsConstructor; |
31 32 | import org.apache.commons.io.FileUtils; |
32 33 | import org.eclipse.jgit.api.Git; |
33 34 | import org.eclipse.jgit.api.ResetCommand; |
34 35 | import org.eclipse.jgit.api.errors.GitAPIException; |
47 48 | { |
48 49 | if ( IS_MAC ) |
49 50 | { |
50 51 | System.out.println( "Sorry, but Macintosh is not currently a supported platform for compilation at this time." ); |
51 52 | System.out.println( "Please run this script on a Windows or Linux PC and then copy the jars to this computer." ); |
52 53 | System.exit( 1 ); |
53 54 | } |
54 55 | |
55 56 | try |
56 57 | { |
57 - | runProcess( "bash -c exit", CWD ); |
58 + | runProcess( CWD, "bash", "-c", "exit" ); |
58 59 | } catch ( Exception ex ) |
59 60 | { |
60 61 | System.out.println( "You must run this jar through bash (msysgit)" ); |
61 62 | System.exit( 1 ); |
62 63 | } |
63 64 | |
64 65 | try |
65 66 | { |
66 - | runProcess( "git config --global user.name", CWD ); |
67 + | runProcess( CWD, "git", "config", "--global", "user.name" ); |
67 68 | } catch ( Exception ex ) |
68 69 | { |
69 70 | System.out.println( "Git name not set, setting it to default value." ); |
70 - | runProcess( "git config --global user.name BuildTools", CWD ); |
71 + | runProcess( CWD, "git", "config", "--global", "user.name", "BuildTools" ); |
71 72 | } |
72 73 | try |
73 74 | { |
74 - | runProcess( "git config --global user.email", CWD ); |
75 + | runProcess( CWD, "git", "config", "--global", "user.email" ); |
75 76 | } catch ( Exception ex ) |
76 77 | { |
77 78 | System.out.println( "Git email not set, setting it to default value." ); |
78 - | runProcess( "git config --global user.email unconfigured@null.spigotmc.org", CWD ); |
79 + | runProcess( CWD, "git", "config", "--global", "user.email", "unconfigured@null.spigotmc.org" ); |
79 80 | } |
80 81 | |
81 82 | File workDir = new File( "work" ); |
82 83 | workDir.mkdir(); |
83 84 | |
84 85 | File bukkit = new File( "Bukkit" ); |
85 86 | if ( !bukkit.exists() ) |
86 87 | { |
87 88 | clone( "https://hub.spigotmc.org/stash/scm/spigot/bukkit.git", bukkit ); |
88 89 | } |
163 164 | String mappingsVersion = mappingsHash.hash().toString().substring( 24 ); // Last 8 chars |
164 165 | |
165 166 | File finalMappedJar = new File( workDir, "mapped." + mappingsVersion + ".jar" ); |
166 167 | if ( !finalMappedJar.exists() ) |
167 168 | { |
168 169 | System.out.println( "Final mapped jar: " + finalMappedJar + " does not exist, creating!" ); |
169 170 | |
170 171 | File clMappedJar = new File( finalMappedJar + "-cl" ); |
171 172 | File mMappedJar = new File( finalMappedJar + "-m" ); |
172 173 | |
173 - | runProcess( "java -jar BuildData/bin/SpecialSource.jar -i " + vanillaJar + " -m BuildData/mappings/bukkit-1.8-cl.csrg -o " + clMappedJar, CWD ); |
174 - | runProcess( "java -jar BuildData/bin/SpecialSource-2.jar map -i " + clMappedJar + " -m " + "BuildData/mappings/bukkit-1.8-members.csrg -o " + mMappedJar, CWD ); |
175 - | runProcess( "java -jar BuildData/bin/SpecialSource.jar -i " + mMappedJar + " --access-transformer BuildData/mappings/bukkit-1.8.at " |
176 - | + "-m BuildData/mappings/package.srg -o " + finalMappedJar, CWD ); |
174 + | runProcess( CWD, "java", "-jar", "BuildData/bin/SpecialSource.jar", "-i", "vanillaJar", "-m", "BuildData/mappings/bukkit-1.8-cl.csrg", "-o", clMappedJar.getPath() ); |
175 + | |
176 + | runProcess( CWD, "java", "-jar", "BuildData/bin/SpecialSource-2.jar", "map", "-i", clMappedJar.getPath(), |
177 + | "-m", "BuildData/mappings/bukkit-1.8-members.csrg", "-o", mMappedJar.getPath() ); |
178 + | |
179 + | runProcess( CWD, "java", "-jar", "BuildData/bin/SpecialSource.jar", "-i", mMappedJar.getPath(), "--access-transformer", "BuildData/mappings/bukkit-1.8.at", |
180 + | "-m", "BuildData/mappings/package.srg", "-o", finalMappedJar.getPath() ); |
177 181 | } |
178 182 | |
179 - | runProcess( mvnCmd + " install:install-file -Dfile=" + finalMappedJar + " -Dpackaging=jar -DgroupId=org.spigotmc -DartifactId=minecraft-server -Dversion=1.8-SNAPSHOT", CWD ); |
183 + | runProcess( CWD, mvnCmd, "install:install-file", "-Dfile=" + finalMappedJar, "-Dpackaging=jar", "-DgroupId=org.spigotmc", |
184 + | "-DartifactId=minecraft-server", "-Dversion=1.8-SNAPSHOT" ); |
180 185 | |
181 186 | File decompileDir = new File( workDir, "decompile-" + mappingsVersion ); |
182 187 | if ( !decompileDir.exists() ) |
183 188 | { |
184 189 | decompileDir.mkdir(); |
185 190 | |
186 191 | File clazzDir = new File( decompileDir, "classes" ); |
187 192 | unzip( finalMappedJar, clazzDir, new Predicate<String>() |
188 193 | { |
189 194 | |
190 195 | |
191 196 | public boolean apply(String input) |
192 197 | { |
193 198 | return input.startsWith( "net/minecraft/server" ); |
194 199 | } |
195 200 | } ); |
196 201 | |
197 - | runProcess( "java -jar BuildData/bin/fernflower.jar -dgs=1 -hdc=0 -rbr=0 -asc=1 " + clazzDir + " " + decompileDir, CWD ); |
202 + | runProcess( CWD, "java", "-jar", "BuildData/bin/fernflower.jar", "-dgs=1", "-hdc=0", "-rbr=0", "-asc=1", clazzDir.getPath(), decompileDir.getPath() ); |
198 203 | |
199 204 | String jacobePath = jacobeDir.getPath() + "/jacobe"; |
200 205 | if ( IS_WINDOWS ) |
201 206 | { |
202 207 | jacobePath += ".exe"; |
203 208 | } |
204 - | runProcess( jacobePath + " -cfg=BuildData/bin/jacobe.cfg -nobackup -overwrite -outext=java " + decompileDir + "/net/minecraft/server", CWD ); |
209 + | runProcess( CWD, jacobePath, "-cfg=BuildData/bin/jacobe.cfg", "-nobackup", "-overwrite", "-outext=java", decompileDir + "/net/minecraft/server" ); |
205 210 | } |
206 211 | |
207 212 | System.out.println( "Applying CraftBukkit Patches" ); |
208 213 | File nmsDir = new File( craftBukkit, "src/main/java/net" ); |
209 214 | if ( nmsDir.exists() ) |
210 215 | { |
211 216 | System.out.println( "Backing up NMS dir" ); |
212 217 | FileUtils.moveDirectory( nmsDir, new File( workDir, "nms.old." + System.currentTimeMillis() ) ); |
213 218 | } |
214 219 | File patchDir = new File( craftBukkit, "nms-patches" ); |
251 256 | } |
252 257 | File spigotServer = new File( spigot, "CraftBukkit" ); |
253 258 | if ( !spigotServer.exists() ) |
254 259 | { |
255 260 | clone( "file://" + craftBukkit.getAbsolutePath(), spigotServer ); |
256 261 | } |
257 262 | |
258 263 | // Git spigotApiGit = Git.open( spigotApi ); |
259 264 | // Git spigotServerGit = Git.open( spigotServer ); |
260 265 | System.out.println( "Compiling Bukkit" ); |
261 - | runProcess( mvnCmd + " clean install", bukkit ); |
266 + | runProcess( bukkit, mvnCmd, "clean", "install" ); |
262 267 | |
263 268 | System.out.println( "Compiling CraftBukkit" ); |
264 - | runProcess( mvnCmd + " clean install", craftBukkit ); |
269 + | runProcess( craftBukkit, mvnCmd, "clean", "install" ); |
265 270 | |
266 271 | try |
267 272 | { |
268 - | runProcess( "bash applyPatches.sh", spigot ); |
273 + | runProcess( spigot, "bash", "applyPatches.sh" ); |
269 274 | System.out.println( "*** Spigot patches applied!" ); |
270 275 | System.out.println( "Compiling Spigot & Spigot-API" ); |
271 - | runProcess( mvnCmd + " clean install", spigot ); |
276 + | runProcess( spigot, mvnCmd, "clean", "install" ); |
272 277 | } catch ( Exception ex ) |
273 278 | { |
274 279 | System.err.println( "Error compiling Spigot, are you running this jar via msysgit?" ); |
275 280 | ex.printStackTrace(); |
276 281 | System.exit( 1 ); |
277 282 | } |
278 283 | } |
279 284 | |
280 285 | public static void getJacobe() throws Exception |
281 286 | { |
282 287 | if ( IS_WINDOWS ) |
283 288 | { |
284 289 | File jacobeWindows = new File( "jacobe.win32.zip" ); |
285 290 | download( "http://www.tiobe.com/content/products/jacobe/jacobe.win32.zip", jacobeWindows ); |
286 291 | unzip( jacobeWindows, jacobeDir ); |
287 292 | } else |
288 293 | { |
289 294 | File jacobeLinux = new File( "jacobe.linux.tar.gz" ); |
290 295 | download( "http://www.tiobe.com/content/products/jacobe/jacobe.linux.tar.gz", jacobeLinux ); |
291 296 | |
292 297 | jacobeDir.mkdir(); |
293 - | runProcess( "tar xzvf " + jacobeLinux.getPath() + " -C " + jacobeDir.getPath(), CWD ); |
298 + | runProcess( CWD, "tar", "xzvf", jacobeLinux.getPath(), "-C", jacobeDir.getPath() ); |
294 299 | } |
295 300 | } |
296 301 | |
297 302 | public static void pull(Git repo) throws Exception |
298 303 | { |
299 304 | System.out.println( "Pulling updates for " + repo.getRepository().getDirectory() ); |
300 305 | |
301 306 | repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call(); |
302 307 | boolean result = repo.pull().call().isSuccessful(); |
303 308 | |
304 309 | if ( !result ) |
305 310 | { |
306 311 | throw new RuntimeException( "Could not pull updates!" ); |
307 312 | } |
308 313 | |
309 314 | System.out.println( "Successfully pulled updates!" ); |
310 315 | } |
311 316 | |
312 - | public static int runProcess(String command, File workDir) throws Exception |
317 + | public static int runProcess(File workDir, String... command) throws Exception |
313 318 | { |
314 - | final Process ps = new ProcessBuilder( command.split( " " ) ).directory( workDir ).start(); |
319 + | final Process ps = new ProcessBuilder( command ).directory( workDir ).start(); |
315 320 | |
316 321 | new Thread( new StreamRedirector( ps.getInputStream(), System.out ) ).start(); |
317 322 | new Thread( new StreamRedirector( ps.getErrorStream(), System.err ) ).start(); |
318 323 | |
319 324 | int status = ps.waitFor(); |
320 325 | |
321 326 | if ( status != 0 ) |
322 327 | { |
323 - | throw new RuntimeException( "Error running command, return status !=0: " + command ); |
328 + | throw new RuntimeException( "Error running command, return status !=0: " + Arrays.toString( command ) ); |
324 329 | } |
325 330 | |
326 331 | return status; |
327 332 | } |
328 333 | |
329 334 | |
330 335 | private static class StreamRedirector implements Runnable |
331 336 | { |
332 337 | |
333 338 | private final InputStream in; |