Fix various code issues as detected by Sonar
Mostly minor changes: - Add deprecated javadoc tag on deprecated members - Reduce duplication (FlatFile, BackupService, ...) - Make methods static - Reduce size of anonymous classes - Replace name with displayName in PermissionsSystemType (avoids confusing with Enum name()) - Tabs to spaces - Merge if statements Code from third-party sources (BCryptService, BinTools, PHPBB) not modified.
This commit is contained in:
@@ -9,7 +9,6 @@ import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
@@ -295,19 +294,11 @@ public class FlatFile implements DataSource {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
return false;
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
return false;
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
silentClose(br);
|
||||
}
|
||||
if (newAuth != null) {
|
||||
removeAuth(auth.getNickname());
|
||||
@@ -330,19 +321,11 @@ public class FlatFile implements DataSource {
|
||||
}
|
||||
}
|
||||
return countIp;
|
||||
} catch (FileNotFoundException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
return new ArrayList<>();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
silentClose(br);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,12 +346,7 @@ public class FlatFile implements DataSource {
|
||||
} catch (IOException ex) {
|
||||
ConsoleLogger.warning(ex.getMessage());
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
silentClose(br);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MySQL implements DataSource {
|
||||
private int phpBbGroup;
|
||||
private String wordpressPrefix;
|
||||
|
||||
public MySQL(Settings settings) throws ClassNotFoundException, SQLException, PoolInitializationException {
|
||||
public MySQL(Settings settings) throws ClassNotFoundException, SQLException {
|
||||
setParameters(settings);
|
||||
|
||||
// Set the connection arguments (and check if connection is ok)
|
||||
@@ -102,12 +102,12 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private void setConnectionArguments() throws RuntimeException {
|
||||
private void setConnectionArguments() {
|
||||
ds = new HikariDataSource();
|
||||
ds.setPoolName("AuthMeMYSQLPool");
|
||||
|
||||
// Pool size
|
||||
ds.setMaximumPoolSize(poolSize);
|
||||
ds.setMaximumPoolSize(poolSize);
|
||||
|
||||
// Database URL
|
||||
ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||
@@ -134,7 +134,7 @@ public class MySQL implements DataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() throws RuntimeException {
|
||||
public void reload() {
|
||||
if (ds != null) {
|
||||
ds.close();
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ package fr.xephi.authme.datasource;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.Columns;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
@@ -397,7 +394,7 @@ public class SQLite implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private void close(Statement st) {
|
||||
private static void close(Statement st) {
|
||||
if (st != null) {
|
||||
try {
|
||||
st.close();
|
||||
@@ -407,7 +404,7 @@ public class SQLite implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private void close(Connection con) {
|
||||
private static void close(Connection con) {
|
||||
if (con != null) {
|
||||
try {
|
||||
con.close();
|
||||
@@ -417,7 +414,7 @@ public class SQLite implements DataSource {
|
||||
}
|
||||
}
|
||||
|
||||
private void close(ResultSet rs) {
|
||||
private static void close(ResultSet rs) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
@@ -479,7 +476,7 @@ public class SQLite implements DataSource {
|
||||
pst.setString(1, user);
|
||||
rs = pst.executeQuery();
|
||||
if (rs.next())
|
||||
return (rs.getInt(col.IS_LOGGED) == 1);
|
||||
return rs.getInt(col.IS_LOGGED) == 1;
|
||||
} catch (SQLException ex) {
|
||||
logSqlException(ex);
|
||||
} finally {
|
||||
|
||||
@@ -43,20 +43,7 @@ public class CrazyLoginConverter implements Converter {
|
||||
try (BufferedReader users = new BufferedReader(new FileReader(source))) {
|
||||
while ((line = users.readLine()) != null) {
|
||||
if (line.contains("|")) {
|
||||
String[] args = line.split("\\|");
|
||||
if (args.length < 2 || "name".equalsIgnoreCase(args[0])) {
|
||||
continue;
|
||||
}
|
||||
String playerName = args[0];
|
||||
String password = args[1];
|
||||
if (password != null) {
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(playerName.toLowerCase())
|
||||
.realName(playerName)
|
||||
.password(password, null)
|
||||
.build();
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
migrateAccount(line);
|
||||
}
|
||||
}
|
||||
ConsoleLogger.info("CrazyLogin database has been imported correctly");
|
||||
@@ -66,4 +53,26 @@ public class CrazyLoginConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves an account from CrazyLogin to the AuthMe database.
|
||||
*
|
||||
* @param line line read from the CrazyLogin file (one account)
|
||||
*/
|
||||
private void migrateAccount(String line) {
|
||||
String[] args = line.split("\\|");
|
||||
if (args.length < 2 || "name".equalsIgnoreCase(args[0])) {
|
||||
return;
|
||||
}
|
||||
String playerName = args[0];
|
||||
String password = args[1];
|
||||
if (password != null) {
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(playerName.toLowerCase())
|
||||
.realName(playerName)
|
||||
.password(password, null)
|
||||
.build();
|
||||
database.saveAuth(auth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user