[ANY] IDEA Code Cleanup

This commit is contained in:
Gravit 2019-01-15 10:32:46 +07:00
parent dc6e87ef30
commit a2b3ac523b
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
25 changed files with 73 additions and 93 deletions

View file

@ -98,7 +98,7 @@ public ArrayList<String> getSuperClasses(String type) {
} }
@Override @Override
public void close() throws IOException { public void close() {
cp.stream().forEach(IOHelper::close); cp.stream().forEach(IOHelper::close);
cp.clear(); cp.clear();
} }

View file

@ -22,7 +22,7 @@ public class JsonFilePermissionsHandler extends PermissionsHandler implements Re
public static Map<String,ClientPermissions> map; public static Map<String,ClientPermissions> map;
@Override @Override
public void reload() throws Exception { public void reload() {
map.clear(); map.clear();
Path path = Paths.get(filename); Path path = Paths.get(filename);
Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType(); Type type = new TypeToken<Map<String,ClientPermissions>>(){}.getType();

View file

@ -40,24 +40,22 @@ public void close() {
@Override @Override
public void reconfig(String action, String[] args) { public void reconfig(String action, String[] args) {
if(action.equals("message")) switch (action) {
{ case "message":
message = args[0]; message = args[0];
LogHelper.info("New reject message: %s", message); LogHelper.info("New reject message: %s", message);
} break;
else if(action.equals("whitelist.add")) case "whitelist.add":
{ if (whitelist == null) whitelist = new ArrayList<>();
if(whitelist == null) whitelist = new ArrayList<>(); whitelist.add(args[0]);
whitelist.add(args[0]); break;
} case "whitelist.remove":
else if(action.equals("whitelist.remove")) if (whitelist == null) whitelist = new ArrayList<>();
{ whitelist.remove(args[0]);
if(whitelist == null) whitelist = new ArrayList<>(); break;
whitelist.remove(args[0]); case "whitelist.clear":
} whitelist.clear();
else if(action.equals("whitelist.clear")) break;
{
whitelist.clear();
} }
} }

View file

@ -8,22 +8,14 @@
public final class TaskUtil { public final class TaskUtil {
public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) { public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
List<LauncherBuildTask> indexes = new ArrayList<>(); List<LauncherBuildTask> indexes = new ArrayList<>();
tasks.stream().filter(pred).forEach(e -> { tasks.stream().filter(pred).forEach(e -> indexes.add(e));
indexes.add(e); indexes.forEach(e -> tasks.add(tasks.indexOf(e)+count, taskAdd));
});
indexes.forEach(e -> {
tasks.add(tasks.indexOf(e)+count, taskAdd);
});
} }
public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) { public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
List<LauncherBuildTask> indexes = new ArrayList<>(); List<LauncherBuildTask> indexes = new ArrayList<>();
tasks.stream().filter(pred).forEach(e -> { tasks.stream().filter(pred).forEach(e -> indexes.add(e));
indexes.add(e); indexes.forEach(e -> tasks.set(tasks.indexOf(e)+count, taskRep));
});
indexes.forEach(e -> {
tasks.set(tasks.indexOf(e)+count, taskRep);
});
} }
public static void addPre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) { public static void addPre(List<LauncherBuildTask> tasks, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {

View file

@ -19,7 +19,7 @@ public String getUsageDescription() {
} }
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) {
server.reconfigurableManager.printReconfigurables(); server.reconfigurableManager.printReconfigurables();
} }
} }

View file

@ -19,7 +19,7 @@ public String getUsageDescription() {
} }
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) {
server.reloadManager.printReloadables(); server.reloadManager.printReloadables();
} }
} }

View file

