Skip to content

Commit

Permalink
APPNG-2207 compare versions the semantic way
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Aug 23, 2018
1 parent fc8b6b4 commit 4d2ff5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions appng-core/pom.xml
Expand Up @@ -360,6 +360,11 @@
<artifactId>appng-rest-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.skuzzle</groupId>
<artifactId>semantic-version</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<!-- END DEPENDENCY MANAGEMENT -->
</project>
Expand Up @@ -20,10 +20,11 @@
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.appng.core.domain.PackageArchiveImpl;
import org.appng.xml.application.PackageInfo;

import de.skuzzle.semantic.Version;

/**
* Utility class offering methods that help dealing with {@link PackageVersion}s and {@link PackageInfo}rmations.
*
Expand Down Expand Up @@ -73,10 +74,10 @@ public static boolean isNewer(PackageInfo packageA, PackageInfo packageB) {
if (null == packageB) {
return true;
} else {
Long timestampA = getDate(packageA).getTime();
Long timestampB = getDate(packageB).getTime();
int isVersionNewer = StringUtils.compare(packageA.getVersion(), packageB.getVersion());
return (0 == isVersionNewer) ? (timestampA > timestampB) : (0 > isVersionNewer ? false : true);
Version versionA = Version.parseVersion(packageA.getVersion() + "-" + packageA.getTimestamp(), true);
Version versionB = Version.parseVersion(packageB.getVersion() + "-" + packageB.getTimestamp(), true);
int isVersionNewer = versionB.compareTo(versionA);
return 0 > isVersionNewer ? true : false;
}
}

Expand Down
Expand Up @@ -22,17 +22,17 @@
import org.junit.Test;

public class RepositoryUtilsTest {

@Test
public void testIsSnapshot(){
public void testIsSnapshot() {
Assert.assertFalse(RepositoryUtils.isSnapshot("snapshot"));
Assert.assertFalse(RepositoryUtils.isSnapshot("SNAPSHOT"));
Assert.assertFalse(RepositoryUtils.isSnapshot("sNaPsHoT"));
Assert.assertTrue(RepositoryUtils.isSnapshot(RepositoryUtils.SNAPSHOT));
}

@Test
public void testGetDate(){
public void testGetDate() {
ApplicationInfo app = new ApplicationInfo();
app.setTimestamp("19700101-0100");
Date date = RepositoryUtils.getDate(app);
Expand Down Expand Up @@ -69,6 +69,15 @@ public void testIsNewer() {
Assert.assertTrue(RepositoryUtils.isNewer(v2_0_0, v1_0_0_a));
Assert.assertTrue(RepositoryUtils.isNewer(v2_0_0, v1_0_0_b));
Assert.assertTrue(RepositoryUtils.isNewer(v2_0_0, v1_1_0));

ApplicationInfo v0_9_0 = new ApplicationInfo();
v0_9_0.setVersion("0.9.0");
ApplicationInfo v0_40_0 = new ApplicationInfo();
v0_40_0.setVersion("0.40.0");

Assert.assertTrue(RepositoryUtils.isNewer(v0_40_0, v0_9_0));
Assert.assertTrue(RepositoryUtils.isNewer(v0_40_0, v0_9_0));
Assert.assertTrue(RepositoryUtils.isNewer(v0_40_0, v0_9_0));
}

}

0 comments on commit 4d2ff5d

Please sign in to comment.