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