Skip to content

Commit

Permalink
Support for version numbers such as 4.0-M1
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jan 7, 2019
1 parent a6b72f5 commit 5004153
Showing 1 changed file with 13 additions and 1 deletion.
Expand Up @@ -34,6 +34,8 @@
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Determines the action that should be done against the database (none, stop, warn, create, upgrade)
Expand All @@ -56,6 +58,8 @@ class SchemaActionComputer {

private static final String RELEASE_NOTES_URL_PREFIX = "https://wiki.evolveum.com/display/midPoint/Release+";
private static final String SQL_SCHEMA_SCRIPTS_URL = "https://wiki.evolveum.com/display/midPoint/SQL+Schema+Scripts";

private static final Pattern VERSION_SUFFIX_PATTERN = Pattern.compile("(.*)-[^.]+");

@Autowired private LocalizationService localizationService;
@Autowired private BaseHelper baseHelper;
Expand Down Expand Up @@ -287,7 +291,7 @@ private String getRequiredDatabaseSchemaVersion() {
private String getMajorMidPointVersion() {
String version = localizationService
.translate(LocalizableMessageBuilder.buildKey("midPointVersion"), Locale.getDefault());
String noSnapshot = StringUtils.removeEnd(version, "-SNAPSHOT");
String noSnapshot = removeSuffix(version);
int firstDot = noSnapshot.indexOf('.');
if (firstDot < 0) {
throw new SystemException("Couldn't determine midPoint version from '" + version + "'");
Expand All @@ -300,6 +304,14 @@ private String getMajorMidPointVersion() {
}
}

private String removeSuffix(String version) {
Matcher matcher = VERSION_SUFFIX_PATTERN.matcher(version);
if (matcher.find()) {
return matcher.group(1);
}
return version;
}

private String determineUpgradeScriptFileName(@NotNull String from, @NotNull String to) {
SqlRepositoryConfiguration.Database database = getDatabase();
return database.name().toLowerCase() + "-upgrade-" + from + "-" + to + getVariantSuffix() + ".sql";
Expand Down

0 comments on commit 5004153

Please sign in to comment.