1 | |
package org.apache.maven.plugins.site; |
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 java.util.List; |
26 | |
import java.util.Locale; |
27 | |
|
28 | |
import org.apache.maven.plugin.MojoExecutionException; |
29 | |
import org.apache.maven.project.MavenProjectHelper; |
30 | |
|
31 | |
import org.codehaus.plexus.util.FileUtils; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class SiteDescriptorAttachMojo |
42 | |
extends AbstractSiteMojo |
43 | |
{ |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
private File basedir; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
private MavenProjectHelper projectHelper; |
59 | |
|
60 | |
public void execute() |
61 | |
throws MojoExecutionException |
62 | |
{ |
63 | 0 | List<Locale> localesList = siteTool.getAvailableLocales( locales ); |
64 | |
|
65 | 0 | for ( Locale locale : localesList ) |
66 | |
{ |
67 | 0 | File descriptorFile = siteTool.getSiteDescriptorFromBasedir( |
68 | |
siteTool.getRelativePath( siteDirectory.getAbsolutePath(), project.getBasedir().getAbsolutePath() ), |
69 | |
basedir, locale ); |
70 | |
|
71 | 0 | if ( descriptorFile.exists() ) |
72 | |
{ |
73 | |
|
74 | 0 | String classifier = getClassifier( descriptorFile ); |
75 | |
|
76 | 0 | String filename = project.getArtifactId() + "-" + project.getVersion() + "-" + descriptorFile.getName(); |
77 | 0 | File targetDescriptorFile = new File( project.getBuild().getDirectory(), filename ); |
78 | |
|
79 | |
try |
80 | |
{ |
81 | |
|
82 | 0 | FileUtils.copyFile( descriptorFile, targetDescriptorFile ); |
83 | |
|
84 | 0 | getLog().debug( "Attaching the site descriptor '" + targetDescriptorFile.getAbsolutePath() |
85 | |
+ "' with classifier '" + classifier + "' to the project." ); |
86 | 0 | projectHelper.attachArtifact( project, "xml", classifier, targetDescriptorFile ); |
87 | |
} |
88 | 0 | catch ( IOException e ) |
89 | |
{ |
90 | 0 | throw new MojoExecutionException( "Unable to copy site descriptor", e ); |
91 | 0 | } |
92 | |
} |
93 | 0 | } |
94 | 0 | } |
95 | |
|
96 | |
private static String getClassifier( final File descriptorFile ) |
97 | |
throws MojoExecutionException |
98 | |
{ |
99 | 0 | final int index = descriptorFile.getName().lastIndexOf( '.' ); |
100 | |
|
101 | 0 | if ( index > 0 ) |
102 | |
{ |
103 | 0 | return descriptorFile.getName().substring( 0, index ); |
104 | |
} |
105 | |
else |
106 | |
{ |
107 | 0 | throw new MojoExecutionException( "Unable to determine the classifier to use" ); |
108 | |
} |
109 | |
} |
110 | |
} |