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.ScmException;
027import org.apache.maven.scm.command.checkin.CheckInScmResult;
028import org.apache.maven.scm.repository.ScmRepository;
029
030/**
031 * Commit changes to the configured scm url.
032 *
033 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
034 */
035@Mojo(name = "checkin", aggregator = true)
036public class CheckinMojo extends AbstractScmMojo {
037    /**
038     * Commit log.
039     */
040    @Parameter(property = "message")
041    private String message;
042
043    /**
044     * The configured scm url to use.
045     */
046    @Parameter(property = "connectionType", defaultValue = "developerConnection")
047    private String connectionType;
048
049    /**
050     * The version type (branch/tag/revision) of scmVersion.
051     */
052    @Parameter(property = "scmVersionType")
053    private String scmVersionType;
054
055    /**
056     * The version (revision number/branch name/tag name).
057     */
058    @Parameter(property = "scmVersion")
059    private String scmVersion;
060
061    /** {@inheritDoc} */
062    public void execute() throws MojoExecutionException {
063        super.execute();
064
065        setConnectionType(connectionType);
066
067        try {
068            ScmRepository repository = getScmRepository();
069
070            CheckInScmResult result = getScmManager()
071                    .checkIn(repository, getFileSet(), getScmVersion(scmVersionType, scmVersion), message);
072
073            checkResult(result);
074        } catch (IOException | ScmException e) {
075            throw new MojoExecutionException("Cannot run checkin command : ", e);
076        }
077    }
078}