Hi,
It looks you want a zipArchiver.

You can use :

    /**
     * The Jar archiver.
     *
     * @parameter
expression="${component.org.codehaus.plexus.archiver.Archiver#zip}"
     * @required
     */
    private ZipArchiver zipArchiver;

Or with the new annotation

    /**
     * The Jar archiver.
     *
     * @component role="org.codehaus.plexus.archiver.Archiver" roleHint="zip"
     * @required
     */
    private ZipArchiver zipArchiver;

HTH,
--
Olivier

2008/7/27 Andreas Gies <[EMAIL PROTECTED]>:
> Hello,
>
> I am inteh process of writing a series of plugins. The last plugin is
> supposed to package some generated sourcefiles into an archive.
> I was thinking to reuse the Archiver Component from the plexus libraries for
> this. So my code looks like this:
>
> package com.sonicsw.maven.plugins;
>
> import java.io.File;
>
> import org.apache.maven.plugin.MojoExecutionException;
> import org.apache.maven.plugin.MojoFailureException;
> import org.codehaus.plexus.archiver.Archiver;
> import org.codehaus.plexus.archiver.manager.ArchiverManager;
>
> /**
> * Packaging an ESB application.
> *
> * @goal package
> */
>
> public class MavenEsbPackage extends AbstractESBMojo {
>
>  /**
>  * To look up Archiver/UnArchiver implementations
>  *
>  * @parameter
> expression="${component.org.codehaus.plexus.archiver.manager.ArchiverManager}"
>  */
>  protected ArchiverManager archiverManager;
>
>  public void execute() throws MojoExecutionException, MojoFailureException {
>
>   getLog().info("Packaging ESB application: ");
>     getLog().info("Project : " + artifactId);   getLog().info("Group   : " +
> groupId);   getLog().info("Version : " + version);
>   getLog().info("Source  : " + sourceDirectory);
>   getLog().info("Build   : " + buildDirectory);
>   getLog().info("XAR     : " + xarDirectory);
>
>   File archiveFile = new File(buildDirectory, finalName + ".xar");
>
>   try {
>     getLog().info("Creating archive : " + archiveFile.getAbsolutePath());
>         Archiver archiver = archiverManager.getArchiver("zip");
>
>     archiver.setDestFile(archiveFile);
>     //archiver.addDirectory(new File(buildDirectory, xarDirectory));
>     archiver.addDirectory(new File("generated-src/" + xarDirectory));
>         archiver.createArchive();
>   } catch(Exception e) {
>     throw new MojoExecutionException("Failed to create ESB archive " +
> archiveFile.getAbsolutePath(), e);
>   }
>  }
> }
>
> However, when I try to retrieve the Archiver, I get a NPE:
>
> [INFO] Trace
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to create ESB
> archive
> E:\LHSys\maven\snapshots\com.lhsystems.iocc\iocc-esb-flow-pubopflightp\1.0-SNAPSHOT\target\iocc-esb-flow-pubopflightp-1.0-SNAPSHOT.xar
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:583)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
>       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
>       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
>       at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:585)
>       at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
>       at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
>       at
> org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
>       at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
> Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to create
> ESB archive
> E:\LHSys\maven\snapshots\com.lhsystems.iocc\iocc-esb-flow-pubopflightp\1.0-SNAPSHOT\target\iocc-esb-flow-pubopflightp-1.0-SNAPSHOT.xar
>       at
> com.sonicsw.maven.plugins.MavenEsbPackage.execute(MavenEsbPackage.java:49)
>       at
> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
>       at
> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
>       ... 16 more
> Caused by: java.lang.NullPointerException
>       at
> org.codehaus.plexus.archiver.manager.DefaultArchiverManager.getArchiver(DefaultArchiverManager.java:60)
>       at
> com.sonicsw.maven.plugins.MavenEsbPackage.execute(MavenEsbPackage.java:41)
>       ... 18 more
>
> It seems that the ArchiverManager doesn't know about the Plexus Context
> (looking at (DefaultArchiverManager.java:60) ). I am guessing that I miss a
> basic initialization step in order to reuse a component.
> Am I missing something?--Could you perhaps point me to more documentation on
> reusing components in a plugin (I have read the
> http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook and the
> Mojo tutorial ...).
>
>
> Thanks in advance
> Andreas
>
>
> ---------------------------------------------------------------------
> 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]

Reply via email to