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

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

Go to download

The Versions Maven Plugin is used when you want to manage the versions of artifacts in a project's POM.

The newest version!
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 javax.inject.Inject;
import javax.xml.stream.XMLStreamException;

import java.util.Map;

import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
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.apache.maven.wagon.Wagon;
import org.codehaus.mojo.versions.api.Property;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;

/**
 * Sets a property to the latest version in a given range of associated artifacts.
 *
 * @author Eric Pabst
 * @since 1.3
 */
@Mojo(name = "update-property", threadSafe = true)
public class UpdatePropertyMojo extends UpdatePropertiesMojoBase {
    /**
     * A property to update.
     *
     * @since 1.3
     */
    @Parameter(property = "property")
    protected 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 the version to be used exactly you have to use it like this: * -DnewVersion=[19.0] otherwise a newer existing version will be used. If you need to downgrade a * version you have to define -DallowDowngrade=true as well otherwise * the version will be kept. * * @since 1.3 */ @Parameter(property = "newVersion") private String newVersion = null; @Inject public UpdatePropertyMojo( ArtifactHandlerManager artifactHandlerManager, RepositorySystem repositorySystem, Map wagonMap, Map changeRecorders) { super(artifactHandlerManager, repositorySystem, wagonMap, changeRecorders); } /** * @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(MutableXMLStreamReader) * @since 1.0-alpha-1 */ protected void update(MutableXMLStreamReader pom) throws MojoExecutionException, MojoFailureException, XMLStreamException { update( pom, getHelper() .getVersionPropertiesMap(VersionsHelper.VersionPropertiesMapRequest.builder() .withMavenProject(getProject()) .withPropertyDefinitions(new Property[] { new Property(property) { { setVersion(newVersion); } } }) .withIncludeProperties(property) .withAutoLinkItems(autoLinkItems) .withIncludeParent(includeParent) .build())); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy