View Javadoc
1   package org.apache.maven.plugins.stage;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.AbstractMojo;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.annotations.Component;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  import org.apache.maven.wagon.WagonException;
28  import org.apache.maven.wagon.repository.Repository;
29  
30  import java.io.IOException;
31  
32  /**
33   * Copies artifacts from one repository to another repository.
34   * 
35   * @author Jason van Zyl
36   */
37  @Mojo( name = "copy", requiresProject = false )
38  public class CopyRepositoryMojo
39      extends AbstractMojo
40  {
41      /**
42       * The URL to the source repository.
43       */
44      @Parameter( property = "source" )
45      private String source;
46  
47      /**
48       * The URL to the target repository.
49       * <p/>
50       * <p>
51       * <strong>Note:</strong> currently only <code>scp:</code> URLs are allowed
52       * as a target URL.
53       * </p>
54       */
55      @Parameter( property = "target" )
56      private String target;
57  
58      /**
59       * The id of the source repository, required if you need the configuration from the user settings.
60       */
61      @Parameter( property = "sourceRepositoryId", defaultValue = "source" )
62      private String sourceRepositoryId;
63  
64      /**
65       * The id of the target repository, required if you need the configuration from the user settings.
66       */
67      @Parameter( property = "targetRepositoryId", defaultValue = "target" )
68      private String targetRepositoryId;
69  
70      /**
71       * The version of the artifact that is to be copied.
72       * <p>
73       * <b>Note:</b> This is currently only used for naming temporary files.
74       * <i>All</i> versions of the artifacts will be copied.
75       * </p>
76       */
77      @Parameter( property = "version", required = true )
78      private String version;
79  
80      /**
81       * The repository copier to use.
82       */
83      @Component
84      private RepositoryCopier copier;
85  
86      public void execute()
87          throws MojoExecutionException
88      {
89          try
90          {
91              Repository sourceRepository = new Repository( sourceRepositoryId, source );
92              Repository targetRepository = new Repository( targetRepositoryId, target );
93              copier.copy( sourceRepository, targetRepository, version );
94          }
95          catch ( IOException e )
96          {
97              throw new MojoExecutionException(
98                  "Error copying repository from " + source + " to " + target, e );
99          }
100         catch ( WagonException e )
101         {
102             throw new MojoExecutionException(
103                 "Error copying repository from " + source + " to " + target, e );
104         }
105     }
106 }
107