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