001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm.plugin;
020
021import java.io.IOException;
022
023import org.apache.maven.plugin.MojoExecutionException;
024import org.apache.maven.plugins.annotations.Mojo;
025import org.apache.maven.plugins.annotations.Parameter;
026import org.apache.maven.scm.CommandParameter;
027import org.apache.maven.scm.CommandParameters;
028import org.apache.maven.scm.ScmException;
029import org.apache.maven.scm.command.untag.UntagScmResult;
030import org.apache.maven.scm.provider.ScmProvider;
031import org.apache.maven.scm.repository.ScmRepository;
032
033/**
034 * Untag the project.
035 */
036@Mojo(name = "untag", aggregator = true)
037public class UntagMojo extends AbstractScmMojo {
038    /**
039     * The tag name.
040     */
041    @Parameter(property = "tag", required = true)
042    private String tag;
043
044    /**
045     * The commit message.
046     */
047    @Parameter(property = "message", required = false)
048    private String message;
049
050    /** {@inheritDoc} */
051    public void execute() throws MojoExecutionException {
052        super.execute();
053
054        try {
055            ScmRepository repository = getScmRepository();
056            ScmProvider provider = getScmManager().getProviderByRepository(repository);
057
058            String finalTag = provider.sanitizeTagName(tag);
059            getLog().info("Final Tag Name: '" + finalTag + "'");
060
061            CommandParameters parameters = new CommandParameters();
062            parameters.setString(CommandParameter.TAG_NAME, finalTag);
063            parameters.setString(CommandParameter.MESSAGE, message);
064
065            UntagScmResult result = provider.untag(repository, getFileSet(), parameters);
066
067            checkResult(result);
068        } catch (IOException | ScmException e) {
069            throw new MojoExecutionException("Cannot run untag command", e);
070        }
071    }
072}