Example usage for org.apache.maven.project ProjectBuildingRequest getLocalRepository

List of usage examples for org.apache.maven.project ProjectBuildingRequest getLocalRepository

Introduction

In this page you can find the example usage for org.apache.maven.project ProjectBuildingRequest getLocalRepository.

Prototype

ArtifactRepository getLocalRepository();

Source Link

Usage

From source file:org.dugilos.m2e.nar.internal.NarPluginConfiguration.java

License:Open Source License

public NarPluginConfiguration(IProject project, MavenProject mavenProject, String pluginId, Log log)
        throws CoreException {

    this.mavenProject = mavenProject;
    this.pluginId = pluginId;

    // extract local repository (containing nar files dependencies)
    ProjectBuildingRequest buildingRequest = mavenProject.getProjectBuildingRequest();
    ArtifactRepository artifactRepository = buildingRequest.getLocalRepository();

    // extract project directories
    absoluteProjectBaseDir = project.getLocation().toFile();
    projectBuildDirectory = mavenProject.getBuild().getDirectory();

    // extract com.github.maven-nar:nar-maven-plugin plugin
    narMavenPlugin = getNarMavenPlugin(mavenProject);
    MgtNarMavenPlugin = getMgtNarMavenPlugin(mavenProject);
    // If the plugin isn't used in the project, it's useless to go further
    if (narMavenPlugin == null) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId,
                "Plugin " + NAR_MAVEN_PLUGIN_GROUPID + ":" + NAR_MAVEN_PLUGIN_ARTIFACTID + " not found");
        throw new CoreException(status);
    }/*from   ww w  . j a  va2s .c o m*/

    String arch = NarUtil.getArchitecture(null);
    String os = NarUtil.getOS(null);
    String aolPrefix = arch + "." + os + ".";

    NarProperties narProperties = null;
    try {
        narProperties = NarProperties.getInstance(mavenProject);
    } catch (MojoFailureException e) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId, e.getMessage(), e);
        throw new CoreException(status);
    }

    String configLinkerName = getConfigurationLinkerName();
    linker = new Linker(configLinkerName, log);
    // if configLinkerName is null we call getName(NarProperties properties, String prefix) to initialise the name from AOL
    if (configLinkerName == null) {
        try {
            linker.getName(narProperties, aolPrefix);
        } catch (MojoFailureException e) {
            int severity = IStatus.ERROR;
            Status status = new Status(severity, pluginId, e.getMessage(), e);
            throw new CoreException(status);
        } catch (MojoExecutionException e) {
            int severity = IStatus.ERROR;
            Status status = new Status(severity, pluginId, e.getMessage(), e);
            throw new CoreException(status);
        }
    }

    try {
        narManager = new NarManager(log, artifactRepository, mavenProject, arch, os, linker);
    } catch (MojoFailureException e) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId, e.getMessage(), e);
        throw new CoreException(status);
    } catch (MojoExecutionException e) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId, e.getMessage(), e);
        throw new CoreException(status);
    }

    try {
        aol = NarUtil.getAOL(mavenProject, arch, os, linker, null, log);
    } catch (MojoFailureException e) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId, e.getMessage(), e);
        throw new CoreException(status);
    } catch (MojoExecutionException e) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId, e.getMessage(), e);
        throw new CoreException(status);
    }

    String layoutName = getLayoutName();
    try {
        narLayout = AbstractNarLayout.getLayout(layoutName, log);
    } catch (MojoExecutionException e) {
        int severity = IStatus.ERROR;
        Status status = new Status(severity, pluginId, e.getMessage(), e);
        throw new CoreException(status);
    }
}