private boolean updateVersions()

in src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java [478:543]


    private boolean updateVersions(
            final String fileName,
            final Feature rawFeature,
            final UpdateResult result,
            final Map<String, Set<String>> globalPropertyUpdates)
            throws MojoExecutionException {
        // update artifacts
        final Iterator<ArtifactUpdate> iter = result.updates.iterator();
        while (iter.hasNext()) {
            final ArtifactUpdate update = iter.next();

            final Artifacts container;
            if (update.extension == null) {
                container = rawFeature.getBundles();
            } else {
                container = rawFeature
                        .getExtensions()
                        .getByName(update.extension.getName())
                        .getArtifacts();
            }
            final int pos = container.indexOf(update.artifact);
            final Artifact oldArtifact = pos == -1 ? null : container.get(pos);
            if (!container.removeExact(update.artifact.getId())) {
                // check if property is used
                final Artifact same = container.getSame(update.artifact.getId());
                boolean found = same != null;
                if (same != null) {
                    if (!same.getId().getVersion().startsWith("${")
                            || !same.getId().getVersion().endsWith("}")) {
                        found = false;
                    } else {
                        final String propName = same.getId()
                                .getVersion()
                                .substring(2, same.getId().getVersion().length() - 1);
                        if (!update.artifact
                                .getId()
                                .getVersion()
                                .equals(this.project.getProperties().get(propName))) {
                            found = false;
                        } else {
                            Set<String> versions = globalPropertyUpdates.get(propName);
                            if (versions == null) {
                                versions = new HashSet<>();
                                globalPropertyUpdates.put(propName, versions);
                            }
                            versions.add(update.newVersion);
                            result.propertyUpdates.put(propName, update.newVersion);
                        }
                    }
                }
                if (!found) {
                    throw new MojoExecutionException("Unable to update artifact as it's not found in feature: "
                            + update.artifact.getId().toMvnId());
                }
                iter.remove();
            } else {
                // oldArtifact is not null (removeExact returned true)
                final Artifact newArtifact =
                        new Artifact(update.artifact.getId().changeVersion(update.newVersion));
                newArtifact.getMetadata().putAll(oldArtifact.getMetadata());
                container.add(pos, newArtifact);
            }
        }

        return !result.updates.isEmpty();
    }