Commits

Antony Riley authored and md_5 committed 7b889b881fe
Log output to BuildTools.log.txt

Conflicts: src/main/java/org/spigotmc/builder/Builder.java
No tags

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

Modified
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 10 import com.google.common.io.Files;
11 11 import com.google.common.io.Resources;
12 12 import difflib.DiffUtils;
13 13 import difflib.Patch;
14 +import java.io.BufferedOutputStream;
14 15 import java.io.BufferedReader;
15 16 import java.io.BufferedWriter;
16 17 import java.io.File;
18 +import java.io.FileDescriptor;
19 +import java.io.FileNotFoundException;
17 20 import java.io.FileOutputStream;
18 21 import java.io.FileWriter;
19 22 import java.io.FilenameFilter;
20 23 import java.io.IOException;
21 24 import java.io.InputStream;
22 25 import java.io.InputStreamReader;
23 26 import java.io.OutputStream;
24 27 import java.io.PrintStream;
25 28 import java.net.URL;
26 29 import java.security.KeyManagementException;
27 30 import java.security.NoSuchAlgorithmException;
31 +import java.security.SecureRandom;
28 32 import java.security.cert.X509Certificate;
29 33 import java.util.Arrays;
30 34 import java.util.Date;
31 35 import java.util.Enumeration;
32 36 import java.util.List;
33 37 import java.util.zip.ZipEntry;
34 38 import java.util.zip.ZipFile;
35 39 import javax.net.ssl.HostnameVerifier;
36 40 import javax.net.ssl.HttpsURLConnection;
37 41 import javax.net.ssl.SSLContext;
38 42 import javax.net.ssl.SSLSession;
39 43 import javax.net.ssl.TrustManager;
40 44 import javax.net.ssl.X509TrustManager;
41 45 import lombok.RequiredArgsConstructor;
42 46 import org.apache.commons.io.FileUtils;
47 +import org.apache.commons.io.output.TeeOutputStream;
43 48 import org.eclipse.jgit.api.Git;
44 49 import org.eclipse.jgit.api.ResetCommand;
45 50 import org.eclipse.jgit.api.errors.GitAPIException;
46 51 import org.eclipse.jgit.revwalk.RevCommit;
47 52
48 53 public class Builder
49 54 {
50 55
56 + public static final String LOG_FILE = "BuildTools.log.txt";
51 57 public static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" );
52 58 public static final boolean IS_MAC = System.getProperty( "os.name" ).startsWith( "Mac" );
53 59 public static final File CWD = new File( "." );
54 60 public static final String MC_VERSION = "1.8";
55 61 private static final File jacobeDir = new File( "jacobe" );
56 62 private static boolean dontUpdate;
57 63
58 64 public static void main(String[] args) throws Exception
59 65 {
60 66 for ( String s : args )
61 67 {
62 68 if ( "--disable-certificate-check".equals( s ) )
63 69 {
64 70 disableHttpsCertificateCheck();
65 71 }
66 72 if ( "--dont-update".equals( s ) )
67 73 {
68 74 dontUpdate = true;
69 75 }
70 76 }
77 +
78 + logOutput();
79 +
71 80 if ( IS_MAC )
72 81 {
73 82 System.out.println( "Sorry, but Macintosh is not currently a supported platform for compilation at this time." );
74 83 System.out.println( "Please run this script on a Windows or Linux PC and then copy the jars to this computer." );
75 84 System.exit( 1 );
76 85 }
77 86
78 87 try
79 88 {
80 89 runProcess( CWD, "bash", "-c", "exit" );
292 301 System.out.println( "*** Spigot patches applied!" );
293 302 System.out.println( "Compiling Spigot & Spigot-API" );
294 303 runProcess( spigot, "sh", mvn, "clean", "install" );
295 304 } catch ( Exception ex )
296 305 {
297 306 System.err.println( "Error compiling Spigot, are you running this jar via msysgit?" );
298 307 ex.printStackTrace();
299 308 System.exit( 1 );
300 309 }
301 310
302 - for ( int i = 0; i < 35; i++ ) System.out.println( " " );
311 + for ( int i = 0; i < 35; i++ )
312 + {
313 + System.out.println( " " );
314 + }
303 315 System.out.println( "Success! Everything compiled successfully. Copying final .jar files now." );
304 316 copyJar( "CraftBukkit/target", "craftbukkit", "craftbukkit-" + MC_VERSION + ".jar" );
305 317 copyJar( "Spigot/Spigot-Server/target", "spigot", "spigot-" + MC_VERSION + ".jar" );
306 318 }
307 319
308 - public static void copyJar( String path, final String jarPrefix, String outJarName ) throws Exception
320 + public static void copyJar(String path, final String jarPrefix, String outJarName) throws Exception
309 321 {
310 322 File[] files = new File( path ).listFiles( new FilenameFilter()
311 323 {
312 324 @Override
313 - public boolean accept( File dir, String name )
325 + public boolean accept(File dir, String name)
314 326 {
315 327 return name.startsWith( jarPrefix ) && name.endsWith( ".jar" );
316 328 }
317 329 } );
318 330 for ( File file : files )
319 331 {
320 332 System.out.println( "Copying " + file.getName() + " to " + CWD.getAbsolutePath() );
321 333 Files.copy( file, new File( CWD, outJarName ) );
322 334 System.out.println( " - Saved as " + outJarName );
323 335 }
473 485
474 486 byte[] bytes = Resources.toByteArray( new URL( url ) );
475 487
476 488 System.out.println( "Downloaded file: " + target + " with md5: " + Hashing.md5().hashBytes( bytes ).toString() );
477 489
478 490 Files.write( bytes, target );
479 491
480 492 return target;
481 493 }
482 494
483 - public static void disableHttpsCertificateCheck() {
495 + public static void disableHttpsCertificateCheck()
496 + {
484 497 // This globally disables certificate checking
485 498 // http://stackoverflow.com/questions/19723415/java-overriding-function-to-disable-ssl-certificate-check
486 499 try
487 500 {
488 - TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
489 - public java.security.cert.X509Certificate[] getAcceptedIssuers() {
490 - return null;
491 - }
492 - public void checkClientTrusted(X509Certificate[] certs, String authType) {
493 - }
494 - public void checkServerTrusted(X509Certificate[] certs, String authType) {
501 + TrustManager[] trustAllCerts = new TrustManager[]
502 + {
503 + new X509TrustManager()
504 + {
505 + @Override
506 + public java.security.cert.X509Certificate[] getAcceptedIssuers()
507 + {
508 + return null;
509 + }
510 +
511 + @Override
512 + public void checkClientTrusted(X509Certificate[] certs, String authType)
513 + {
514 + }
515 +
516 + @Override
517 + public void checkServerTrusted(X509Certificate[] certs, String authType)
518 + {
519 + }
495 520 }
496 - }
497 521 };
498 - SSLContext sc = SSLContext.getInstance("SSL");
499 - sc.init(null, trustAllCerts, new java.security.SecureRandom());
500 - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
501 -
502 - HostnameVerifier allHostsValid = new HostnameVerifier() {
503 - public boolean verify(String hostname, SSLSession session) {
522 +
523 + // Trust SSL certs
524 + SSLContext sc = SSLContext.getInstance( "SSL" );
525 + sc.init( null, trustAllCerts, new SecureRandom() );
526 + HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory() );
527 +
528 + // Trust host names
529 + HostnameVerifier allHostsValid = new HostnameVerifier()
530 + {
531 + @Override
532 + public boolean verify(String hostname, SSLSession session)
533 + {
504 534 return true;
505 535 }
506 536 };
507 - HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
537 + HttpsURLConnection.setDefaultHostnameVerifier( allHostsValid );
508 538 } catch ( NoSuchAlgorithmException ex )
509 539 {
510 - System.out.println("Failed to disable https certificate check");
511 - ex.printStackTrace(System.out);
540 + System.out.println( "Failed to disable https certificate check" );
541 + ex.printStackTrace( System.err );
512 542 } catch ( KeyManagementException ex )
513 543 {
514 - System.out.println("Failed to disable https certificate check");
515 - ex.printStackTrace(System.out);
544 + System.out.println( "Failed to disable https certificate check" );
545 + ex.printStackTrace( System.err );
546 + }
547 + }
548 +
549 + public static void logOutput()
550 + {
551 + try
552 + {
553 + final OutputStream logOut = new BufferedOutputStream( new FileOutputStream( LOG_FILE ) );
554 +
555 + Runtime.getRuntime().addShutdownHook( new Thread()
556 + {
557 + @Override
558 + public void run()
559 + {
560 + System.setOut( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
561 + System.setErr( new PrintStream( new FileOutputStream( FileDescriptor.err ) ) );
562 + try
563 + {
564 + logOut.close();
565 + } catch ( IOException ex )
566 + {
567 + // We're shutting the jvm down anyway.
568 + }
569 + }
570 + } );
571 +
572 + System.setOut( new PrintStream( new TeeOutputStream( System.out, logOut ) ) );
573 + System.setErr( new PrintStream( new TeeOutputStream( System.err, logOut ) ) );
574 + } catch ( FileNotFoundException ex )
575 + {
576 + System.err.println( "Failed to create log file: " + LOG_FILE );
516 577 }
517 578 }
518 579 }

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

Add shortcut