Package com.day.jcr.vault.packaging

Examples of com.day.jcr.vault.packaging.Version


        JcrUtil.copy(thumbnailNode, packageOneDefNode, "thumbnail.png");
    }

    @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());
    }
View Full Code Here


        assertEquals(expected.toString(), actual.toString());
    }

    @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());
    }
View Full Code Here

     */
    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;
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.day.jcr.vault.packaging.Version

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.