Search in sources :

Example 1 with Version

use of org.apache.jackrabbit.vault.packaging.Version in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImplTest method testGetNextVersion_incrementMinor.

@Test
public void testGetNextVersion_incrementMinor() throws Exception {
    final Version expected = Version.create("2.1.0");
    final Version actual = packageHelper.getNextVersion(jcrPackageManager, packageGroup, packageName, "1.0.0");
    assertEquals(expected.toString(), actual.toString());
}
Also used : Version(org.apache.jackrabbit.vault.packaging.Version) Test(org.junit.Test)

Example 2 with Version

use of org.apache.jackrabbit.vault.packaging.Version in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImpl method getNextVersion.

@SuppressWarnings("squid:S3776")
public Version getNextVersion(final JcrPackageManager jcrPackageManager, final String groupName, final String name, final String version) throws RepositoryException {
    final Node packageRoot = jcrPackageManager.getPackageRoot(false);
    final Version configVersion = Version.create(version);
    if (!packageRoot.hasNode(groupName)) {
        return configVersion;
    }
    final Node packageGroupNode = packageRoot.getNode(groupName);
    if (packageGroupNode == null) {
        return configVersion;
    } else {
        final NodeIterator children = packageGroupNode.getNodes();
        Version latestVersion = configVersion;
        boolean configVersionEligible = true;
        while (children.hasNext()) {
            final Node child = children.nextNode();
            final JcrPackage jcrPackage = jcrPackageManager.open(child, true);
            if (jcrPackage == null || jcrPackage.getDefinition() == null || jcrPackage.getDefinition().getId() == null) {
                log.warn("Could not covert node [ {} ] into a proper JCR Package, moving to next node", child.getPath());
                continue;
            } else if (!StringUtils.equals(name, jcrPackage.getDefinition().getId().getName())) {
                // Name mismatch - so just skip
                continue;
            }
            final Version packageVersion = jcrPackage.getDefinition().getId().getVersion();
            log.debug(packageVersion.toString() + " compareTo " + latestVersion.toString() + " = " + packageVersion.compareTo(latestVersion));
            if (packageVersion.compareTo(latestVersion) >= 1) {
                latestVersion = packageVersion;
                log.debug("Found a new latest version: {}", latestVersion.toString());
            } else if (packageVersion.compareTo(configVersion) == 0) {
                configVersionEligible = false;
                log.debug("Found a package with the same version as the config version");
            }
        }
        log.debug("Current latest version: {}", latestVersion.toString());
        if (configVersionEligible && latestVersion.equals(configVersion)) {
            // If the config-specified version is newer than any existing package, jump to the config version
            return configVersion;
        } else {
            // Else increment the latest known version's minor
            latestVersion = this.normalizeVersion(latestVersion);
            final String[] segments = latestVersion.getNormalizedSegments();
            // Increment minor
            segments[1] = String.valueOf(Integer.parseInt(segments[1]) + 1);
            final Version nextVersion = Version.create(segments);
            log.debug("Next version: {}", nextVersion);
            return nextVersion;
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Version(org.apache.jackrabbit.vault.packaging.Version) Node(javax.jcr.Node) JcrPackage(org.apache.jackrabbit.vault.packaging.JcrPackage)

Example 3 with Version

use of org.apache.jackrabbit.vault.packaging.Version in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImplTest method testGetNextVersion_paramVersion.

@Test
public void testGetNextVersion_paramVersion() throws Exception {
    final Version expected = Version.create("3.0.0");
    final Version actual = packageHelper.getNextVersion(jcrPackageManager, packageGroup, packageName, "3.0.0");
    assertEquals(expected.toString(), actual.toString());
}
Also used : Version(org.apache.jackrabbit.vault.packaging.Version) Test(org.junit.Test)

Aggregations

Version (org.apache.jackrabbit.vault.packaging.Version)3 Test (org.junit.Test)2 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 JcrPackage (org.apache.jackrabbit.vault.packaging.JcrPackage)1