Java Code Examples for org.codehaus.mojo.versions.api.PomHelper#setPropertyVersion()

The following examples show how to use org.codehaus.mojo.versions.api.PomHelper#setPropertyVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractVersionsUpdaterMojo.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
protected void updatePropertyToNewestVersion( ModifiedPomXMLEventReader pom, Property property,
                                              PropertyVersions version, String currentVersion,
                                              boolean allowDowngrade, int segment )
    throws MojoExecutionException, XMLStreamException
{
    ArtifactVersion winner =
        version.getNewestVersion( currentVersion, property, this.allowSnapshots, this.reactorProjects,
                                  this.getHelper(), allowDowngrade, segment );

    if ( winner == null || currentVersion.equals( winner.toString() ) )
    {
        getLog().info( "Property ${" + property.getName() + "}: Leaving unchanged as " + currentVersion );
    }
    else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.getName(), winner.toString() ) )
    {
        getLog().info( "Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner );
    }
}
 
Example 2
Source File: PomUpdater.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private boolean setPropertyVersion(String propertyName, String version) {
	try {
		if (StringUtils.isEmpty(version)) {
			this.log.warn(
					"Version for [" + propertyName + "] is empty. Will not set it");
			return false;
		}
		return PomHelper.setPropertyVersion(this.pom, null, propertyName, version);
	}
	catch (XMLStreamException e) {
		this.log.error("Exception occurred while trying to set property version", e);
		return false;
	}
}
 
Example 3
Source File: CompareDependenciesMojo.java    From versions-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the properties holding a version if necessary.
 */
private List<String> updatePropertyVersions( ModifiedPomXMLEventReader pom,
                                             Map<Property, PropertyVersions> versionProperties,
                                             Map<String, Dependency> remoteDependencies )
    throws XMLStreamException
{
    List<String> result = new ArrayList<>();
    for ( Map.Entry<Property, PropertyVersions> entry : versionProperties.entrySet() )
    {
        Property property = entry.getKey();
        PropertyVersions version = entry.getValue();

        String candidateVersion = computeCandidateVersion( remoteDependencies, property, version );
        if ( candidateVersion != null )
        {
            String originalVersion = version.getAssociations()[0].getArtifact().getVersion(); // Yekes
            if ( !candidateVersion.equals( originalVersion ) ) // Update needed
            {
                result.add( writeDiffMessage( property.getName(), originalVersion, candidateVersion ).toString() );
                if ( !reportMode
                    && PomHelper.setPropertyVersion( pom, null, property.getName(), candidateVersion ) )
                {
                    getLog().info( "Updated ${" + property.getName() + "} from " + originalVersion + " to "
                        + candidateVersion );
                }
            }
        }
    }
    return result;
}
 
Example 4
Source File: POM.java    From pomutils with Apache License 2.0 5 votes vote down vote up
public void setPropertyToValue(String profileId, String property, String newPropertyValue) throws XMLStreamException, IOException {
	if (property == null) {
		logger.debug("Property is null, nothing to do.");
		return;
	}
	if (newPropertyValue == null) {
		logger.debug("newPropertyValue of property [{}] is null, nothing to do.", property);
		return;
	}

	if (profileId == null && newPropertyValue.equals(getProperties().getProperty(property))) {
		return;
	}

	if (profileId != null && newPropertyValue.equals(getProfileProperties(profileId).getProperty(property))) {
		return;
	}

	if (profileId == null) {
		logger.debug("Adjusting property  [{}] from [{}] to [{}] of [{}]", property, getProperties().getProperty(property), newPropertyValue, getPath());

	} else {
		logger.debug("Adjusting property [{}] from [{}] to [{}] of profile [{}] of [{}]", property, getProperties().getProperty(property),
		        newPropertyValue,
		        profileId, getPath());
	}
	boolean propertyChanged = PomHelper.setPropertyVersion(pom, profileId, property, newPropertyValue);
	if (propertyChanged) {
		changed = true;
		rawModel = PomHelper.getRawModel(pom);
	}
}