All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.mojo.versions.UpdatePropertyMojo Maven / Gradle / Ivy

package org.codehaus.mojo.versions;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;

import javax.xml.stream.XMLStreamException;
import java.util.Map;

/**
 * Sets a property to the latest version in a given range of associated artifacts.
 *
 * @author Eric Pabst
 * @since 1.3
 */
@Mojo( name = "update-property", requiresProject = true, requiresDirectInvocation = true )
public class UpdatePropertyMojo
    extends AbstractVersionsUpdaterMojo
{

    // ------------------------------ FIELDS ------------------------------

    /**
     * A property to update.
     * 
     * @since 1.3
     */
    @Parameter( property = "property" )
    private String property = null;

    /**
     * The new version to set the property to (can be a version range to find a version within).
     * 
    *
  • 1.0x >= 1.0. The default Maven meaning for 1.0 is everything (,) but with 1.0 recommended.
  • *
  • [1.0,2.0) Versions 1.0 (included) to 2.0 (not included)
  • *
  • [1.0,2.0] Versions 1.0 to 2.0 (both included)
  • *
  • [1.5,) Versions 1.5 and higher
  • *
  • (,1.0],[1.2,) Versions up to 1.0 (included) and 1.2 or higher
  • *
* If you like to define version to be used exactly you have to use something like this: * -DnewVersion=[19.0] otherwise a newer existing version will be used. * * @since 1.3 */ @Parameter( property = "newVersion" ) private String newVersion = null; /** * Whether properties linking versions should be auto-detected or not. * * @since 1.0-alpha-2 */ @Parameter( property = "autoLinkItems", defaultValue = "true" ) private boolean autoLinkItems; /** * If a property points to a version like 1.2.3-SNAPSHOT and your repo contains a version like * 1.1.0 without settings this to true the property will not being changed. * * @since 3.0.0 */ @Parameter( property = "allowDowngrade", defaultValue = "false" ) private boolean allowDowngrade; /** * Whether to allow the major version number to be changed. * * @since 2.4 */ @Parameter( property = "allowMajorUpdates", defaultValue = "true" ) protected Boolean allowMajorUpdates; /** * Whether to allow the minor version number to be changed. * * @since 2.4 */ @Parameter( property = "allowMinorUpdates", defaultValue = "true" ) protected Boolean allowMinorUpdates; /** * Whether to allow the incremental version number to be changed. * * @since 2.4 */ @Parameter( property = "allowIncrementalUpdates", defaultValue = "true" ) protected Boolean allowIncrementalUpdates; // -------------------------- STATIC METHODS -------------------------- // -------------------------- OTHER METHODS -------------------------- /** * @param pom the pom to update. * @throws MojoExecutionException when things go wrong * @throws MojoFailureException when things go wrong in a very bad way * @throws XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) * @since 1.0-alpha-1 */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { Property propertyConfig = new Property( property ); propertyConfig.setVersion( newVersion ); Map propertyVersions = this.getHelper().getVersionPropertiesMap( getProject(), new Property[] { propertyConfig }, property, "", autoLinkItems ); for ( Map.Entry entry : propertyVersions.entrySet() ) { Property property = entry.getKey(); PropertyVersions version = entry.getValue(); final String currentVersion = getProject().getProperties().getProperty( property.getName() ); if ( currentVersion == null ) { continue; } int segment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); updatePropertyToNewestVersion( pom, property, version, currentVersion, allowDowngrade, segment ); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy