Search in sources :

Example 11 with ICProject

use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.

the class OpenGmonAction method getDefaultBinary.

private String getDefaultBinary(IPath file) {
    IProject project = null;
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    if (c != null) {
        project = c.getProject();
        if (project != null && project.exists()) {
            ICProject cproject = CoreModel.getDefault().create(project);
            if (cproject != null) {
                try {
                    IBinary[] b = cproject.getBinaryContainer().getBinaries();
                    if (b != null && b.length > 0 && b[0] != null) {
                        IResource r = b[0].getResource();
                        return r.getLocation().toOSString();
                    }
                } catch (CModelException e) {
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 12 with ICProject

use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.

the class GcovTest method setUp.

@Before
public void setUp() throws Exception {
    if (project == null) {
        ICProject cproject = createProjectAndBuild(FrameworkUtil.getBundle(this.getClass()), getTestProjectName());
        project = cproject.getProject();
        isCppProject = project.getNature(CCProjectNature.CC_NATURE_ID) != null;
        gcovFiles = new TreeSet<>();
        do {
            for (IResource r : project.members()) {
                if (r.getType() == IResource.FILE && r.exists()) {
                    String fileName = r.getName();
                    if (fileName.endsWith(".gcda") || fileName.endsWith(".gcno")) {
                        gcovFiles.add(fileName);
                    }
                }
            }
        } while (gcovFiles.size() < 1);
    }
}
Also used : ICProject(org.eclipse.cdt.core.model.ICProject) IResource(org.eclipse.core.resources.IResource) Before(org.junit.Before)

Example 13 with ICProject

use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.

the class CProjectHelper method createCProject.

/**
 * Creates a ICProject.
 */
private static ICProject createCProject(final String projectName, String binFolderName, final String indexerID) throws CoreException {
    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final ICProject[] newProject = new ICProject[1];
    ws.run((IWorkspaceRunnable) monitor -> {
        IWorkspaceRoot root = ws.getRoot();
        IProject project = root.getProject(projectName);
        if (indexerID != null) {
            IndexerPreferences.set(project, IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "true");
            IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, indexerID);
        }
        if (!project.exists()) {
            project.create(null);
        } else {
            project.refreshLocal(IResource.DEPTH_INFINITE, null);
        }
        if (!project.isOpen()) {
            project.open(null);
        }
        if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
            String projectId = PLUGIN_ID + ".TestProject";
            addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
            CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
        }
        addDefaultBinaryParser(project);
        newProject[0] = CCorePlugin.getDefault().getCoreModel().create(project);
    }, null);
    return newProject[0];
}
Also used : CProjectNature(org.eclipse.cdt.core.CProjectNature) IndexerPreferences(org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences) ICConfigExtensionReference(org.eclipse.cdt.core.settings.model.ICConfigExtensionReference) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) CoreException(org.eclipse.core.runtime.CoreException) ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CCProjectNature(org.eclipse.cdt.core.CCProjectNature) CCorePlugin(org.eclipse.cdt.core.CCorePlugin) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) IResource(org.eclipse.core.resources.IResource) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ICProject(org.eclipse.cdt.core.model.ICProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject)

Example 14 with ICProject

use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.

the class ProfileLaunchShortcut method searchAndLaunch.

/**
 * Search and launch binary.
 *
 * @param elements Binaries to search.
 * @param mode Launch mode.
 */
private void searchAndLaunch(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List<IBinary> results = new ArrayList<>();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getActiveWorkbenchShell());
            IRunnableWithProgress runnable = pm -> {
                int nElements = elements.length;
                pm.beginTask(Messages.ProfileLaunchShortcut_Looking_for_executables, nElements);
                try {
                    IProgressMonitor sub = SubMonitor.convert(pm, 1);
                    for (int i = 0; i < nElements; i++) {
                        if (elements[i] instanceof IAdaptable) {
                            IResource r = ((IAdaptable) elements[i]).getAdapter(IResource.class);
                            if (r != null) {
                                ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                if (cproject != null) {
                                    try {
                                        IBinary[] bins = cproject.getBinaryContainer().getBinaries();
                                        for (IBinary bin1 : bins) {
                                            if (bin1.isExecutable()) {
                                                results.add(bin1);
                                            }
                                        }
                                    } catch (CModelException e) {
                                    // TODO should this be simply ignored ?
                                    }
                                }
                            }
                        }
                        if (pm.isCanceled()) {
                            throw new InterruptedException();
                        }
                        sub.done();
                    }
                } finally {
                    pm.done();
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                handleFail(e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                handleFail(Messages.ProfileLaunchShortcut_Binary_not_found);
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        handleFail(Messages.ProfileLaunchShortcut_no_project_selected);
    }
}
Also used : IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) DebugPlugin(org.eclipse.debug.core.DebugPlugin) SubMonitor(org.eclipse.core.runtime.SubMonitor) CoreModel(org.eclipse.cdt.core.model.CoreModel) CoreException(org.eclipse.core.runtime.CoreException) DebugUITools(org.eclipse.debug.ui.DebugUITools) ArrayList(java.util.ArrayList) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) Messages(org.eclipse.linuxtools.internal.profiling.launch.Messages) ILaunchShortcut(org.eclipse.debug.ui.ILaunchShortcut) IPath(org.eclipse.core.runtime.IPath) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) ICProject(org.eclipse.cdt.core.model.ICProject) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorPart(org.eclipse.ui.IEditorPart) IAdaptable(org.eclipse.core.runtime.IAdaptable) CDebugUtils(org.eclipse.cdt.debug.core.CDebugUtils) Shell(org.eclipse.swt.widgets.Shell) ProfileLaunchPlugin(org.eclipse.linuxtools.internal.profiling.launch.ProfileLaunchPlugin) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IBinary(org.eclipse.cdt.core.model.IBinary) CModelException(org.eclipse.cdt.core.model.CModelException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) List(java.util.List) Window(org.eclipse.jface.window.Window) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) IAdaptable(org.eclipse.core.runtime.IAdaptable) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IBinary(org.eclipse.cdt.core.model.IBinary) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 15 with ICProject

