Forráskód Böngészése

New feature to run database installers with parameters from console or
script

Example: java -jar Database_Installer_LS.jar -h localhost -p 3306 -u
root -pw toor -d l2jls -m u

-h Host: IP, DNS
-p Port: Numeric
-u Username: SQL Server username
-pw Password: SQL Server password
-d Database name
-m Mode: u Update, c Clean

Zoey76 10 éve
szülő
commit
24a988fc65

+ 44 - 0
L2J_Server/java/com/l2jserver/tools/dbinstaller/AbstractDBLauncher.java

@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2004-2015 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server 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
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.tools.dbinstaller;
+
+/**
+ * Abstract Database Launcher.
+ * @author Zoey76
+ */
+public abstract class AbstractDBLauncher
+{
+	protected static String getArg(String arg, String[] args)
+	{
+		try
+		{
+			int i = 0;
+			do
+			{
+				// Nothing is missing here.
+			}
+			while (!arg.equalsIgnoreCase(args[i++]));
+			return args[i];
+		}
+		catch (Exception e)
+		{
+			return null;
+		}
+	}
+}

+ 11 - 5
L2J_Server/java/com/l2jserver/tools/dbinstaller/LauncherGS.java

@@ -29,13 +29,19 @@ import com.l2jserver.tools.dbinstaller.gui.DBConfigGUI;
  * Contains main class for Database Installer If system doesn't support the graphical UI, start the installer in console mode.
  * @author mrTJO
  */
-public class LauncherGS
+public class LauncherGS extends AbstractDBLauncher
 {
 	public static void main(String[] args)
 	{
-		String mode = "l2jgs";
+		String defDatabase = "l2jgs";
 		String dir = "../sql/game/";
-		String cleanUp = "gs_cleanup.sql";
+		String cleanUpScript = "gs_cleanup.sql";
+		
+		if ((args != null) && (args.length > 0))
+		{
+			new DBInstallerConsole(defDatabase, dir, cleanUpScript, getArg("-h", args), getArg("-p", args), getArg("-u", args), getArg("-pw", args), getArg("-d", args), getArg("-m", args));
+			return;
+		}
 		
 		try
 		{
@@ -48,11 +54,11 @@ public class LauncherGS
 		
 		try
 		{
-			new DBConfigGUI(mode, dir, cleanUp);
+			new DBConfigGUI(defDatabase, dir, cleanUpScript);
 		}
 		catch (HeadlessException e)
 		{
-			new DBInstallerConsole(mode, dir, cleanUp);
+			new DBInstallerConsole(defDatabase, dir, cleanUpScript);
 		}
 	}
 }

+ 11 - 5
L2J_Server/java/com/l2jserver/tools/dbinstaller/LauncherLS.java

@@ -29,13 +29,19 @@ import com.l2jserver.tools.dbinstaller.gui.DBConfigGUI;
  * Contains main class for Database Installer If system doesn't support the graphical UI, start the installer in console mode.
  * @author mrTJO
  */
-public class LauncherLS
+public class LauncherLS extends AbstractDBLauncher
 {
 	public static void main(String[] args)
 	{
-		String mode = "l2jls";
+		String defDatabase = "l2jls";
 		String dir = "../sql/login/";
-		String cleanUp = "ls_cleanup.sql";
+		String cleanUpScript = "ls_cleanup.sql";
+		
+		if ((args != null) && (args.length > 0))
+		{
+			new DBInstallerConsole(defDatabase, dir, cleanUpScript, getArg("-h", args), getArg("-p", args), getArg("-u", args), getArg("-pw", args), getArg("-d", args), getArg("-m", args));
+			return;
+		}
 		
 		try
 		{
@@ -48,11 +54,11 @@ public class LauncherLS
 		
 		try
 		{
-			new DBConfigGUI(mode, dir, cleanUp);
+			new DBConfigGUI(defDatabase, dir, cleanUpScript);
 		}
 		catch (HeadlessException e)
 		{
-			new DBInstallerConsole(mode, dir, cleanUp);
+			new DBInstallerConsole(defDatabase, dir, cleanUpScript);
 		}
 	}
 }

+ 33 - 3
L2J_Server/java/com/l2jserver/tools/dbinstaller/console/DBInstallerConsole.java

@@ -34,7 +34,7 @@ public class DBInstallerConsole implements DBOutputInterface
 {
 	Connection _con;
 	
-	public DBInstallerConsole(String db, String dir, String cleanUp)
+	public DBInstallerConsole(String db, String dir, String cleanUpScript)
 	{
 		System.out.println("Welcome to L2J DataBase installer");
 		Preferences prop = Preferences.userRoot();
@@ -71,12 +71,12 @@ public class DBInstallerConsole implements DBOutputInterface
 				System.out.print("Do you really want to destroy your db (Y/N)?");
 				if (scn.next().equalsIgnoreCase("y"))
 				{
-					rt = new RunTasks(this, db, dir, cleanUp, true);
+					rt = new RunTasks(this, db, dir, cleanUpScript, true);
 				}
 			}
 			else if (resp.equalsIgnoreCase("u"))
 			{
-				rt = new RunTasks(this, db, dir, cleanUp, false);
+				rt = new RunTasks(this, db, dir, cleanUpScript, false);
 			}
 		}
 		
@@ -90,6 +90,36 @@ public class DBInstallerConsole implements DBOutputInterface
 		}
 	}
 	
+	/**
+	 * Database Console Installer constructor.
+	 * @param defDatabase the default database name
+	 * @param dir the SQL script's directory
+	 * @param cleanUpScript the clean up SQL script
+	 * @param host the host name
+	 * @param port the port
+	 * @param user the user name
+	 * @param pass the password
+	 * @param database the database name
+	 * @param mode the mode, c: Clean, u:update
+	 */
+	public DBInstallerConsole(String defDatabase, String dir, String cleanUpScript, String host, String port, String user, String pass, String database, String mode)
+	{
+		if ((database == null) || database.isEmpty())
+		{
+			database = defDatabase;
+		}
+		
+		final MySqlConnect connector = new MySqlConnect(host, port, user, pass, database, true);
+		
+		_con = connector.getConnection();
+		
+		if ((mode != null) && ("c".equalsIgnoreCase(mode) || "u".equalsIgnoreCase(mode)))
+		{
+			final RunTasks rt = new RunTasks(this, database, dir, cleanUpScript, "c".equalsIgnoreCase(mode));
+			rt.run();
+		}
+	}
+	
 	@Override
 	public void appendToProgressArea(String text)
 	{