Search in sources :

Example 1 with NarBuildArtifact

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

the class NarExecutionBuilder method build.

public NarExecution build(final String buildType) throws CoreException {
    try {
        NarExecution settings = new NarExecution(mojoExecution);
        settings.setSkip(narCompileMojo.isSkip());
        settings.setOS(narCompileMojo.getOS());
        settings.setLinkerName(narCompileMojo.getLinker().getName());
        List<NarBuildArtifact> artifactSettings = settings.getArtifactSettings();
        if (NarExecution.MAIN.equals(buildType)) {
            List<?> libraries = narCompileMojo.getLibraries();
            for (Iterator<?> iter = libraries.iterator(); iter.hasNext(); ) {
                ILibrary library = (ILibrary) iter.next();
                NarBuildArtifact buildArtifact = buildArtifactSettings(library.getType(), buildType, library.linkCPP(), null);
                buildArtifact.setArtifactName(narCompileMojo.getOutput(library.getType()));
                buildArtifact.setConfigName(CdtUtils.getConfigName(mojoExecution, buildArtifact));
                artifactSettings.add(buildArtifact);
            }
        } else if (NarExecution.TEST.equals(buildType)) {
            List<?> tests = narCompileMojo.getTests();
            for (Iterator<?> iter = tests.iterator(); iter.hasNext(); ) {
                ITest test = (ITest) iter.next();
                NarBuildArtifact buildArtifact = buildArtifactSettings(NarBuildArtifact.EXECUTABLE, buildType, true, test);
                buildArtifact.setArtifactName(test.getName());
                buildArtifact.setConfigName(CdtUtils.getTestConfigName(mojoExecution, buildArtifact));
                artifactSettings.add(buildArtifact);
            }
        }
        return settings;
    } catch (MojoFailureException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Mojo failure", e));
    } catch (MojoExecutionException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Mojo execution failed", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ILibrary(com.github.maven_nar.ILibrary) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) NarBuildArtifact(com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact) CoreException(org.eclipse.core.runtime.CoreException) ITest(com.github.maven_nar.ITest) Iterator(java.util.Iterator) List(java.util.List) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Example 2 with NarBuildArtifact

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

the class CProjectConfigurator method configure.

@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    final ConfiguratorContext context = new ConfiguratorContext(maven, projectManager);
    IProject project = request.getProject();
    monitor.setTaskName(Messages.CProjectConfigurator_task_name + project.getName());
    logger.info("configure");
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    // Set the first created configuration as active.
    boolean setActive = true;
    final IMavenProjectFacade facade = request.getMavenProjectFacade();
    List<NarExecution> narExecutions = MavenUtils.buildCompileNarExecutions(context, facade, monitor);
    narExecutions.addAll(MavenUtils.buildTestCompileNarExecutions(context, facade, monitor));
    for (NarExecution narSettings : narExecutions) {
        if (!narSettings.isSkip()) {
            final String os = narSettings.getOS();
            final String linkerName = narSettings.getLinkerName();
            final AbstractSettingsSynchroniser synchro = SynchroniserFactory.getSettingsSynchroniser(os, linkerName);
            final String toolchain = synchro.getToolchain();
            for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) {
                final String configName = artifactSettings.getConfigName();
                final String cdtArtefactType = CdtUtils.convertArtefactType(artifactSettings.getType());
                IToolChain tc = getToolChain(toolchain, cdtArtefactType);
                ICProjectDescription desc = getCdtProject(project, tc, cdtArtefactType, monitor);
                ICConfigurationDescription cfg = getCdtMavenConfig(project, desc, tc, cdtArtefactType, configName, setActive, monitor);
                setActive = false;
                synchro.fullSync(cfg, artifactSettings);
                mngr.setProjectDescription(project, desc);
            }
        }
    }
    AbstractProjectConfigurator jConfig = LifecycleMappingFactory.createProjectConfigurator(JAVA_CONFIGURATOR_ID);
    jConfig.configure(request, monitor);
    // ensure CDT builder is after the Maven one
    boolean changed = false;
    IProjectDescription description = project.getDescription();
    ICommand cdtBuilder = null;
    ICommand mavenBuilder = null;
    ArrayList<ICommand> newSpec = new ArrayList<ICommand>();
    for (ICommand command : description.getBuildSpec()) {
        if (ManagedCProjectNature.getBuilderID().equals(command.getBuilderName()) && mavenBuilder == null) {
            cdtBuilder = command;
        } else {
            newSpec.add(command);
        }
        if (IMavenConstants.BUILDER_ID.equals(command.getBuilderName())) {
            mavenBuilder = command;
            if (cdtBuilder != null) {
                newSpec.add(cdtBuilder);
                changed = true;
            }
        }
    }
    if (changed) {
        description.setBuildSpec(newSpec.toArray(new ICommand[newSpec.size()]));
        project.setDescription(description, monitor);
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IToolChain(org.eclipse.cdt.managedbuilder.core.IToolChain) ArrayList(java.util.ArrayList) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) IProject(org.eclipse.core.resources.IProject) NarBuildArtifact(com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact) ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription) AbstractSettingsSynchroniser(com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser) AbstractProjectConfigurator(org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Example 3 with NarBuildArtifact

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

the class BuildPathManager method updateCdtBuildPaths.

private boolean updateCdtBuildPaths(final ICProjectDescription des, final SettingsSynchroniser synchro, final NarExecution narSettings) throws CoreException {
    boolean changed = false;
    for (NarBuildArtifact artifactSettings : narSettings.getArtifactSettings()) {
        final String configName = artifactSettings.getConfigName();
        final ICConfigurationDescription cfg = des.getConfigurationByName(configName);
        if (cfg != null) {
            logger.debug("updateBuildPaths: updating config " + configName);
            synchro.pathsOnlySync(cfg, artifactSettings);
            changed = true;
        } else {
            logger.debug("updateBuildPaths: could not find config " + configName);
        }
    }
    return changed;
}
Also used : NarBuildArtifact(com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 4 with NarBuildArtifact

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

the class NarExecutionBuilder method buildArtifactSettings.

@SuppressWarnings("unchecked")
private NarBuildArtifact buildArtifactSettings(final String type, final String buildType, final boolean linkCPP, final ITest test) throws MojoExecutionException, MojoFailureException {
    NarBuildArtifact settings = new NarBuildArtifact();
    settings.setType(type);
    List<String> projectRefs = settings.getProjectReferences();
    List<com.github.maven_nar.NarArtifact> narArtifacts = narCompileMojo.getNarArtifacts();
    for (com.github.maven_nar.NarArtifact artifact : narArtifacts) {
        if (artifact.getNarLayout() instanceof EclipseNarLayout) {
            EclipseNarLayout layout = (EclipseNarLayout) artifact.getNarLayout();
            projectRefs.add(layout.getProject().getProject().getName());
        }
    }
    settings.setLinkerSettings(buildLinkerSettings(narCompileMojo.getLinker(), linkCPP, test));
    settings.setCppSettings(buildCompilerSettings(narCompileMojo.getCpp(), buildType, test));
    settings.setCSettings(buildCompilerSettings(narCompileMojo.getC(), buildType, test));
    List<String> javahIncludePaths = settings.getJavahIncludePaths();
    javahIncludePaths.addAll(narCompileMojo.getJavahIncludePaths());
    List<String> javaIncludePaths = settings.getJavaIncludePaths();
    javaIncludePaths.addAll(narCompileMojo.getJavaIncludePaths());
    List<File> dependencyIncludePaths = settings.getDependencyIncludePaths();
    logger.debug("include paths size " + narCompileMojo.getDependencyIncludePaths().size());
    dependencyIncludePaths.addAll(narCompileMojo.getDependencyIncludePaths());
    List<NarLib> dependencyLibs = settings.getDependencyLibs();
    logger.debug("library size " + narCompileMojo.getDependencyLibs(type, test).size());
    for (Iterator<?> it = narCompileMojo.getDependencyLibs(type, test).iterator(); it.hasNext(); ) {
        dependencyLibs.add(buildLibSettings((ILib) it.next()));
    }
    List<NarSysLib> dependencySysLibs = settings.getDependencySysLibs();
    for (Iterator<?> it = narCompileMojo.getDependencySysLibs(type).iterator(); it.hasNext(); ) {
        dependencySysLibs.add(buildSysLibSettings((ISysLib) it.next()));
    }
    List<String> dependencyOptions = settings.getDependencyOptions();
    dependencyOptions.addAll(narCompileMojo.getDependencyOptions(type));
    return settings;
}
Also used : NarLib(com.github.sdedwards.m2e_nar.internal.model.NarLib) NarSysLib(com.github.sdedwards.m2e_nar.internal.model.NarSysLib) ISysLib(com.github.maven_nar.ISysLib) NarBuildArtifact(com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact) EclipseNarLayout(com.github.maven_nar.EclipseNarLayout) File(java.io.File) ILib(com.github.maven_nar.ILib)

Aggregations

NarBuildArtifact (com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact)4 NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)2 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)2 EclipseNarLayout (com.github.maven_nar.EclipseNarLayout)1 ILib (com.github.maven_nar.ILib)1 ILibrary (com.github.maven_nar.ILibrary)1 ISysLib (com.github.maven_nar.ISysLib)1 ITest (com.github.maven_nar.ITest)1 AbstractSettingsSynchroniser (com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser)1 NarLib (com.github.sdedwards.m2e_nar.internal.model.NarLib)1 NarSysLib (com.github.sdedwards.m2e_nar.internal.model.NarSysLib)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)1 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)1 IToolChain (org.eclipse.cdt.managedbuilder.core.IToolChain)1