use of org.eclipse.core.runtime.ICoreRunnable in project xtext-xtend by eclipse.
the class AbstractXtendRenameRefactoringTest method renameTo.
protected IFile renameTo(IFile file, String newFileName, IProgressMonitor monitor) throws OperationCanceledException, CoreException {
RenameResourceProcessor renameResourceProcessor = new RenameResourceProcessor(file);
renameResourceProcessor.setNewResourceName(newFileName);
RenameRefactoring renameRefactoring = new RenameRefactoring(renameResourceProcessor);
renameRefactoring.checkAllConditions(monitor);
Change change = renameRefactoring.createChange(monitor);
workspace.run(new ICoreRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
change.perform(monitor);
}
}, monitor);
IResource newFile = testHelper.getProject().findMember(new Path("src/" + newFileName));
assertTrue(newFile.exists());
assertTrue(newFile instanceof IFile);
return (IFile) newFile;
}
use of org.eclipse.core.runtime.ICoreRunnable 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);
}
use of org.eclipse.core.runtime.ICoreRunnable in project arduino-eclipse-plugin by Sloeber.
the class SloeberProject method setActiveConfigInRunnable.
/**
* This method set the active configuration This means the core and library
* folders of the project are updated. To avoid many update notifications this
* is done in a runnable with AVOID_UPDATE
*
* @param confDesc
* a writable configuration setting to be made active
*
* @return true if the configuration setting has been changed and needs tioo be
* saved
*/
private boolean setActiveConfigInRunnable(ICConfigurationDescription confDesc) {
class MyRunnable implements ICoreRunnable {
public boolean projConfMustBeSaved = false;
@Override
public void run(IProgressMonitor internalMonitor) throws CoreException {
projConfMustBeSaved = setActiveConfig(confDesc);
}
}
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
MyRunnable runnable = new MyRunnable();
try {
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, null);
} catch (Exception e) {
ICProjectDescription projDesc = confDesc.getProjectDescription();
String confDescName = confDesc.getName();
String projName = projDesc.getProject().getName();
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Setting config " + confDescName + " for project " + projName + " failed", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
e));
}
return runnable.projConfMustBeSaved;
}
use of org.eclipse.core.runtime.ICoreRunnable in project arduino-eclipse-plugin by Sloeber.
the class SloeberProject method convertToArduinoProject.
/**
* convenient method to create project
*
* @param proj1Name
* @param object
* @param proj1BoardDesc
* @param codeDesc
* @param proj1CompileDesc
* @param otherDesc
* @param nullProgressMonitor
* @return
*/
public static void convertToArduinoProject(IProject project, IProgressMonitor monitor) {
if (project == null) {
return;
}
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
ICoreRunnable runnable = new ICoreRunnable() {
@Override
public void run(IProgressMonitor internalMonitor) throws CoreException {
IndexerController.doNotIndex(project);
try {
// create a sloeber project
SloeberProject sloeberProject = new SloeberProject(project);
if (!sloeberProject.readConfigFromFiles()) {
String RELEASE = "Release";
sloeberProject.setBoardDescription(RELEASE, new BoardDescription(), false);
sloeberProject.setCompileDescription(RELEASE, new CompileDescription());
sloeberProject.setOtherDescription(RELEASE, new OtherDescription());
// we failed to read from disk so we set opourselfves some values
// faking the stuf is in memory
}
String configName = sloeberProject.myBoardDescriptions.keySet().iterator().next();
BoardDescription boardDescriptor = sloeberProject.getBoardDescription(configName, true);
// Add the arduino code folders
List<IPath> addToIncludePath = Helpers.addArduinoCodeToProject(project, boardDescriptor);
// make the eclipse project a cdt project
CCorePlugin.getDefault().createCProject(null, project, new NullProgressMonitor(), ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID);
// add the required natures
ManagedCProjectNature.addManagedNature(project, internalMonitor);
ManagedCProjectNature.addManagedBuilder(project, internalMonitor);
// $NON-NLS-1$
ManagedCProjectNature.addNature(project, "org.eclipse.cdt.core.ccnature", internalMonitor);
ManagedCProjectNature.addNature(project, 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(project);
IManagedProject newProject = ManagedBuildManager.createManagedProject(project, sloeberProjType);
ManagedBuildManager.setNewProjectVersion(project);
// 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());
// Make the first configuration the default
if (i == 0) {
defaultConfig = curConfig;
}
}
ManagedBuildManager.setDefaultConfiguration(project, defaultConfig);
Map<String, String> configs2 = new HashMap<>();
CCorePlugin cCorePlugin = CCorePlugin.getDefault();
ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(project);
ICConfigurationDescription activeConfig = prjCDesc.getActiveConfiguration();
for (String curConfigName : sloeberProject.myBoardDescriptions.keySet()) {
ICConfigurationDescription curConfigDesc = prjCDesc.getConfigurationByName(curConfigName);
if (curConfigDesc == null) {
String id = CDataUtil.genId(null);
curConfigDesc = prjCDesc.createConfiguration(id, curConfigName, activeConfig);
}
Helpers.addIncludeFolder(curConfigDesc, addToIncludePath, true);
String curConfigKey = getConfigKey(curConfigDesc);
sloeberProject.myEnvironmentVariables.put(curConfigKey, sloeberProject.getEnvVars(curConfigKey));
configs2.put(curConfigName, curConfigDesc.getId());
}
sloeberProject.myIsInMemory = true;
sloeberProject.createSloeberConfigFiles(prjCDesc);
SubMonitor refreshMonitor = SubMonitor.convert(internalMonitor, 3);
project.refreshLocal(IResource.DEPTH_INFINITE, refreshMonitor);
cCorePlugin.setProjectDescription(project, prjCDesc, true, null);
} catch (Exception e) {
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project conversion failed: ", // $NON-NLS-1$
e));
}
IndexerController.index(project);
}
};
try {
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
} catch (Exception e) {
// $NON-NLS-1$
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "Project conversion failed: ", e));
}
}
use of org.eclipse.core.runtime.ICoreRunnable in project arduino-eclipse-plugin by Sloeber.
the class resourceChangeListener method resourceChanged.
@Override
public void resourceChanged(IResourceChangeEvent event) {
// we are only interested in POST_CHANGE events
if (event.getType() != IResourceChangeEvent.POST_CHANGE)
return;
final ArrayList<IProject> changedSloeberCfgFiles = new ArrayList<>();
IResourceDelta rootDelta = event.getDelta();
for (IResourceDelta projectDelta : rootDelta.getAffectedChildren()) {
IResourceDelta sloeberCfgDelta = projectDelta.findMember(new Path(SLOEBER_CFG));
if (sloeberCfgDelta != null) {
if (sloeberCfgDelta.getKind() != IResourceDelta.REMOVED) {
IProject iProject = sloeberCfgDelta.getResource().getProject();
// stop the indexer
IndexerController.doNotIndex(iProject);
// log to process later
changedSloeberCfgFiles.add(iProject);
}
} else {
// it is not a new type Sloeber project check whether it is an old type Sloeber
// project
// $NON-NLS-1$
IResourceDelta cProjectDelta = projectDelta.findMember(new Path(".cproject"));
if (cProjectDelta != null)
if (projectDelta.getFlags() == IResourceDelta.OPEN) {
// as it is a open of a cdt project assume it is a sloeber project.
// We will find out later if not
IProject iProject = cProjectDelta.getResource().getProject();
SloeberProject curSloeberProject = SloeberProject.getSloeberProject(iProject);
if (curSloeberProject != null) {
if (!curSloeberProject.isInMemory()) {
// stop the indexer
IndexerController.doNotIndex(iProject);
curSloeberProject.configure();
}
}
// log to process later
// changedSloeberCfgFiles.add(iProject);
}
}
}
// no sloeber.cfg files have been modified
if (changedSloeberCfgFiles.size() == 0)
return;
Job job = new // $NON-NLS-1$
Job(// $NON-NLS-1$
"Sloeber.cfg modification processor") {
@Override
protected IStatus run(IProgressMonitor monitor) {
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
ICoreRunnable runnable = new ICoreRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
for (IProject curProject : changedSloeberCfgFiles) {
if (curProject.isOpen()) {
SloeberProject curSloeberProject = SloeberProject.getSloeberProject(curProject);
if (curSloeberProject == null) {
// this is not a sloeber project;
// make it one?
} else {
// no use updating the cfg if it wasn't read already
if (curSloeberProject.isInMemory()) {
curSloeberProject.sloeberCfgChanged();
}
}
}
IndexerController.index(curProject);
}
}
};
try {
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, null);
} catch (Exception e) {
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), "failed to start sloeber.cfg updater", // $NON-NLS-1$
e));
}
return Status.OK_STATUS;
}
};
job.setPriority(Job.SHORT);
job.schedule();
}
Aggregations