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