@ -22,7 +22,7 @@ public String getUsageDescription() {
} }
@Override @Override
public void invoke(String... args) throws Exception { public void invoke(String... args) {
LogHelper.info("Show server status"); LogHelper.info("Show server status");
LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(),JVMHelper.RUNTIME.maxMemory()); LogHelper.info("Memory: free %d | total: %d | max: %d", JVMHelper.RUNTIME.freeMemory(), JVMHelper.RUNTIME.totalMemory(),JVMHelper.RUNTIME.maxMemory());
long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000; long uptime = JVMHelper.RUNTIME_MXBEAN.getUptime() / 1000;

View file

@ -29,38 +29,34 @@ public void invoke(String... args) throws Exception {
verifyArgs(args,2); verifyArgs(args,2);
if(providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length]; if(providersCache == null) providersCache = new AuthProvider[server.config.authProvider.length];
int index = Integer.valueOf(args[0]); int index = Integer.valueOf(args[0]);
if(args[1].equals("accept")) switch (args[1]) {
{ case "accept":
if(providersCache[index] == null) if (providersCache[index] == null) {
{ AcceptAuthProvider provider = new AcceptAuthProvider();
AcceptAuthProvider provider = new AcceptAuthProvider(); providersCache[index] = server.config.authProvider[index];
providersCache[index] = server.config.authProvider[index]; server.config.authProvider[index] = provider;
server.config.authProvider[index] = provider; LogHelper.info("AuthProvider[%d] is AcceptAuthProvider", index);
LogHelper.info("AuthProvider[%d] is AcceptAuthProvider",index); } else LogHelper.error("Changes detected. Use undo");
} break;
else LogHelper.error("Changes detected. Use undo"); case "reject":
} else if(args[1].equals("reject")) if (providersCache[index] == null) {
{ RejectAuthProvider rejectAuthProvider;
if(providersCache[index] == null) if (args.length < 3) rejectAuthProvider = new RejectAuthProvider();
{ else rejectAuthProvider = new RejectAuthProvider(args[2]);
RejectAuthProvider rejectAuthProvider; providersCache[index] = server.config.authProvider[index];
if(args.length < 3) rejectAuthProvider = new RejectAuthProvider(); server.config.authProvider[index] = rejectAuthProvider;
else rejectAuthProvider = new RejectAuthProvider(args[2]); LogHelper.info("AuthProvider[%d] is RejectAuthProvider", index);
providersCache[index] = server.config.authProvider[index]; } else LogHelper.error("Changes detected. Use undo");
server.config.authProvider[index] = rejectAuthProvider; break;
LogHelper.info("AuthProvider[%d] is RejectAuthProvider",index); case "undo":
} if (providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible");
else LogHelper.error("Changes detected. Use undo"); else {
} else if(args[1].equals("undo")) server.config.authProvider[index].close();
{ server.config.authProvider[index] = providersCache[index];
if(providersCache[index] == null) LogHelper.error("Cache clean. Undo impossible"); providersCache[index] = null;
else }
{
server.config.authProvider[index].close();
server.config.authProvider[index] = providersCache[index];
providersCache[index] = null;
}
break;
} }
} }
} }

View file

@ -34,7 +34,7 @@ public URL getClientsURL(String client) throws MalformedURLException {
protected ArrayList<Mirror> list = new ArrayList<>(); protected ArrayList<Mirror> list = new ArrayList<>();
private Mirror defaultMirror; private Mirror defaultMirror;
public void addMirror(String mirror) throws MalformedURLException { public void addMirror(String mirror) {
Mirror m = new Mirror(mirror); Mirror m = new Mirror(mirror);
m.enabled = true; m.enabled = true;
if (defaultMirror == null) defaultMirror = m; if (defaultMirror == null) defaultMirror = m;

View file

@ -19,7 +19,7 @@ public void printHelp(String name)
{ {
RECONFIGURABLE.get(name).printConfigHelp(); RECONFIGURABLE.get(name).printConfigHelp();
} }
public void call(String name, String action, String[] args) throws Exception { public void call(String name, String action, String[] args) {
RECONFIGURABLE.get(name).reconfig(action,args); RECONFIGURABLE.get(name).reconfig(action,args);
} }
public void printReconfigurables() public void printReconfigurables()

View file

@ -31,7 +31,7 @@ public void channelActive(ChannelHandlerContext ctx) {
} }
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) {
// ping and pong frames already handled // ping and pong frames already handled
if (frame instanceof TextWebSocketFrame) { if (frame instanceof TextWebSocketFrame) {

View file

@ -11,7 +11,7 @@ public String getType() {
} }
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
} }
} }

View file

@ -15,7 +15,7 @@ public String getType() {
} }
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
if (!client.isAuth) { if (!client.isAuth) {
service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied"));
return; return;

View file

@ -18,7 +18,7 @@ public String getType() {
} }
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
try { try {
LaunchServer.server.config.authHandler.checkServer(username, serverID); LaunchServer.server.config.authHandler.checkServer(username, serverID);
} catch (AuthException e) { } catch (AuthException e) {

View file

@ -19,7 +19,7 @@ public String getType() {
} }
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
boolean success; boolean success;
try { try {
success = LaunchServer.server.config.authHandler.joinServer(username, accessToken, serverID); success = LaunchServer.server.config.authHandler.joinServer(username, accessToken, serverID);

View file

@ -24,7 +24,7 @@ public String getType() {
} }
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
byte[] bytes = Base64.getDecoder().decode(hash); byte[] bytes = Base64.getDecoder().decode(hash);
if (launcher_type == 1) // JAR if (launcher_type == 1) // JAR
{ {

View file

@ -16,7 +16,7 @@ public String getType() {
} }
@Override @Override
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
if (!client.isAuth) { if (!client.isAuth) {
service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied"));
return; return;

View file

@ -61,7 +61,7 @@ public static Path getLauncherDir(String projectname) throws IOException {
} }
@LauncherAPI @LauncherAPI
public static Path getLegacyLauncherDir(String projectname) throws IOException { public static Path getLegacyLauncherDir(String projectname) {
return IOHelper.HOME_DIR.resolve(projectname); return IOHelper.HOME_DIR.resolve(projectname);
} }

View file

@ -17,7 +17,6 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.SignatureException;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
public class FunctionalBridge { public class FunctionalBridge {
@ -33,7 +32,7 @@ public class FunctionalBridge {
public static Thread getHWID = null; public static Thread getHWID = null;
@LauncherAPI @LauncherAPI
public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception { public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) {
return () -> { return () -> {
if (hdir == null) { if (hdir == null) {
Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName));
@ -44,7 +43,7 @@ public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, S
} }
@LauncherAPI @LauncherAPI
public static LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException { public static LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException {
if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) { if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) {
Request.requestError("Запуск в оффлайн-режиме невозможен"); Request.requestError("Запуск в оффлайн-режиме невозможен");
} }

View file

@ -62,7 +62,7 @@ public void load() throws SignatureException {
} }
@LauncherAPI @LauncherAPI
public void save() throws SignatureException { public void save() {
LogHelper.debug("Save settings file"); LogHelper.debug("Save settings file");
try { try {
try (HOutput output = new HOutput(IOHelper.newOutput(file))) { try (HOutput output = new HOutput(IOHelper.newOutput(file))) {

View file

@ -14,7 +14,6 @@
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.SignatureException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -46,7 +45,7 @@ public byte[] getDigest() {
public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe"); public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe");
@LauncherAPI @LauncherAPI
public static void update(LauncherConfig config, Result result) throws SignatureException, IOException { public static void update(LauncherConfig config, Result result) throws IOException {
List<String> args = new ArrayList<>(8); List<String> args = new ArrayList<>(8);
args.add(IOHelper.resolveJavaBin(null).toString()); args.add(IOHelper.resolveJavaBin(null).toString());
if (LogHelper.isDebugEnabled()) if (LogHelper.isDebugEnabled())

View file

@ -51,7 +51,7 @@ public void send(String js) throws IOException {
session.getBasicRemote().sendText(js); session.getBasicRemote().sendText(js);
} }
public void sendAsync(String js) throws IOException { public void sendAsync(String js) {
session.getAsyncRemote().sendText(js); session.getAsyncRemote().sendText(js);
} }
} }

View file

@ -30,7 +30,7 @@ public static void addJVMClassPath(String path) throws IOException {
inst.appendToSystemClassLoaderSearch(new JarFile(path)); inst.appendToSystemClassLoaderSearch(new JarFile(path));
} }
public static void addJVMClassPath(JarFile file) throws IOException { public static void addJVMClassPath(JarFile file) {
LogHelper.debug("Load %s", file.getName()); LogHelper.debug("Load %s", file.getName());
inst.appendToSystemClassLoaderSearch(file); inst.appendToSystemClassLoaderSearch(file);
} }

View file

@ -6,7 +6,6 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.*;
@ -383,7 +382,7 @@ else if(f.dependenciesCount.size() <= 1)
} }
} }
public void pushOptional(HashedDir dir, boolean digest) throws IOException { public void pushOptional(HashedDir dir, boolean digest) {
for (OptionalFile opt : updateOptional) { for (OptionalFile opt : updateOptional) {
if (!opt.mark) dir.removeR(opt.file); if (!opt.mark) dir.removeR(opt.file);
} }
@ -592,10 +591,7 @@ public boolean equals(Object obj) {
} else if (!version.equals(other.version)) } else if (!version.equals(other.version))
return false; return false;
if (whitelist == null) { if (whitelist == null) {
if (other.whitelist != null) return other.whitelist == null;
return false; } else return whitelist.equals(other.whitelist);
} else if (!whitelist.equals(other.whitelist)) }
return false;
return true;
}
} }

@ -1 +1 @@
Subproject commit ee2f9e6646a8f1972ceda68d56e88e71ab74f78f Subproject commit bb4430df933db257638191857577824820b18c4a