[Minor] Automated Code cleanup: Dereference of 'realmMigrations' may produce 'NullPointerException'
This commit is contained in:
parent
3c08be1314
commit
73d6fe9120
|
@ -24,11 +24,11 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
import li.strolch.agent.api.ComponentContainer;
|
import li.strolch.agent.api.ComponentContainer;
|
||||||
import li.strolch.agent.api.StrolchAgent;
|
import li.strolch.agent.api.StrolchAgent;
|
||||||
|
import li.strolch.handler.operationslog.OperationsLog;
|
||||||
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.log.LogMessage;
|
import li.strolch.model.log.LogMessage;
|
||||||
import li.strolch.model.log.LogMessageState;
|
import li.strolch.model.log.LogMessageState;
|
||||||
import li.strolch.model.log.LogSeverity;
|
import li.strolch.model.log.LogSeverity;
|
||||||
import li.strolch.handler.operationslog.OperationsLog;
|
|
||||||
import li.strolch.model.Locator;
|
|
||||||
import li.strolch.privilege.model.Certificate;
|
import li.strolch.privilege.model.Certificate;
|
||||||
import li.strolch.utils.Version;
|
import li.strolch.utils.Version;
|
||||||
import li.strolch.utils.collections.MapOfLists;
|
import li.strolch.utils.collections.MapOfLists;
|
||||||
|
@ -141,8 +141,8 @@ public class Migrations {
|
||||||
for (Version version : list) {
|
for (Version version : list) {
|
||||||
LogMessage logMessage = new LogMessage(realm, SYSTEM_USER_AGENT,
|
LogMessage logMessage = new LogMessage(realm, SYSTEM_USER_AGENT,
|
||||||
locator.append(StrolchAgent.getUniqueId()), LogSeverity.Info, LogMessageState.Information,
|
locator.append(StrolchAgent.getUniqueId()), LogSeverity.Info, LogMessageState.Information,
|
||||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.migrations.version")
|
ResourceBundle.getBundle("strolch-service"), "execution.handler.migrations.version").value(
|
||||||
.value("version", version.toString());
|
"version", version.toString());
|
||||||
operationsLog.addMessage(logMessage);
|
operationsLog.addMessage(logMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,7 @@ public class Migrations {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cert
|
*
|
||||||
* @param codeMigrationsByRealm
|
|
||||||
*/
|
*/
|
||||||
public void runCodeMigrations(Certificate cert, Map<String, MigrationVersion> currentVersions,
|
public void runCodeMigrations(Certificate cert, Map<String, MigrationVersion> currentVersions,
|
||||||
MapOfLists<String, CodeMigration> codeMigrationsByRealm) {
|
MapOfLists<String, CodeMigration> codeMigrationsByRealm) {
|
||||||
|
@ -234,25 +233,30 @@ public class Migrations {
|
||||||
Map<String, SortedSet<DataMigration>> migrationsByRealm = new HashMap<>();
|
Map<String, SortedSet<DataMigration>> migrationsByRealm = new HashMap<>();
|
||||||
|
|
||||||
File dataDir = new File(migrationsPath, "data");
|
File dataDir = new File(migrationsPath, "data");
|
||||||
if (dataDir.exists()) {
|
if (!dataDir.exists())
|
||||||
DBC.PRE.assertTrue("migrations/data must be a directory!", dataDir.isDirectory());
|
return migrationsByRealm;
|
||||||
|
|
||||||
// only list directories where name is a realmName
|
DBC.PRE.assertTrue("migrations/data must be a directory!", dataDir.isDirectory());
|
||||||
File[] realmMigrations = dataDir.listFiles(path -> realmNames.contains(path.getName()));
|
|
||||||
|
|
||||||
for (File realmMigration : realmMigrations) {
|
// only list directories where name is a realmName
|
||||||
String realm = realmMigration.getName();
|
File[] realmMigrations = dataDir.listFiles(path -> realmNames.contains(path.getName()));
|
||||||
|
if (realmMigrations == null)
|
||||||
|
return migrationsByRealm;
|
||||||
|
|
||||||
SortedSet<DataMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
|
for (File realmMigration : realmMigrations) {
|
||||||
migrationsByRealm.put(realm, migrations);
|
String realm = realmMigration.getName();
|
||||||
|
|
||||||
File[] migrationFiles = realmMigration
|
SortedSet<DataMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
|
||||||
.listFiles(pathname -> pathname.getName().endsWith(".xml"));
|
migrationsByRealm.put(realm, migrations);
|
||||||
for (File file : migrationFiles) {
|
|
||||||
String name = file.getName();
|
File[] migrationFiles = realmMigration.listFiles(pathname -> pathname.getName().endsWith(".xml"));
|
||||||
Version version = Version.valueOf(name.substring(0, name.length() - 4));
|
if (migrationFiles == null)
|
||||||
migrations.add(new DataMigration(realm, version, file));
|
continue;
|
||||||
}
|
|
||||||
|
for (File file : migrationFiles) {
|
||||||
|
String name = file.getName();
|
||||||
|
Version version = Version.valueOf(name.substring(0, name.length() - 4));
|
||||||
|
migrations.add(new DataMigration(realm, version, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,24 +269,29 @@ public class Migrations {
|
||||||
Map<String, SortedSet<CodeMigration>> migrationsByRealm = new HashMap<>(); //new TreeSet<>((o1, o2) -> o1.getVersion().compareTo(o2.getVersion()));
|
Map<String, SortedSet<CodeMigration>> migrationsByRealm = new HashMap<>(); //new TreeSet<>((o1, o2) -> o1.getVersion().compareTo(o2.getVersion()));
|
||||||
|
|
||||||
File codeDir = new File(migrationsPath, "code");
|
File codeDir = new File(migrationsPath, "code");
|
||||||
if (codeDir.exists()) {
|
if (!codeDir.exists())
|
||||||
DBC.PRE.assertTrue("migrations/code must be a directory!", codeDir.isDirectory());
|
return migrationsByRealm;
|
||||||
|
|
||||||
File[] realmMigrations = codeDir.listFiles(path -> realmNames.contains(path.getName()));
|
DBC.PRE.assertTrue("migrations/code must be a directory!", codeDir.isDirectory());
|
||||||
|
|
||||||
for (File realmMigration : realmMigrations) {
|
File[] realmMigrations = codeDir.listFiles(path -> realmNames.contains(path.getName()));
|
||||||
String realm = realmMigration.getName();
|
if (realmMigrations == null)
|
||||||
|
return migrationsByRealm;
|
||||||
|
|
||||||
SortedSet<CodeMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
|
for (File realmMigration : realmMigrations) {
|
||||||
migrationsByRealm.put(realm, migrations);
|
String realm = realmMigration.getName();
|
||||||
|
|
||||||
File[] migrationFiles = realmMigration
|
SortedSet<CodeMigration> migrations = new TreeSet<>(Comparator.comparing(Migration::getVersion));
|
||||||
.listFiles(pathname -> pathname.getName().endsWith(".xml"));
|
migrationsByRealm.put(realm, migrations);
|
||||||
for (File file : migrationFiles) {
|
|
||||||
String name = file.getName();
|
File[] migrationFiles = realmMigration.listFiles(pathname -> pathname.getName().endsWith(".xml"));
|
||||||
Version version = Version.valueOf(name.substring(0, name.length() - 4));
|
if (migrationFiles == null)
|
||||||
migrations.add(new CodeMigration(realm, version, file));
|
continue;
|
||||||
}
|
|
||||||
|
for (File file : migrationFiles) {
|
||||||
|
String name = file.getName();
|
||||||
|
Version version = Version.valueOf(name.substring(0, name.length() - 4));
|
||||||
|
migrations.add(new CodeMigration(realm, version, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue