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