Fork me on GitHub

NAR Library

Other plugins may need to use some of the functionality of the NAR Plugin, such as downloading and unpacking. The NAR Plugin therefore groups most of its functionality into the NAR Manager and allows other plugins and the NAR Plugin itself to call on the NAR Manager.

The SWIG Plugin which needs the swig native executable uses the NAR Manager to download, unpack and call the executable.

To use the NAR Manager, see the API Docs, add the following to your POM file:

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>com.github.maven-nar</groupId>
      <artifactId>nar-maven-plugin</artifactId>
      <version>3.5.0</version>
    </dependency>
  </dependencies>
</project>

and use the code with the following snippet:

import com.github.maven_nar.Linker;
import com.github.maven_nar.NarManager;
import com.github.maven_nar.NarUtil;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

/**
 * Description...
 * 
 * @goal your-goal
 * @phase your-phase
 * @requiresDependencyResolution compile
 */
public class YourMojo extends AbstractMojo {

    /**
     * Level of logging messages, 0 is minimum.
     * 
     * @parameter property="logLevel" default-value="0"
     */
    private int logLevel;

    /**
     * @parameter property="localRepository"
     * @required
     * @readonly
     */
    private ArtifactRepository localRepository;

    /**
     * @parameter property="project"
     * @required
     * @readonly
     */
    private MavenProject project;

    /**
     * The Architecture for picking up swig, Some choices are: "x86", "i386",
     * "amd64", "ppc", "sparc", ... Defaults to ${os.arch}
     * 
     * @parameter property="os.arch"
     * @required
     */
    private String architecture;

    /**
     * The Operating System for picking up swig. Some choices are: "Windows",
     * "Linux", "MacOSX", "SunOS", ... Defaults to a derived value from
     * ${os.name}
     * 
     * @parameter default-value=""
     */
    private String os;

    private NarManager narManager;

    public void execute() throws MojoExecutionException, MojoFailureException {

        os = NarUtil.getOS(os);
                // FIXME, should have some function in NarUtil
        Linker linker = new Linker("g++");
        narManager = new NarManager(getLog(), logLevel, localRepository, project,
            architecture, os, linker);

        ... DO WHATEVER YOU NEED WITH THE NarManager
    }
}