use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project irontest by zheng-wang.
the class UpgradeActions method getApplicableUpgradeResourceFiles.
/**
* Result is sorted by fromVersion.
* @param oldVersion
* @param newVersion
* @param subPackage
* @param prefix
* @param extension
* @return
*/
private List<ResourceFile> getApplicableUpgradeResourceFiles(DefaultArtifactVersion oldVersion, DefaultArtifactVersion newVersion, String subPackage, String prefix, String extension) {
List<ResourceFile> result = new ArrayList<>();
Reflections reflections = new Reflections(getClass().getPackage().getName() + "." + subPackage, new ResourcesScanner());
Set<String> upgradeFilePaths = reflections.getResources(Pattern.compile(prefix + ".*\\." + extension));
for (String upgradeFilePath : upgradeFilePaths) {
String[] upgradeFilePathFragments = upgradeFilePath.split("/");
String upgradeFileName = upgradeFilePathFragments[upgradeFilePathFragments.length - 1];
String[] versionsInUpgradeFileName = upgradeFileName.replace(prefix + "_", "").replace("." + extension, "").split("_To_");
DefaultArtifactVersion fromVersionInUpgradeFileName = new DefaultArtifactVersion(versionsInUpgradeFileName[0].replace("_", "."));
DefaultArtifactVersion toVersionInUpgradeFileName = new DefaultArtifactVersion(versionsInUpgradeFileName[1].replace("_", "."));
if (fromVersionInUpgradeFileName.compareTo(oldVersion) >= 0 && toVersionInUpgradeFileName.compareTo(newVersion) <= 0) {
ResourceFile upgradeResourceFile = new ResourceFile();
upgradeResourceFile.setResourcePath(upgradeFilePath);
upgradeResourceFile.setFromVersion(fromVersionInUpgradeFileName);
upgradeResourceFile.setToVersion(toVersionInUpgradeFileName);
result.add(upgradeResourceFile);
}
}
Collections.sort(result);
return result;
}
use of org.apache.maven.artifact.versioning.DefaultArtifactVersion in project irontest by zheng-wang.
the class IronTestApplication method checkVersion.
/**
* @param systemDBJdbi
* @return true if version check finds no problem, false otherwise.
*/
private boolean checkVersion(Jdbi systemDBJdbi) {
DefaultArtifactVersion systemDBVersion = Utils.getSystemDBVersion(systemDBJdbi);
DefaultArtifactVersion jarFileVersion = new DefaultArtifactVersion(Version.VERSION);
int comparison = systemDBVersion.compareTo(jarFileVersion);
if ("SNAPSHOT".equals(systemDBVersion.getQualifier()) || "SNAPSHOT".equals(jarFileVersion.getQualifier())) {
// SNAPSHOT jar or system DB is not considered for upgrade
return true;
} else if (comparison == 0) {
// system database and the jar file are of the same version
return true;
} else if (comparison > 0) {
// system database version is bigger than the jar file version
System.out.printf(Constants.PROMPT_TEXT_WHEN_SYSTEM_DB_VERSION_IS_BIGGER_THAN_JAR_VERSION, systemDBVersion, jarFileVersion);
System.out.println();
return false;
} else {
// system database version is smaller than the jar file version
System.out.printf("System database version %1$s is smaller than jar file version %2$s.%n", systemDBVersion, jarFileVersion);
System.out.println("Please download and build the latest release of Iron Test. Under the dist directory, " + "run command 'java -jar <jarFileName> upgrade <IronTest_Home>' to upgrade your existing " + "Iron Test instance.");
System.out.println("Follow the instructions to finish upgrade. In the end, you should see in the " + "command line output 'UPGRADE SUCCESS'.");
return false;
}
}
Aggregations