Update checkstyle config and CodeClimate exclusions

- Add new checkstyle checks: require Javadoc on large private methods, default in switch, declaration order & others
- Update path exclusions in CodeClimate config to match newly renamed classes (e.g. PHPBB -> PhpBB)
  - Create consistency check testing that excluded paths exist as classes
- Fix some trivial violations
This commit is contained in:
ljacqu
2017-03-23 10:34:28 +01:00
parent e77828b228
commit 32a664ef59
27 changed files with 185 additions and 93 deletions
@@ -127,7 +127,8 @@ public class NewAPI {
public Location getLastLocation(Player player) {
PlayerAuth auth = playerCache.getAuth(player.getName());
if (auth != null) {
return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
return new Location(Bukkit.getWorld(auth.getWorld()),
auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
}
return null;
}
@@ -66,6 +66,10 @@ public class CommandInitializer {
return commands;
}
/**
* Builds the command description objects for all available AuthMe commands.
*/
@SuppressWarnings({"checkstyle:LocalVariableName", "checkstyle:AbbreviationAsWordInName"})
private void buildCommands() {
// Register the base AuthMe Reloaded command
final CommandDescription AUTHME_BASE = CommandDescription.builder()
@@ -31,12 +31,12 @@ public class VersionCommand implements ExecutableCommand {
printDeveloper(sender, "games647", "games647", "Developer", onlinePlayers);
printDeveloper(sender, "Tim Visee", "timvisee", "Developer", onlinePlayers);
printDeveloper(sender, "Gabriele C.", "sgdc3", "Project manager, Contributor", onlinePlayers);
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE +
"http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.WHITE
+ "http://dev.bukkit.org/bukkit-plugins/authme-reloaded/");
sender.sendMessage(ChatColor.GOLD + "License: " + ChatColor.WHITE + "GNU GPL v3.0"
+ ChatColor.GRAY + ChatColor.ITALIC + " (See LICENSE file)");
sender.sendMessage(ChatColor.GOLD + "Copyright: " + ChatColor.WHITE
+ "Copyright (c) AuthMe-Team 2016. All rights reserved.");
+ "Copyright (c) AuthMe-Team 2017. All rights reserved.");
}
/**
@@ -3,7 +3,7 @@ package fr.xephi.authme.command.executable.authme.debug;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.mail.SendMailSSL;
import fr.xephi.authme.mail.SendMailSsl;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.bukkit.ChatColor;
@@ -22,7 +22,7 @@ class TestEmailSender implements DebugSection {
private DataSource dataSource;
@Inject
private SendMailSSL sendMailSSL;
private SendMailSsl sendMailSsl;
@Inject
private Server server;
@@ -40,7 +40,7 @@ class TestEmailSender implements DebugSection {
@Override
public void execute(CommandSender sender, List<String> arguments) {
if (!sendMailSSL.hasAllInformation()) {
if (!sendMailSsl.hasAllInformation()) {
sender.sendMessage(ChatColor.RED + "You haven't set all required configurations in config.yml "
+ "for sending emails. Please check your config.yml");
return;
@@ -87,7 +87,7 @@ class TestEmailSender implements DebugSection {
private boolean sendTestEmail(String email) {
HtmlEmail htmlEmail;
try {
htmlEmail = sendMailSSL.initializeMail(email);
htmlEmail = sendMailSsl.initializeMail(email);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create email for sample email:", e);
return false;
@@ -96,6 +96,6 @@ class TestEmailSender implements DebugSection {
htmlEmail.setSubject("AuthMe test email");
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server ("
+ server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
return sendMailSSL.sendEmail(message, htmlEmail);
return sendMailSsl.sendEmail(message, htmlEmail);
}
}
@@ -81,8 +81,8 @@ public class HelpMessagesService implements Reloadable {
public String getMessage(DefaultPermission defaultPermission) {
// e.g. {default_permissions_path}.opOnly for DefaultPermission.OP_ONLY
String path = DEFAULT_PERMISSIONS_PATH +
CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
String path = DEFAULT_PERMISSIONS_PATH
+ CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, defaultPermission.name());
return messageFileHandler.getMessage(path);
}
@@ -31,7 +31,7 @@ import java.util.Set;
public class MySQL implements DataSource {
private boolean useSSL;
private boolean useSsl;
private String host;
private String port;
private String username;
@@ -45,10 +45,10 @@ public class MySQL implements DataSource {
private HikariDataSource ds;
private String phpBbPrefix;
private String IPBPrefix;
private String ipbPrefix;
private int phpBbGroup;
private int IPBGroup;
private int XFGroup;
private int ipbGroup;
private int xfGroup;
private String wordpressPrefix;
public MySQL(Settings settings) throws ClassNotFoundException, SQLException {
@@ -99,15 +99,15 @@ public class MySQL implements DataSource {
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.IPBPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
this.IPBGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
this.XFGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
this.ipbPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
this.ipbGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
this.xfGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX);
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
if (poolSize == -1) {
poolSize = Utils.getCoreCount()*3;
}
this.useSSL = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
}
private void setConnectionArguments() {
@@ -125,7 +125,7 @@ public class MySQL implements DataSource {
ds.setPassword(this.password);
// Request mysql over SSL
ds.addDataSourceProperty("useSSL", useSSL);
ds.addDataSourceProperty("useSSL", useSsl);
// Encoding
ds.addDataSourceProperty("characterEncoding", "utf8");
@@ -347,23 +347,23 @@ public class MySQL implements DataSource {
rs = pst.executeQuery();
if (rs.next()){
// Update player group in core_members
sql = "UPDATE " + IPBPrefix + tableName + " SET "+ tableName + ".member_group_id=? WHERE " + col.NAME + "=?;";
sql = "UPDATE " + ipbPrefix + tableName + " SET "+ tableName + ".member_group_id=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql);
pst2.setInt(1, IPBGroup);
pst2.setInt(1, ipbGroup);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
pst2.close();
// Get current time without ms
long time = System.currentTimeMillis() / 1000;
// update joined date
sql = "UPDATE " + IPBPrefix + tableName + " SET "+ tableName + ".joined=? WHERE " + col.NAME + "=?;";
sql = "UPDATE " + ipbPrefix + tableName + " SET "+ tableName + ".joined=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql);
pst2.setLong(1, time);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
pst2.close();
// Update last_visit
sql = "UPDATE " + IPBPrefix + tableName + " SET " + tableName + ".last_visit=? WHERE " + col.NAME + "=?;";
sql = "UPDATE " + ipbPrefix + tableName + " SET " + tableName + ".last_visit=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql);
pst2.setLong(1, time);
pst2.setString(2, auth.getNickname());
@@ -531,14 +531,14 @@ public class MySQL implements DataSource {
// Update player group in xf_users
sql = "UPDATE " + tableName + " SET "+ tableName + ".user_group_id=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql);
pst2.setInt(1, XFGroup);
pst2.setInt(1, xfGroup);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
pst2.close();
// Update player permission combination in xf_users
sql = "UPDATE " + tableName + " SET "+ tableName + ".permission_combination_id=? WHERE " + col.NAME + "=?;";
pst2 = con.prepareStatement(sql);
pst2.setInt(1, XFGroup);
pst2.setInt(1, xfGroup);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
pst2.close();
@@ -557,7 +557,7 @@ public class MySQL implements DataSource {
sql = "INSERT INTO xf_user_group_relation (user_id, user_group_id, is_primary) VALUES (?,?,?)";
pst2 = con.prepareStatement(sql);
pst2.setInt(1, id);
pst2.setInt(2, XFGroup);
pst2.setInt(2, xfGroup);
pst2.setString(3, "1");
pst2.executeUpdate();
pst2.close();
@@ -46,7 +46,7 @@ public class RakamakConverter implements Converter {
String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
File source = new File(pluginFolder, fileName);
File ipFiles = new File(pluginFolder, ipFileName);
Map<String, String> playerIP = new HashMap<>();
Map<String, String> playerIp = new HashMap<>();
Map<String, HashedPassword> playerPassword = new HashMap<>();
try {
BufferedReader ipFile = new BufferedReader(new FileReader(ipFiles));
@@ -56,7 +56,7 @@ public class RakamakConverter implements Converter {
while ((tempLine = ipFile.readLine()) != null) {
if (tempLine.contains("=")) {
String[] args = tempLine.split("=");
playerIP.put(args[0], args[1]);
playerIp.put(args[0], args[1]);
}
}
}
@@ -75,7 +75,7 @@ public class RakamakConverter implements Converter {
for (Entry<String, HashedPassword> m : playerPassword.entrySet()) {
String playerName = m.getKey();
HashedPassword psw = playerPassword.get(playerName);
String ip = useIp ? playerIP.get(playerName) : "127.0.0.1";
String ip = useIp ? playerIp.get(playerName) : "127.0.0.1";
PlayerAuth auth = PlayerAuth.builder()
.name(playerName)
.realName(playerName)
@@ -25,18 +25,18 @@ public class EmailService {
private final File dataFolder;
private final String serverName;
private final Settings settings;
private final SendMailSSL sendMailSSL;
private final SendMailSsl sendMailSsl;
@Inject
EmailService(@DataFolder File dataFolder, Server server, Settings settings, SendMailSSL sendMailSSL) {
EmailService(@DataFolder File dataFolder, Server server, Settings settings, SendMailSsl sendMailSsl) {
this.dataFolder = dataFolder;
this.serverName = server.getServerName();
this.settings = settings;
this.sendMailSSL = sendMailSSL;
this.sendMailSsl = sendMailSsl;
}
public boolean hasAllInformation() {
return sendMailSSL.hasAllInformation();
return sendMailSsl.hasAllInformation();
}
@@ -56,7 +56,7 @@ public class EmailService {
HtmlEmail email;
try {
email = sendMailSSL.initializeMail(mailAddress);
email = sendMailSsl.initializeMail(mailAddress);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create email with the given settings:", e);
return false;
@@ -75,7 +75,7 @@ public class EmailService {
}
}
boolean couldSendEmail = sendMailSSL.sendEmail(mailText, email);
boolean couldSendEmail = sendMailSsl.sendEmail(mailText, email);
FileUtils.delete(file);
return couldSendEmail;
}
@@ -83,7 +83,7 @@ public class EmailService {
public boolean sendRecoveryCode(String name, String email, String code) {
HtmlEmail htmlEmail;
try {
htmlEmail = sendMailSSL.initializeMail(email);
htmlEmail = sendMailSsl.initializeMail(email);
} catch (EmailException e) {
ConsoleLogger.logException("Failed to create email for recovery code:", e);
return false;
@@ -91,7 +91,7 @@ public class EmailService {
String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(),
name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID));
return sendMailSSL.sendEmail(message, htmlEmail);
return sendMailSsl.sendEmail(message, htmlEmail);
}
private File generateImage(String name, String newPass) throws IOException {
@@ -24,7 +24,7 @@ import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
/**
* Sends emails to players on behalf of the server.
*/
public class SendMailSSL {
public class SendMailSsl {
@Inject
private Settings settings;
@@ -67,7 +67,7 @@ public class SendMailSSL {
}
public boolean sendEmail(String content, HtmlEmail email) {
Thread.currentThread().setContextClassLoader(SendMailSSL.class.getClassLoader());
Thread.currentThread().setContextClassLoader(SendMailSsl.class.getClassLoader());
// Issue #999: Prevent UnsupportedDataTypeException: no object DCH for MIME type multipart/alternative
// cf. http://stackoverflow.com/questions/21856211/unsupporteddatatypeexception-no-object-dch-for-mime-type
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
@@ -79,8 +79,8 @@ public class AuthGroupHandler implements Reloadable {
throw new IllegalStateException("Encountered unhandled auth group type '" + groupType + "'");
}
ConsoleLogger.debug(
() -> player.getName() + " changed to " + groupType + ": has groups " + permissionsManager.getGroups(player));
ConsoleLogger.debug(() -> player.getName() + " changed to "
+ groupType + ": has groups " + permissionsManager.getGroups(player));
}
/**
@@ -74,7 +74,7 @@ public class PermissionsManager implements Reloadable {
// Loop through all the available permissions system types
for (PermissionsSystemType type : PermissionsSystemType.values()) {
try {
PermissionHandler handler = getPermissionHandler(type);
PermissionHandler handler = createPermissionHandler(type);
if (handler != null) {
// Show a success message and return
this.handler = handler;
@@ -91,7 +91,14 @@ public class PermissionsManager implements Reloadable {
ConsoleLogger.info("No supported permissions system found! Permissions are disabled!");
}
private PermissionHandler getPermissionHandler(PermissionsSystemType type) throws PermissionHandlerException {
/**
* Creates a permission handler for the provided permission systems if possible.
*
* @param type the permission systems type for which to create a corresponding permission handler
* @return the permission handler, or {@code null} if not possible
* @throws PermissionHandlerException during initialization of the permission handler
*/
private PermissionHandler createPermissionHandler(PermissionsSystemType type) throws PermissionHandlerException {
// Try to find the plugin for the current permissions system
Plugin plugin = pluginManager.getPlugin(type.getPluginName());
@@ -17,7 +17,7 @@ public interface PermissionHandler {
* @param group The name of the group.
*
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
* False is also returned if this feature isn't supported for the current permissions system.
*/
boolean addToGroup(Player player, String group);
@@ -47,7 +47,7 @@ public interface PermissionHandler {
* @param group The group name.
*
* @return True if the player is in the specified group, false otherwise.
* False is also returned if groups aren't supported by the used permissions system.
* False is also returned if groups aren't supported by the used permissions system.
*/
default boolean isInGroup(Player player, String group) {
return getGroups(player).contains(group);
@@ -60,7 +60,7 @@ public interface PermissionHandler {
* @param group The name of the group.
*
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
* False is also returned if this feature isn't supported for the current permissions system.
*/
boolean removeFromGroup(Player player, String group);
@@ -72,7 +72,7 @@ public interface PermissionHandler {
* @param group The name of the group.
*
* @return True if succeed, false otherwise.
* False is also returned if this feature isn't supported for the current permissions system.
* False is also returned if this feature isn't supported for the current permissions system.
*/
boolean setGroup(Player player, String group);
@@ -96,6 +96,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
* Checks the precondition for authentication (like user known) and returns
* the player's {@link PlayerAuth} object.
*
* @param player the player to check
* @return the PlayerAuth object, or {@code null} if the player doesn't exist or may not log in
* (e.g. because he is already logged in)
*/
@@ -17,6 +17,8 @@ import javax.inject.Inject;
/**
* Registration executor for registration methods where the password
* is supplied by the user.
*
* @param <P> the parameters type
*/
abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegisterParams>
implements RegistrationExecutor<P> {
@@ -4,6 +4,8 @@ import fr.xephi.authme.data.auth.PlayerAuth;
/**
* Performs the registration action.
*
* @param <P> the registration parameters type
*/
public interface RegistrationExecutor<P extends RegistrationParameters> {
@@ -8,6 +8,8 @@ package fr.xephi.authme.process.register.executors;
* classes which perform this registration method. This is essentially a <i>typed enum</i>
* as passing a constant of this class along with a parameters object to a method can
* be restricted to the correct parameters type.
*
* @param <P> the registration parameters type the method uses
*/
public final class RegistrationMethod<P extends RegistrationParameters> {
@@ -44,7 +44,7 @@ public class BukkitService implements SettingsDependent {
@Inject
BukkitService(AuthMe authMe, Settings settings) {
this.authMe = authMe;
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
getOnlinePlayersIsCollection = doesOnlinePlayersMethodReturnCollection();
reload(settings);
}
@@ -301,11 +301,12 @@ public class BukkitService implements SettingsDependent {
/**
* Method run upon initialization to verify whether or not the Bukkit implementation
* returns the online players as a Collection.
* returns the online players as a {@link Collection}.
*
* @return true if a collection is returned by the bukkit implementation, false otherwise
* @see #getOnlinePlayers()
*/
private static boolean initializeOnlinePlayersIsCollectionField() {
private static boolean doesOnlinePlayersMethodReturnCollection() {
try {
Method method = Bukkit.class.getDeclaredMethod("getOnlinePlayers");
return method.getReturnType() == Collection.class;
@@ -12,6 +12,8 @@ import static com.google.common.collect.Sets.newHashSet;
/**
* Property whose value is a set of entries of a given enum.
*
* @param <E> the enum type
*/
public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
@@ -7,6 +7,8 @@ import java.util.concurrent.TimeUnit;
* <p>
* Once the expiration of an entry has been reached, the counter resets
* to 0. The counter returns 0 rather than {@code null} for any given key.
*
* @param <K> the type of the key
*/
public class TimedCounter<K> extends ExpiringMap<K, Integer> {
@@ -47,8 +49,7 @@ public class TimedCounter<K> extends ExpiringMap<K, Integer> {
if (e != null) {
if (e.getValue() <= 0) {
remove(key);
}
else {
} else {
entries.put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
}
}