[CLEANUP] Reformatted code

This commit is contained in:
JKetelaar
2017-08-29 00:19:17 +02:00
parent d3541f795b
commit bcb0ddfab7
120 changed files with 6073 additions and 6255 deletions
@@ -1,14 +1,11 @@
package org.parabot.environment.servers.executers;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.classpath.ClassPath;
import org.parabot.core.desc.ServerProviderInfo;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.FileUtil;
@@ -22,113 +19,111 @@ import java.lang.reflect.Constructor;
import java.net.URL;
/**
*
* Fetches a server provider from the local config file
*
*
* @author JKetelaar
*
*/
public class LocalPublicServerExecuter extends ServerExecuter {
private String serverName;
private String serverUrl;
private String providerUrl;
private ServerProviderInfo serverProviderInfo;
private String serverName;
private String serverUrl;
private String providerUrl;
private ServerProviderInfo serverProviderInfo;
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
this.serverName = serverName;
this.serverUrl = serverUrl;
this.providerUrl = providerUrl;
this.serverProviderInfo = serverProviderInfo;
}
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
this.serverName = serverName;
this.serverUrl = serverUrl;
this.providerUrl = providerUrl;
this.serverProviderInfo = serverProviderInfo;
}
@Override
public void run() {
try {
final File destination = new File(Directories.getCachePath(),
serverProviderInfo.getCRC32() + ".jar");
@Override
public void run() {
try {
final File destination = new File(Directories.getCachePath(),
serverProviderInfo.getCRC32() + ".jar");
Core.verbose("Downloading: " + providerUrl + " ...");
if(destination.exists()) {
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
} else {
File local;
if ((local = new File(providerUrl)).exists()){
FileUtil.copyFile(local, destination);
Core.verbose("Server provider copied...");
}else {
WebUtil.downloadFile(new URL(providerUrl), destination, VerboseLoader.get());
Core.verbose("Server provider downloaded...");
}
}
Core.verbose("Downloading: " + providerUrl + " ...");
final File clientDestination = new File(Directories.getCachePath(),
serverProviderInfo.getClientCRC32() + ".jar");
if (destination.exists()) {
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
} else {
File local;
if ((local = new File(providerUrl)).exists()) {
FileUtil.copyFile(local, destination);
Core.verbose("Server provider copied...");
} else {
WebUtil.downloadFile(new URL(providerUrl), destination, VerboseLoader.get());
Core.verbose("Server provider downloaded...");
}
}
Core.verbose("Downloading: " + serverUrl + " ...");
final File clientDestination = new File(Directories.getCachePath(),
serverProviderInfo.getClientCRC32() + ".jar");
if(clientDestination.exists()) {
Core.verbose("Found cached client [CRC32: " + serverProviderInfo.getClientCRC32() + "]");
} else {
File local;
if ((local = new File(serverUrl)).exists()){
FileUtil.copyFile(local, clientDestination);
Core.verbose("Server client copied...");
}else {
WebUtil.downloadFile(new URL(serverUrl), clientDestination, VerboseLoader.get());
Core.verbose("Server client downloaded...");
}
}
Core.verbose("Downloading: " + serverUrl + " ...");
final ClassPath classPath = new ClassPath();
classPath.addJar(destination);
if (clientDestination.exists()) {
Core.verbose("Found cached client [CRC32: " + serverProviderInfo.getClientCRC32() + "]");
} else {
File local;
if ((local = new File(serverUrl)).exists()) {
FileUtil.copyFile(local, clientDestination);
Core.verbose("Server client copied...");
} else {
WebUtil.downloadFile(new URL(serverUrl), clientDestination, VerboseLoader.get());
Core.verbose("Server client downloaded...");
}
}
BuildPath.add(destination.toURI().toURL());
final ClassPath classPath = new ClassPath();
classPath.addJar(destination);
ServerLoader serverLoader = new ServerLoader(classPath);
final String[] classNames = serverLoader.getServerClassNames();
if (classNames.length == 0) {
UILog.log(
"Error",
"Failed to load server provider, error: [No provider found in jar file.]",
JOptionPane.ERROR_MESSAGE);
return;
} else if (classNames.length > 1) {
UILog.log(
"Error",
"Failed to load server provider, error: [Multiple providers found in jar file.]");
return;
}
BuildPath.add(destination.toURI().toURL());
final String className = classNames[0];
try {
final Class<?> providerClass = serverLoader
.loadClass(className);
final Constructor<?> con = providerClass.getConstructor();
final ServerProvider serverProvider = (ServerProvider) con
.newInstance();
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
super.finalize(serverProvider, this.serverName);
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log(
"Error",
"Failed to load server provider, error: [This server provider is not compatible with this version of parabot]",
JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
t.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider.",
JOptionPane.ERROR_MESSAGE);
}
ServerLoader serverLoader = new ServerLoader(classPath);
final String[] classNames = serverLoader.getServerClassNames();
if (classNames.length == 0) {
UILog.log(
"Error",
"Failed to load server provider, error: [No provider found in jar file.]",
JOptionPane.ERROR_MESSAGE);
return;
} else if (classNames.length > 1) {
UILog.log(
"Error",
"Failed to load server provider, error: [Multiple providers found in jar file.]");
return;
}
} catch (Exception e) {
e.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
final String className = classNames[0];
try {
final Class<?> providerClass = serverLoader
.loadClass(className);
final Constructor<?> con = providerClass.getConstructor();
final ServerProvider serverProvider = (ServerProvider) con
.newInstance();
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
super.finalize(serverProvider, this.serverName);
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log(
"Error",
"Failed to load server provider, error: [This server provider is not compatible with this version of parabot]",
JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
t.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider.",
JOptionPane.ERROR_MESSAGE);
}
}
} catch (Exception e) {
e.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
}
}
@@ -1,55 +1,53 @@
package org.parabot.environment.servers.executers;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.classpath.ClassPath;
import org.parabot.environment.servers.ServerProvider;
import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
/**
*
* Loads locally stored server providers
*
*
* @author Everel
*
*/
public class LocalServerExecuter extends ServerExecuter {
private final Constructor<?> serverProviderConstructor;
private ClassPath classPath;
private String serverName;
private final Constructor<?> serverProviderConstructor;
private ClassPath classPath;
private String serverName;
public LocalServerExecuter(Constructor<?> serverProviderConstructor,
ClassPath classPath, final String serverName) {
this.serverProviderConstructor = serverProviderConstructor;
this.classPath = classPath;
this.serverName = serverName;
}
public LocalServerExecuter(Constructor<?> serverProviderConstructor,
ClassPath classPath, final String serverName) {
this.serverProviderConstructor = serverProviderConstructor;
this.classPath = classPath;
this.serverName = serverName;
}
@Override
public void run() {
// add jar or directory to buildpath.
if (this.classPath.isJar()) {
Core.verbose("Adding server provider jar to buildpath: "
+ this.classPath.lastParsed.toString());
this.classPath.addToBuildPath();
} else {
Core.verbose("Adding server providers directory to buildpath: "
+ Directories.getServerPath().getPath());
try {
BuildPath.add(Directories.getServerPath().toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// finalize
try {
super.finalize((ServerProvider) serverProviderConstructor.newInstance(), this.serverName);
} catch (Throwable t) {
t.printStackTrace();
}
}
@Override
public void run() {
// add jar or directory to buildpath.
if (this.classPath.isJar()) {
Core.verbose("Adding server provider jar to buildpath: "
+ this.classPath.lastParsed.toString());
this.classPath.addToBuildPath();
} else {
Core.verbose("Adding server providers directory to buildpath: "
+ Directories.getServerPath().getPath());
try {
BuildPath.add(Directories.getServerPath().toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// finalize
try {
super.finalize((ServerProvider) serverProviderConstructor.newInstance(), this.serverName);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
@@ -16,106 +16,100 @@ import org.parabot.environment.servers.ServerProvider;
import org.parabot.environment.servers.loader.ServerLoader;
import javax.swing.*;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
/**
*
* Fetches a server provider from the Parabot BDN
*
*
* @author Everel
*
*/
public class PublicServerExecuter extends ServerExecuter {
private String serverName;
private static AccountManager manager;
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
PublicServerExecuter.manager = manager;
}
@Override
public final void setManager(AccountManager manager) {
PublicServerExecuter.manager = manager;
}
};
private String serverName;
};
public PublicServerExecuter(final String serverName) {
this.serverName = serverName;
}
public PublicServerExecuter(final String serverName) {
this.serverName = serverName;
}
@Override
public void run() {
try {
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
+ this.serverName), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
@Override
public void run() {
try {
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
+ this.serverName), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
final File destination = new File(Directories.getCachePath(),
serverProviderInfo.getCRC32() + ".jar");
final String jarUrl = String.format(Configuration.GET_SERVER_PROVIDER, Configuration.BOT_VERSION.isNightly(), serverName);
final File destination = new File(Directories.getCachePath(),
serverProviderInfo.getCRC32() + ".jar");
final String jarUrl = String.format(Configuration.GET_SERVER_PROVIDER, Configuration.BOT_VERSION.isNightly(), serverName);
Core.verbose("Downloading: " + jarUrl + " ...");
if(destination.exists()) {
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
} else {
WebUtil.downloadFile(new URL(jarUrl), destination,
VerboseLoader.get());
Core.verbose("Server provider downloaded...");
}
Core.verbose("Downloading: " + jarUrl + " ...");
if (destination.exists()) {
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
} else {
WebUtil.downloadFile(new URL(jarUrl), destination,
VerboseLoader.get());
Core.verbose("Server provider downloaded...");
}
final ClassPath classPath = new ClassPath();
classPath.addJar(destination);
final ClassPath classPath = new ClassPath();
classPath.addJar(destination);
BuildPath.add(destination.toURI().toURL());
BuildPath.add(destination.toURI().toURL());
ServerLoader serverLoader = new ServerLoader(classPath);
final String[] classNames = serverLoader.getServerClassNames();
if (classNames == null || classNames.length == 0) {
UILog.log(
"Error",
"Failed to load server provider, error: [No provider found in jar file.]",
JOptionPane.ERROR_MESSAGE);
return;
} else if (classNames.length > 1) {
UILog.log(
"Error",
"Failed to load server provider, error: [Multiple providers found in jar file.]");
return;
}
ServerLoader serverLoader = new ServerLoader(classPath);
final String[] classNames = serverLoader.getServerClassNames();
if (classNames == null || classNames.length == 0) {
UILog.log(
"Error",
"Failed to load server provider, error: [No provider found in jar file.]",
JOptionPane.ERROR_MESSAGE);
return;
} else if (classNames.length > 1) {
UILog.log(
"Error",
"Failed to load server provider, error: [Multiple providers found in jar file.]");
return;
}
final String className = classNames[0];
try {
final Class<?> providerClass = serverLoader
.loadClass(className);
final Constructor<?> con = providerClass.getConstructor();
final ServerProvider serverProvider = (ServerProvider) con
.newInstance();
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
super.finalize(serverProvider, this.serverName);
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log(
"Error",
"Failed to load server provider, error: [This server provider is not compitable with this version of parabot]",
JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
t.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
final String className = classNames[0];
try {
final Class<?> providerClass = serverLoader
.loadClass(className);
final Constructor<?> con = providerClass.getConstructor();
final ServerProvider serverProvider = (ServerProvider) con
.newInstance();
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
super.finalize(serverProvider, this.serverName);
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log(
"Error",
"Failed to load server provider, error: [This server provider is not compitable with this version of parabot]",
JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
t.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e) {
e.printStackTrace();
UILog.log(
"Error",
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
JOptionPane.ERROR_MESSAGE);
}
}
}
}