1 | |
package org.apache.maven.scm.plugin; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
import java.io.File; |
19 | |
import java.io.IOException; |
20 | |
|
21 | |
import org.apache.maven.plugin.MojoExecutionException; |
22 | |
import org.apache.maven.scm.ScmException; |
23 | |
import org.apache.maven.scm.ScmFileSet; |
24 | |
import org.apache.maven.scm.command.export.ExportScmResult; |
25 | |
import org.apache.maven.scm.repository.ScmRepository; |
26 | |
import org.codehaus.plexus.util.FileUtils; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 3 | public class ExportMojo |
37 | |
extends AbstractScmMojo |
38 | |
{ |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
private String scmVersionType; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
private String scmVersion; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
private File exportDirectory; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | 3 | private boolean skipExportIfExists = false; |
67 | |
|
68 | |
|
69 | |
|
70 | |
public void execute() |
71 | |
throws MojoExecutionException |
72 | |
{ |
73 | 3 | super.execute(); |
74 | |
|
75 | 3 | if ( this.skipExportIfExists && this.exportDirectory.isDirectory() ) |
76 | |
{ |
77 | 1 | return; |
78 | |
} |
79 | |
|
80 | 2 | export(); |
81 | 2 | } |
82 | |
|
83 | |
protected File getExportDirectory() |
84 | |
{ |
85 | 0 | return this.exportDirectory; |
86 | |
} |
87 | |
|
88 | |
public void setExportDirectory( File exportDirectory ) |
89 | |
{ |
90 | 6 | this.exportDirectory = exportDirectory; |
91 | 6 | } |
92 | |
|
93 | |
protected void export() |
94 | |
throws MojoExecutionException |
95 | |
{ |
96 | |
try |
97 | |
{ |
98 | 2 | ScmRepository repository = getScmRepository(); |
99 | |
|
100 | |
try |
101 | |
{ |
102 | 2 | if ( this.exportDirectory.exists() ) |
103 | |
{ |
104 | 1 | this.getLog().info( "Removing " + this.exportDirectory ); |
105 | |
|
106 | 1 | FileUtils.deleteDirectory( this.exportDirectory ); |
107 | |
} |
108 | |
} |
109 | 0 | catch ( IOException e ) |
110 | |
{ |
111 | 0 | throw new MojoExecutionException( "Cannot remove " + getExportDirectory() ); |
112 | 2 | } |
113 | |
|
114 | 2 | if ( !this.exportDirectory.mkdirs() ) |
115 | |
{ |
116 | 0 | throw new MojoExecutionException( "Cannot create " + this.exportDirectory ); |
117 | |
} |
118 | |
|
119 | 2 | ExportScmResult result = getScmManager().export( repository, |
120 | |
new ScmFileSet( this.exportDirectory.getAbsoluteFile() ), |
121 | |
getScmVersion( scmVersionType, scmVersion ) ); |
122 | |
|
123 | 2 | checkResult( result ); |
124 | |
|
125 | 2 | handleExcludesIncludesAfterCheckoutAndExport( this.exportDirectory ); |
126 | |
} |
127 | 0 | catch ( ScmException e ) |
128 | |
{ |
129 | 0 | throw new MojoExecutionException( "Cannot run export command : ", e ); |
130 | 2 | } |
131 | 2 | } |
132 | |
} |