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