mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-12-25 10:07:38 +01:00
Implement a first tempt and module retrieval system
This commit is contained in:
parent
a426a5ec22
commit
ab1aacbdc9
@ -1,5 +1,6 @@
|
||||
package net.md_5.bungee;
|
||||
|
||||
import net.md_5.bungee.module.ModuleManager;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -1,38 +0,0 @@
|
||||
package net.md_5.bungee;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
public class ModuleManager
|
||||
{
|
||||
|
||||
private class ModuleSpec
|
||||
{
|
||||
}
|
||||
|
||||
public void load(ProxyServer proxy) throws Exception
|
||||
{
|
||||
String version = proxy.getVersion();
|
||||
version = "git:BungeeCord-Proxy:1.7-SNAPSHOT:\"93cf50b\":1337";
|
||||
|
||||
int lastColon = version.lastIndexOf( ':' );
|
||||
int secondLastColon = version.lastIndexOf( ':', lastColon - 1 );
|
||||
String buildNumber = version.substring( lastColon + 1, version.length() );
|
||||
String gitCommit = version.substring( secondLastColon + 1, lastColon ).replaceAll( "\"", "" );
|
||||
|
||||
File moduleDirectory = new File( "modules" );
|
||||
moduleDirectory.mkdir();
|
||||
|
||||
List<ModuleSpec> modules = null;
|
||||
|
||||
// TODO: Use filename filter here and in PluginManager
|
||||
for ( File file : moduleDirectory.listFiles() )
|
||||
{
|
||||
if ( file.isFile() && file.getName().endsWith( ".jar" ) )
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
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 net.md_5.bungee.Util;
|
||||
|
||||
public class JenkinsModuleSource implements ModuleSource
|
||||
{
|
||||
|
||||
@Override
|
||||
public void retrieve(ModuleSpec module, ModuleVersion version)
|
||||
{
|
||||
System.out.println( "Attempting to Jenkins download module " + module.getName() + "v" + version.getBuild() );
|
||||
try
|
||||
{
|
||||
URL website = new URL( "http://ci.md-5.net/job/BungeeCord/" + version.getBuild() + "/artifact/module/" + module.getName().replace( '_', '-' ) + "/target/" + module.getName() + ".jar" );
|
||||
Files.copy( ByteStreams.newInputStreamSupplier( ByteStreams.toByteArray( website.openStream() ) ), module.getFile() );
|
||||
System.out.println( "Download complete" );
|
||||
} catch ( IOException ex )
|
||||
{
|
||||
System.out.println( "Failed to download: " + Util.exception( ex ) );
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
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 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) throws Exception
|
||||
{
|
||||
ModuleVersion bungeeVersion = ModuleVersion.parse( "git:BungeeCord-Proxy:1.7-SNAPSHOT:\"93cf50b\":792" );
|
||||
|
||||
File moduleDirectory = new File( "modules" );
|
||||
moduleDirectory.mkdir();
|
||||
|
||||
Map<String, ModuleSource> modules = new HashMap<>();
|
||||
|
||||
// TODO: Use filename filter here and in PluginManager
|
||||
Yaml yaml = new Yaml();
|
||||
for ( File file : moduleDirectory.listFiles() )
|
||||
{
|
||||
if ( file.isFile() && file.getName().endsWith( ".jar" ) )
|
||||
{
|
||||
String moduleName = file.getName().substring( 0, file.getName().length() - 4 ); // 4 = .jar.length()
|
||||
ModuleSource source = modules.get( moduleName );
|
||||
if ( source == null )
|
||||
{
|
||||
System.out.println( "No source for module in file: " + file );
|
||||
continue;
|
||||
}
|
||||
|
||||
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 = yaml.loadAs( in, PluginDescription.class );
|
||||
ModuleVersion moduleVersion = ModuleVersion.parse( desc.getVersion() );
|
||||
if ( !moduleVersion.equals( bungeeVersion ) )
|
||||
{
|
||||
System.out.println( "Attempting to update plugin from " + moduleVersion + " to " + bungeeVersion );
|
||||
source.retrieve( new ModuleSpec( moduleName, file ), bungeeVersion );
|
||||
}
|
||||
}
|
||||
} catch ( Exception ex )
|
||||
{
|
||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not check module from file " + file, ex );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package net.md_5.bungee.module;
|
||||
|
||||
interface ModuleSource
|
||||
{
|
||||
|
||||
void retrieve(ModuleSpec module, ModuleVersion version);
|
||||
}
|
13
proxy/src/main/java/net/md_5/bungee/module/ModuleSpec.java
Normal file
13
proxy/src/main/java/net/md_5/bungee/module/ModuleSpec.java
Normal file
@ -0,0 +1,13 @@
|
||||
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 ModuleSource provider;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
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 );
|
||||
String buildNumber = version.substring( lastColon + 1, version.length() );
|
||||
String gitCommit = version.substring( secondLastColon + 1, lastColon ).replaceAll( "\"", "" );
|
||||
|
||||
return new ModuleVersion( buildNumber, gitCommit );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user