Log output to BuildTools.log.txt

Conflicts:
	src/main/java/org/spigotmc/builder/Builder.java
This commit is contained in:
Antony Riley 2014-12-12 11:21:43 +11:00 committed by md_5
parent a664e1f263
commit 7b889b881f

View file

@ -11,9 +11,12 @@ import com.google.common.io.Files;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import difflib.DiffUtils; import difflib.DiffUtils;
import difflib.Patch; import difflib.Patch;
import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.FilenameFilter; import java.io.FilenameFilter;
@ -25,6 +28,7 @@ import java.io.PrintStream;
import java.net.URL; import java.net.URL;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -40,6 +44,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.TeeOutputStream;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
@ -48,6 +53,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
public class Builder public class Builder
{ {
public static final String LOG_FILE = "BuildTools.log.txt";
public static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" ); public static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" );
public static final boolean IS_MAC = System.getProperty( "os.name" ).startsWith( "Mac" ); public static final boolean IS_MAC = System.getProperty( "os.name" ).startsWith( "Mac" );
public static final File CWD = new File( "." ); public static final File CWD = new File( "." );
@ -68,6 +74,9 @@ public class Builder
dontUpdate = true; dontUpdate = true;
} }
} }
logOutput();
if ( IS_MAC ) if ( IS_MAC )
{ {
System.out.println( "Sorry, but Macintosh is not currently a supported platform for compilation at this time." ); System.out.println( "Sorry, but Macintosh is not currently a supported platform for compilation at this time." );
@ -299,7 +308,10 @@ public class Builder
System.exit( 1 ); System.exit( 1 );
} }
for ( int i = 0; i < 35; i++ ) System.out.println( " " ); for ( int i = 0; i < 35; i++ )
{
System.out.println( " " );
}
System.out.println( "Success! Everything compiled successfully. Copying final .jar files now." ); System.out.println( "Success! Everything compiled successfully. Copying final .jar files now." );
copyJar( "CraftBukkit/target", "craftbukkit", "craftbukkit-" + MC_VERSION + ".jar" ); copyJar( "CraftBukkit/target", "craftbukkit", "craftbukkit-" + MC_VERSION + ".jar" );
copyJar( "Spigot/Spigot-Server/target", "spigot", "spigot-" + MC_VERSION + ".jar" ); copyJar( "Spigot/Spigot-Server/target", "spigot", "spigot-" + MC_VERSION + ".jar" );
@ -480,27 +492,45 @@ public class Builder
return target; return target;
} }
public static void disableHttpsCertificateCheck() { public static void disableHttpsCertificateCheck()
{
// This globally disables certificate checking // This globally disables certificate checking
// http://stackoverflow.com/questions/19723415/java-overriding-function-to-disable-ssl-certificate-check // http://stackoverflow.com/questions/19723415/java-overriding-function-to-disable-ssl-certificate-check
try try
{ {
TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { TrustManager[] trustAllCerts = new TrustManager[]
public java.security.cert.X509Certificate[] getAcceptedIssuers() { {
new X509TrustManager()
{
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
return null; return null;
} }
public void checkClientTrusted(X509Certificate[] certs, String authType) {
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType)
{
} }
public void checkServerTrusted(X509Certificate[] certs, String authType) {
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType)
{
} }
} }
}; };
// Trust SSL certs
SSLContext sc = SSLContext.getInstance( "SSL" ); SSLContext sc = SSLContext.getInstance( "SSL" );
sc.init(null, trustAllCerts, new java.security.SecureRandom()); sc.init( null, trustAllCerts, new SecureRandom() );
HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory() ); HttpsURLConnection.setDefaultSSLSocketFactory( sc.getSocketFactory() );
HostnameVerifier allHostsValid = new HostnameVerifier() { // Trust host names
public boolean verify(String hostname, SSLSession session) { HostnameVerifier allHostsValid = new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true; return true;
} }
}; };
@ -508,11 +538,42 @@ public class Builder
} catch ( NoSuchAlgorithmException ex ) } catch ( NoSuchAlgorithmException ex )
{ {
System.out.println( "Failed to disable https certificate check" ); System.out.println( "Failed to disable https certificate check" );
ex.printStackTrace(System.out); ex.printStackTrace( System.err );
} catch ( KeyManagementException ex ) } catch ( KeyManagementException ex )
{ {
System.out.println( "Failed to disable https certificate check" ); System.out.println( "Failed to disable https certificate check" );
ex.printStackTrace(System.out); ex.printStackTrace( System.err );
}
}
public static void logOutput()
{
try
{
final OutputStream logOut = new BufferedOutputStream( new FileOutputStream( LOG_FILE ) );
Runtime.getRuntime().addShutdownHook( new Thread()
{
@Override
public void run()
{
System.setOut( new PrintStream( new FileOutputStream( FileDescriptor.out ) ) );
System.setErr( new PrintStream( new FileOutputStream( FileDescriptor.err ) ) );
try
{
logOut.close();
} catch ( IOException ex )
{
// We're shutting the jvm down anyway.
}
}
} );
System.setOut( new PrintStream( new TeeOutputStream( System.out, logOut ) ) );
System.setErr( new PrintStream( new TeeOutputStream( System.err, logOut ) ) );
} catch ( FileNotFoundException ex )
{
System.err.println( "Failed to create log file: " + LOG_FILE );
} }
} }
} }