Skip to content

Commit 98496fd

Browse files
committed
Fixed issue with relative path script
1 parent e1c0537 commit 98496fd

4 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/main/java/org/codehaus/mojo/rpm/AbstractRPMMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ public final void execute()
773773
/**
774774
* @return The Maven project used by this MOJO
775775
*/
776-
private MavenProject getProject()
776+
MavenProject getProject()
777777
{
778778
if ( project.getExecutionProject() != null )
779779
{

src/main/java/org/codehaus/mojo/rpm/BaseTrigger.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* under the License.
2020
*/
2121

22-
import org.apache.maven.shared.utils.io.FileUtils;
2322

2423
import java.io.IOException;
2524
import java.io.PrintWriter;
@@ -90,16 +89,16 @@ protected String buildScriptletLine( String directive )
9089
}
9190

9291
/**
93-
* Writes the complete trigger directive. Use instead of {@link #write(PrintWriter, String)}.
92+
* Writes the complete trigger directive.
9493
*
9594
* @param writer {@code PrintWriter} to write the trigger directive to.
96-
* @param filterWrappers The filter wrappers to be applied when writing the content.
95+
* @param mojo the {@code AbstractRPMMojo} which contains any resources needed when writing the trigger.
9796
* @throws IOException
9897
*/
99-
protected void writeTrigger( PrintWriter writer, final List<FileUtils.FilterWrapper> filterWrappers )
98+
protected void writeTrigger( PrintWriter writer, final AbstractRPMMojo mojo )
10099
throws IOException
101100
{
102-
write( writer, getDirective(), filterWrappers );
101+
write( writer, getDirective(), mojo );
103102
}
104103

105104
/**

src/main/java/org/codehaus/mojo/rpm/Scriptlet.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.io.PrintWriter;
3333
import java.io.Reader;
3434
import 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
}

src/main/java/org/codehaus/mojo/rpm/SpecWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void writeSpecFile()
133133
if ( mojo.getInstallScriptlet() != null )
134134
{
135135
spec.println();
136-
mojo.getInstallScriptlet().writeContent( spec , mojo.getFilterWrappers() );
136+
mojo.getInstallScriptlet().writeContent( spec , mojo );
137137

138138
}
139139

@@ -145,7 +145,7 @@ public void writeSpecFile()
145145
{
146146
for ( BaseTrigger trigger : mojo.getTriggers() )
147147
{
148-
trigger.writeTrigger( spec, mojo.getFilterWrappers() );
148+
trigger.writeTrigger( spec, mojo );
149149
}
150150
}
151151

@@ -574,7 +574,7 @@ private void writeScripts()
574574
{
575575
if ( scriptlets[i] != null )
576576
{
577-
scriptlets[i].write( spec, directives[i], mojo.getFilterWrappers() );
577+
scriptlets[i].write( spec, directives[i], mojo );
578578
}
579579
}
580580
}

0 commit comments

Comments
 (0)