Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CheckoutMojo |
|
| 2.6;2.6 |
1 | package org.apache.maven.scm.plugin; | |
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.MojoExecutionException; | |
23 | import org.apache.maven.scm.ScmException; | |
24 | import org.apache.maven.scm.ScmFileSet; | |
25 | import org.apache.maven.scm.command.checkout.CheckOutScmResult; | |
26 | import org.apache.maven.scm.repository.ScmRepository; | |
27 | import org.codehaus.plexus.util.FileUtils; | |
28 | ||
29 | import java.io.File; | |
30 | import java.io.IOException; | |
31 | ||
32 | /** | |
33 | * Get a fresh copy of the latest source from the configured scm url. | |
34 | * | |
35 | * @author <a href="evenisse@apache.org">Emmanuel Venisse</a> | |
36 | * @version $Id: CheckoutMojo.java 608636 2008-01-03 21:29:09Z dantran $ | |
37 | * @goal checkout | |
38 | * @description Check out a project | |
39 | * @requiresProject false | |
40 | */ | |
41 | 10 | public class CheckoutMojo |
42 | extends AbstractScmMojo | |
43 | { | |
44 | /** | |
45 | * The directory to checkout the sources to for the bootstrap and checkout goals. | |
46 | * | |
47 | * @parameter expression="${checkoutDirectory}" default-value="${project.build.directory}/checkout" | |
48 | */ | |
49 | private File checkoutDirectory; | |
50 | ||
51 | /** | |
52 | * Skip checkout if checkoutDirectory exists. | |
53 | * | |
54 | * @parameter expression="${skipCheckoutIfExists}" default-value="false" | |
55 | */ | |
56 | 10 | private boolean skipCheckoutIfExists = false; |
57 | ||
58 | /** | |
59 | * The version type (branch/tag/revision) of scmVersion. | |
60 | * | |
61 | * @parameter expression="${scmVersionType}" | |
62 | */ | |
63 | private String scmVersionType; | |
64 | ||
65 | /** | |
66 | * The version (revision number/branch name/tag name). | |
67 | * | |
68 | * @parameter expression="${scmVersion}" | |
69 | */ | |
70 | private String scmVersion; | |
71 | ||
72 | /** | |
73 | * allow extended mojo (ie BootStrap ) to see checkout result | |
74 | */ | |
75 | private CheckOutScmResult checkoutResult; | |
76 | ||
77 | public void execute() | |
78 | throws MojoExecutionException | |
79 | { | |
80 | 9 | super.execute(); |
81 | ||
82 | //skip checkout if checkout directory is already created. See SCM-201 | |
83 | 9 | checkoutResult = null; |
84 | 9 | if ( !getCheckoutDirectory().isDirectory() || !this.skipCheckoutIfExists ) |
85 | { | |
86 | 8 | checkoutResult = checkout(); |
87 | } | |
88 | 8 | } |
89 | ||
90 | protected File getCheckoutDirectory() | |
91 | { | |
92 | 37 | return this.checkoutDirectory; |
93 | } | |
94 | ||
95 | public void setCheckoutDirectory( File checkoutDirectory ) | |
96 | { | |
97 | 16 | this.checkoutDirectory = checkoutDirectory; |
98 | 16 | } |
99 | ||
100 | protected CheckOutScmResult checkout() | |
101 | throws MojoExecutionException | |
102 | { | |
103 | try | |
104 | { | |
105 | 8 | ScmRepository repository = getScmRepository(); |
106 | ||
107 | try | |
108 | { | |
109 | 7 | this.getLog().info( "Removing " + getCheckoutDirectory() ); |
110 | ||
111 | 7 | FileUtils.deleteDirectory( getCheckoutDirectory() ); |
112 | } | |
113 | 0 | catch ( IOException e ) |
114 | { | |
115 | 0 | throw new MojoExecutionException( "Cannot remove " + getCheckoutDirectory() ); |
116 | 7 | } |
117 | ||
118 | 7 | if ( !getCheckoutDirectory().mkdirs() ) |
119 | { | |
120 | 0 | throw new MojoExecutionException( "Cannot create " + getCheckoutDirectory() ); |
121 | } | |
122 | ||
123 | 7 | CheckOutScmResult result = getScmManager().checkOut( repository, new ScmFileSet( |
124 | getCheckoutDirectory().getAbsoluteFile() ), getScmVersion( scmVersionType, scmVersion ) ); | |
125 | ||
126 | 7 | checkResult( result ); |
127 | ||
128 | 7 | return result; |
129 | } | |
130 | 1 | catch ( ScmException e ) |
131 | { | |
132 | 1 | throw new MojoExecutionException( "Cannot run checkout command : ", e ); |
133 | } | |
134 | } | |
135 | ||
136 | protected CheckOutScmResult getCheckoutResult() | |
137 | { | |
138 | 0 | return checkoutResult; |
139 | } | |
140 | } |