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 "";
}
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);
}
}
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];
}
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);
}
}
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);
}
}
Aggregations