Search in sources :

Example 41 with ICProjectDescription

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

the class ConfigurationChangeListener method handleEvent.

@Override
public void handleEvent(CProjectDescriptionEvent event) {
    IProject activeProject = event.getProject();
    SloeberProject sloeberProject = SloeberProject.getSloeberProject(activeProject);
    if (sloeberProject == null) {
        // this is not a sloeber project so ignore
        return;
    }
    // don't do stuff during project creation
    if (IndexerController.isPosponed(activeProject)) {
        Common.log(new Status(Const.SLOEBER_STATUS_DEBUG, Activator.getId(), // $NON-NLS-1$
        "Ignoring configuration change during project creation " + activeProject.getName()));
        return;
    }
    switch(event.getEventType()) {
        case CProjectDescriptionEvent.ABOUT_TO_APPLY:
            {
                ICProjectDescription newProjDesc = event.getNewCProjectDescription();
                ICProjectDescription oldProjDesc = event.getOldCProjectDescription();
                sloeberProject.configChangeAboutToApply(newProjDesc, oldProjDesc);
                break;
            }
        default:
            {
            // should not happen
            }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) SloeberProject(io.sloeber.core.api.SloeberProject) IProject(org.eclipse.core.resources.IProject)

Example 42 with ICProjectDescription

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

the class RegressionTest method openAndCloseUsesSavedSettings.

/**
 * open and close a project should keep the compileDescription and
 * BoardDescriotion
 *
 * @throws Exception
 */
@Test
public void openAndCloseUsesSavedSettings() throws Exception {
    CodeDescription codeDesc = new CodeDescription(CodeDescription.CodeTypes.defaultCPP);
    String proj1Name = "openModAndClose1";
    BoardDescription proj1BoardDesc = Arduino.uno().getBoardDescriptor();
    OtherDescription otherDesc = new OtherDescription();
    otherDesc.setVersionControlled(true);
    CompileDescription proj1CompileDesc = getBunkersCompileDescription();
    IProject proj1 = SloeberProject.createArduinoProject(proj1Name, null, proj1BoardDesc, codeDesc, proj1CompileDesc, otherDesc, new NullProgressMonitor());
    String proj2Name = "openModAndClose2";
    BoardDescription proj2BoardDesc = Arduino.mega2560Board().getBoardDescriptor();
    CompileDescription proj2CompileDesc = new CompileDescription();
    IProject proj2 = SloeberProject.createArduinoProject(proj2Name, null, proj2BoardDesc, codeDesc, proj2CompileDesc, new NullProgressMonitor());
    // Read the data we want to test
    // for the indexer
    Shared.waitForAllJobsToFinish();
    SloeberProject proj1SloeberDesc = SloeberProject.getSloeberProject(proj1);
    ICProjectDescription proj1Desc = CoreModel.getDefault().getProjectDescription(proj1);
    ICConfigurationDescription proj1ConfDesc = proj1Desc.getActiveConfiguration();
    BoardDescription proj1CreatedBoardDesc = proj1SloeberDesc.getBoardDescription(proj1ConfDesc.getName(), false);
    CompileDescription proj1CreatedCompileDesc = proj1SloeberDesc.getCompileDescription(proj1ConfDesc.getName(), false);
    SloeberProject proj2SloeberDesc = SloeberProject.getSloeberProject(proj2);
    ICProjectDescription proj2Desc = CoreModel.getDefault().getProjectDescription(proj2);
    ICConfigurationDescription proj2ConfDesc = proj2Desc.getActiveConfiguration();
    BoardDescription proj2CreatedBoardDesc = proj2SloeberDesc.getBoardDescription(proj2ConfDesc.getName(), false);
    CompileDescription proj2CreatedCompileDesc = proj2SloeberDesc.getCompileDescription(proj2ConfDesc.getName(), false);
    // get the filenames to copy
    IFile file = proj1.getFile(SLOEBER_CFG);
    File proj1SloeberFile = file.getLocation().toFile();
    file = proj2.getFile(SLOEBER_CFG);
    File proj2SloeberFile = file.getLocation().toFile();
    // close and reopen the project
    proj2.close(null);
    // just wait a while
    Thread.sleep(1000);
    Shared.waitForAllJobsToFinish();
    // copy from proj1 to proj2
    FileUtils.copyFile(proj1SloeberFile, proj2SloeberFile);
    // reopen the project
    proj2.open(null);
    Thread.sleep(1000);
    Shared.waitForAllJobsToFinish();
    // reread project 2
    proj2SloeberDesc = SloeberProject.getSloeberProject(proj2);
    proj2Desc = CoreModel.getDefault().getProjectDescription(proj2);
    proj2ConfDesc = proj2Desc.getActiveConfiguration();
    BoardDescription proj2OpenedBoardDesc = proj2SloeberDesc.getBoardDescription(proj2ConfDesc.getName(), false);
    CompileDescription proj2OpenedCompileDesc = proj2SloeberDesc.getCompileDescription(proj2ConfDesc.getName(), false);
    // check the setup was done correctly
    if (!proj1BoardDesc.equals(proj1CreatedBoardDesc)) {
        fail("Project 1 not created properly.");
    }
    if (!proj2BoardDesc.equals(proj2CreatedBoardDesc)) {
        fail("Project 2 not created properly.");
    }
    if (!proj1CompileDesc.equals(proj1CreatedCompileDesc)) {
        fail("Project 1 not created properly.");
    }
    if (!proj2CompileDesc.equals(proj2CreatedCompileDesc)) {
        fail("Project 2 not created properly.");
    }
    // check wether the file modification was taken into account
    if (!proj1BoardDesc.equals(proj2OpenedBoardDesc)) {
        fail("Project 2 not created properly.");
    }
    if (!proj1CompileDesc.equals(proj2OpenedCompileDesc)) {
        fail("Project 2 not created properly.");
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) BoardDescription(io.sloeber.core.api.BoardDescription) IFile(org.eclipse.core.resources.IFile) CodeDescription(io.sloeber.core.api.CodeDescription) SloeberProject(io.sloeber.core.api.SloeberProject) OtherDescription(io.sloeber.core.api.OtherDescription) CompileDescription(io.sloeber.core.api.CompileDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 43 with ICProjectDescription

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

the class RegressionTest method openAndClosePreservesSettings.

/**
 * open and close a project should keep the compileDescription and
 * BoardDescriotion
 *
 * @throws Exception
 */
@Test
public void openAndClosePreservesSettings() throws Exception {
    BoardDescription unoBoardid = Arduino.uno().getBoardDescriptor();
    IProject theTestProject = null;
    String projectName = "openAndClose";
    CodeDescription codeDescriptor = new CodeDescription(CodeDescription.CodeTypes.defaultCPP);
    CompileDescription inCompileDescription = getBunkersCompileDescription();
    theTestProject = SloeberProject.createArduinoProject(projectName, null, unoBoardid, codeDescriptor, inCompileDescription, new NullProgressMonitor());
    // Read the data we want to test
    // for the indexer
    Shared.waitForAllJobsToFinish();
    SloeberProject sloeberDesc = SloeberProject.getSloeberProject(theTestProject);
    ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(theTestProject);
    ICConfigurationDescription confDesc = projDesc.getActiveConfiguration();
    BoardDescription createdBoardDesc = sloeberDesc.getBoardDescription(confDesc.getName(), false);
    CompileDescription createdCompileDesc = sloeberDesc.getCompileDescription(confDesc.getName(), false);
    // close and reopen the project
    theTestProject.close(null);
    // just wait a while
    Thread.sleep(1000);
    Shared.waitForAllJobsToFinish();
    theTestProject.open(null);
    Shared.waitForAllJobsToFinish();
    // read the data we want to test
    sloeberDesc = SloeberProject.getSloeberProject(theTestProject);
    projDesc = CoreModel.getDefault().getProjectDescription(theTestProject);
    confDesc = projDesc.getActiveConfiguration();
    BoardDescription reopenedBoardDesc = sloeberDesc.getBoardDescription(confDesc.getName(), false);
    CompileDescription reopenedCompileDesc = sloeberDesc.getCompileDescription(confDesc.getName(), false);
    // check the data is equal
    boolean createBoardsDiff = !unoBoardid.equals(createdBoardDesc);
    boolean createCompileDiff = !inCompileDescription.equals(createdCompileDesc);
    boolean openBoardsDiff = !reopenedBoardDesc.equals(createdBoardDesc);
    boolean openCompileDiff = !reopenedCompileDesc.equals(createdCompileDesc);
    if (createBoardsDiff || createCompileDiff) {
        fail("Created project does not match creation parameters.");
    }
    if (openBoardsDiff || openCompileDiff) {
        fail("Opened project does not match closed project parameters.");
    }
    // also do a build
    // for the indexer
    Shared.waitForAllJobsToFinish();
    theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, null);
    if (Shared.hasBuildErrors(theTestProject)) {
        fail("Failed to compile the project:" + projectName);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) BoardDescription(io.sloeber.core.api.BoardDescription) CodeDescription(io.sloeber.core.api.CodeDescription) SloeberProject(io.sloeber.core.api.SloeberProject) CompileDescription(io.sloeber.core.api.CompileDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 44 with ICProjectDescription

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

the class Import_Libraries_Page method PerformFinish.

@SuppressWarnings("restriction")
public boolean PerformFinish() {
    // windows only
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        IFolder folder = this.myProject.getFolder(Const.LIBRARY_PATH_SUFFIX);
        if (!folder.exists()) {
            try {
                folder.create(false, true, null);
            } catch (CoreException e) {
                log(new Status(IStatus.ERROR, PLUGIN_ID, // $NON-NLS-1$
                "Failed to create \"libraries\" folder.\nThis is probably a windows case insensetivity problem", e));
                return true;
            }
        }
    }
    TreeItem[] selectedTreeItems = this.myLibrarySelector.getItems();
    Set<String> selectedLibraries = new TreeSet<>();
    Set<String> unselectedLibraries = new TreeSet<>();
    for (TreeItem CurItem : selectedTreeItems) {
        if (CurItem.getChecked())
            selectedLibraries.add(CurItem.getText());
        else
            unselectedLibraries.add(CurItem.getText());
    }
    ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
    ICProjectDescription projDesc = mngr.getProjectDescription(myProject, true);
    ICConfigurationDescription activeConfDesc = projDesc.getActiveConfiguration();
    boolean descNeedsSaving1 = Sketch.removeLibrariesFromProject(myProject, projDesc, unselectedLibraries);
    boolean descNeedsSaving2 = Sketch.addLibrariesToProject(myProject, activeConfDesc, selectedLibraries);
    if (descNeedsSaving1 || descNeedsSaving2) {
        try {
            mngr.setProjectDescription(myProject, projDesc, true, null);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) CoreException(org.eclipse.core.runtime.CoreException) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeSet(java.util.TreeSet) ICProjectDescriptionManager(org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription) IFolder(org.eclipse.core.resources.IFolder)

Example 45 with ICProjectDescription

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

the class SloeberCpropertyTab method createControls.

@Override
public void createControls(Composite parent, ICPropertyProvider provider) {
    super.createControls(parent, provider);
    // make sure all configurations hold their description
    // This is needed so that when a copy is made
    // the root compile description is known
    ICProjectDescription projDesc = getConfdesc().getProjectDescription();
    mySloeberProject = SloeberProject.getSloeberProject(projDesc.getProject());
    for (ICConfigurationDescription curConfig : projDesc.getConfigurations()) {
        Object description = getFromSloeber(curConfig);
        if (description == null) {
            description = getnewDefaultObject();
        }
        setDescription(curConfig, description);
    }
// We can now safely assume confDesc.getSessionProperty(sloeberQualifiedName);
// is not null
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

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