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 import java.io.InputStream;
25
26 import java.util.List;
27 import java.util.Properties;
28
29 import org.apache.maven.artifact.repository.ArtifactRepository;
30 import org.apache.maven.artifact.versioning.ComparableVersion;
31 import org.apache.maven.doxia.tools.SiteTool;
32 import org.apache.maven.plugin.AbstractMojo;
33 import org.apache.maven.plugins.annotations.Component;
34 import org.apache.maven.plugins.annotations.Parameter;
35 import org.apache.maven.project.MavenProject;
36
37 import org.codehaus.plexus.i18n.I18N;
38 import org.codehaus.plexus.util.IOUtil;
39 import org.codehaus.plexus.util.ReaderFactory;
40
41
42
43
44
45
46 public abstract class AbstractSiteMojo
47 extends AbstractMojo
48 {
49
50
51
52
53 @Parameter( property = "locales" )
54 protected String locales;
55
56
57
58
59 @Component
60 protected SiteTool siteTool;
61
62
63
64
65 @Component
66 protected I18N i18n;
67
68
69
70
71 @Parameter( defaultValue = "${basedir}/src/site" )
72 protected File siteDirectory;
73
74
75
76
77 @Component
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 @Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
96 private String inputEncoding;
97
98
99
100
101 @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
102 private String outputEncoding;
103
104
105
106
107
108
109 protected String getInputEncoding()
110 {
111 return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : inputEncoding;
112 }
113
114
115
116
117
118
119 protected String getOutputEncoding()
120 {
121 return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding;
122 }
123
124
125
126
127 protected static boolean isMaven3OrMore()
128 {
129 return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0;
130 }
131
132 protected static String getMavenVersion()
133 {
134
135
136
137
138 final Properties properties = new Properties();
139 final InputStream in =
140 MavenProject.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/pom.properties" );
141 try
142 {
143 properties.load( in );
144 }
145 catch ( IOException ioe )
146 {
147 return "";
148 }
149 finally
150 {
151 IOUtil.close( in );
152 }
153
154 return properties.getProperty( "version" ).trim();
155 }
156 }