Search in sources :

Example 11 with ICProjectDescription

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

the class BuildPathManager method updateBuildPaths.

private void updateBuildPaths(IProject project, IProgressMonitor monitor) throws CoreException {
    final IMavenProjectFacade facade = projectManager.getProject(project);
    if (facade != null) {
        final ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
        final ICProjectDescription des = mngr.getProjectDescription(project, true);
        if (des != null) {
            boolean changed = false;
            logger.debug("updateBuildPaths: project=" + project.getName());
            final ConfiguratorContext context = new ConfiguratorContext(MavenPlugin.getMaven(), projectManager);
            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);
                    changed = updateCdtBuildPaths(des, synchro, narSettings);
                }
            }
            if (changed) {
                mngr.setProjectDescription(project, des);
            }
        }
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) AbstractSettingsSynchroniser(com.github.sdedwards.m2e_nar.internal.cdt.AbstractSettingsSynchroniser) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) NarExecution(com.github.sdedwards.m2e_nar.internal.model.NarExecution)

Example 12 with ICProjectDescription

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

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

the class AbstractTestBuild method buildAllConfigurations.

protected void buildAllConfigurations(final IProject project) {
    final ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(project, false);
    if (prjd != null) {
        final ICConfigurationDescription[] cfgDescriptions = prjd.getConfigurations();
        if (cfgDescriptions != null && cfgDescriptions.length > 0) {
            final IConfiguration[] cfgs = new IConfiguration[cfgDescriptions.length];
            for (int i = 0; i < cfgDescriptions.length; ++i) {
                cfgs[i] = ManagedBuildManager.getConfigurationForDescription(cfgDescriptions[i]);
            }
            final Job job = new Job("Building all configurations") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        ManagedBuildManager.buildConfigurations(cfgs, monitor);
                    } catch (CoreException e) {
                        return e.getStatus();
                    }
                    return Status.OK_STATUS;
                }
            };
            job.schedule();
            waitForJobs();
        }
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration) Job(org.eclipse.core.runtime.jobs.Job)

Example 14 with ICProjectDescription

use of org.eclipse.cdt.core.settings.model.ICProjectDescription in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class TestProjectHolder method setupProjectReferencesAsync.

