Search in sources :

Example 6 with NarExecution

use of com.github.sdedwards.m2e_nar.internal.model.NarExecution 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)

Example 7 with NarExecution

use of com.github.sdedwards.m2e_nar.internal.model.NarExecution in project m2e-nar by maven-nar.

the class MavenUtils method buildTestCompileNarExecutions.

public static List<NarExecution> buildTestCompileNarExecutions(final ConfiguratorContext context, final IMavenProjectFacade facade, final IProgressMonitor monitor) throws CoreException {
    List<NarExecution> narExecutions = new ArrayList<NarExecution>();
    List<MojoExecution> testCompileExecutions = MavenUtils.getTestCompileExecutions(context, facade, monitor);
    for (MojoExecution testCompileExecution : testCompileExecutions) {
        NarExecution narSettings = MavenUtils.readTestCompileSettings(context, facade, testCompileExecution, monitor);
        narExecutions.add(narSettings);
    }
    return narExecutions;
}
Also used : MojoExecution(org.apache.maven.plugin.MojoExecution) ArrayList(java.util.ArrayList) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Aggregations

NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)7 ArrayList (java.util.ArrayList)3 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)3 AbstractSettingsSynchroniser (com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser)2 NarBuildArtifact (com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact)2 MojoExecution (org.apache.maven.plugin.MojoExecution)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)2 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ILibrary (com.github.maven_nar.ILibrary)1 ITest (com.github.maven_nar.ITest)1 NarProperties (com.github.maven_nar.NarProperties)1 File (java.io.File)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AbstractMojo (org.apache.maven.plugin.AbstractMojo)1