Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CopyRepositoryMojo |
|
| 5.0;5 |
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.wagon.WagonException; | |
25 | import org.apache.maven.wagon.repository.Repository; | |
26 | ||
27 | import java.io.IOException; | |
28 | ||
29 | /** | |
30 | * Copies artifacts from one repository to another repository. | |
31 | * | |
32 | * @author Jason van Zyl | |
33 | * @requiresProject false | |
34 | * @goal copy | |
35 | */ | |
36 | 0 | public class CopyRepositoryMojo |
37 | extends AbstractMojo | |
38 | { | |
39 | /** | |
40 | * The URL to the source repository. | |
41 | * | |
42 | * @parameter expression="${source}" | |
43 | */ | |
44 | private String source; | |
45 | ||
46 | /** | |
47 | * The URL to the target repository. | |
48 | * | |
49 | * <p> | |
50 | * <strong>Note:</strong> currently only <code>scp:</code> URLs are allowed | |
51 | * as a target URL. | |
52 | * </p> | |
53 | * | |
54 | * @parameter expression="${target}" | |
55 | */ | |
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 expression="${sourceRepositoryId}" default-value="source" | |
62 | */ | |
63 | private String sourceRepositoryId; | |
64 | ||
65 | /** | |
66 | * The id of the target repository, required if you need the configuration from the user settings. | |
67 | * | |
68 | * @parameter expression="${targetRepositoryId}" default-value="target" | |
69 | */ | |
70 | private String targetRepositoryId; | |
71 | ||
72 | /** | |
73 | * The version of the artifact that is to be copied. | |
74 | * <p> | |
75 | * <b>Note:</b> This is currently only used for naming temporary files. | |
76 | * <i>All</i> versions of the artifacts will be copied. | |
77 | * </p> | |
78 | * | |
79 | * @parameter expression="${version}" | |
80 | * @required | |
81 | */ | |
82 | private String version; | |
83 | ||
84 | /** | |
85 | * The repository copier to use. | |
86 | * | |
87 | * @component | |
88 | */ | |
89 | private RepositoryCopier copier; | |
90 | ||
91 | public void execute() | |
92 | throws MojoExecutionException | |
93 | { | |
94 | try | |
95 | { | |
96 | 0 | Repository sourceRepository = new Repository( sourceRepositoryId, source ); |
97 | 0 | Repository targetRepository = new Repository( targetRepositoryId, target ); |
98 | 0 | copier.copy( sourceRepository, targetRepository, version ); |
99 | } | |
100 | 0 | catch ( IOException e ) |
101 | { | |
102 | 0 | throw new MojoExecutionException( |
103 | "Error copying repository from " + source + " to " + target, e ); | |
104 | } | |
105 | 0 | catch ( WagonException e ) |
106 | { | |
107 | 0 | throw new MojoExecutionException( |
108 | "Error copying repository from " + source + " to " + target, e ); | |
109 | 0 | } |
110 | 0 | } |
111 | } | |
112 |