@Override
public ProjectHolderJob setupProjectReferencesAsync() {
    return ProjectHolderJob.create("Setup members of project " + projectName, ITestProjectHolder.SETUP_PROJECT_REFERENCES_JOB_FAMILY, mon -> {
        if (!referencedProjects.isEmpty()) {
            final ICProjectDescription description = CCorePlugin.getDefault().getProjectDescription(getProject(), true);
            for (final ICConfigurationDescription config : description.getConfigurations()) {
                final Map<String, String> refMap = config.getReferenceInfo();
                for (final ICProject refProject : referencedProjects) {
                    refMap.put(refProject.getProject().getName(), "");
                }
                config.setReferenceInfo(refMap);
            }
            CCorePlugin.getDefault().setProjectDescription(getProject(), description);
        }
    });
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProject(org.eclipse.cdt.core.model.ICProject) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 15 with ICProjectDescription

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

the class SloeberProject method createArduinoProject.

/*
     * Method to create a project based on the board
     */
public static IProject createArduinoProject(String projectName, URI projectURI, BoardDescription boardDescriptor, CodeDescription codeDesc, CompileDescription compileDescriptor, OtherDescription otherDesc, IProgressMonitor monitor) {
    String realProjectName = Common.MakeNameCompileSafe(projectName);
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    ICoreRunnable runnable = new ICoreRunnable() {

        @Override
        public void run(IProgressMonitor internalMonitor) throws CoreException {
            IProject newProjectHandle = root.getProject(realProjectName);
            IndexerController.doNotIndex(newProjectHandle);
            try {
                // create a eclipse project
                IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
                if (projectURI != null) {
                    description.setLocationURI(projectURI);
                }
                newProjectHandle.create(description, internalMonitor);
                newProjectHandle.open(internalMonitor);
                // Add the sketch code
                Map<String, IPath> librariesToAdd = codeDesc.createFiles(newProjectHandle, internalMonitor);
                // Add the arduino code folders
                List<IPath> addToIncludePath = Helpers.addArduinoCodeToProject(newProjectHandle, boardDescriptor);
                Map<String, List<IPath>> pathMods = Libraries.addLibrariesToProject(newProjectHandle, librariesToAdd);
                // make the eclipse project a cdt project
                CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
                // add the required natures
                ManagedCProjectNature.addManagedNature(newProjectHandle, internalMonitor);
                ManagedCProjectNature.addManagedBuilder(newProjectHandle, internalMonitor);
                // $NON-NLS-1$
                ManagedCProjectNature.addNature(newProjectHandle, "org.eclipse.cdt.core.ccnature", internalMonitor);
                ManagedCProjectNature.addNature(newProjectHandle, Const.ARDUINO_NATURE_ID, internalMonitor);
                // make the cdt project a managed build project
                // $NON-NLS-1$
                IProjectType sloeberProjType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch");
                ManagedBuildManager.createBuildInfo(newProjectHandle);
                IManagedProject newProject = ManagedBuildManager.createManagedProject(newProjectHandle, sloeberProjType);
                ManagedBuildManager.setNewProjectVersion(newProjectHandle);
                // Copy over the Sloeber configs
                IConfiguration defaultConfig = null;
                IConfiguration[] configs = sloeberProjType.getConfigurations();
                for (int i = 0; i < configs.length; ++i) {
                    IConfiguration curConfig = newProject.createConfiguration(configs[i], // $NON-NLS-1$
                    sloeberProjType.getId() + "." + i);
                    curConfig.setArtifactName(newProject.getDefaultArtifactName());
                    curConfig.getEditableBuilder().setParallelBuildOn(compileDescriptor.isParallelBuildEnabled());
                    // Make the first configuration the default
                    if (i == 0) {
                        defaultConfig = curConfig;
                    }
                }
                // create a sloeber project
                SloeberProject arduinoProjDesc = new SloeberProject(newProjectHandle);
                arduinoProjDesc.myIsInMemory = true;
                // the line below will trigger environment var requests causing loops if called to early
                ManagedBuildManager.setDefaultConfiguration(newProjectHandle, defaultConfig);
                Map<String, String> configs2 = new HashMap<>();
                CCorePlugin cCorePlugin = CCorePlugin.getDefault();
                ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(newProjectHandle);
                for (ICConfigurationDescription curConfigDesc : prjCDesc.getConfigurations()) {
                    arduinoProjDesc.myCompileDescriptions.put(getConfigKey(curConfigDesc), compileDescriptor);
                    arduinoProjDesc.myBoardDescriptions.put(getConfigKey(curConfigDesc), boardDescriptor);
                    arduinoProjDesc.myOtherDescriptions.put(getConfigKey(curConfigDesc), otherDesc);
                    Libraries.adjustProjectDescription(curConfigDesc, pathMods);
                    Helpers.addIncludeFolder(curConfigDesc, addToIncludePath, true);
                    String curConfigKey = getConfigKey(curConfigDesc);
                    arduinoProjDesc.myEnvironmentVariables.put(curConfigKey, arduinoProjDesc.getEnvVars(curConfigKey));
                    configs2.put(curConfigDesc.getName(), curConfigDesc.getId());
                }
                arduinoProjDesc.createSloeberConfigFiles(prjCDesc);
                arduinoProjDesc.setAllEnvironmentVars(prjCDesc);
                arduinoProjDesc.myIsInMemory = true;
                SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);
                newProjectHandle.open(refreshMonitor);
                newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor);
                cCorePlugin.setProjectDescription(newProjectHandle, prjCDesc, true, null);
            } catch (Exception e) {
                Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project creation failed: " + realProjectName, // $NON-NLS-1$
                e));
            }
            Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(), // $NON-NLS-1$
            "internal creation of project is done: " + realProjectName));
            IndexerController.index(newProjectHandle);
        }
    };
    try {
        workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
    } catch (Exception e) {
        Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project creation failed: " + realProjectName, // $NON-NLS-1$
        e));
    }
    monitor.done();
    return root.getProject(realProjectName);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) HashMap(java.util.HashMap) ICoreRunnable(org.eclipse.core.runtime.ICoreRunnable) IManagedProject(org.eclipse.cdt.managedbuilder.core.IManagedProject) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) List(java.util.List) LinkedList(java.util.LinkedList) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) IProjectType(org.eclipse.cdt.managedbuilder.core.IProjectType) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IConfiguration(org.eclipse.cdt.managedbuilder.core.IConfiguration)

Aggregations

ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)45 ICConfigurationDescription (org.eclipse.cdt.core.settings.model.ICConfigurationDescription)31 CoreException (org.eclipse.core.runtime.CoreException)17 IProject (org.eclipse.core.resources.IProject)13 Status (org.eclipse.core.runtime.Status)10 ICProjectDescriptionManager (org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager)9 IPath (org.eclipse.core.runtime.IPath)9 IStatus (org.eclipse.core.runtime.IStatus)9 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IConfiguration (org.eclipse.cdt.managedbuilder.core.IConfiguration)7 IOException (java.io.IOException)5 BoardDescription (io.sloeber.core.api.BoardDescription)4 CodeDescription (io.sloeber.core.api.CodeDescription)4 CompileDescription (io.sloeber.core.api.CompileDescription)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 BoardDescriptor (io.sloeber.core.api.BoardDescriptor)3