Search in sources :

Example 6 with ICProjectDescriptionManager

use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager 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 7 with ICProjectDescriptionManager

use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager in project arduino-eclipse-plugin by Sloeber.

the class Libraries method addLibrariesToProject.

public static void addLibrariesToProject(IProject project, Set<String> selectedLibraries) {
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    ICProjectDescription projectDescription = mngr.getProjectDescription(project, true);
    ICConfigurationDescription configurationDescription = projectDescription.getActiveConfiguration();
    addLibrariesToProject(project, configurationDescription, selectedLibraries);
    try {
        mngr.setProjectDescription(project, projectDescription, true, null);
    } catch (CoreException e) {
        e.printStackTrace();
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 8 with ICProjectDescriptionManager

use of org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager in project m2e-nar by maven-nar.

the class CProjectConfigurator method getCdtProject.

private ICProjectDescription getCdtProject(IProject project, IToolChain tc, String artefactType, IProgressMonitor monitor) throws CoreException {
    try {
        ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
        if (!project.hasNature(CCProjectNature.CC_NATURE_ID)) {
            MavenNarPlugin.getDefault().log("Configuring project with " + tc.getUniqueRealName() + " tool chain");
            // Add the C++ Nature
            CCorePlugin.getDefault().convertProjectToNewCC(project, ManagedBuildManager.CFG_DATA_PROVIDER_ID, monitor);
            ICProjectDescription des = mngr.createProjectDescription(project, false, false);
            IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
            List<IConfiguration> cfgs = getCfgs(tc, artefactType);
            if (cfgs.isEmpty()) {
                throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot find any configurations"));
            }
            IConfiguration cf = cfgs.get(0);
            IManagedProject mProj = ManagedBuildManager.createManagedProject(project, cf.getProjectType());
            info.setManagedProject(mProj);
            return des;
        } else {
            ICProjectDescription des = mngr.getProjectDescription(project, true);
            return des;
        }
    } catch (BuildException e) {
        throw new CoreException(new Status(IStatus.ERROR, MavenNarPlugin.PLUGIN_ID, "Cannot create CDT managed project", e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IManagedProject(org.eclipse.cdt.managedbuilder.core.IManagedProject) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IManagedBuildInfo(org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) BuildException(org.eclipse.cdt.managedbuilder.core.BuildException) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Aggregations

ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)8 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)8 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)6 CoreException (org.eclipse.core.runtime.CoreException)5 AbstractSettingsSynchroniser (com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser)2 NarExecution (com.github.sdedwards.m2e_nar.internal.model.NarExecution)2 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)2 IToolChain (org.eclipse.cdt.managedbuilder.core.IToolChain)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)2 NarBuildArtifact (com.github.sdedwards.m2e_nar.internal.model.NarBuildArtifact)1 ConfigurationDescriptor (io.sloeber.core.api.ConfigurationDescriptor)1 IInstallLibraryHandler (io.sloeber.core.api.IInstallLibraryHandler)1 LibraryDescriptor (io.sloeber.core.api.LibraryDescriptor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1