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 javax.inject.Inject;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.scm.ScmException;
30 import org.apache.maven.scm.ScmFileSet;
31 import org.apache.maven.scm.command.export.ExportScmResult;
32 import org.apache.maven.scm.manager.ScmManager;
33 import org.apache.maven.scm.repository.ScmRepository;
34 import org.apache.maven.settings.crypto.SettingsDecrypter;
35 import org.codehaus.plexus.util.FileUtils;
36
37
38
39
40
41
42 @Mojo(name = "export", requiresProject = false)
43 public class ExportMojo extends AbstractScmMojo {
44
45
46
47 @Parameter(property = "scmVersionType")
48 private String scmVersionType;
49
50
51
52
53 @Parameter(property = "scmVersion")
54 private String scmVersion;
55
56
57
58
59 @Parameter(property = "exportDirectory", defaultValue = "${project.build.directory}/export", required = true)
60 private File exportDirectory;
61
62
63
64
65 @Parameter(property = "skipExportIfExists", defaultValue = "false")
66 private boolean skipExportIfExists = false;
67
68 @Inject
69 public ExportMojo(ScmManager manager, SettingsDecrypter settingsDecrypter) {
70 super(manager, settingsDecrypter);
71 }
72
73
74
75
76 public void execute() throws MojoExecutionException {
77 super.execute();
78
79 if (this.skipExportIfExists && this.exportDirectory.isDirectory()) {
80 return;
81 }
82
83 export();
84 }
85
86 protected File getExportDirectory() {
87 return this.exportDirectory;
88 }
89
90 public void setExportDirectory(File exportDirectory) {
91 this.exportDirectory = exportDirectory;
92 }
93
94 protected void export() throws MojoExecutionException {
95 if (this.exportDirectory.getPath().contains("${project.basedir}")) {
96
97 this.exportDirectory = new File(this.getBasedir(), "target/export");
98 }
99 try {
100 ScmRepository repository = getScmRepository();
101
102 try {
103 if (this.exportDirectory.exists()) {
104 this.getLog().debug("Removing " + this.exportDirectory);
105
106 FileUtils.deleteDirectory(this.exportDirectory);
107 }
108 } catch (IOException e) {
109 throw new MojoExecutionException("Cannot remove " + getExportDirectory());
110 }
111
112 if (!this.exportDirectory.mkdirs()) {
113 throw new MojoExecutionException("Cannot create " + this.exportDirectory);
114 }
115
116 ExportScmResult result = getScmManager()
117 .export(
118 repository,
119 new ScmFileSet(this.exportDirectory.getAbsoluteFile()),
120 getScmVersion(scmVersionType, scmVersion));
121
122 checkResult(result);
123
124 handleExcludesIncludesAfterCheckoutAndExport(this.exportDirectory);
125 } catch (ScmException e) {
126 throw new MojoExecutionException("Cannot run export command : ", e);
127 }
128 }
129 }