Search in sources :

Example 36 with DefaultArtifactVersion

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;
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 37 with DefaultArtifactVersion

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;
    }
}
Also used : DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion)

Aggregations

DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)37 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)12 File (java.io.File)8 IOException (java.io.IOException)7 Model (org.apache.maven.model.Model)5 FileNotFoundException (java.io.FileNotFoundException)4 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)4 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 Artifact (org.apache.maven.artifact.Artifact)3 SPluginBundle (org.bimserver.interfaces.objects.SPluginBundle)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 FileReader (java.io.FileReader)2 InputStream (java.io.InputStream)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2