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
54
55 @Parameter( property = "locales" )
56 protected String locales;
57
58
59
60
61 @Component
62 protected SiteTool siteTool;
63
64
65
66
67 @Component
68 protected I18N i18n;
69
70
71
72
73
74
75 @Parameter( defaultValue = "${basedir}/src/site" )
76 protected File siteDirectory;
77
78
79
80
81 @Parameter( defaultValue = "${project}", readonly = true )
82 protected MavenProject project;
83
84
85
86
87 @Parameter( defaultValue = "${localRepository}", readonly = true )
88 protected ArtifactRepository localRepository;
89
90
91
92
93 @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
94 protected List<MavenProject> reactorProjects;
95
96
97
98
99
100
101 @Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
102 private String inputEncoding;
103
104
105
106
107
108
109 @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" )
110 private String outputEncoding;
111
112
113
114
115
116
117 protected String getInputEncoding()
118 {
119 return ( inputEncoding == null ) ? ReaderFactory.ISO_8859_1 : inputEncoding;
120 }
121
122
123
124
125
126
127 protected String getOutputEncoding()
128 {
129 return ( outputEncoding == null ) ? ReaderFactory.UTF_8 : outputEncoding;
130 }
131
132
133
134
135 protected static boolean isMaven3OrMore()
136 {
137 return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0;
138 }
139
140 protected static String getMavenVersion()
141 {
142
143
144
145
146 final Properties properties = new Properties();
147 final InputStream in =
148 MavenProject.class.getClassLoader().getResourceAsStream( "META-INF/maven/org.apache.maven/maven-core/pom.properties" );
149 try
150 {
151 properties.load( in );
152 }
153 catch ( IOException ioe )
154 {
155 return "";
156 }
157 finally
158 {
159 IOUtil.close( in );
160 }
161
162 return properties.getProperty( "version" ).trim();
163 }
164 }