Commits

md_5 authored d6948df6b90
Get info about what to build from Jenkins.

- Will allow us to pin builds - Won't build stuff Jenkins hasn't already built
No tags

src/main/java/org/spigotmc/builder/Builder.java

Modified
1 1 package org.spigotmc.builder;
2 2
3 3 import com.google.common.base.Charsets;
4 4 import com.google.common.base.Predicate;
5 5 import com.google.common.base.Throwables;
6 6 import com.google.common.collect.Iterables;
7 7 import com.google.common.hash.Hasher;
8 8 import com.google.common.hash.Hashing;
9 9 import com.google.common.io.ByteStreams;
10 +import com.google.common.io.CharStreams;
10 11 import com.google.common.io.Files;
11 12 import com.google.common.io.Resources;
13 +import com.google.gson.Gson;
12 14 import difflib.DiffUtils;
13 15 import difflib.Patch;
14 16 import java.io.BufferedOutputStream;
15 17 import java.io.BufferedReader;
16 18 import java.io.BufferedWriter;
17 19 import java.io.File;
18 20 import java.io.FileDescriptor;
19 21 import java.io.FileNotFoundException;
20 22 import java.io.FileOutputStream;
21 23 import java.io.FileWriter;
22 24 import java.io.FilenameFilter;
23 25 import java.io.IOException;
24 26 import java.io.InputStream;
25 27 import java.io.InputStreamReader;
26 28 import java.io.OutputStream;
27 29 import java.io.PrintStream;
28 30 import java.net.URL;
31 +import java.net.URLConnection;
29 32 import java.security.KeyManagementException;
30 33 import java.security.NoSuchAlgorithmException;
31 34 import java.security.SecureRandom;
32 35 import java.security.cert.X509Certificate;
33 36 import java.util.Arrays;
34 37 import java.util.Date;
35 38 import java.util.Enumeration;
36 39 import java.util.List;
37 40 import java.util.zip.ZipEntry;
38 41 import java.util.zip.ZipFile;
54 57 {
55 58
56 59 public static final String LOG_FILE = "BuildTools.log.txt";
57 60 public static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" );
58 61 public static final File CWD = new File( "." );
59 62 public static final String MC_VERSION = "1.8";
60 63 private static boolean dontUpdate;
61 64 private static boolean skipCompile;
62 65 private static boolean generateSource;
63 66 private static boolean generateDocs;
67 + private static boolean dev;
64 68
65 69 public static void main(String[] args) throws Exception
66 70 {
67 71 for ( String s : args )
68 72 {
69 73 if ( "--disable-certificate-check".equals( s ) )
70 74 {
71 75 disableHttpsCertificateCheck();
72 76 }
73 77 if ( "--dont-update".equals( s ) )
79 83 skipCompile = true;
80 84 }
81 85 if ( "--generate-source".equals( s ) )
82 86 {
83 87 generateSource = true;
84 88 }
85 89 if ( "--generate-docs".equals( s ) )
86 90 {
87 91 generateDocs = true;
88 92 }
93 + if ( "--dev".equals( s ) )
94 + {
95 + dev = true;
96 + }
89 97 }
90 98
91 99 logOutput();
92 100
93 101 if ( Float.parseFloat( System.getProperty( "java.class.version" ) ) < 51.0 )
94 102 {
95 103 System.err.println( "*** ERROR *** BuildTools should be run with Java 7 or above." );
96 104 System.err.println( "*** ERROR *** Use java -version to check your Java version." );
97 105 return;
98 106 }
162 170 unzip( mvnTemp, new File( "." ) );
163 171 }
164 172
165 173 String mvn = maven.getAbsolutePath() + "/bin/mvn";
166 174
167 175 Git bukkitGit = Git.open( bukkit );
168 176 Git craftBukkitGit = Git.open( craftBukkit );
169 177 Git spigotGit = Git.open( spigot );
170 178 Git buildGit = Git.open( buildData );
171 179
180 + BuildInfo buildInfo = new BuildInfo( "Dev Build", "Development", new BuildInfo.Refs( "master", "master", "master", "master" ) );
181 +
172 182 if ( !dontUpdate )
173 183 {
174 - pull( bukkitGit );
175 - pull( craftBukkitGit );
176 - pull( spigotGit );
177 - pull( buildGit );
184 + if ( !dev )
185 + {
186 + System.out.println( "Checking for latest version:" );
187 +
188 + String verInfo;
189 + try
190 + {
191 + verInfo = get( "https://hub.spigotmc.org/versions/latest.json" );
192 + } catch ( IOException ex )
193 + {
194 + System.err.println( "Could not get latest version" );
195 + ex.printStackTrace();
196 + return;
197 + }
198 + System.out.println( "Found latest version" );
199 + System.out.println( verInfo );
200 +
201 + buildInfo = new Gson().fromJson( verInfo, BuildInfo.class );
202 + }
203 +
204 + pull( buildGit, buildInfo.getRefs().getBuildData() );
205 + pull( bukkitGit, buildInfo.getRefs().getBukkit() );
206 + pull( craftBukkitGit, buildInfo.getRefs().getCraftBukkit() );
207 + pull( spigotGit, buildInfo.getRefs().getSpigot() );
178 208 }
179 209
180 210 File vanillaJar = new File( workDir, "minecraft_server." + MC_VERSION + ".jar" );
181 211 if ( !vanillaJar.exists() )
182 212 {
183 213 download( String.format( "https://s3.amazonaws.com/Minecraft.Download/versions/%1$s/minecraft_server.%1$s.jar", MC_VERSION ), vanillaJar );
184 214 }
185 215
186 216 Iterable<RevCommit> mappings = buildGit.log()
187 217 .addPath( "mappings/bukkit-1.8.at" )
282 312 }
283 313 bw.close();
284 314 }
285 315 File tmpNms = new File( craftBukkit, "tmp-nms" );
286 316 FileUtils.copyDirectory( nmsDir, tmpNms );
287 317
288 318 craftBukkitGit.branchDelete().setBranchNames( "patched" ).setForce( true ).call();
289 319 craftBukkitGit.checkout().setCreateBranch( true ).setForce( true ).setName( "patched" ).call();
290 320 craftBukkitGit.add().addFilepattern( "src/main/java/net/" ).call();
291 321 craftBukkitGit.commit().setMessage( "CraftBukkit $ " + new Date() ).call();
292 - craftBukkitGit.checkout().setName( "master" ).call();
322 + craftBukkitGit.checkout().setName( buildInfo.getRefs().getCraftBukkit() ).call();
293 323
294 324 FileUtils.moveDirectory( tmpNms, nmsDir );
295 325
296 326 File spigotApi = new File( spigot, "Bukkit" );
297 327 if ( !spigotApi.exists() )
298 328 {
299 329 clone( "file://" + bukkit.getAbsolutePath(), spigotApi );
300 330 }
301 331 File spigotServer = new File( spigot, "CraftBukkit" );
302 332 if ( !spigotServer.exists() )
342 372
343 373 for ( int i = 0; i < 35; i++ )
344 374 {
345 375 System.out.println( " " );
346 376 }
347 377 System.out.println( "Success! Everything compiled successfully. Copying final .jar files now." );
348 378 copyJar( "CraftBukkit/target", "craftbukkit", "craftbukkit-" + MC_VERSION + ".jar" );
349 379 copyJar( "Spigot/Spigot-Server/target", "spigot", "spigot-" + MC_VERSION + ".jar" );
350 380 }
351 381
382 + public static final String get(String url) throws IOException
383 + {
384 + URLConnection con = new URL( url ).openConnection();
385 + con.setConnectTimeout( 5000 );
386 + con.setReadTimeout( 5000 );
387 +
388 + InputStreamReader r = null;
389 + try
390 + {
391 + r = new InputStreamReader( con.getInputStream() );
392 +
393 + return CharStreams.toString( r );
394 + } finally
395 + {
396 + if ( r != null )
397 + {
398 + r.close();
399 + }
400 + }
401 + }
402 +
352 403 public static void copyJar(String path, final String jarPrefix, String outJarName) throws Exception
353 404 {
354 405 File[] files = new File( path ).listFiles( new FilenameFilter()
355 406 {
356 407 @Override
357 408 public boolean accept(File dir, String name)
358 409 {
359 410 return name.startsWith( jarPrefix ) && name.endsWith( ".jar" );
360 411 }
361 412 } );
362 413 for ( File file : files )
363 414 {
364 415 System.out.println( "Copying " + file.getName() + " to " + CWD.getAbsolutePath() );
365 416 Files.copy( file, new File( CWD, outJarName ) );
366 417 System.out.println( " - Saved as " + outJarName );
367 418 }
368 419 }
369 420
370 - public static void pull(Git repo) throws Exception
421 + public static void pull(Git repo, String ref) throws Exception
371 422 {
372 423 System.out.println( "Pulling updates for " + repo.getRepository().getDirectory() );
373 424
374 425 repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call();
375 - boolean result = repo.pull().call().isSuccessful();
426 + repo.fetch().call();
427 +
428 + System.out.println( "Successfully fetched updates!" );
376 429
377 - if ( !result )
430 + repo.checkout().setName( ref ).call();
431 + if ( ref.equals( "master" ) )
378 432 {
379 - throw new RuntimeException( "Could not pull updates!" );
433 + repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call();
380 434 }
381 -
382 - System.out.println( "Successfully pulled updates!" );
435 + System.out.println( "Checked out: " + ref );
383 436 }
384 437
385 438 public static int runProcess(File workDir, String... command) throws Exception
386 439 {
387 440 ProcessBuilder pb = new ProcessBuilder( command );
388 441 pb.directory( workDir );
389 442 pb.environment().put( "JAVA_HOME", System.getProperty( "java.home" ) );
390 443 if ( !pb.environment().containsKey( "MAVEN_OPTS" ) )
391 444 {
392 445 pb.environment().put( "MAVEN_OPTS", "-Xmx1024M" );

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut