From 78dac6fba99c14bfe946f6299225e2b74bcb6065 Mon Sep 17 00:00:00 2001 From: Josh Larson Date: Wed, 8 Mar 2017 21:06:03 -0600 Subject: [PATCH] Improved concurrency of build/test/install and changed all e.printStackTrace to Log.e(e) --- src/com/projectswg/CombinedLightspeed.java | 3 +- src/com/projectswg/LightweightLightspeed.java | 2 +- .../common/callback/CallbackManager.java | 4 +- .../common/data/BuildHistoryTable.java | 7 +- .../common/data/DeploymentTable.java | 11 +- .../projectswg/common/data/ServerTable.java | 11 +- .../projectswg/common/info/ConfigData.java | 4 +- .../common/info/HeavyweightDataManager.java | 4 +- src/com/projectswg/common/info/Log.java | 6 +- .../common/info/RelationalDatabase.java | 16 +- .../common/info/RelationalServerData.java | 16 +- .../common/info/RelationalServerFactory.java | 6 +- .../projectswg/common/network/TCPServer.java | 10 +- .../projectswg/common/network/TCPSocket.java | 7 +- .../network/protocol/AlphaProtocol.java | 2 +- .../common/utilities/TimeUtilities.java | 6 +- .../lightspeed/StarshipProcess.java | 2 +- .../lightspeed/build/BuildService.java | 3 +- .../lightspeed/build/JavaBuildMethod.java | 73 ++++++--- .../lightspeed/build/MavenInterface.java | 3 +- .../build/java_builder/CustomJavaBuild.java | 48 +++--- .../build/java_builder/CustomJavaCommon.java | 6 +- .../build/java_builder/CustomJavaInstall.java | 46 +++--- .../build/java_builder/CustomJavaTest.java | 30 ++-- .../build/java_builder/RepoInstaller.java | 147 ++++++++++++++++++ .../LightspeedFrontendGUI.java | 4 +- 26 files changed, 324 insertions(+), 153 deletions(-) create mode 100644 src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java diff --git a/src/com/projectswg/CombinedLightspeed.java b/src/com/projectswg/CombinedLightspeed.java index dd7cd39..981701d 100644 --- a/src/com/projectswg/CombinedLightspeed.java +++ b/src/com/projectswg/CombinedLightspeed.java @@ -34,6 +34,7 @@ import javax.swing.JFileChooser; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; +import com.projectswg.common.info.Log; import com.projectswg.lightspeed.server.ServerServerData; import com.projectswg.lightspeed_frontend.LightspeedFrontendGUI; @@ -54,7 +55,7 @@ public class CombinedLightspeed { if (System.getProperty("os.name").toLowerCase().contains("win")) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { - e.printStackTrace(); + Log.e(e); } JFileChooser chooser = new JFileChooser(new File("/home/josh/devel/ProjectSWG/swg_workspace/Holocore")); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); diff --git a/src/com/projectswg/LightweightLightspeed.java b/src/com/projectswg/LightweightLightspeed.java index 79c65f0..72b0b9c 100644 --- a/src/com/projectswg/LightweightLightspeed.java +++ b/src/com/projectswg/LightweightLightspeed.java @@ -47,7 +47,7 @@ public class LightweightLightspeed { try { mainThread.join(); } catch (Exception e) { - e.printStackTrace(); + Log.e(e); } LightspeedManager.getDataManager().terminate(); }, "lightspeed-shutdown-hook")); diff --git a/src/com/projectswg/common/callback/CallbackManager.java b/src/com/projectswg/common/callback/CallbackManager.java index 2812119..7e4784b 100644 --- a/src/com/projectswg/common/callback/CallbackManager.java +++ b/src/com/projectswg/common/callback/CallbackManager.java @@ -30,6 +30,8 @@ package com.projectswg.common.callback; import java.util.ArrayList; import java.util.List; +import com.projectswg.common.info.Log; + public class CallbackManager extends BaseCallbackManager { private final List callbacks; @@ -75,7 +77,7 @@ public class CallbackManager extends BaseCallbackManager { try { call.run(callback); } catch (Exception e) { - e.printStackTrace(); + Log.e(e); } } }); diff --git a/src/com/projectswg/common/data/BuildHistoryTable.java b/src/com/projectswg/common/data/BuildHistoryTable.java index 63af01f..c16ed7b 100644 --- a/src/com/projectswg/common/data/BuildHistoryTable.java +++ b/src/com/projectswg/common/data/BuildHistoryTable.java @@ -36,6 +36,7 @@ import java.util.List; import com.projectswg.common.data.SQLBuildData; import com.projectswg.common.data.SQLBuildData.BuildInformationBuilder; import com.projectswg.common.data.TestDetails; +import com.projectswg.common.info.Log; import com.projectswg.common.info.RelationalDatabase; import com.projectswg.common.info.RelationalServerFactory; @@ -85,7 +86,7 @@ class BuildHistoryTable implements AutoCloseable { } } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return history; } @@ -99,7 +100,7 @@ class BuildHistoryTable implements AutoCloseable { return createBuildFromSet(set); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return null; } @@ -142,7 +143,7 @@ class BuildHistoryTable implements AutoCloseable { insertBuildHistoryStatement.executeUpdate(); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } } diff --git a/src/com/projectswg/common/data/DeploymentTable.java b/src/com/projectswg/common/data/DeploymentTable.java index 4704af6..aef60ca 100644 --- a/src/com/projectswg/common/data/DeploymentTable.java +++ b/src/com/projectswg/common/data/DeploymentTable.java @@ -35,6 +35,7 @@ import java.util.List; import com.projectswg.common.data.SQLDeploymentData; import com.projectswg.common.data.SQLDeploymentData.DeploymentInformationBuilder; +import com.projectswg.common.info.Log; import com.projectswg.common.info.RelationalDatabase; import com.projectswg.common.info.RelationalServerFactory; @@ -93,7 +94,7 @@ class DeploymentTable implements AutoCloseable { return insertDeploymentStatement.executeUpdate() == 1; } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return false; } @@ -107,7 +108,7 @@ class DeploymentTable implements AutoCloseable { return createDeploymentFromSet(set); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return null; } @@ -121,7 +122,7 @@ class DeploymentTable implements AutoCloseable { return createDeploymentFromSet(set); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return null; } @@ -136,7 +137,7 @@ class DeploymentTable implements AutoCloseable { deployments.add(createDeploymentFromSet(set)); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return deployments; } @@ -151,7 +152,7 @@ class DeploymentTable implements AutoCloseable { deployments.add(createDeploymentFromSet(set)); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return deployments; } diff --git a/src/com/projectswg/common/data/ServerTable.java b/src/com/projectswg/common/data/ServerTable.java index f868626..3e52366 100644 --- a/src/com/projectswg/common/data/ServerTable.java +++ b/src/com/projectswg/common/data/ServerTable.java @@ -34,6 +34,7 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import com.projectswg.common.info.Log; import com.projectswg.common.info.RelationalDatabase; import com.projectswg.common.info.RelationalServerFactory; @@ -89,7 +90,7 @@ class ServerTable implements AutoCloseable { return insertServerStatement.executeUpdate() == 1; } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return false; } @@ -101,7 +102,7 @@ class ServerTable implements AutoCloseable { return deleteServerStatement.executeUpdate() == 1; } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return false; } @@ -115,7 +116,7 @@ class ServerTable implements AutoCloseable { return new SQLServerData(set.getString("id"), dir.getAbsolutePath(), set.getString("jvm_arguments")); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return null; } @@ -129,7 +130,7 @@ class ServerTable implements AutoCloseable { return new SQLServerData(id, set.getString("directory"), set.getString("jvm_arguments")); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return null; } @@ -143,7 +144,7 @@ class ServerTable implements AutoCloseable { servers.add(set.getString("id")); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } return servers; } diff --git a/src/com/projectswg/common/info/ConfigData.java b/src/com/projectswg/common/info/ConfigData.java index 37ffa29..8e2c269 100644 --- a/src/com/projectswg/common/info/ConfigData.java +++ b/src/com/projectswg/common/info/ConfigData.java @@ -91,7 +91,7 @@ class ConfigData { line = reader.readLine(); } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); return null; } finally { if (reader != null) { @@ -122,7 +122,7 @@ class ConfigData { } return true; } catch (IOException e) { - e.printStackTrace(); + Log.e(e); return false; } finally { if (writer != null) { diff --git a/src/com/projectswg/common/info/HeavyweightDataManager.java b/src/com/projectswg/common/info/HeavyweightDataManager.java index 63b1a03..e56018f 100644 --- a/src/com/projectswg/common/info/HeavyweightDataManager.java +++ b/src/com/projectswg/common/info/HeavyweightDataManager.java @@ -83,13 +83,13 @@ public class HeavyweightDataManager implements DataManager { Log.e(getClass().getSimpleName(), "Failed to create parent directories for config: " + file.getCanonicalPath()); } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } try { if (!file.createNewFile()) Log.e(getClass().getSimpleName(), "Failed to create new config: " + file.getCanonicalPath()); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } return file.exists(); } diff --git a/src/com/projectswg/common/info/Log.java b/src/com/projectswg/common/info/Log.java index f7e58ca..b557b12 100644 --- a/src/com/projectswg/common/info/Log.java +++ b/src/com/projectswg/common/info/Log.java @@ -84,7 +84,7 @@ public class Log { try { LOG.open(); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } } @@ -92,7 +92,7 @@ public class Log { try { LOG.close(); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } } @@ -134,7 +134,7 @@ public class Log { try { LOG.write(log); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } } } diff --git a/src/com/projectswg/common/info/RelationalDatabase.java b/src/com/projectswg/common/info/RelationalDatabase.java index 39074ba..39c4185 100644 --- a/src/com/projectswg/common/info/RelationalDatabase.java +++ b/src/com/projectswg/common/info/RelationalDatabase.java @@ -48,7 +48,7 @@ public abstract class RelationalDatabase implements Closeable { Class.forName(jdbcClass); initialize(url); } catch (ClassNotFoundException e) { - e.printStackTrace(); + Log.e(e); online = false; } } @@ -58,7 +58,7 @@ public abstract class RelationalDatabase implements Closeable { Class.forName(jdbcClass); initialize(url, user, pass); } catch (ClassNotFoundException e) { - e.printStackTrace(); + Log.e(e); online = false; } } @@ -70,7 +70,7 @@ public abstract class RelationalDatabase implements Closeable { url += "?" + params; initialize(url, user, pass); } catch (ClassNotFoundException e) { - e.printStackTrace(); + Log.e(e); online = false; } } @@ -83,7 +83,7 @@ public abstract class RelationalDatabase implements Closeable { url += "?" + params; initialize(url, user, pass); } catch (ClassNotFoundException e) { - e.printStackTrace(); + Log.e(e); online = false; } } @@ -115,7 +115,7 @@ public abstract class RelationalDatabase implements Closeable { connection.close(); online = false; } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } } @@ -137,7 +137,7 @@ public abstract class RelationalDatabase implements Closeable { try { return connection.prepareStatement(sql); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); return null; } } @@ -156,7 +156,7 @@ public abstract class RelationalDatabase implements Closeable { } return s.getResultSet(); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); if (s != null) { try { s.close(); } catch (SQLException ex) { } } @@ -172,7 +172,7 @@ public abstract class RelationalDatabase implements Closeable { return s.executeUpdate(query); } } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); return 0; } } diff --git a/src/com/projectswg/common/info/RelationalServerData.java b/src/com/projectswg/common/info/RelationalServerData.java index be05d16..0659d44 100644 --- a/src/com/projectswg/common/info/RelationalServerData.java +++ b/src/com/projectswg/common/info/RelationalServerData.java @@ -93,7 +93,7 @@ public class RelationalServerData extends RelationalDatabase { return true; } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } return false; } @@ -211,13 +211,13 @@ public class RelationalServerData extends RelationalDatabase { if (set.next()) return set.getLong("last_imported"); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } finally { if (set != null) { try { set.close(); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } } } @@ -233,7 +233,7 @@ public class RelationalServerData extends RelationalDatabase { if (updateTableMetadata.executeUpdate() > 0) return; } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); return; } } @@ -243,7 +243,7 @@ public class RelationalServerData extends RelationalDatabase { insertTableMetadata.setLong(2, lastImported); insertTableMetadata.executeUpdate(); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } } } @@ -257,9 +257,9 @@ public class RelationalServerData extends RelationalDatabase { reader.readNormal(); return true; } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } catch (IllegalArgumentException e) { Log.e("RelationalServerData", "Invalid file format. Aborting read of %s! Message: %s", sdb, e.getMessage()); } @@ -288,7 +288,7 @@ public class RelationalServerData extends RelationalDatabase { try { insert.close(); } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } } } diff --git a/src/com/projectswg/common/info/RelationalServerFactory.java b/src/com/projectswg/common/info/RelationalServerFactory.java index 98027a8..0e12d78 100644 --- a/src/com/projectswg/common/info/RelationalServerFactory.java +++ b/src/com/projectswg/common/info/RelationalServerFactory.java @@ -73,7 +73,7 @@ public class RelationalServerFactory { return true; data.close(); } catch (Exception e) { - e.printStackTrace(); + Log.e(e); data.close(); } return false; @@ -93,7 +93,7 @@ public class RelationalServerFactory { executeCommand(data, command, parserData); return data; } catch (Exception e) { - e.printStackTrace(); + Log.e(e); } data.close(); return null; @@ -128,7 +128,7 @@ public class RelationalServerFactory { try (ResultSet set = data.executeQuery(command)) { } catch (SQLException e) { - e.printStackTrace(); + Log.e(e); } } else if (command.startsWith("IF")) { // VERY SIMPLE 'if' logic, no parenthesis and no AND/OR's - expects 3 arguments: parserData.addConditional(evaluateIf(data, command.substring(2).trim())); diff --git a/src/com/projectswg/common/network/TCPServer.java b/src/com/projectswg/common/network/TCPServer.java index 047b02e..6530ebd 100644 --- a/src/com/projectswg/common/network/TCPServer.java +++ b/src/com/projectswg/common/network/TCPServer.java @@ -121,7 +121,7 @@ public class TCPServer { callbackManager.callOnEach((callback) -> callback.onConnectionDisconnect(s, sock)); return true; } catch (IOException e) { - e.printStackTrace(); + Log.e(e); return false; } } @@ -146,7 +146,7 @@ public class TCPServer { channel.close(); return true; } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } return false; } @@ -213,7 +213,7 @@ public class TCPServer { selector.select(); processSelectionKeys(selector); } catch (Exception e) { - e.printStackTrace(); + Log.e(e); try { Thread.sleep(100); } catch (InterruptedException e1) { @@ -222,7 +222,7 @@ public class TCPServer { } } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } } @@ -264,7 +264,7 @@ public class TCPServer { callbackManager.callOnEach((callback) -> callback.onIncomingConnection(sc.socket())); } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } } diff --git a/src/com/projectswg/common/network/TCPSocket.java b/src/com/projectswg/common/network/TCPSocket.java index e8001cc..4452875 100644 --- a/src/com/projectswg/common/network/TCPSocket.java +++ b/src/com/projectswg/common/network/TCPSocket.java @@ -34,6 +34,7 @@ import java.nio.channels.SocketChannel; import java.util.concurrent.atomic.AtomicBoolean; import com.projectswg.common.callback.CallbackManager; +import com.projectswg.common.info.Log; public class TCPSocket { @@ -67,7 +68,7 @@ public class TCPSocket { listener.start(); callbackManager.callOnEach((callback) -> callback.onConnected(this)); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); callbackManager.callOnEach((callback) -> callback.onDisconnected(this)); callbackManager.stop(); } @@ -83,7 +84,7 @@ public class TCPSocket { callbackManager.callOnEach((callback) -> callback.onDisconnected(this)); return true; } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } return false; } @@ -96,7 +97,7 @@ public class TCPSocket { } return true; } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } return false; } diff --git a/src/com/projectswg/common/network/protocol/AlphaProtocol.java b/src/com/projectswg/common/network/protocol/AlphaProtocol.java index cf700a3..2d20ba2 100644 --- a/src/com/projectswg/common/network/protocol/AlphaProtocol.java +++ b/src/com/projectswg/common/network/protocol/AlphaProtocol.java @@ -82,7 +82,7 @@ public class AlphaProtocol extends Protocol { } stream.compact(); } catch (Exception e) { - e.printStackTrace(); + Log.e(e); } } } diff --git a/src/com/projectswg/common/utilities/TimeUtilities.java b/src/com/projectswg/common/utilities/TimeUtilities.java index 23fd98d..84044fa 100644 --- a/src/com/projectswg/common/utilities/TimeUtilities.java +++ b/src/com/projectswg/common/utilities/TimeUtilities.java @@ -34,6 +34,8 @@ import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; +import com.projectswg.common.info.Log; + public class TimeUtilities { private static final String DATE_TIME_FORMAT = "EEE, dd MMM yyyy HH:mm:ss z"; @@ -71,7 +73,7 @@ public class TimeUtilities { try { return DATE_TIME_FORMATTER_UTC.parse(str).getTime(); } catch (ParseException e) { - e.printStackTrace(); + Log.e(e); return -1; } } @@ -82,7 +84,7 @@ public class TimeUtilities { try { return DATE_TIME_FORMATTER_CUR.parse(str).getTime(); } catch (ParseException e) { - e.printStackTrace(); + Log.e(e); return -1; } } diff --git a/src/com/projectswg/lightspeed/StarshipProcess.java b/src/com/projectswg/lightspeed/StarshipProcess.java index 38f69b4..eb76e31 100644 --- a/src/com/projectswg/lightspeed/StarshipProcess.java +++ b/src/com/projectswg/lightspeed/StarshipProcess.java @@ -101,7 +101,7 @@ public class StarshipProcess { p = builder.start(); } catch (IOException e) { p = null; - e.printStackTrace(); + Log.e(e); } process = p; return process != null; diff --git a/src/com/projectswg/lightspeed/build/BuildService.java b/src/com/projectswg/lightspeed/build/BuildService.java index 953bb37..0e58b7a 100644 --- a/src/com/projectswg/lightspeed/build/BuildService.java +++ b/src/com/projectswg/lightspeed/build/BuildService.java @@ -219,7 +219,8 @@ public class BuildService extends Service { private Build removeInProgress() { synchronized (inprogress) { Build build = inprogress.remove(serverId); - Assert.notNull(build); + if (build == null) + return null; getBackendData().insertBuild(build.get()); return build; } diff --git a/src/com/projectswg/lightspeed/build/JavaBuildMethod.java b/src/com/projectswg/lightspeed/build/JavaBuildMethod.java index 6df45c8..3d6561b 100644 --- a/src/com/projectswg/lightspeed/build/JavaBuildMethod.java +++ b/src/com/projectswg/lightspeed/build/JavaBuildMethod.java @@ -37,23 +37,17 @@ import com.projectswg.lightspeed.build.java_builder.CustomJavaBuild; import com.projectswg.lightspeed.build.java_builder.CustomJavaException; import com.projectswg.lightspeed.build.java_builder.CustomJavaInstall; import com.projectswg.lightspeed.build.java_builder.CustomJavaTest; +import com.projectswg.lightspeed.build.java_builder.RepoInstaller; import com.projectswg.lightspeed.server.ServerServerData; public class JavaBuildMethod { private static final String SEP = File.separator; - private final CustomJavaBuild build; - private final CustomJavaTest test; - private final CustomJavaInstall install; + private final File jdk; public JavaBuildMethod(File jdk) { - String ext = ""; - if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) - ext = ".exe"; - build = new CustomJavaBuild(new File(jdk.getAbsolutePath() + SEP+"bin"+SEP+"javac"+ext)); - test = new CustomJavaTest(new File(jdk.getAbsolutePath() + SEP+"bin"+SEP+"java"+ext)); - install = new CustomJavaInstall(new File(jdk.getAbsolutePath() + SEP+"bin"+SEP+"jar"+ext)); + this.jdk = jdk; } public void createJar(ServerBuildData build, ServerServerData server, InstallationCallback callback) { @@ -73,31 +67,60 @@ public class JavaBuildMethod { private void createJar(String repo, ServerBuildData buildData, InstallationCallback callback) { try { Log.i("Creating jar..."); + RepoInstaller installer = new RepoInstaller(new File(repo), jdk); buildData.setTime(TimeUtilities.getTime()); - updateState(buildData, callback, InstallationState.BUILDING); - build.compile(buildData, "main.ProjectSWG"); - if (detectCancelled(buildData, callback)) + if (!build(installer, buildData, callback)) { + updateState(buildData, callback, InstallationState.FAILED); return; - - updateState(buildData, callback, InstallationState.TESTING); - TestDetails details = test.test(buildData); - if (details.getFailures() > 0) - throw new CustomJavaException("Test: Failed tests"); - if (detectCancelled(buildData, callback)) + } + if (!test(installer, buildData, callback)) { + updateState(buildData, callback, InstallationState.FAILED); return; - - updateState(buildData, callback, InstallationState.INSTALLING); - install.createRawJar(buildData, "main.ProjectSWG"); + } + if (!install(installer, buildData, callback)) { + updateState(buildData, callback, InstallationState.FAILED); + return; + } updateState(buildData, callback, InstallationState.SUCCESS); - } catch (CustomJavaException e) { - System.err.println(e.getMessage()); - updateState(buildData, callback, InstallationState.FAILED); } catch (Exception e) { - e.printStackTrace(); + Log.e(e); updateState(buildData, callback, InstallationState.FAILED); } } + private boolean build(RepoInstaller installer, ServerBuildData buildData, InstallationCallback callback) { + updateState(buildData, callback, InstallationState.BUILDING); + CustomJavaBuild build = new CustomJavaBuild(installer); + if (!build.compile(buildData, "main.ProjectSWG")) + return false; + if (detectCancelled(buildData, callback)) + return false; + return true; + } + + private boolean test(RepoInstaller installer, ServerBuildData buildData, InstallationCallback callback) { + updateState(buildData, callback, InstallationState.TESTING); + CustomJavaTest test = new CustomJavaTest(installer); + TestDetails details = test.test(buildData); + if (details.getFailures() > 0 || details.getTotal() < 0) + return false; + if (detectCancelled(buildData, callback)) + return false; + return true; + } + + private boolean install(RepoInstaller installer, ServerBuildData buildData, InstallationCallback callback) { + updateState(buildData, callback, InstallationState.INSTALLING); + try { + CustomJavaInstall install = new CustomJavaInstall(installer); + install.createRawJar(buildData, "main.ProjectSWG"); + return true; + } catch (CustomJavaException e) { + Log.e(e); + return false; + } + } + private boolean detectCancelled(ServerBuildData buildData, InstallationCallback callback) { if (buildData.getState() == InstallationState.CANCELLED) { updateState(buildData, callback, InstallationState.CANCELLED); diff --git a/src/com/projectswg/lightspeed/build/MavenInterface.java b/src/com/projectswg/lightspeed/build/MavenInterface.java index 85e8be0..f218e97 100644 --- a/src/com/projectswg/lightspeed/build/MavenInterface.java +++ b/src/com/projectswg/lightspeed/build/MavenInterface.java @@ -34,6 +34,7 @@ import java.io.InputStreamReader; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.projectswg.common.info.Log; import com.projectswg.lightspeed.build.ServerBuildData.InstallationCallback; public class MavenInterface implements BuildMethod { @@ -90,7 +91,7 @@ public class MavenInterface implements BuildMethod { builder.append(line + '\n'); return builder.toString(); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); return null; } } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java index eb9825d..0859def 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaBuild.java @@ -28,53 +28,51 @@ package com.projectswg.lightspeed.build.java_builder; import java.io.File; +import java.util.ArrayList; +import java.util.List; import com.projectswg.common.info.Log; import com.projectswg.lightspeed.build.ServerBuildData; public class CustomJavaBuild { - private static final String SRC_DIR = CustomJavaCommon.SRC_DIR; - private static final String TST_DIR = CustomJavaCommon.TST_DIR; - private static final String BIN_DIR = CustomJavaCommon.BIN_DIR; - private static final String LIB_DIR = CustomJavaCommon.LIB_DIR; - private static final String SEP = CustomJavaCommon.SEP; + private final RepoInstaller installer; - private final File javac; - - public CustomJavaBuild(File javac) { - this.javac = javac; + public CustomJavaBuild(RepoInstaller installer) { + this.installer = installer; } - public void compile(ServerBuildData buildData, String file) throws CustomJavaException { + public boolean compile(ServerBuildData buildData, String file) { String repo = buildData.getServer().getDirectory(); file = file.replace('.', File.separatorChar); - new File(repo, BIN_DIR).mkdirs(); + installer.getBin().mkdirs(); String [] command = { - javac.getAbsolutePath(), - "-d", repo + SEP + BIN_DIR, - "-classpath", CustomJavaCommon.getFiles(LIB_DIR + SEP, repo + SEP, ".jar", File.pathSeparatorChar)+File.pathSeparator+".", - "-sourcepath", repo + SEP + SRC_DIR + installer.getJdkJavac().getAbsolutePath(), + "-d", installer.getBin().getAbsolutePath(), + "-classpath", installer.getFilesRelative(installer.getLib(), ".jar", File.pathSeparatorChar)+File.pathSeparator+".", + "-sourcepath", installer.getSrc().getAbsolutePath() }; - String [] commands = CustomJavaCommon.merge(command, getFiles(repo)); StringBuilder builder = new StringBuilder(); long start = System.nanoTime(); Log.i("Starting build..."); - int ret = CustomJavaCommon.execute(commands, new File(repo), builder, false); + int ret = CustomJavaCommon.execute(getFullCommand(command), new File(repo), builder, false); buildData.setCompileTime((System.nanoTime()-start)/1E9); buildData.setBuildString(builder.toString()); buildData.setBuildSuccess(ret == 0); Log.i("Build return value: %d", ret); - if (ret != 0) - throw new CustomJavaException("Build: Failed to compile project!"); + return ret == 0; } - private String [] getFiles(String repo) { - String fileSpaceSplit = ""; - fileSpaceSplit += CustomJavaCommon.getFiles(SRC_DIR+SEP, repo+SEP, ".java", ' '); - fileSpaceSplit += ' '; - fileSpaceSplit += CustomJavaCommon.getFiles(TST_DIR+SEP, repo+SEP, ".java", ' '); - return fileSpaceSplit.split(" "); + private String [] getFullCommand(String [] header) { + List files = new ArrayList<>(); + files.addAll(installer.getFileList(installer.getSrc(), ".java")); + files.addAll(installer.getFileList(installer.getTest(), ".java")); + String [] command = new String[header.length + files.size()]; + System.arraycopy(header, 0, command, 0, header.length); + for (int i = 0; i < files.size(); i++) { + command[header.length + i] = files.get(i).getAbsolutePath(); + } + return command; } } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaCommon.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaCommon.java index 14bb52c..51e0e7c 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaCommon.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaCommon.java @@ -65,7 +65,7 @@ public class CustomJavaCommon { out.append(getOutput(process.getInputStream())); return process.waitFor(); } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } catch (InterruptedException e) { } @@ -81,7 +81,7 @@ public class CustomJavaCommon { builder.append(line + '\n'); } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } return builder.toString(); } @@ -95,7 +95,7 @@ public class CustomJavaCommon { System.out.println(line); } } catch (IOException e) { - e.printStackTrace(); + Log.e(e); } } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java index e7071ff..d6d60ed 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaInstall.java @@ -45,30 +45,24 @@ import com.projectswg.lightspeed.build.ServerBuildData; public class CustomJavaInstall { - private static final String OUT_JAR = CustomJavaCommon.OUT_JAR; - private static final String BIN_DIR = CustomJavaCommon.BIN_DIR; - private static final String LIB_DIR = CustomJavaCommon.LIB_DIR; - private static final String SEP = CustomJavaCommon.SEP; + private final RepoInstaller installer; - private final File jar; - - public CustomJavaInstall(File jar) { - this.jar = jar; + public CustomJavaInstall(RepoInstaller installer) { + this.installer = installer; } public void createRawJar(ServerBuildData buildData, String file) throws CustomJavaException { String repo = buildData.getServer().getDirectory(); File manifestFile = createManifest(repo, file); - String manifest = manifestFile.getAbsolutePath(); - CustomJavaCommon.execute(getCommandLineArgs(repo, manifest), new File(repo)); + installer.execute(getCommandLineArgs(manifestFile)); manifestFile.delete(); - installLoader(repo); - buildData.setJar(new File(repo, OUT_JAR)); + installLoader(); + buildData.setJar(installer.getJar()); } private File createManifest(String repo, String file) throws CustomJavaException { String manifest = "Rsrc-Main-Class: " + file + "\n"; - manifest += "Rsrc-Class-Path: ./ " + CustomJavaCommon.getFiles(LIB_DIR + SEP, repo + SEP, ".jar", ' ') + "\n"; + manifest += "Rsrc-Class-Path: ./ " + installer.getFiles(installer.getLib(), ".jar", ' ') + "\n"; manifest += "Main-Class: com.projectswg.lightspeed.build.jar_loader.LightspeedJarLoader\n"; manifest += "Class-Path: .\n"; try { @@ -82,30 +76,30 @@ public class CustomJavaInstall { } } - private String [] getCommandLineArgs(String repo, String manifest) { - List classFiles = CustomJavaCommon.getJavaFilesRecursive(".class", new File(repo, BIN_DIR)); - List libFiles = CustomJavaCommon.getJavaFilesRecursive(".jar", new File(repo, LIB_DIR)); + private String [] getCommandLineArgs(File manifest) { + List classFiles = installer.getFileList(installer.getBin(), ".class"); + List libFiles = installer.getFileList(installer.getLib(), ".jar"); String [] command = new String[4 + classFiles.size()*3 + libFiles.size()]; int i = 0; - command[i++] = jar.getAbsolutePath(); + command[i++] = installer.getJdkJar().getAbsolutePath(); command[i++] = "cvfm"; - command[i++] = OUT_JAR; - command[i++] = manifest; - for (String f : classFiles) { + command[i++] = installer.getJar().getAbsolutePath(); + command[i++] = manifest.getAbsolutePath(); + for (File f : classFiles) { command[i++] = "-C"; - command[i++] = BIN_DIR; - command[i++] = f.substring(repo.length()+1+BIN_DIR.length()+1); + command[i++] = installer.getBin().getAbsolutePath(); + command[i++] = f.getAbsolutePath(); } - for (String f : libFiles) { - command[i++] = f.substring(repo.length()+1); + for (File f : libFiles) { + command[i++] = f.getAbsolutePath(); } return command; } - private boolean installLoader(String repo) throws CustomJavaException { + private boolean installLoader() throws CustomJavaException { File dir = createTempDirectory(); unzip("LightspeedJarLoader.zip", dir.getAbsolutePath()); - CustomJavaCommon.execute(new String[]{jar.getAbsolutePath(), "uvf", OUT_JAR, "-C", dir.getAbsolutePath(), "."}, new File(repo)); + installer.execute(new String[]{installer.getJdkJar().getAbsolutePath(), "uvf", installer.getJar().getAbsolutePath(), "-C", dir.getAbsolutePath(), "."}); deleteDirectory(dir); return true; } diff --git a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java index ac82c42..859e496 100644 --- a/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java +++ b/src/com/projectswg/lightspeed/build/java_builder/CustomJavaTest.java @@ -40,19 +40,16 @@ public class CustomJavaTest { private static final Pattern JUNIT_OK_PATTERN = Pattern.compile("OK \\((\\d+) tests\\)"); private static final Pattern JUNIT_FAIL_PATTERN = Pattern.compile("Tests run: (\\d+), Failures: (\\d+)"); - private static final String LIB_DIR = CustomJavaCommon.LIB_DIR; - private static final String SEP = CustomJavaCommon.SEP; + private final RepoInstaller installer; - private final File java; - - public CustomJavaTest(File java) { - this.java = java; + public CustomJavaTest(RepoInstaller installer) { + this.installer = installer; } public TestDetails test(ServerBuildData buildData) { Log.i("Testing..."); StringBuilder outBuilder = new StringBuilder(); - int ret = executeTest(buildData.getServer().getDirectory(), outBuilder); + int ret = executeTest(outBuilder); String out = outBuilder.toString(); TestDetails details = parseOutput(ret, out); buildData.setTestDetails(details); @@ -62,17 +59,18 @@ public class CustomJavaTest { return details; } - private int executeTest(String repo, StringBuilder oldBuilder) { - String libs = repo+SEP+"bin"+File.pathSeparatorChar+CustomJavaCommon.getFiles(LIB_DIR + SEP, repo + SEP, ".jar", File.pathSeparatorChar); - libs += File.pathSeparatorChar+new File("hamcrest-core-1.3.jar").getAbsolutePath(); - libs += File.pathSeparatorChar+new File("junit-4.12.jar").getAbsolutePath(); + private int executeTest(StringBuilder oldBuilder) { + String libs = installer.getBin().getAbsolutePath(); + libs += File.pathSeparatorChar + installer.getFilesRelative(installer.getLib(), ".jar", File.pathSeparatorChar); + libs += File.pathSeparatorChar + new File("hamcrest-core-1.3.jar").getAbsolutePath(); + libs += File.pathSeparatorChar + new File("junit-4.12.jar").getAbsolutePath(); String [] command = { - java.getAbsolutePath(), + installer.getJdkJava().getAbsolutePath(), "-cp", libs, "org.junit.runner.JUnitCore", "main.TestAll" }; - return CustomJavaCommon.execute(command, new File(repo), oldBuilder, true); + return installer.execute(command, oldBuilder); } private TestDetails parseOutput(int ret, String out) { @@ -83,7 +81,7 @@ public class CustomJavaTest { } else { System.out.println(out); } - return new TestDetails(0, 0); + return new TestDetails(-1, 0); } private TestDetails parseOK(String out) { @@ -91,7 +89,7 @@ public class CustomJavaTest { Matcher m = JUNIT_OK_PATTERN.matcher(line); if (!m.matches()) { System.err.println("Failed to match OK pattern: " + line); - return new TestDetails(0, 0); + return new TestDetails(-1, 0); } return new TestDetails(Integer.parseInt(m.group(1)), 0); } @@ -101,7 +99,7 @@ public class CustomJavaTest { Matcher m = JUNIT_FAIL_PATTERN.matcher(line); if (!m.matches()) { System.err.println("Failed to match FAIL pattern: " + line); - return new TestDetails(0, 0); + return new TestDetails(-1, 0); } return new TestDetails(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2))); } diff --git a/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java b/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java new file mode 100644 index 0000000..a4c844d --- /dev/null +++ b/src/com/projectswg/lightspeed/build/java_builder/RepoInstaller.java @@ -0,0 +1,147 @@ +/*********************************************************************************** +* Copyright (c) 2015 /// Project SWG /// www.projectswg.com * +* * +* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * +* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * +* Our goal is to create an emulator which will provide a server for players to * +* continue playing a game similar to the one they used to play. We are basing * +* it on the final publish of the game prior to end-game events. * +* * +* This file is part of Holocore. * +* * +* -------------------------------------------------------------------------------- * +* * +* Holocore is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Affero General Public License as * +* published by the Free Software Foundation, either version 3 of the * +* License, or (at your option) any later version. * +* * +* Holocore is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with Holocore. If not, see . * +* * +***********************************************************************************/ +package com.projectswg.lightspeed.build.java_builder; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class RepoInstaller { + + private static final String SEP = File.separator; + + private final File repo; + private final File bin; + private final File src; + private final File lib; + private final File test; + private final File jar; + + private final File jdk; + private final File jdkJava; + private final File jdkJavac; + private final File jdkJar; + + public RepoInstaller(File repo, File jdk) { + this.repo = repo; + this.bin = new File(repo, "bin"); + this.src = new File(repo, "src"); + this.lib = new File(repo, "lib"); + this.test= new File(repo, "test"); + this.jar = new File(bin, "ProjectSWG.jar"); + this.jdk = jdk; + String ext = ""; + if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) + ext = ".exe"; + this.jdkJava = new File(jdk, "bin" + SEP + "java" + ext); + this.jdkJavac = new File(jdk, "bin" + SEP + "javac" + ext); + this.jdkJar = new File(jdk, "bin" + SEP + "jar" + ext); + } + + public File getRepo() { + return repo; + } + + public File getBin() { + return bin; + } + + public File getSrc() { + return src; + } + + public File getLib() { + return lib; + } + + public File getTest() { + return test; + } + + public File getJar() { + return jar; + } + + public File getJdk() { + return jdk; + } + + public File getJdkJava() { + return jdkJava; + } + + public File getJdkJavac() { + return jdkJavac; + } + + public File getJdkJar() { + return jdkJar; + } + + public int execute(String [] command) { + return execute(command, false); + } + + public int execute(String [] command, StringBuilder output) { + return CustomJavaCommon.execute(command, repo, output, false); + } + + public int execute(String [] command, boolean output) { + return CustomJavaCommon.execute(command, repo, null, output); + } + + public String getFilesRelative(File dir, String extension, char delim) { + return getFiles(dir, extension, delim).replace(repo.getAbsolutePath()+SEP, ""); + } + + public String getFiles(File dir, String extension, char delim) { + List files = getFileList(dir, extension); + StringBuilder str = new StringBuilder(""); + for (File file : files) { + str.append(file.getAbsolutePath()); + str.append(delim); + } + if (str.length() == 0) + return ""; + return str.substring(0, str.length()-1); + } + + public List getFileList(File dir, String extension) { + List files = new ArrayList<>(); + for (String subStr : dir.list()) { + File sub = new File(dir, subStr); + if (sub.isDirectory()) { + files.addAll(getFileList(sub, extension)); + } else if (sub.getName().endsWith(extension)) { + files.add(sub); + } + } + return files; + } + +} diff --git a/src/com/projectswg/lightspeed_frontend/LightspeedFrontendGUI.java b/src/com/projectswg/lightspeed_frontend/LightspeedFrontendGUI.java index fa23089..d44ed1c 100644 --- a/src/com/projectswg/lightspeed_frontend/LightspeedFrontendGUI.java +++ b/src/com/projectswg/lightspeed_frontend/LightspeedFrontendGUI.java @@ -84,7 +84,7 @@ public class LightspeedFrontendGUI extends Application { try { port = Integer.parseInt(named.get("port")); } catch (NumberFormatException e) { - e.printStackTrace(); + Log.e(e); } } try { @@ -92,7 +92,7 @@ public class LightspeedFrontendGUI extends Application { frontend.connect(sock); primaryView.setConnectAddress(sock); } catch (UnknownHostException e) { - e.printStackTrace(); + Log.e(e); } }