diff --git a/.github/ISSUE_TEMPLATE.MD b/.github/ISSUE_TEMPLATE.MD index 0527d7ffc..c3a5da7a2 100644 --- a/.github/ISSUE_TEMPLATE.MD +++ b/.github/ISSUE_TEMPLATE.MD @@ -21,5 +21,5 @@ This can be found by running `/authme version` ### Error Log: Pastebin/Hastebin/Gist link of the error logo or stacktrace (if any) -### COnfiguration: -Pastebin/Hastebin/Gist link of your config.yml file (remember to delete any sesible data) +### Configuration: +Pastebin/Hastebin/Gist link of your config.yml file (remember to delete any sensible data) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index ca5df4faa..0d317fb7a 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -68,14 +68,16 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.messaging.Messenger; import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.scheduler.BukkitTask; +import org.bukkit.scheduler.BukkitWorker; import java.io.File; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.Iterator; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_ACCOUNT; @@ -113,10 +115,6 @@ public class AuthMe extends JavaPlugin { private BukkitService bukkitService; private AuthMeServiceInitializer initializer; private GeoLiteAPI geoLiteApi; - - /* - * Private instances (mail and ProtocolLib) - */ private SendMailSSL mail; /** @@ -281,7 +279,7 @@ public class AuthMe extends JavaPlugin { // If server is using PermissionsBukkit, print a warning that some features may not be supported if (PermissionsSystemType.PERMISSIONS_BUKKIT.equals(permsMan.getPermissionSystem())) { - ConsoleLogger.info("Warning! This server uses PermissionsBukkit for permissions! Some permissions features may not be supported!"); + ConsoleLogger.showError("Warning! This server uses PermissionsBukkit for permissions. Some permissions features may not be supported!"); } // Purge on start if enabled @@ -453,35 +451,50 @@ public class AuthMe extends JavaPlugin { if (newSettings != null) { new PerformBackup(this, newSettings).doBackup(PerformBackup.BackupCause.STOP); } - final AuthMe pluginInstance = this; + new Thread(new Runnable() { @Override public void run() { List pendingTasks = new ArrayList<>(); - for (BukkitTask pendingTask : getServer().getScheduler().getPendingTasks()) { - if (pendingTask.getOwner().equals(pluginInstance) && !pendingTask.isSync()) { + //returns only the async takss + for (BukkitWorker pendingTask : getServer().getScheduler().getActiveWorkers()) { + if (pendingTask.getOwner().equals(AuthMe.this) + //it's not a peridic task + && !getServer().getScheduler().isQueued(pendingTask.getTaskId())) { pendingTasks.add(pendingTask.getTaskId()); } } - getLogger().info("Waiting for " + pendingTasks.size() + " tasks to finish"); + + getLogger().log(Level.INFO, "Waiting for {0} tasks to finish", pendingTasks.size()); int progress = 0; - for (int taskId : pendingTasks) { - int maxTries = 5; - while (getServer().getScheduler().isCurrentlyRunning(taskId)) { - if (maxTries <= 0) { - getLogger().info("Async task " + taskId + " times out after to many tries"); - break; - } - try { - Thread.sleep(1000); - } catch (InterruptedException ignored) { - } - maxTries--; + + //one minute + some time checking the running state + int tries = 60; + while (!pendingTasks.isEmpty()) { + if (tries <= 0) { + getLogger().log(Level.INFO, "Async tasks times out after to many tries {0}", pendingTasks); + break; } - progress++; - getLogger().info("Progress: " + progress + " / " + pendingTasks.size()); + try { + Thread.sleep(1000); + } catch (InterruptedException ignored) { + Thread.currentThread().interrupt(); + break; + } + + for (Iterator iterator = pendingTasks.iterator(); iterator.hasNext();) { + int taskId = iterator.next(); + if (!getServer().getScheduler().isCurrentlyRunning(taskId)) { + iterator.remove(); + progress++; + getLogger().log(Level.INFO, "Progress: {0} / {1}", new Object[]{progress, pendingTasks.size()}); + } + } + + tries--; } + if (database != null) { database.close(); } diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index fbf51eb92..3902e3e55 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -31,34 +31,23 @@ import java.util.Set; public class MySQL implements DataSource { - private final String host; - private final String port; - private final String username; - private final String password; - private final String database; - private final String tableName; - private final List columnOthers; - private final Columns col; - private final HashAlgorithm hashAlgorithm; + private String host; + private String port; + private String username; + private String password; + private String database; + private String tableName; + private List columnOthers; + private Columns col; + private HashAlgorithm hashAlgorithm; private HikariDataSource ds; - private final String phpBbPrefix; - private final int phpBbGroup; - private final String wordpressPrefix; + private String phpBbPrefix; + private int phpBbGroup; + private String wordpressPrefix; public MySQL(NewSetting settings) throws ClassNotFoundException, SQLException, PoolInitializationException { - this.host = settings.getProperty(DatabaseSettings.MYSQL_HOST); - this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT); - this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME); - this.password = settings.getProperty(DatabaseSettings.MYSQL_PASSWORD); - this.database = settings.getProperty(DatabaseSettings.MYSQL_DATABASE); - this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE); - this.columnOthers = settings.getProperty(HooksSettings.MYSQL_OTHER_USERNAME_COLS); - this.col = new Columns(settings); - this.hashAlgorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH); - this.phpBbPrefix = settings.getProperty(HooksSettings.PHPBB_TABLE_PREFIX); - this.phpBbGroup = settings.getProperty(HooksSettings.PHPBB_ACTIVATED_GROUP_ID); - this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX); + setParameters(settings); // Set the connection arguments (and check if connection is ok) try { @@ -67,7 +56,7 @@ public class MySQL implements DataSource { if (e instanceof IllegalArgumentException) { ConsoleLogger.showError("Invalid database arguments! Please check your configuration!"); ConsoleLogger.showError("If this error persists, please report it to the developer!"); - throw new IllegalArgumentException(e); + throw e; } if (e instanceof PoolInitializationException) { ConsoleLogger.showError("Can't initialize database connection! Please check your configuration!"); @@ -80,17 +69,22 @@ public class MySQL implements DataSource { // Initialize the database try { - this.setupConnection(); + setupConnection(); } catch (SQLException e) { - this.close(); - ConsoleLogger.showError("Can't initialize the MySQL database... Please check your database settings in the config.yml file! SHUTDOWN..."); - ConsoleLogger.showError("If this error persists, please report it to the developer!"); + close(); + ConsoleLogger.logException("Can't initialize the MySQL database:", e); + ConsoleLogger.showError("Please check your database settings in the config.yml file!"); throw e; } } @VisibleForTesting MySQL(NewSetting settings, HikariDataSource hikariDataSource) { + ds = hikariDataSource; + setParameters(settings); + } + + private void setParameters(NewSetting settings) { this.host = settings.getProperty(DatabaseSettings.MYSQL_HOST); this.port = settings.getProperty(DatabaseSettings.MYSQL_PORT); this.username = settings.getProperty(DatabaseSettings.MYSQL_USERNAME); @@ -103,7 +97,6 @@ public class MySQL implements DataSource { this.phpBbPrefix = settings.getProperty(HooksSettings.PHPBB_TABLE_PREFIX); this.phpBbGroup = settings.getProperty(HooksSettings.PHPBB_ACTIVATED_GROUP_ID); this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX); - ds = hikariDataSource; } private void setConnectionArguments() throws RuntimeException { @@ -148,16 +141,14 @@ public class MySQL implements DataSource { } private void setupConnection() throws SQLException { - try (Connection con = getConnection()) { - Statement st = con.createStatement(); - DatabaseMetaData md = con.getMetaData(); + try (Connection con = getConnection(); Statement st = con.createStatement()) { // Create table if not exists. String sql = "CREATE TABLE IF NOT EXISTS " + tableName + " (" - + col.ID + " INTEGER AUTO_INCREMENT," + + col.ID + " MEDIUMINT(8) UNSIGNED AUTO_INCREMENT," + col.NAME + " VARCHAR(255) NOT NULL UNIQUE," + col.REAL_NAME + " VARCHAR(255) NOT NULL," - + col.PASSWORD + " VARCHAR(255) NOT NULL," - + col.IP + " VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'," + + col.PASSWORD + " VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL," + + col.IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL DEFAULT '127.0.0.1'," + col.LAST_LOGIN + " BIGINT NOT NULL DEFAULT 0," + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0'," + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0'," @@ -165,100 +156,81 @@ public class MySQL implements DataSource { + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com'," + col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0'," - + "CONSTRAINT table_const_prim PRIMARY KEY (" + col.ID + ")" - + ");"; + + "PRIMARY KEY (" + col.ID + ")" + + ") CHARACTER SET = utf8"; st.executeUpdate(sql); - ResultSet rs = md.getColumns(null, null, tableName, col.NAME); - if (!rs.next()) { + DatabaseMetaData md = con.getMetaData(); + if (isColumnMissing(md, col.NAME)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.NAME + " VARCHAR(255) NOT NULL UNIQUE AFTER " + col.ID + ";"); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.REAL_NAME); - if (!rs.next()) { + if (isColumnMissing(md, col.REAL_NAME)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.REAL_NAME + " VARCHAR(255) NOT NULL AFTER " + col.NAME + ";"); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.PASSWORD); - if (!rs.next()) { + if (isColumnMissing(md, col.PASSWORD)) { st.executeUpdate("ALTER TABLE " + tableName - + " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) NOT NULL;"); - } - rs.close(); - - if (!col.SALT.isEmpty()) { - rs = md.getColumns(null, null, tableName, col.SALT); - if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName - + " ADD COLUMN " + col.SALT + " VARCHAR(255);"); - } - rs.close(); + + " ADD COLUMN " + col.PASSWORD + " VARCHAR(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;"); } - rs = md.getColumns(null, null, tableName, col.IP); - if (!rs.next()) { + if (!col.SALT.isEmpty() && isColumnMissing(md, col.SALT)) { st.executeUpdate("ALTER TABLE " + tableName - + " ADD COLUMN " + col.IP + " VARCHAR(40) NOT NULL;"); + + " ADD COLUMN " + col.SALT + " VARCHAR(255);"); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.LAST_LOGIN); - if (!rs.next()) { + if (isColumnMissing(md, col.IP)) { + st.executeUpdate("ALTER TABLE " + tableName + + " ADD COLUMN " + col.IP + " VARCHAR(40) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;"); + } + + if (isColumnMissing(md, col.LAST_LOGIN)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LAST_LOGIN + " BIGINT NOT NULL DEFAULT 0;"); } else { - migrateLastLoginColumnToBigInt(con, rs); + migrateLastLoginColumnToBigInt(con, md); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.LASTLOC_X); - if (!rs.next()) { + if (isColumnMissing(md, col.LASTLOC_X)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LAST_LOGIN + " , ADD " + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_X + " , ADD " + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0' AFTER " + col.LASTLOC_Y); - } - rs.close(); - - rs = md.getColumns(null, null, tableName, col.LASTLOC_X); - if (rs.next()) { + } else { st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + col.LASTLOC_X + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + col.LASTLOC_Y + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + col.LASTLOC_Z + " DOUBLE NOT NULL DEFAULT '0.0';"); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.LASTLOC_WORLD); - if (!rs.next()) { + if (isColumnMissing(md, col.LASTLOC_WORLD)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.LASTLOC_WORLD + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + col.LASTLOC_Z); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.EMAIL); - if (!rs.next()) { + if (isColumnMissing(md, col.EMAIL)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.EMAIL + " VARCHAR(255) DEFAULT 'your@email.com' AFTER " + col.LASTLOC_WORLD); } - rs.close(); - rs = md.getColumns(null, null, tableName, col.IS_LOGGED); - if (!rs.next()) { + if (isColumnMissing(md, col.IS_LOGGED)) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + col.IS_LOGGED + " SMALLINT NOT NULL DEFAULT '0' AFTER " + col.EMAIL); } - rs.close(); st.close(); } ConsoleLogger.info("MySQL setup finished"); } + private boolean isColumnMissing(DatabaseMetaData metaData, String columnName) throws SQLException { + try (ResultSet rs = metaData.getColumns(null, null, tableName, columnName)) { + return !rs.next(); + } + } + @Override public boolean isAuthAvailable(String user) { String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; @@ -933,10 +905,18 @@ public class MySQL implements DataSource { * Check if the lastlogin column is of type timestamp and, if so, revert it to the bigint format. * * @param con Connection to the database - * @param rs ResultSet containing meta data for the lastlogin column + * @param metaData metaData meta data of the database */ - private void migrateLastLoginColumnToBigInt(Connection con, ResultSet rs) throws SQLException { - final int columnType = rs.getInt("DATA_TYPE"); + private void migrateLastLoginColumnToBigInt(Connection con, DatabaseMetaData metaData) throws SQLException { + final int columnType; + try (ResultSet rs = metaData.getColumns(null, null, tableName, col.LAST_LOGIN)) { + if (!rs.next()) { + ConsoleLogger.showError("Could not get LAST_LOGIN meta data. This should never happen!"); + return; + } + columnType = rs.getInt("DATA_TYPE"); + } + if (columnType == Types.TIMESTAMP) { ConsoleLogger.info("Migrating lastlogin column from timestamp to bigint"); final String lastLoginOld = col.LAST_LOGIN + "_old"; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeInventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeInventoryPacketAdapter.java index 88d83f611..0d5d4b7c4 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeInventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeInventoryPacketAdapter.java @@ -31,7 +31,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.logging.Level; -public class AuthMeInventoryPacketAdapter extends PacketAdapter { +class AuthMeInventoryPacketAdapter extends PacketAdapter { private static final int PLAYER_INVENTORY = 0; // http://wiki.vg/Inventory#Inventory (0-4 crafting, 5-8 armor, 9-35 main inventory, 36-44 hotbar, 45 off hand) diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTabCompletePacketAdapter.java b/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTabCompletePacketAdapter.java index ad4d1e0bf..2aef7d066 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTabCompletePacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTabCompletePacketAdapter.java @@ -6,16 +6,12 @@ import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.reflect.FieldAccessException; - import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerCache; -import javax.inject.Inject; +class AuthMeTabCompletePacketAdapter extends PacketAdapter { -public class AuthMeTabCompletePacketAdapter extends PacketAdapter { - - @Inject public AuthMeTabCompletePacketAdapter(AuthMe plugin) { super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE); } diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTablistPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTablistPacketAdapter.java index a26bec83c..75e06cd57 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTablistPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/AuthMeTablistPacketAdapter.java @@ -21,7 +21,6 @@ import fr.xephi.authme.util.BukkitService; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.Iterator; @@ -29,12 +28,11 @@ import java.util.List; import java.util.UUID; import java.util.logging.Level; -public class AuthMeTablistPacketAdapter extends PacketAdapter { +class AuthMeTablistPacketAdapter extends PacketAdapter { private final BukkitService bukkitService; private boolean isRegistered; - @Inject public AuthMeTablistPacketAdapter(AuthMe plugin, BukkitService bukkitService) { super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO); this.bukkitService = bukkitService; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java index 8788be9db..18b134952 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java @@ -104,11 +104,9 @@ public class ProtocolLibService implements SettingsDependent { * @param player The player to send the packet to. */ public void sendBlankInventoryPacket(Player player) { - if (!isEnabled || inventoryPacketAdapter == null) { - return; + if (isEnabled && inventoryPacketAdapter != null) { + inventoryPacketAdapter.sendBlankInventoryPacket(player); } - - inventoryPacketAdapter.sendBlankInventoryPacket(player); } /** @@ -117,11 +115,9 @@ public class ProtocolLibService implements SettingsDependent { * @param player The player to send the packet to. */ public void sendTabList(Player player) { - if (!isEnabled || tablistPacketAdapter == null) { - return; + if (isEnabled && tablistPacketAdapter != null) { + tablistPacketAdapter.sendTablist(player); } - - tablistPacketAdapter.sendTablist(player); } @Override diff --git a/src/main/java/fr/xephi/authme/task/PurgeService.java b/src/main/java/fr/xephi/authme/task/PurgeService.java index 7549371b1..e84fae41d 100644 --- a/src/main/java/fr/xephi/authme/task/PurgeService.java +++ b/src/main/java/fr/xephi/authme/task/PurgeService.java @@ -76,7 +76,7 @@ public class PurgeService implements Reloadable { if (!settings.getProperty(PurgeSettings.USE_AUTO_PURGE)) { return; } else if (daysBeforePurge <= 0) { - ConsoleLogger.showError("Configured days before purging must be positive"); + ConsoleLogger.showError("Did not run auto purge: configured days before purging must be positive"); return; } diff --git a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java index 25e95f83f..722089925 100644 --- a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java +++ b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java @@ -72,7 +72,7 @@ public class AuthMeInitializationTest { public void initAuthMe() throws IOException { dataFolder = temporaryFolder.newFolder(); settingsFile = new File(dataFolder, "config.yml"); - Files.copy(TestHelper.getJarFile("/initialization/config.test.yml"), settingsFile); + Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "config.test.yml"), settingsFile); // Mock / wire various Bukkit components given(server.getLogger()).willReturn(mock(Logger.class)); diff --git a/src/test/java/fr/xephi/authme/TestHelper.java b/src/test/java/fr/xephi/authme/TestHelper.java index bef656219..58f3355cb 100644 --- a/src/test/java/fr/xephi/authme/TestHelper.java +++ b/src/test/java/fr/xephi/authme/TestHelper.java @@ -28,6 +28,8 @@ import static org.mockito.Mockito.verify; */ public final class TestHelper { + public static final String PROJECT_ROOT = "/fr/xephi/authme/"; + private TestHelper() { } diff --git a/src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java b/src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java index 0183c613e..615ef915c 100644 --- a/src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java +++ b/src/test/java/fr/xephi/authme/converter/CrazyLoginConverterTest.java @@ -45,7 +45,7 @@ public class CrazyLoginConverterTest { private NewSetting settings; @DataFolder - private File dataFolder = TestHelper.getJarFile("/converter/"); + private File dataFolder = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "converter/"); @BeforeClass public static void initializeLogger() { diff --git a/src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java b/src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java index 6f6082cee..903c58ff3 100644 --- a/src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java +++ b/src/test/java/fr/xephi/authme/converter/ForceFlatToSqliteTest.java @@ -41,7 +41,7 @@ public class ForceFlatToSqliteTest { @Before public void copyFile() throws IOException { - File source = TestHelper.getJarFile("/datasource-integration/flatfile-test.txt"); + File source = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "datasource/flatfile-test.txt"); File destination = temporaryFolder.newFile(); Files.copy(source, destination); flatFile = new FlatFile(destination); diff --git a/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java index 0c0ab8e1e..853cbd78c 100644 --- a/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/FlatFileIntegrationTest.java @@ -35,7 +35,7 @@ public class FlatFileIntegrationTest { @Before public void copyFileToTemporaryFolder() throws IOException { - File originalFile = TestHelper.getJarFile("/datasource-integration/flatfile-test.txt"); + File originalFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "datasource/flatfile-test.txt"); File copy = temporaryFolder.newFile(); Files.copy(originalFile, copy); dataSource = new FlatFile(copy); diff --git a/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java index ec90dab09..397693069 100644 --- a/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/MySqlIntegrationTest.java @@ -54,7 +54,7 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest { set(DatabaseSettings.MYSQL_TABLE, "authme"); TestHelper.setupLogger(); - Path sqlInitFile = TestHelper.getJarPath("/datasource-integration/sql-initialize.sql"); + Path sqlInitFile = TestHelper.getJarPath(TestHelper.PROJECT_ROOT + "datasource/sql-initialize.sql"); sqlInitialize = new String(Files.readAllBytes(sqlInitFile)); } diff --git a/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java b/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java index 3cfe9eb26..a654fca66 100644 --- a/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/datasource/SQLiteIntegrationTest.java @@ -53,7 +53,7 @@ public class SQLiteIntegrationTest extends AbstractDataSourceIntegrationTest { set(DatabaseSettings.MYSQL_TABLE, "authme"); TestHelper.setupLogger(); - Path sqlInitFile = TestHelper.getJarPath("/datasource-integration/sql-initialize.sql"); + Path sqlInitFile = TestHelper.getJarPath(TestHelper.PROJECT_ROOT + "datasource/sql-initialize.sql"); // Note ljacqu 20160221: It appears that we can only run one statement per Statement.execute() so we split // the SQL file by ";\n" as to get the individual statements sqlInitialize = new String(Files.readAllBytes(sqlInitFile)).split(";(\\r?)\\n"); diff --git a/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java b/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java index 61eea6a97..cea523c48 100644 --- a/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java @@ -33,8 +33,8 @@ import static org.mockito.Mockito.verify; */ public class MessagesIntegrationTest { - private static final String YML_TEST_FILE = "/messages_test.yml"; - private static final String YML_DEFAULT_TEST_FILE = "/messages_default.yml"; + private static final String YML_TEST_FILE = TestHelper.PROJECT_ROOT + "output/messages_test.yml"; + private static final String YML_DEFAULT_TEST_FILE = TestHelper.PROJECT_ROOT + "output/messages_default.yml"; private Messages messages; @BeforeClass @@ -255,7 +255,8 @@ public class MessagesIntegrationTest { // assumption: message comes back as defined in messages_test.yml assumeThat(messages.retrieveSingle(key), equalTo("§cWrong password!")); NewSetting settings = mock(NewSetting.class); - given(settings.getMessagesFile()).willReturn(TestHelper.getJarFile("/messages_test2.yml")); + given(settings.getMessagesFile()).willReturn(TestHelper.getJarFile( + TestHelper.PROJECT_ROOT + "output/messages_test2.yml")); // when messages.loadSettings(settings); diff --git a/src/test/java/fr/xephi/authme/security/crypts/CryptPBKDF2Test.java b/src/test/java/fr/xephi/authme/security/crypts/CryptPBKDF2Test.java index 2e9f6380f..36ce7106a 100644 --- a/src/test/java/fr/xephi/authme/security/crypts/CryptPBKDF2Test.java +++ b/src/test/java/fr/xephi/authme/security/crypts/CryptPBKDF2Test.java @@ -6,7 +6,7 @@ import org.junit.Ignore; * Test for {@link CryptPBKDF2}. */ @Ignore -// TODO #369: This algorithm seems broken +// TODO #685: This algorithm seems broken public class CryptPBKDF2Test extends AbstractEncryptionMethodTest { public CryptPBKDF2Test() { diff --git a/src/test/java/fr/xephi/authme/settings/NewSettingIntegrationTest.java b/src/test/java/fr/xephi/authme/settings/NewSettingIntegrationTest.java index 1ee5a50c0..4663b2145 100644 --- a/src/test/java/fr/xephi/authme/settings/NewSettingIntegrationTest.java +++ b/src/test/java/fr/xephi/authme/settings/NewSettingIntegrationTest.java @@ -32,11 +32,11 @@ import static org.junit.Assert.assertThat; public class NewSettingIntegrationTest { /** File name of the sample config including all {@link TestConfiguration} values. */ - private static final String COMPLETE_FILE = "/config-sample-values.yml"; + private static final String COMPLETE_FILE = TestHelper.PROJECT_ROOT + "settings/config-sample-values.yml"; /** File name of the sample config missing certain {@link TestConfiguration} values. */ - private static final String INCOMPLETE_FILE = "/config-incomplete-sample.yml"; + private static final String INCOMPLETE_FILE = TestHelper.PROJECT_ROOT + "settings/config-incomplete-sample.yml"; /** File name for testing difficult values. */ - private static final String DIFFICULT_FILE = "/config-difficult-values.yml"; + private static final String DIFFICULT_FILE = TestHelper.PROJECT_ROOT + "settings/config-difficult-values.yml"; private static PropertyMap propertyMap = TestConfiguration.generatePropertyMap(); diff --git a/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java b/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java index c489e785f..941c30f18 100644 --- a/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java +++ b/src/test/java/fr/xephi/authme/settings/SpawnLoaderTest.java @@ -54,7 +54,7 @@ public class SpawnLoaderTest { public void setup() throws IOException { // Copy test config into a new temporary folder testFolder = temporaryFolder.newFolder(); - File source = TestHelper.getJarFile("/spawn/spawn-firstspawn.yml"); + File source = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/spawn-firstspawn.yml"); File destination = new File(testFolder, "spawn.yml"); Files.copy(source, destination); diff --git a/src/test/java/tools/bathelpers/freshen_jar.bat b/src/test/java/tools/bathelpers/freshen_jar.bat new file mode 100644 index 000000000..3eba26dbb --- /dev/null +++ b/src/test/java/tools/bathelpers/freshen_jar.bat @@ -0,0 +1,5 @@ +: Shortcut for quickbuild / move to plugins / run server + +call quick_build.bat +call move_plugin.bat +call run_server.bat diff --git a/src/test/java/tools/bathelpers/move_plugin.bat b/src/test/java/tools/bathelpers/move_plugin.bat index a8bec5013..ac89c05f3 100644 --- a/src/test/java/tools/bathelpers/move_plugin.bat +++ b/src/test/java/tools/bathelpers/move_plugin.bat @@ -1,11 +1,10 @@ : Moves the AuthMe JAR file to the plugins folder of the test server -: You will have to hit 'Y' to really replace it if it already exists if "%jarfile%" == "" ( call setvars.bat ) if exist %jarfile% ( - xcopy %jarfile% %plugins% + xcopy %jarfile% %plugins% /y ) else ( echo Target file not found: '%jarfile%' ) diff --git a/src/test/java/tools/bathelpers/quick_build.bat b/src/test/java/tools/bathelpers/quick_build.bat index 2010e00af..543b53b04 100644 --- a/src/test/java/tools/bathelpers/quick_build.bat +++ b/src/test/java/tools/bathelpers/quick_build.bat @@ -3,4 +3,4 @@ if "%jarfile%" == "" ( call setvars.bat ) -mvn install -f "%pomfile%" -Dmaven.test.skip \ No newline at end of file +mvn install -o -f "%pomfile%" -Dmaven.test.skip diff --git a/src/test/resources/initialization/config.test.yml b/src/test/resources/fr/xephi/authme/config.test.yml similarity index 100% rename from src/test/resources/initialization/config.test.yml rename to src/test/resources/fr/xephi/authme/config.test.yml diff --git a/src/test/resources/converter/crazylogin.db b/src/test/resources/fr/xephi/authme/converter/crazylogin.db similarity index 100% rename from src/test/resources/converter/crazylogin.db rename to src/test/resources/fr/xephi/authme/converter/crazylogin.db diff --git a/src/test/resources/datasource-integration/flatfile-test.txt b/src/test/resources/fr/xephi/authme/datasource/flatfile-test.txt similarity index 100% rename from src/test/resources/datasource-integration/flatfile-test.txt rename to src/test/resources/fr/xephi/authme/datasource/flatfile-test.txt diff --git a/src/test/resources/datasource-integration/sql-initialize.sql b/src/test/resources/fr/xephi/authme/datasource/sql-initialize.sql similarity index 100% rename from src/test/resources/datasource-integration/sql-initialize.sql rename to src/test/resources/fr/xephi/authme/datasource/sql-initialize.sql diff --git a/src/test/resources/messages_default.yml b/src/test/resources/fr/xephi/authme/output/messages_default.yml similarity index 100% rename from src/test/resources/messages_default.yml rename to src/test/resources/fr/xephi/authme/output/messages_default.yml diff --git a/src/test/resources/messages_test.yml b/src/test/resources/fr/xephi/authme/output/messages_test.yml similarity index 100% rename from src/test/resources/messages_test.yml rename to src/test/resources/fr/xephi/authme/output/messages_test.yml diff --git a/src/test/resources/messages_test2.yml b/src/test/resources/fr/xephi/authme/output/messages_test2.yml similarity index 100% rename from src/test/resources/messages_test2.yml rename to src/test/resources/fr/xephi/authme/output/messages_test2.yml diff --git a/src/test/resources/config-difficult-values.yml b/src/test/resources/fr/xephi/authme/settings/config-difficult-values.yml similarity index 100% rename from src/test/resources/config-difficult-values.yml rename to src/test/resources/fr/xephi/authme/settings/config-difficult-values.yml diff --git a/src/test/resources/config-incomplete-sample.yml b/src/test/resources/fr/xephi/authme/settings/config-incomplete-sample.yml similarity index 100% rename from src/test/resources/config-incomplete-sample.yml rename to src/test/resources/fr/xephi/authme/settings/config-incomplete-sample.yml diff --git a/src/test/resources/config-sample-values.yml b/src/test/resources/fr/xephi/authme/settings/config-sample-values.yml similarity index 100% rename from src/test/resources/config-sample-values.yml rename to src/test/resources/fr/xephi/authme/settings/config-sample-values.yml diff --git a/src/test/resources/spawn/spawn-firstspawn.yml b/src/test/resources/fr/xephi/authme/settings/spawn-firstspawn.yml similarity index 100% rename from src/test/resources/spawn/spawn-firstspawn.yml rename to src/test/resources/fr/xephi/authme/settings/spawn-firstspawn.yml