View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.plugin;
20  
21  import javax.inject.Inject;
22  
23  import java.io.IOException;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.Parameter;
28  import org.apache.maven.scm.CommandParameter;
29  import org.apache.maven.scm.CommandParameters;
30  import org.apache.maven.scm.CommandParameters.SignOption;
31  import org.apache.maven.scm.ScmException;
32  import org.apache.maven.scm.ScmVersion;
33  import org.apache.maven.scm.command.checkin.CheckInScmResult;
34  import org.apache.maven.scm.manager.ScmManager;
35  import org.apache.maven.scm.repository.ScmRepository;
36  import org.apache.maven.settings.crypto.SettingsDecrypter;
37  
38  /**
39   * Commit changes to the configured scm url.
40   *
41   * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
42   */
43  @Mojo(name = "checkin", aggregator = true)
44  public class CheckinMojo extends AbstractScmMojo {
45      /**
46       * Commit log.
47       */
48      @Parameter(property = "message")
49      private String message;
50  
51      /**
52       * The configured scm url to use.
53       */
54      @Parameter(property = "connectionType", defaultValue = "developerConnection")
55      private String connectionType;
56  
57      /**
58       * The version type (branch/tag/revision) of scmVersion.
59       */
60      @Parameter(property = "scmVersionType")
61      private String scmVersionType;
62  
63      /**
64       * The version (revision number/branch name/tag name).
65       */
66      @Parameter(property = "scmVersion")
67      private String scmVersion;
68  
69      /**
70       * Toggles the signing for the commit used during checkin (only applicable to SCMs that support signing).
71       *
72       * @since 2.2.1
73       */
74      @Parameter(property = "signOption")
75      private SignOption signOption;
76  
77      @Inject
78      public CheckinMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
79          super(manager, settingsDecrypter);
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      public void execute() throws MojoExecutionException {
86          super.execute();
87  
88          setConnectionType(connectionType);
89  
90          try {
91              ScmRepository repository = getScmRepository();
92  
93              CommandParameters parameters = new CommandParameters();
94  
95              ScmVersion version = getScmVersion(scmVersionType, scmVersion);
96              if (version != null) {
97                  parameters.setScmVersion(CommandParameter.SCM_VERSION, version);
98              }
99              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 }