-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
217 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import java.time.Duration; | ||
|
||
@Deprecated | ||
public interface DelaySettings { | ||
|
||
Duration delay(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
eternalcore-core/src/main/java/com/eternalcode/core/configuration/migration/Migration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.eternalcode.core.configuration.migration; | ||
|
||
public interface Migration { | ||
|
||
boolean migrate(); | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...-core/src/main/java/com/eternalcode/core/configuration/migration/MigrationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.eternalcode.core.configuration.migration; | ||
|
||
import com.eternalcode.core.configuration.ConfigurationManager; | ||
import com.eternalcode.core.configuration.ReloadableConfig; | ||
import com.eternalcode.core.injector.annotations.Inject; | ||
import com.eternalcode.core.injector.annotations.component.Controller; | ||
import com.eternalcode.core.publish.Subscribe; | ||
import com.eternalcode.core.publish.event.EternalInitializeEvent; | ||
import java.util.logging.Logger; | ||
|
||
@Controller | ||
class MigrationController { | ||
|
||
private final MigrationService migrationService; | ||
private final ConfigurationManager configurationManager; | ||
private final Logger logger; | ||
|
||
@Inject | ||
MigrationController(MigrationService migrationService, ConfigurationManager configurationManager, Logger logger) { | ||
this.migrationService = migrationService; | ||
this.configurationManager = configurationManager; | ||
this.logger = logger; | ||
} | ||
|
||
@Subscribe | ||
void onMigration(EternalInitializeEvent event) { | ||
for (ReloadableConfig config : configurationManager.getConfigs()) { | ||
boolean wasMigrated = migrationService.migrate(config); | ||
|
||
if (wasMigrated) { | ||
configurationManager.save(config); | ||
logger.info("Configuration " + config.getClass().getSimpleName() + " was migrated and saved."); | ||
} | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ore-core/src/main/java/com/eternalcode/core/configuration/migration/MigrationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.eternalcode.core.configuration.migration; | ||
|
||
import com.eternalcode.core.configuration.ReloadableConfig; | ||
import com.eternalcode.core.injector.annotations.component.Service; | ||
import com.eternalcode.core.util.ReflectUtil; | ||
import java.lang.reflect.Field; | ||
import net.dzikoysk.cdn.entity.Contextual; | ||
|
||
@Service | ||
class MigrationService { | ||
|
||
public <T extends ReloadableConfig> boolean migrate(T config) { | ||
return reflectMigrate(config); | ||
} | ||
|
||
private <T> boolean reflectMigrate(T config) { | ||
boolean isMigrated = false; | ||
|
||
for (Field declaredField : ReflectUtil.getAllSuperFields(config.getClass())) { | ||
Class<?> fieldType = declaredField.getType(); | ||
|
||
if (Migration.class.isAssignableFrom(fieldType)) { | ||
Migration migration = ReflectUtil.getFieldValue(declaredField, config); | ||
boolean wasMigrationSuccessful = migration.migrate(); | ||
isMigrated |= wasMigrationSuccessful; | ||
} | ||
|
||
if (fieldType.isAnnotationPresent(Contextual.class)) { | ||
Object fieldValue = ReflectUtil.getFieldValue(declaredField, config); | ||
isMigrated |= reflectMigrate(fieldValue); | ||
} | ||
} | ||
|
||
return isMigrated; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.