Commits
md_5 authored 925ce399c85
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 + | import com.google.common.collect.ObjectArrays; |
7 8 | import com.google.common.hash.Hasher; |
8 9 | import com.google.common.hash.Hashing; |
9 10 | import com.google.common.io.ByteStreams; |
10 11 | import com.google.common.io.CharStreams; |
11 12 | import com.google.common.io.Files; |
12 13 | import com.google.common.io.Resources; |
13 14 | import com.google.gson.Gson; |
14 15 | import difflib.DiffUtils; |
15 16 | import difflib.Patch; |
16 17 | import java.awt.Desktop; |
68 69 | public static final String LOG_FILE = "BuildTools.log.txt"; |
69 70 | public static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" ); |
70 71 | public static final File CWD = new File( "." ); |
71 72 | private static final boolean autocrlf = !"\n".equals( System.getProperty( "line.separator" ) ); |
72 73 | private static boolean dontUpdate; |
73 74 | private static boolean skipCompile; |
74 75 | private static boolean generateSource; |
75 76 | private static boolean generateDocs; |
76 77 | private static boolean dev; |
77 78 | private static String applyPatchesShell = "sh"; |
79 + | // |
80 + | private static File msysDir; |
78 81 | |
79 82 | public static void main(String[] args) throws Exception |
80 83 | { |
81 84 | if ( CWD.getAbsolutePath().contains( "'" ) || CWD.getAbsolutePath().contains( "#" ) ) |
82 85 | { |
83 86 | System.err.println( "Please do not run in a path with special characters!" ); |
84 87 | return; |
85 88 | } |
86 89 | |
87 90 | if ( false && System.console() == null ) |
136 139 | generateDocs = options.has( generateDocsFlag ); |
137 140 | dev = options.has( devFlag ); |
138 141 | |
139 142 | logOutput(); |
140 143 | |
141 144 | try |
142 145 | { |
143 146 | runProcess( CWD, "sh", "-c", "exit" ); |
144 147 | } catch ( Exception ex ) |
145 148 | { |
146 - | System.out.println( "You must run this jar through bash (msysgit)" ); |
147 - | System.exit( 1 ); |
149 + | if ( IS_WINDOWS ) |
150 + | { |
151 + | String gitVersion = "PortableGit-2.15.0-" + ( System.getProperty( "os.arch" ).endsWith( "64" ) ? "64" : "32" ) + "-bit"; |
152 + | msysDir = new File( gitVersion, "PortableGit" ); |
153 + | |
154 + | if ( !msysDir.isDirectory() ) |
155 + | { |
156 + | System.out.println( "*** Could not find PortableGit installation, downloading. ***" ); |
157 + | |
158 + | String gitName = gitVersion + ".7z.exe"; |
159 + | File gitInstall = new File( gitVersion, gitName ); |
160 + | gitInstall.getParentFile().mkdirs(); |
161 + | |
162 + | if ( !gitInstall.exists() ) |
163 + | { |
164 + | download( "https://static.spigotmc.org/git/" + gitName, gitInstall ); |
165 + | } |
166 + | |
167 + | System.out.println( "Extracting downloaded git install" ); |
168 + | // yes to all, silent, don't run. Only -y seems to work |
169 + | runProcess( gitInstall.getParentFile(), gitInstall.getAbsolutePath(), "-y", "-gm2", "-nr" ); |
170 + | |
171 + | gitInstall.delete(); |
172 + | } |
173 + | |
174 + | System.out.println( "*** Using downloaded git " + msysDir + " ***" ); |
175 + | System.out.println( "*** Please note that this is a beta feature, so if it does not work please also try a manual install of git from https://git-for-windows.github.io/ ***" ); |
176 + | } else |
177 + | { |
178 + | System.out.println( "You must run this jar through bash (msysgit)" ); |
179 + | System.exit( 1 ); |
180 + | } |
148 181 | } |
149 182 | |
150 183 | try |
151 184 | { |
152 185 | runProcess( CWD, "git", "config", "--global", "--includes", "user.name" ); |
153 186 | } catch ( Exception ex ) |
154 187 | { |
155 188 | System.out.println( "Git name not set, setting it to default value." ); |
156 189 | runProcess( CWD, "git", "config", "--global", "user.name", "BuildTools" ); |
157 190 | } |
532 565 | |
533 566 | repo.reset().setRef( ref ).setMode( ResetCommand.ResetType.HARD ).call(); |
534 567 | if ( ref.equals( "master" ) ) |
535 568 | { |
536 569 | repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call(); |
537 570 | } |
538 571 | System.out.println( "Checked out: " + ref ); |
539 572 | } |
540 573 | |
541 574 | public static int runProcess(File workDir, String... command) throws Exception |
575 + | { |
576 + | if ( msysDir != null ) |
577 + | { |
578 + | if ( "bash".equals( command[0] ) ) |
579 + | { |
580 + | command[0] = "git-bash"; |
581 + | } |
582 + | String[] shim = new String[] |
583 + | { |
584 + | "cmd.exe", "/C" |
585 + | }; |
586 + | command = ObjectArrays.concat( shim, command, String.class ); |
587 + | } |
588 + | return runProcess0( workDir, command ); |
589 + | } |
590 + | |
591 + | private static int runProcess0(File workDir, String... command) throws Exception |
542 592 | { |
543 593 | ProcessBuilder pb = new ProcessBuilder( command ); |
544 594 | pb.directory( workDir ); |
545 595 | pb.environment().put( "JAVA_HOME", System.getProperty( "java.home" ) ); |
546 596 | if ( !pb.environment().containsKey( "MAVEN_OPTS" ) ) |
547 597 | { |
548 598 | pb.environment().put( "MAVEN_OPTS", "-Xmx1024M" ); |
549 599 | } |
600 + | if ( msysDir != null ) |
601 + | { |
602 + | String pathEnv = null; |
603 + | for ( String key : pb.environment().keySet() ) |
604 + | { |
605 + | if ( key.equalsIgnoreCase( "path" ) ) |
606 + | { |
607 + | pathEnv = key; |
608 + | } |
609 + | } |
610 + | if ( pathEnv == null ) |
611 + | { |
612 + | throw new IllegalStateException( "Could not find path variable!" ); |
613 + | } |
614 + | |
615 + | String path = pb.environment().get( pathEnv ); |
616 + | path += ";" + msysDir.getAbsolutePath(); |
617 + | path += ";" + new File( msysDir, "bin" ).getAbsolutePath(); |
618 + | pb.environment().put( pathEnv, path ); |
619 + | } |
550 620 | |
551 621 | final Process ps = pb.start(); |
552 622 | |
553 623 | new Thread( new StreamRedirector( ps.getInputStream(), System.out ) ).start(); |
554 624 | new Thread( new StreamRedirector( ps.getErrorStream(), System.err ) ).start(); |
555 625 | |
556 626 | int status = ps.waitFor(); |
557 627 | |
558 628 | if ( status != 0 ) |
559 629 | { |