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.scm.ScmException;
28  import org.apache.maven.scm.command.add.AddScmResult;
29  import org.apache.maven.scm.manager.ScmManager;
30  import org.apache.maven.scm.repository.ScmRepository;
31  import org.apache.maven.settings.crypto.SettingsDecrypter;
32  
33  /**
34   * Add a file set to the project.
35   *
36   * @author <a href="julien.henry@capgemini.com">Julien Henry</a>
37   */
38  @Mojo(name = "add", aggregator = true)
39  public class AddMojo extends AbstractScmMojo {
40  
41      @Inject
42      public AddMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
43          super(manager, settingsDecrypter);
44      }
45  
46      /** {@inheritDoc} */
47      public void execute() throws MojoExecutionException {
48          super.execute();
49  
50          try {
51              ScmRepository repository = getScmRepository();
52  
53              AddScmResult result = getScmManager().add(repository, getFileSet());
54  
55              checkResult(result);
56  
57              getLog().info("" + result.getAddedFiles().size() + " files successfully added.");
58  
59          } catch (IOException | ScmException e) {
60              throw new MojoExecutionException("Cannot run add command : ", e);
61          }
62      }
63  }