3232import java .io .PrintWriter ;
3333import java .io .Reader ;
3434import java .io .UnsupportedEncodingException ;
35- import java .util .List ;
3635
3736/**
3837 * Defines a scriptlet including the optinal {@link #getSubpackage()} and {@link #getProgram()}. The (optional) contents
@@ -219,18 +218,18 @@ public void setFilter( boolean filter )
219218 *
220219 * @param writer {@code PrintWriter} to write content to.
221220 * @param directive The directive for the scriptlet.
222- * @param filterWrappers The filter wrappers to be applied when writing the content .
221+ * @param mojo the {@code AbstractRPMMojo} which contains any resources needed when writing the scriptlet .
223222 * @throws IOException
224223 */
225224 protected final void write ( final PrintWriter writer , final String directive ,
226- final List < FileUtils . FilterWrapper > filterWrappers ) throws IOException
225+ final AbstractRPMMojo mojo ) throws IOException
227226 {
228227 if ( script != null || scriptFile != null || program != null )
229228 {
230229 writer .println ();
231230 writer .println ( buildScriptletLine ( directive ) );
232231
233- writeContent ( writer , filterWrappers );
232+ writeContent ( writer , mojo );
234233 }
235234 }
236235
@@ -260,7 +259,8 @@ protected String buildScriptletLine( final String directive )
260259 return builder .toString ();
261260 }
262261
263- private Reader getScriptReader ( String path ) throws FileNotFoundException , UnsupportedEncodingException
262+ private Reader getScriptReader ( String path , AbstractRPMMojo mojo ) throws FileNotFoundException ,
263+ UnsupportedEncodingException
264264 {
265265 String classpathPrefix = "classpath:" ;
266266 Reader reader ;
@@ -278,14 +278,14 @@ private Reader getScriptReader( String path ) throws FileNotFoundException, Unsu
278278 }
279279 else
280280 {
281- File file = new File ( path );
281+ File file = FileUtils . resolveFile ( mojo . getProject (). getBasedir (), path );
282282 if ( !file .exists () )
283283 {
284284 throw new RuntimeException ( "Invalid scriptlet declaration found - defined scriptFile does not exist: "
285285 + path );
286286 }
287287 reader = fileEncoding != null ? new InputStreamReader ( new FileInputStream ( file ), fileEncoding )
288- : new FileReader ( scriptFile );
288+ : new FileReader ( file );
289289 }
290290 return reader ;
291291 }
@@ -294,10 +294,10 @@ private Reader getScriptReader( String path ) throws FileNotFoundException, Unsu
294294 * Writes the content (either {@link #getScript()} or {@link #getScriptFile()}) to <i>writer</i>.
295295 *
296296 * @param writer {@code PrintWriter} to write content to.
297- * @param filterWrappers The filter wrappers to be applied when writing the content .
297+ * @param mojo the {@code AbstractRPMMojo} which contains any resources needed when writing the scriptlet .
298298 * @throws IOException
299299 */
300- protected final void writeContent ( PrintWriter writer , final List < FileUtils . FilterWrapper > filterWrappers )
300+ protected final void writeContent ( PrintWriter writer , final AbstractRPMMojo mojo )
301301 throws IOException
302302 {
303303 if ( script != null )
@@ -306,10 +306,10 @@ protected final void writeContent( PrintWriter writer, final List<FileUtils.Filt
306306 }
307307 else if ( scriptFile != null )
308308 {
309- Reader reader = getScriptReader ( scriptFile );
309+ Reader reader = getScriptReader ( scriptFile , mojo );
310310 if ( filter )
311311 {
312- for ( FileUtils .FilterWrapper filterWrapper : filterWrappers )
312+ for ( FileUtils .FilterWrapper filterWrapper : mojo . getFilterWrappers () )
313313 {
314314 reader = filterWrapper .getReader ( reader );
315315 }
0 commit comments