Commits
md_5 authored 8c3c4ef42ee Merge
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 | } |
116 117 | { |
117 118 | System.out.println( "Maven does not exist, downloading. Please wait." ); |
118 119 | |
119 120 | File mvnTemp = new File( "mvn.zip" ); |
120 121 | mvnTemp.deleteOnExit(); |
121 122 | |
122 123 | download( "http://static.spigotmc.org/maven/apache-maven-3.2.3-bin.zip", mvnTemp ); |
123 124 | unzip( mvnTemp, new File( "." ) ); |
124 125 | } |
125 126 | |
126 - | String mvnCmd = maven.getAbsolutePath() + "/bin/mvn"; |
127 - | if ( IS_WINDOWS ) |
128 - | { |
129 - | mvnCmd += ".bat"; |
130 - | } else |
131 - | { |
132 - | mvnCmd = "/bin/sh " + mvnCmd; |
133 - | } |
127 + | String mvn = maven.getAbsolutePath() + "/bin/mvn"; |
134 128 | |
135 129 | Git bukkitGit = Git.open( bukkit ); |
136 130 | Git craftBukkitGit = Git.open( craftBukkit ); |
137 131 | Git spigotGit = Git.open( spigot ); |
138 132 | Git buildGit = Git.open( buildData ); |
139 133 | |
140 134 | pull( bukkitGit ); |
141 135 | pull( craftBukkitGit ); |
142 136 | pull( spigotGit ); |
143 137 | pull( buildGit ); |
163 157 | String mappingsVersion = mappingsHash.hash().toString().substring( 24 ); // Last 8 chars |
164 158 | |
165 159 | File finalMappedJar = new File( workDir, "mapped." + mappingsVersion + ".jar" ); |
166 160 | if ( !finalMappedJar.exists() ) |
167 161 | { |
168 162 | System.out.println( "Final mapped jar: " + finalMappedJar + " does not exist, creating!" ); |
169 163 | |
170 164 | File clMappedJar = new File( finalMappedJar + "-cl" ); |
171 165 | File mMappedJar = new File( finalMappedJar + "-m" ); |
172 166 | |
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 ); |
167 + | runProcess( CWD, "java", "-jar", "BuildData/bin/SpecialSource.jar", "-i", vanillaJar.getPath(), "-m", "BuildData/mappings/bukkit-1.8-cl.csrg", "-o", clMappedJar.getPath() ); |
168 + | |
169 + | runProcess( CWD, "java", "-jar", "BuildData/bin/SpecialSource-2.jar", "map", "-i", clMappedJar.getPath(), |
170 + | "-m", "BuildData/mappings/bukkit-1.8-members.csrg", "-o", mMappedJar.getPath() ); |
171 + | |
172 + | runProcess( CWD, "java", "-jar", "BuildData/bin/SpecialSource.jar", "-i", mMappedJar.getPath(), "--access-transformer", "BuildData/mappings/bukkit-1.8.at", |
173 + | "-m", "BuildData/mappings/package.srg", "-o", finalMappedJar.getPath() ); |
177 174 | } |
178 175 | |
179 - | runProcess( mvnCmd + " install:install-file -Dfile=" + finalMappedJar + " -Dpackaging=jar -DgroupId=org.spigotmc -DartifactId=minecraft-server -Dversion=1.8-SNAPSHOT", CWD ); |
176 + | runProcess( CWD, "sh", mvn, "install:install-file", "-Dfile=" + finalMappedJar, "-Dpackaging=jar", "-DgroupId=org.spigotmc", |
177 + | "-DartifactId=minecraft-server", "-Dversion=1.8-SNAPSHOT" ); |
180 178 | |
181 179 | File decompileDir = new File( workDir, "decompile-" + mappingsVersion ); |
182 180 | if ( !decompileDir.exists() ) |
183 181 | { |
184 182 | decompileDir.mkdir(); |
185 183 | |
186 184 | File clazzDir = new File( decompileDir, "classes" ); |
187 185 | unzip( finalMappedJar, clazzDir, new Predicate<String>() |
188 186 | { |
189 187 | |
190 188 | |
191 189 | public boolean apply(String input) |
192 190 | { |
193 191 | return input.startsWith( "net/minecraft/server" ); |
194 192 | } |
195 193 | } ); |
196 194 | |
197 - | runProcess( "java -jar BuildData/bin/fernflower.jar -dgs=1 -hdc=0 -rbr=0 -asc=1 " + clazzDir + " " + decompileDir, CWD ); |
195 + | runProcess( CWD, "java", "-jar", "BuildData/bin/fernflower.jar", "-dgs=1", "-hdc=0", "-rbr=0", "-asc=1", clazzDir.getPath(), decompileDir.getPath() ); |
198 196 | |
199 197 | String jacobePath = jacobeDir.getPath() + "/jacobe"; |
200 198 | if ( IS_WINDOWS ) |
201 199 | { |
202 200 | jacobePath += ".exe"; |
203 201 | } |
204 - | runProcess( jacobePath + " -cfg=BuildData/bin/jacobe.cfg -nobackup -overwrite -outext=java " + decompileDir + "/net/minecraft/server", CWD ); |
202 + | runProcess( CWD, jacobePath, "-cfg=BuildData/bin/jacobe.cfg", "-nobackup", "-overwrite", "-outext=java", decompileDir + "/net/minecraft/server" ); |
205 203 | } |
206 204 | |
207 205 | System.out.println( "Applying CraftBukkit Patches" ); |
208 206 | File nmsDir = new File( craftBukkit, "src/main/java/net" ); |
209 207 | if ( nmsDir.exists() ) |
210 208 | { |
211 209 | System.out.println( "Backing up NMS dir" ); |
212 210 | FileUtils.moveDirectory( nmsDir, new File( workDir, "nms.old." + System.currentTimeMillis() ) ); |
213 211 | } |
214 212 | File patchDir = new File( craftBukkit, "nms-patches" ); |
251 249 | } |
252 250 | File spigotServer = new File( spigot, "CraftBukkit" ); |
253 251 | if ( !spigotServer.exists() ) |
254 252 | { |
255 253 | clone( "file://" + craftBukkit.getAbsolutePath(), spigotServer ); |
256 254 | } |
257 255 | |
258 256 | // Git spigotApiGit = Git.open( spigotApi ); |
259 257 | // Git spigotServerGit = Git.open( spigotServer ); |
260 258 | System.out.println( "Compiling Bukkit" ); |
261 - | runProcess( mvnCmd + " clean install", bukkit ); |
259 + | runProcess( bukkit, "sh", mvn, "clean", "install" ); |
262 260 | |
263 261 | System.out.println( "Compiling CraftBukkit" ); |
264 - | runProcess( mvnCmd + " clean install", craftBukkit ); |
262 + | runProcess( craftBukkit, "sh", mvn, "clean", "install" ); |
265 263 | |
266 264 | try |
267 265 | { |
268 - | runProcess( "bash applyPatches.sh", spigot ); |
266 + | runProcess( spigot, "bash", "applyPatches.sh" ); |
269 267 | System.out.println( "*** Spigot patches applied!" ); |
270 268 | System.out.println( "Compiling Spigot & Spigot-API" ); |
271 - | runProcess( mvnCmd + " clean install", spigot ); |
269 + | runProcess( spigot, "sh", mvn, "clean", "install" ); |
272 270 | } catch ( Exception ex ) |
273 271 | { |
274 272 | System.err.println( "Error compiling Spigot, are you running this jar via msysgit?" ); |
275 273 | ex.printStackTrace(); |
276 274 | System.exit( 1 ); |
277 275 | } |
278 276 | } |
279 277 | |
280 278 | public static void getJacobe() throws Exception |
281 279 | { |
282 280 | if ( IS_WINDOWS ) |
283 281 | { |
284 282 | File jacobeWindows = new File( "jacobe.win32.zip" ); |
285 283 | download( "http://www.tiobe.com/content/products/jacobe/jacobe.win32.zip", jacobeWindows ); |
286 284 | unzip( jacobeWindows, jacobeDir ); |
287 285 | } else |
288 286 | { |
289 287 | File jacobeLinux = new File( "jacobe.linux.tar.gz" ); |
290 288 | download( "http://www.tiobe.com/content/products/jacobe/jacobe.linux.tar.gz", jacobeLinux ); |
291 289 | |
292 290 | jacobeDir.mkdir(); |
293 - | runProcess( "tar xzvf " + jacobeLinux.getPath() + " -C " + jacobeDir.getPath(), CWD ); |
291 + | runProcess( CWD, "tar", "xzvf", jacobeLinux.getPath(), "-C", jacobeDir.getPath() ); |
294 292 | } |
295 293 | } |
296 294 | |
297 295 | public static void pull(Git repo) throws Exception |
298 296 | { |
299 297 | System.out.println( "Pulling updates for " + repo.getRepository().getDirectory() ); |
300 298 | |
301 299 | repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call(); |
302 300 | boolean result = repo.pull().call().isSuccessful(); |
303 301 | |
304 302 | if ( !result ) |
305 303 | { |
306 304 | throw new RuntimeException( "Could not pull updates!" ); |
307 305 | } |
308 306 | |
309 307 | System.out.println( "Successfully pulled updates!" ); |
310 308 | } |
311 309 | |
312 - | public static int runProcess(String command, File workDir) throws Exception |
310 + | public static int runProcess(File workDir, String... command) throws Exception |
313 311 | { |
314 - | final Process ps = new ProcessBuilder( command.split( " " ) ).directory( workDir ).start(); |
312 + | final Process ps = new ProcessBuilder( command ).directory( workDir ).start(); |
315 313 | |
316 314 | new Thread( new StreamRedirector( ps.getInputStream(), System.out ) ).start(); |
317 315 | new Thread( new StreamRedirector( ps.getErrorStream(), System.err ) ).start(); |
318 316 | |
319 317 | int status = ps.waitFor(); |
320 318 | |
321 319 | if ( status != 0 ) |
322 320 | { |
323 - | throw new RuntimeException( "Error running command, return status !=0: " + command ); |
321 + | throw new RuntimeException( "Error running command, return status !=0: " + Arrays.toString( command ) ); |
324 322 | } |
325 323 | |
326 324 | return status; |
327 325 | } |
328 326 | |
329 327 | |
330 328 | private static class StreamRedirector implements Runnable |
331 329 | { |
332 330 | |
333 331 | private final InputStream in; |