Hi Wim,
I had to do something like this as well w/ the antrun Plugin. Ant expects to
find a real File for build.xml, and won't extract it from JAR. So I simply
used Ant to do all the work. You can ignore the part where I build the <ant>
task. The pertinent part is shown below. BTW. you could even use Ant to
<exec> to run your BAT file. It has all the features you'd eventually
need...
//-----------------------------
protected void executeTasks( Target target, MavenProject mproject, String
msgLevel )
throws MojoExecutionException
{
verifySetup();
String antFileName = getAntFileName();
String antTargetName = getAntTargetName();
//-------------------------
// Create the <unzip> Task
//-------------------------
Task unzipTask = createUnzipTask( antFileName );
addTask( target, unzipTask );
//-------------------------
// Create the <ant> Task
//-------------------------
Task antTask = createAntTask( antFileName, antTargetName );
addTask( target, antTask );
//-------------------------
// Set Ant project properties
//-------------------------
setCommonAntProperties( target );
setAntProperties( target );
//-------------------------
// Execute the Tasks
//-------------------------
getLog().info( "*** target= " + target.getTasks().length );
super.executeTasks( target, mproject, msgLevel );
}
//-----------------------------
private Task createUnzipTask( String antFileName )
{
String pluginGroupId = getPluginGroupId();
String pluginArtifactId = getPluginArtifactId();
String pluginVersion = getPluginVersion() ;
ArtifactRepository localRepository = getLocalRepository();
String targetDirectory = getTargetDirectory();
getLog().info( "pluginGroupId= " + pluginGroupId );
getLog().info( "pluginArtifactId= " + pluginArtifactId );
getLog().info( "pluginVersion= " + pluginVersion );
getLog().info( "localRepository= " + localRepository.getUrl() );
getLog().info( "targetDirectory = " + targetDirectory );
// First, get build the source JAR file
// convert groupId to path (. ==> /)
// FIXME: this is probably possible in maven somewhere??
String groupIdPath = pluginGroupId.replace( '.', '/' );
String slocalRepo = localRepository.getUrl();
// Strip off the file:/ -- there's probably a better way to do this
// but converting to a File and pulling the Path was giving incorrect
results (on windoze)
slocalRepo = slocalRepo.replaceAll( "file://", "" );
getLog().info( "\n*** slocalRepo= " + slocalRepo );
// build full path to plugin jar -- src="${plugin.artifact}
// FIXME: this is probably possible in maven somewhere??
String src = slocalRepo + "/" + groupIdPath + "/" + pluginArtifactId + "/"
+
pluginVersion + "/" + pluginArtifactId + "-" + pluginVersion + ".jar" ;
getLog().info( "*** src= " + src );
File srcFile = new File( src );
getLog().info( "*** srcFile= " + srcFile );
//..............................
// Get the destination dir -- dest="${targetdir}"
File destFile = new File( targetDirectory );
getLog().info( "\n==========> targetDirectory= " + targetDirectory );
getLog().info( "\n==========> destFile= " + targetDirectory );
//..............................
// build the <unzip> Task
//
// <unzip src="${plugin.artifact}"
// dest="${targetdir}">
// <patternset>
// <include name="ant/axis-build.xml"/>
// </patternset>
// </unzip>
Expand unzipTask = new Expand();
unzipTask.setTaskName( "unzip" );
unzipTask.setSrc( srcFile );
unzipTask.setDest( destFile );
unzipTask.setOverwrite( true );
PatternSet pset = new PatternSet();
pset.setIncludes( antFileName );
unzipTask.addPatternset( pset );
return unzipTask;
}
On 11/22/05, Emmanuel Venisse <[EMAIL PROTECTED]> wrote:
>
> you need to extract your file first (perhaps with plexus-archiver) and
> then run your script with
> Commandline
>
>
> Wim Deblauwe a écrit :
> > What do you mean? I see the use of the Commanline class, but it calls an
> > executable that is on the PATH. I'm talking about running a bat file
> that is
> > delivered with my plugin (in the plugin jar).
> >
> >
> > 2005/11/22, Emmanuel Venisse <[EMAIL PROTECTED]>:
> >
> >>look at release:perform goal.
> >>
> >>Emmanuel
> >>
> >>Wim Deblauwe a écrit :
> >>
> >>>Hi,
> >>>
> >>>I would like to run a bat file from my plugin. I know that this will
> >>
> >>make my
> >>
> >>>plugin very unportable to other platforms, but I only need to run on
> >>>windows. What would be the best way to do this? Since running a bat
> file
> >>>from within a jar is not supported, I guess the best way is to extract
> >>
> >>that
> >>
> >>>bat file from the plugin jar to some temp directory and run it from
> >>
> >>there.
> >>
> >>>Any other ideas?
> >>>
> >>>regards,
> >>>
> >>>Wim
> >>>
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>