Skip to content

Commit e55862a

Browse files
committed
Avoid to call two times loadInstalledModuleStatus in SilverpeasMigrationTask. Specify the type of some objects
1 parent 39f6c9b commit e55862a

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/main/groovy/org/silverpeas/setup/migration/DatasourceMigration.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class DatasourceMigration {
111111
}
112112

113113
private void performUpgrade(Sql sql, Map settings) throws Exception {
114-
logger.info " Upgrade of the module ${module} to version ${toVersion}"
114+
logger.info " Upgrade of the module ${module} from version ${fromVersion} to version ${toVersion}"
115115
String status = 'OK'
116116
try {
117117
sql.withTransaction {

src/main/groovy/org/silverpeas/setup/migration/MigrationModule.groovy

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package org.silverpeas.setup.migration
2626
import com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory
2727
import groovy.transform.builder.Builder
2828
import groovy.transform.builder.SimpleStrategy
29-
import org.gradle.api.Project
3029
import org.gradle.api.tasks.TaskExecutionException
3130
import org.silverpeas.setup.api.FileLogger
3231
import org.silverpeas.setup.api.Script
@@ -53,9 +52,8 @@ class MigrationModule {
5352
private String module
5453
private Integer order
5554
private List<DatasourceMigration> migrations = []
56-
def status
55+
Map<String, String> status
5756
Map settings
58-
Project project
5957
FileLogger logger
6058

6159
/**
@@ -119,8 +117,8 @@ class MigrationModule {
119117
logger.info "Load migration descriptor ${descriptor.name}"
120118
validateDescriptor(descriptor)
121119
def migrationDescriptor = new XmlSlurper().parse(descriptor)
122-
module = migrationDescriptor.@module.text()
123-
order = migrationDescriptor.@order?.text() ? migrationDescriptor.@order.text() as int : UNORDERED
120+
this.module = migrationDescriptor.@module.text()
121+
this.order = migrationDescriptor.@order?.text() ? migrationDescriptor.@order.text() as int : UNORDERED
124122
String actualVersion = status[module]
125123
String toVersion = migrationDescriptor.current.@version.text()
126124
if (actualVersion) {

src/main/groovy/org/silverpeas/setup/migration/SilverpeasMigrationTask.groovy

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class SilverpeasMigrationTask extends DefaultTask {
7070

7171
@TaskAction
7272
void performMigration() {
73-
initMigrationTask()
74-
loadMigrationModules().each { module ->
73+
Map<String, String> modulesStatus = initMigrationTask()
74+
loadMigrationModules(modulesStatus).each { module ->
7575
try {
7676
module.migrate()
7777
} catch (Exception ex) {
@@ -82,13 +82,13 @@ class SilverpeasMigrationTask extends DefaultTask {
8282
}
8383

8484
/**
85-
* Initializes the migration task first by loading the settings of the migration process, then by
86-
* performing any migration of these settings if it is required.
87-
* </p>
88-
* The migration settings are also persisted in a data source and they could be subject to a
89-
* migration before doing anything.
85+
* Initializes the migration task first by loading the actual status of each modules in Silverpeas
86+
* and then by migrating, if needed, the migration process module itself (the status of this
87+
* module is also persisted into the Silverpeas data source).
88+
* @return the status of each module in a dictionary; in each entry, the key is the name of the
89+
* module and the value the actual version of the module.
9090
*/
91-
private void initMigrationTask() {
91+
private Map<String, String> initMigrationTask() {
9292
log.info 'Migration initialization...'
9393
def status = loadInstalledModuleStatus()
9494
Path descriptor = Paths.get(migrationHome.path, 'modules', MIGRATION_SETTING_MODULE)
@@ -99,14 +99,18 @@ class SilverpeasMigrationTask extends DefaultTask {
9999
.loadMigrationsFrom(descriptor.toFile())
100100
module.migrate()
101101
log.info 'Migration initialization done'
102+
return status
102103
}
103104

104105
/**
105-
* Loads all the available migration modules in Silverpeas.
106+
* Loads all of the available migration modules in Silverpeas from their descriptor and the
107+
* specified status. The descriptor of each module is an XML file located in a predefined
108+
* folder of the Silverpeas distribution home directory.
109+
* @param status the status of all the modules from which each module will know what migration
110+
* it has to do.
106111
* @return a list of the available migration modules.
107112
*/
108-
private List<MigrationModule> loadMigrationModules() {
109-
def status = loadInstalledModuleStatus()
113+
private List<MigrationModule> loadMigrationModules(Map<String, String> status) {
110114
List<MigrationModule> modules = []
111115
new File(migrationHome, 'modules').listFiles().each { descriptor ->
112116
if (descriptor.name != MIGRATION_SETTING_MODULE) {
@@ -123,10 +127,17 @@ class SilverpeasMigrationTask extends DefaultTask {
123127
}
124128
}
125129

126-
private def loadInstalledModuleStatus() {
130+
/**
131+
* Loads from the Silverpeas data source the status of all of the currently installed modules.
132+
* If it is a fresh installation, then the returned status will be empty as there will be no
133+
* modules yet installed.
134+
* @return the status of all of the modules actually installed. It is a dictionary with, for each
135+
* entry, the name of the module as the key and the actual version of that module as value.
136+
*/
137+
private Map<String, String> loadInstalledModuleStatus() {
127138
def level = logging.level
128139
logging.captureStandardOutput(LogLevel.ERROR)
129-
def status = [:]
140+
Map<String, String> status = [:]
130141
DataSourceProvider dataSourceProvider = ManagedBeanContainer.get(DataSourceProvider.class)
131142
Sql sql = new Sql(dataSourceProvider.dataSource)
132143
try {

0 commit comments

Comments
 (0)