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 javax.inject.Inject; 022 023import java.io.IOException; 024 025import org.apache.maven.plugin.MojoExecutionException; 026import org.apache.maven.plugins.annotations.Mojo; 027import org.apache.maven.plugins.annotations.Parameter; 028import org.apache.maven.scm.CommandParameter; 029import org.apache.maven.scm.CommandParameters; 030import org.apache.maven.scm.CommandParameters.SignOption; 031import org.apache.maven.scm.ScmException; 032import org.apache.maven.scm.ScmVersion; 033import org.apache.maven.scm.command.checkin.CheckInScmResult; 034import org.apache.maven.scm.manager.ScmManager; 035import org.apache.maven.scm.repository.ScmRepository; 036import org.apache.maven.settings.crypto.SettingsDecrypter; 037 038/** 039 * Commit changes to the configured scm url. 040 * 041 * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> 042 */ 043@Mojo(name = "checkin", aggregator = true) 044public class CheckinMojo extends AbstractScmMojo { 045 /** 046 * Commit log. 047 */ 048 @Parameter(property = "message") 049 private String message; 050 051 /** 052 * The configured scm url to use. 053 */ 054 @Parameter(property = "connectionType", defaultValue = "developerConnection") 055 private String connectionType; 056 057 /** 058 * The version type (branch/tag/revision) of scmVersion. 059 */ 060 @Parameter(property = "scmVersionType") 061 private String scmVersionType; 062 063 /** 064 * The version (revision number/branch name/tag name). 065 */ 066 @Parameter(property = "scmVersion") 067 private String scmVersion; 068 069 /** 070 * Toggles the signing for the commit used during checkin (only applicable to SCMs that support signing). 071 * 072 * @since 2.2.1 073 */ 074 @Parameter(property = "signOption") 075 private SignOption signOption; 076 077 @Inject 078 public CheckinMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) { 079 super(manager, settingsDecrypter); 080 } 081 082 /** 083 * {@inheritDoc} 084 */ 085 public void execute() throws MojoExecutionException { 086 super.execute(); 087 088 setConnectionType(connectionType); 089 090 try { 091 ScmRepository repository = getScmRepository(); 092 093 CommandParameters parameters = new CommandParameters(); 094 095 ScmVersion version = getScmVersion(scmVersionType, scmVersion); 096 if (version != null) { 097 parameters.setScmVersion(CommandParameter.SCM_VERSION, version); 098 } 099 if (message != null) { 100 parameters.setString(CommandParameter.MESSAGE, message); 101 } 102 if (signOption != null) { 103 parameters.setSignOption(CommandParameter.SIGN_OPTION, signOption); 104 } 105 CheckInScmResult result = getScmManager().checkIn(repository, getFileSet(), parameters); 106 107 checkResult(result); 108 } catch (IOException | ScmException e) { 109 throw new MojoExecutionException("Cannot run checkin command : ", e); 110 } 111 } 112}