mirror of
https://hub.spigotmc.org/stash/scm/spigot/buildtools.git
synced 2025-08-31 22:29:10 +00:00
#41: Fix for Empty Repo Folders & New Flag for CI Tools
This commit is contained in:
parent
dad88319bd
commit
19d26b6581
1 changed files with 30 additions and 10 deletions
|
@ -68,6 +68,7 @@ import org.eclipse.jgit.api.errors.GitAPIException;
|
||||||
import org.eclipse.jgit.api.errors.JGitInternalException;
|
import org.eclipse.jgit.api.errors.JGitInternalException;
|
||||||
import org.eclipse.jgit.lib.StoredConfig;
|
import org.eclipse.jgit.lib.StoredConfig;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
|
import org.eclipse.jgit.transport.FetchResult;
|
||||||
|
|
||||||
public class Builder
|
public class Builder
|
||||||
{
|
{
|
||||||
|
@ -82,6 +83,7 @@ public class Builder
|
||||||
private static boolean generateDocs;
|
private static boolean generateDocs;
|
||||||
private static boolean dev;
|
private static boolean dev;
|
||||||
private static String applyPatchesShell = "sh";
|
private static String applyPatchesShell = "sh";
|
||||||
|
private static boolean didClone = false;
|
||||||
//
|
//
|
||||||
private static File msysDir;
|
private static File msysDir;
|
||||||
|
|
||||||
|
@ -149,6 +151,7 @@ public class Builder
|
||||||
OptionSpec<Compile> toCompile = parser.accepts( "compile", "Software to compile" ).withRequiredArg().ofType( Compile.class ).withValuesConvertedBy( new EnumConverter<Compile>( Compile.class )
|
OptionSpec<Compile> toCompile = parser.accepts( "compile", "Software to compile" ).withRequiredArg().ofType( Compile.class ).withValuesConvertedBy( new EnumConverter<Compile>( Compile.class )
|
||||||
{
|
{
|
||||||
} ).withValuesSeparatedBy( ',' );
|
} ).withValuesSeparatedBy( ',' );
|
||||||
|
OptionSpec<Void> compileIfChanged = parser.accepts( "compile-if-changed", "Run BuildTools only when changes are detected in the repository" );
|
||||||
|
|
||||||
OptionSet options = parser.parse( args );
|
OptionSet options = parser.parse( args );
|
||||||
|
|
||||||
|
@ -249,25 +252,25 @@ public class Builder
|
||||||
workDir.mkdir();
|
workDir.mkdir();
|
||||||
|
|
||||||
File bukkit = new File( "Bukkit" );
|
File bukkit = new File( "Bukkit" );
|
||||||
if ( !bukkit.exists() )
|
if ( !bukkit.exists() || !containsGit( bukkit ) )
|
||||||
{
|
{
|
||||||
clone( "https://hub.spigotmc.org/stash/scm/spigot/bukkit.git", bukkit );
|
clone( "https://hub.spigotmc.org/stash/scm/spigot/bukkit.git", bukkit );
|
||||||
}
|
}
|
||||||
|
|
||||||
File craftBukkit = new File( "CraftBukkit" );
|
File craftBukkit = new File( "CraftBukkit" );
|
||||||
if ( !craftBukkit.exists() )
|
if ( !craftBukkit.exists() || !containsGit( craftBukkit ) )
|
||||||
{
|
{
|
||||||
clone( "https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git", craftBukkit );
|
clone( "https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git", craftBukkit );
|
||||||
}
|
}
|
||||||
|
|
||||||
File spigot = new File( "Spigot" );
|
File spigot = new File( "Spigot" );
|
||||||
if ( !spigot.exists() )
|
if ( !spigot.exists() || !containsGit( spigot ) )
|
||||||
{
|
{
|
||||||
clone( "https://hub.spigotmc.org/stash/scm/spigot/spigot.git", spigot );
|
clone( "https://hub.spigotmc.org/stash/scm/spigot/spigot.git", spigot );
|
||||||
}
|
}
|
||||||
|
|
||||||
File buildData = new File( "BuildData" );
|
File buildData = new File( "BuildData" );
|
||||||
if ( !buildData.exists() )
|
if ( !buildData.exists() || !containsGit( buildData ) )
|
||||||
{
|
{
|
||||||
clone( "https://hub.spigotmc.org/stash/scm/spigot/builddata.git", buildData );
|
clone( "https://hub.spigotmc.org/stash/scm/spigot/builddata.git", buildData );
|
||||||
}
|
}
|
||||||
|
@ -355,10 +358,18 @@ public class Builder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pull( buildGit, buildInfo.getRefs().getBuildData() );
|
boolean buildDataChanged = pull( buildGit, buildInfo.getRefs().getBuildData() );
|
||||||
pull( bukkitGit, buildInfo.getRefs().getBukkit() );
|
boolean bukkitChanged = pull( bukkitGit, buildInfo.getRefs().getBukkit() );
|
||||||
pull( craftBukkitGit, buildInfo.getRefs().getCraftBukkit() );
|
boolean craftBukkitChanged = pull( craftBukkitGit, buildInfo.getRefs().getCraftBukkit() );
|
||||||
pull( spigotGit, buildInfo.getRefs().getSpigot() );
|
boolean spigotChanged = pull( spigotGit, buildInfo.getRefs().getSpigot() );
|
||||||
|
|
||||||
|
// Checks if any of the 4 repositories have been updated via a fetch, the --compile-if-changed flag is set and none of the repositories were cloned in this run.
|
||||||
|
if ( !buildDataChanged && !bukkitChanged && !craftBukkitChanged && !spigotChanged && options.has( compileIfChanged ) && !didClone )
|
||||||
|
{
|
||||||
|
System.out.println( "*** No changes detected in any of the repositories!" );
|
||||||
|
System.out.println( "*** Exiting due to the --compile-if-changes" );
|
||||||
|
System.exit( 0 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VersionInfo versionInfo = new Gson().fromJson(
|
VersionInfo versionInfo = new Gson().fromJson(
|
||||||
|
@ -700,7 +711,7 @@ public class Builder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pull(Git repo, String ref) throws Exception
|
public static boolean pull(Git repo, String ref) throws Exception
|
||||||
{
|
{
|
||||||
System.out.println( "Pulling updates for " + repo.getRepository().getDirectory() );
|
System.out.println( "Pulling updates for " + repo.getRepository().getDirectory() );
|
||||||
|
|
||||||
|
@ -712,7 +723,7 @@ public class Builder
|
||||||
System.err.println( "*** Warning, could not find origin/master ref, but continuing anyway." );
|
System.err.println( "*** Warning, could not find origin/master ref, but continuing anyway." );
|
||||||
System.err.println( "*** If further errors occur please delete " + repo.getRepository().getDirectory().getParent() + " and retry." );
|
System.err.println( "*** If further errors occur please delete " + repo.getRepository().getDirectory().getParent() + " and retry." );
|
||||||
}
|
}
|
||||||
repo.fetch().call();
|
FetchResult result = repo.fetch().call();
|
||||||
|
|
||||||
System.out.println( "Successfully fetched updates!" );
|
System.out.println( "Successfully fetched updates!" );
|
||||||
|
|
||||||
|
@ -722,6 +733,9 @@ public class Builder
|
||||||
repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call();
|
repo.reset().setRef( "origin/master" ).setMode( ResetCommand.ResetType.HARD ).call();
|
||||||
}
|
}
|
||||||
System.out.println( "Checked out: " + ref );
|
System.out.println( "Checked out: " + ref );
|
||||||
|
|
||||||
|
// Return true if fetch changed any tracking refs.
|
||||||
|
return !result.getTrackingRefUpdates().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int runProcess(File workDir, String... command) throws Exception
|
public static int runProcess(File workDir, String... command) throws Exception
|
||||||
|
@ -899,6 +913,7 @@ public class Builder
|
||||||
config.setBoolean( "core", null, "autocrlf", autocrlf );
|
config.setBoolean( "core", null, "autocrlf", autocrlf );
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
|
didClone = true;
|
||||||
System.out.println( "Cloned git repository " + url + " to " + target.getAbsolutePath() + ". Current HEAD: " + commitHash( result ) );
|
System.out.println( "Cloned git repository " + url + " to " + target.getAbsolutePath() + ". Current HEAD: " + commitHash( result ) );
|
||||||
} finally
|
} finally
|
||||||
{
|
{
|
||||||
|
@ -1043,4 +1058,9 @@ public class Builder
|
||||||
|
|
||||||
public abstract HashFunction getHash();
|
public abstract HashFunction getHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean containsGit(File file)
|
||||||
|
{
|
||||||
|
return new File( file, ".git" ).isDirectory();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue