Remove modules and startup delay
We don’t need them for Pandacube
This commit is contained in:
@@ -74,7 +74,6 @@ import net.md_5.bungee.jni.NativeCode;
|
||||
import net.md_5.bungee.log.BungeeLogger;
|
||||
import net.md_5.bungee.log.LoggingForwardHandler;
|
||||
import net.md_5.bungee.log.LoggingOutputStream;
|
||||
import net.md_5.bungee.module.ModuleManager;
|
||||
import net.md_5.bungee.netty.PipelineUtils;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
@@ -153,7 +152,6 @@ public class BungeeCord extends ProxyServer
|
||||
private final Logger logger;
|
||||
@Getter
|
||||
private ConnectionThrottle connectionThrottle;
|
||||
private final ModuleManager moduleManager = new ModuleManager();
|
||||
|
||||
{
|
||||
// TODO: Proper fallback when we interface the manager
|
||||
@@ -278,10 +276,6 @@ public class BungeeCord extends ProxyServer
|
||||
|
||||
eventLoops = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
|
||||
|
||||
File moduleDirectory = new File( "modules" );
|
||||
moduleManager.load( this, moduleDirectory );
|
||||
pluginManager.detectPlugins( moduleDirectory );
|
||||
|
||||
pluginsFolder.mkdir();
|
||||
pluginManager.detectPlugins( pluginsFolder );
|
||||
|
||||
|
@@ -5,7 +5,6 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@@ -58,8 +57,7 @@ public class BungeeCordLauncher
|
||||
System.err.println( "*** Warning, this build is outdated ***" );
|
||||
System.err.println( "*** Please download a new build from http://ci.md-5.net/job/BungeeCord ***" );
|
||||
System.err.println( "*** You will get NO support regarding this build ***" );
|
||||
System.err.println( "*** Server will start in 10 seconds ***" );
|
||||
Thread.sleep( TimeUnit.SECONDS.toMillis( 10 ) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,35 +0,0 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.Files;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import lombok.Data;
|
||||
import net.md_5.bungee.Util;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
@Data
|
||||
public class JenkinsModuleSource implements ModuleSource
|
||||
{
|
||||
|
||||
@Override
|
||||
public void retrieve(ModuleSpec module, ModuleVersion version)
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().info( "Attempting to Jenkins download module " + module.getName() + " v" + version.getBuild() );
|
||||
try
|
||||
{
|
||||
URL website = new URL( "https://ci.md-5.net/job/BungeeCord/" + version.getBuild() + "/artifact/module/" + module.getName().replace( '_', '-' ) + "/target/" + module.getName() + ".jar" );
|
||||
URLConnection con = website.openConnection();
|
||||
// 15 second timeout at various stages
|
||||
con.setConnectTimeout( 15000 );
|
||||
con.setReadTimeout( 15000 );
|
||||
|
||||
Files.write( ByteStreams.toByteArray( con.getInputStream() ), module.getFile() );
|
||||
ProxyServer.getInstance().getLogger().info( "Download complete" );
|
||||
} catch ( IOException ex )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().warning( "Failed to download: " + Util.exception( ex ) );
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,147 +0,0 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.PluginDescription;
|
||||
import net.md_5.bungee.util.CaseInsensitiveMap;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
public class ModuleManager
|
||||
{
|
||||
|
||||
private final Map<String, ModuleSource> knownSources = new HashMap<>();
|
||||
|
||||
public ModuleManager()
|
||||
{
|
||||
knownSources.put( "jenkins", new JenkinsModuleSource() );
|
||||
}
|
||||
|
||||
public void load(ProxyServer proxy, File moduleDirectory) throws Exception
|
||||
{
|
||||
moduleDirectory.mkdir();
|
||||
|
||||
ModuleVersion bungeeVersion = ModuleVersion.parse( proxy.getVersion() );
|
||||
if ( bungeeVersion == null )
|
||||
{
|
||||
proxy.getLogger().warning( "Couldn't detect bungee version. Custom build?" );
|
||||
return;
|
||||
}
|
||||
|
||||
List<ModuleSpec> modules = new ArrayList<>();
|
||||
File configFile = new File( "modules.yml" );
|
||||
// Start Yaml
|
||||
DumperOptions options = new DumperOptions();
|
||||
options.setDefaultFlowStyle( DumperOptions.FlowStyle.BLOCK );
|
||||
Yaml yaml = new Yaml( options );
|
||||
|
||||
Map<String, Object> config;
|
||||
|
||||
configFile.createNewFile();
|
||||
try ( InputStream is = new FileInputStream( configFile ) )
|
||||
{
|
||||
config = (Map) yaml.load( is );
|
||||
}
|
||||
|
||||
if ( config == null )
|
||||
{
|
||||
config = new CaseInsensitiveMap<>();
|
||||
} else
|
||||
{
|
||||
config = new CaseInsensitiveMap<>( config );
|
||||
}
|
||||
// End yaml
|
||||
|
||||
List<String> defaults = new ArrayList<>();
|
||||
Object readModules = config.get( "modules" );
|
||||
if ( readModules != null )
|
||||
{
|
||||
defaults.addAll( (Collection) readModules );
|
||||
}
|
||||
int version = ( config.containsKey( "version" ) ) ? (int) config.get( "version" ) : 0;
|
||||
switch ( version )
|
||||
{
|
||||
case 0:
|
||||
defaults.add( "jenkins://cmd_alert" );
|
||||
defaults.add( "jenkins://cmd_find" );
|
||||
defaults.add( "jenkins://cmd_list" );
|
||||
defaults.add( "jenkins://cmd_send" );
|
||||
defaults.add( "jenkins://cmd_server" );
|
||||
case 1:
|
||||
defaults.add( "jenkins://reconnect_yaml" );
|
||||
}
|
||||
config.put( "modules", defaults );
|
||||
config.put( "version", 2 );
|
||||
|
||||
try ( FileWriter wr = new FileWriter( configFile ) )
|
||||
{
|
||||
yaml.dump( config, wr );
|
||||
}
|
||||
|
||||
for ( String s : (List<String>) config.get( "modules" ) )
|
||||
{
|
||||
URI uri = new URI( s );
|
||||
|
||||
ModuleSource source = knownSources.get( uri.getScheme() );
|
||||
if ( source == null )
|
||||
{
|
||||
proxy.getLogger().warning( "Unknown module source: " + s );
|
||||
continue;
|
||||
}
|
||||
String name = uri.getAuthority();
|
||||
if ( name == null )
|
||||
{
|
||||
proxy.getLogger().warning( "Unknown module host: " + s );
|
||||
continue;
|
||||
}
|
||||
|
||||
ModuleSpec spec = new ModuleSpec( name, new File( moduleDirectory, name + ".jar" ), source );
|
||||
modules.add( spec );
|
||||
proxy.getLogger().info( "Discovered module: " + spec );
|
||||
}
|
||||
|
||||
for ( ModuleSpec module : modules )
|
||||
{
|
||||
ModuleVersion moduleVersion = ( module.getFile().exists() ) ? getVersion( module.getFile() ) : null;
|
||||
|
||||
if ( !bungeeVersion.equals( moduleVersion ) )
|
||||
{
|
||||
proxy.getLogger().info( "Attempting to update plugin from " + moduleVersion + " to " + bungeeVersion );
|
||||
module.getProvider().retrieve( module, bungeeVersion );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ModuleVersion getVersion(File file)
|
||||
{
|
||||
try ( JarFile jar = new JarFile( file ) )
|
||||
{
|
||||
JarEntry pdf = jar.getJarEntry( "plugin.yml" );
|
||||
Preconditions.checkNotNull( pdf, "Plugin must have a plugin.yml" );
|
||||
|
||||
try ( InputStream in = jar.getInputStream( pdf ) )
|
||||
{
|
||||
PluginDescription desc = new Yaml().loadAs( in, PluginDescription.class );
|
||||
return ModuleVersion.parse( desc.getVersion() );
|
||||
}
|
||||
} catch ( Exception ex )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not check module from file " + file, ex );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
interface ModuleSource
|
||||
{
|
||||
|
||||
void retrieve(ModuleSpec module, ModuleVersion version);
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
import java.io.File;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ModuleSpec
|
||||
{
|
||||
|
||||
private final String name;
|
||||
private final File file;
|
||||
private final ModuleSource provider;
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ModuleVersion
|
||||
{
|
||||
|
||||
private final String build;
|
||||
private final String git;
|
||||
|
||||
public static ModuleVersion parse(String version)
|
||||
{
|
||||
int lastColon = version.lastIndexOf( ':' );
|
||||
int secondLastColon = version.lastIndexOf( ':', lastColon - 1 );
|
||||
|
||||
if ( lastColon == -1 || secondLastColon == -1 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String buildNumber = version.substring( lastColon + 1, version.length() );
|
||||
String gitCommit = version.substring( secondLastColon + 1, lastColon ).replaceAll( "\"", "" );
|
||||
|
||||
if ( "unknown".equals( buildNumber ) || "unknown".equals( gitCommit ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ModuleVersion( buildNumber, gitCommit );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user