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.IOException;
23 import java.io.InputStream;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Properties;
27
28 import org.apache.maven.artifact.repository.ArtifactRepository;
29 import org.apache.maven.artifact.versioning.ComparableVersion;
30 import org.apache.maven.doxia.tools.SiteTool;
31 import org.apache.maven.plugin.AbstractMojo;
32 import org.apache.maven.plugins.annotations.Component;
33 import org.apache.maven.plugins.annotations.Parameter;
34 import org.apache.maven.project.MavenProject;
35 import org.codehaus.plexus.i18n.I18N;
36 import org.codehaus.plexus.util.IOUtil;
37
38
39
40
41
42
43 public abstract class AbstractSiteMojo
44 extends AbstractMojo
45 {
46
47
48
49
50
51
52 @Parameter( property = "locales", defaultValue = "en" )
53 private String locales;
54
55
56
57
58
59
60 @Parameter( property = "maven.site.skip", defaultValue = "false" )
61 protected boolean skip;
62
63
64
65
66 @Component
67 protected SiteTool siteTool;
68
69
70
71
72 @Component
73 protected I18N i18n;
74
75
76
77
78 @Parameter( defaultValue = "${project}", readonly = true )
79 protected MavenProject project;
80
81
82
83
84 @Parameter( defaultValue = "${localRepository}", readonly = true )
85 protected ArtifactRepository localRepository;
86
87
88
89
90 @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
91 protected List<MavenProject> reactorProjects;
92
93
94
95
96 protected static boolean isMaven3OrMore()
97 {
98 return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0;
99 }
100
101 protected static String getMavenVersion()
102 {
103
104
105
106
107 final Properties properties = new Properties();
108 final String corePomProperties = "META-INF/maven/org.apache.maven/maven-core/pom.properties";
109 final InputStream in = MavenProject.class.getClassLoader().getResourceAsStream( corePomProperties );
110 try
111 {
112 properties.load( in );
113 }
114 catch ( IOException ioe )
115 {
116 return "";
117 }
118 finally
119 {
120 IOUtil.close( in );
121 }
122
123 return properties.getProperty( "version" ).trim();
124 }
125
126 protected List<Locale> getLocales()
127 {
128 return siteTool.getSiteLocales( locales );
129 }
130 }