Search in sources :

Example 1 with NarProperties

use of com.github.maven_nar.NarProperties in project m2e-nar by maven-nar.

the class MavenUtils method readSettings.

public static <T extends AbstractCompileMojo> NarExecution readSettings(final ConfiguratorContext context, final IMavenProjectFacade facade, final MojoExecution compileExecution, final Class<T> mojoType, final String buildType, final IProgressMonitor monitor) throws CoreException {
    final IMaven maven = context.getMaven();
    final MavenProject mavenProject = facade.getMavenProject();
    NarExecution settings = null;
    if (compileExecution != null) {
        // Load plugin with Maven in order to check config
        // and to get at aol.properties resource inside the plugin
        AbstractMojo narMojo = loadMojo(maven, mavenProject, compileExecution, AbstractMojo.class, monitor);
        try {
            // ClassRealm pluginRealm =
            // compileExecution.getMojoDescriptor().getPluginDescriptor().getClassRealm();
            // NarClassloader classloader = new NarClassloader(pluginRealm);
            // INarExecutionBuilder builder =
            // classloader.createNarExecutionBuilder(mavenProject,
            // compileMojo);
            // settings = builder.build(NarExecution.MAIN);
            T compileMojo = getConfiguredMojo(maven, mavenProject, compileExecution, mojoType, narMojo.getLog(), monitor);
            compileMojo.setNarProperties(new NarProperties(mavenProject, narMojo.getClass()));
            // Need to call validate to set up defaults
            compileMojo.validate();
            // Resolve the NAR artifacts, possibly from workspace
            compileMojo.prepareNarArtifacts(context, facade, monitor);
            NarExecutionBuilder builder = new NarExecutionBuilder(compileMojo, compileExecution);
            settings = builder.build(buildType);
        } catch (MojoFailureException e) {
            throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't configure mojo"));
        } catch (MojoExecutionException e) {
            throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't configure mojo"));
        } finally {
            releaseMojo(maven, mavenProject, narMojo, compileExecution, monitor);
        }
    } else {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Couldn't find default-nar-compile execution"));
    }
    return settings;
}
Also used : NarProperties(com.github.maven_nar.NarProperties) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AbstractMojo(org.apache.maven.plugin.AbstractMojo) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IMaven(org.eclipse.m2e.core.embedder.IMaven) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Aggregations

NarProperties (com.github.maven_nar.NarProperties)1 NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)1 AbstractMojo (org.apache.maven.plugin.AbstractMojo)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 MavenProject (org.apache.maven.project.MavenProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IMaven (org.eclipse.m2e.core.embedder.IMaven)1