use of org.eclipse.cdt.core.model.ICProject in project linuxtools by eclipse.

the class RemoteProxyCMainTab method initializeProgramName.

/**
 * Set the program name attributes on the working copy based on the
 * ICElement.
 * @param cElement The element to get data from.
 * @param config The configuration to initialize
 */
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
    boolean renamed = false;
    if (!(cElement instanceof IBinary)) {
        cElement = cElement.getCProject();
    }
    if (cElement instanceof ICProject) {
        IProject project = cElement.getCProject().getProject();
        String name = project.getName();
        ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
        if (projDes != null) {
            String buildConfigName = projDes.getActiveConfiguration().getName();
            // Bug 234951
            name = NLS.bind(LaunchMessages.CMainTab_Configuration_name, name, buildConfigName);
        }
        name = getLaunchConfigurationDialog().generateName(name);
        config.rename(name);
        renamed = true;
    }
    IBinary binary = null;
    if (cElement instanceof ICProject) {
        IBinary[] bins = getBinaryFiles((ICProject) cElement);
        if (bins != null && bins.length == 1) {
            binary = bins[0];
        }
    } else if (cElement instanceof IBinary) {
        binary = (IBinary) cElement;
    }
    String projectDir = EMPTY_STRING;
    IProject project = null;
    try {
        project = ConfigUtils.getProject(ConfigUtils.getProjectName(config));
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
    }
    if (project != null) {
        try {
            projectDir = RemoteProxyManager.getInstance().getRemoteProjectLocation(project);
        } catch (CoreException e) {
            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
        }
    }
    String path = EMPTY_STRING;
    if (binary != null) {
        path = binary.getResource().getProjectRelativePath().toOSString();
        if (!renamed) {
            String name = binary.getElementName();
            int index = name.lastIndexOf('.');
            if (index > 0) {
                name = name.substring(0, index);
            }
            name = getLaunchConfigurationDialog().generateName(name);
            config.rename(name);
            renamed = true;
        }
    }
    config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectDir + IPath.SEPARATOR + path);
    if (!renamed) {
        String name = getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
        config.rename(name);
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject)

Aggregations

ICProject (org.eclipse.cdt.core.model.ICProject)18 CoreException (org.eclipse.core.runtime.CoreException)14 IProject (org.eclipse.core.resources.IProject)10 IResource (org.eclipse.core.resources.IResource)10 IBinary (org.eclipse.cdt.core.model.IBinary)7 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)6 IPath (org.eclipse.core.runtime.IPath)6 CCorePlugin (org.eclipse.cdt.core.CCorePlugin)5 ICProjectDescription (org.eclipse.cdt.core.settings.model.ICProjectDescription)5 IFile (org.eclipse.core.resources.IFile)5 IWorkspace (org.eclipse.core.resources.IWorkspace)5 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 CCProjectNature (org.eclipse.cdt.core.CCProjectNature)4 CProjectNature (org.eclipse.cdt.core.CProjectNature)4 CModelException (org.eclipse.cdt.core.model.CModelException)4 ICConfigExtensionReference (org.eclipse.cdt.core.settings.model.ICConfigExtensionReference)4 IProjectDescription (org.eclipse.core.resources.IProjectDescription)4 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)4 Path (org.eclipse.core.runtime.Path)4