use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.
the class XtextBuilder method doBuild.
/**
* @param toBeBuilt
* the URIs that will be processed in this build run.
* @param removedProjects
* the projects that are no longer considered by XtextBuilders but are yet to be removed from the index.
* @param monitor
* the progress monitor for the build.
* @param type
* indicates the kind of build that is running.
*
* @since 2.18
*/
protected void doBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor, BuildType type) throws CoreException {
buildLogger.log("Building " + getProject().getName());
// return early if there's nothing to do.
// we reuse the isEmpty() implementation from BuildData assuming that it doesnT access the ResourceSet which is still null
// and would be expensive to create.
boolean indexingOnly = type == BuildType.RECOVERY;
if (new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects).isEmpty())
return;
SubMonitor progress = SubMonitor.convert(monitor, 2);
ResourceSet resourceSet = getResourceSetProvider().get(getProject());
resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects);
ImmutableList<Delta> deltas = builderState.update(buildData, progress.split(1));
if (participant != null && !indexingOnly) {
SourceLevelURICache sourceLevelURIs = buildData.getSourceLevelURICache();
Set<URI> sources = sourceLevelURIs.getSources();
participant.build(new BuildContext(this, resourceSet, deltas, sources, type), progress.split(1));
try {
getProject().getWorkspace().checkpoint(false);
} catch (NoClassDefFoundError e) {
// guard against broken Eclipse installations / bogus project configuration
log.error(e.getMessage(), e);
}
} else {
progress.worked(1);
}
resourceSet.eSetDeliver(false);
for (Resource resource : resourceSet.getResources()) {
resource.eSetDeliver(false);
}
resourceSet.getResources().clear();
resourceSet.eAdapters().clear();
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.
the class GenericResourceDescriptionManagerTest method testCreateDeltaAndIsAffected.
@Test
public void testCreateDeltaAndIsAffected() {
GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager();
EClass eClass = EcoreFactory.eINSTANCE.createEClass();
eClass.setName("Test");
eClass.getESuperTypes().add(EcorePackage.Literals.EPACKAGE);
Resource resource = new XMIResourceImpl(URI.createFileURI("test.ecore"));
resource.getContents().add(eClass);
EPackage copyOfEPackage = EcoreUtil.copy(EcorePackage.eINSTANCE);
Resource ecoreResource = new XMIResourceImpl(URI.createURI(copyOfEPackage.getNsURI()));
ecoreResource.getContents().add(copyOfEPackage);
IResourceDescription oldDescription = new CopiedResourceDescription(manager.getResourceDescription(ecoreResource));
oldDescription.getExportedObjects();
copyOfEPackage.setName("ecore_new");
IResourceDescription newDescription = manager.getResourceDescription(ecoreResource);
Delta delta = manager.createDelta(oldDescription, newDescription);
assertTrue(delta.haveEObjectDescriptionsChanged());
IResourceDescription referrerDescription = manager.getResourceDescription(resource);
assertTrue(manager.isAffected(delta, referrerDescription));
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.
the class ResourceDescriptionUpdaterTest method affectedResourcesContain.
private synchronized boolean affectedResourcesContain(final String projectName, final String fileName) {
try {
final URI expected = URI.createPlatformResourceURI(projectName + "/" + SRC_FOLDER + "/" + fileName + F_EXT, true);
Iterables.find(getContext().getDeltas(), new Predicate<IResourceDescription.Delta>() {
@Override
public boolean apply(Delta actual) {
return expected.equals(actual.getUri());
}
});
return true;
} catch (NoSuchElementException e) {
return false;
}
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.
the class JavaProjectBasedBuilderParticipant method build.
@Override
public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
final IProject builtProject = context.getBuiltProject();
IJavaProject javaProject = JavaCore.create(builtProject);
if (!javaProject.exists())
return;
final IFolder srcGenFolder = getSrcGenFolder(builtProject);
if (!srcGenFolder.exists())
return;
if (!isValidOutputFolder(javaProject, srcGenFolder))
return;
for (IResourceDescription.Delta delta : context.getDeltas()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
final Set<String> oldFiles = newHashSet();
if (sourceTargetMap.containsKey(delta.getUri())) {
oldFiles.addAll(sourceTargetMap.get(delta.getUri()));
}
final Set<String> newFiles = newHashSet();
IFileSystemAccess fileSystemAccess = getConfiguredFileSystemAccess(srcGenFolder, new IAcceptor<String>() {
@Override
public void accept(String fileName) {
oldFiles.remove(fileName);
newFiles.add(fileName);
}
});
if (delta.getNew() == null) {
handleDeletion(delta, context, fileSystemAccess);
} else {
try {
handleChangedContents(delta, context, fileSystemAccess);
} catch (Exception e) {
logger.error("Error during compilation of '" + delta.getUri() + "'.", e);
}
}
for (String removeFile : oldFiles) {
fileSystemAccess.deleteFile(removeFile);
}
if (!newFiles.isEmpty()) {
sourceTargetMap.put(delta.getUri(), newFiles);
}
}
}
use of org.eclipse.xtext.resource.IResourceDescription.Delta in project xtext-eclipse by eclipse.
the class XtextBuilder method doBuild.
/**
* @param monitor the progress monitor to use for reporting progress to the user. It is the caller's responsibility
* to call done() on the given monitor. Accepts null, indicating that no progress should be
* reported and that the operation cannot be cancelled.
*/
protected void doBuild(ToBeBuilt toBeBuilt, IProgressMonitor monitor, BuildType type) throws CoreException {
buildLogger.log("Building " + getProject().getName());
// return early if there's nothing to do.
// we reuse the isEmpty() impl from BuildData assuming that it doesnT access the ResourceSet which is still null
// and would be expensive to create.
boolean indexingOnly = type == BuildType.RECOVERY;
if (new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly).isEmpty())
return;
SubMonitor progress = SubMonitor.convert(monitor, 2);
ResourceSet resourceSet = getResourceSetProvider().get(getProject());
resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData, indexingOnly);
ImmutableList<Delta> deltas = builderState.update(buildData, progress.newChild(1));
if (participant != null && !indexingOnly) {
SourceLevelURICache sourceLevelURIs = buildData.getSourceLevelURICache();
Set<URI> sources = sourceLevelURIs.getSources();
participant.build(new BuildContext(this, resourceSet, deltas, sources, type), progress.newChild(1));
try {
getProject().getWorkspace().checkpoint(false);
} catch (NoClassDefFoundError e) {
// guard against broken Eclipse installations / bogus project configuration
log.error(e.getMessage(), e);
}
} else {
progress.worked(1);
}
resourceSet.eSetDeliver(false);
for (Resource resource : resourceSet.getResources()) {
resource.eSetDeliver(false);
}
resourceSet.getResources().clear();
resourceSet.eAdapters().clear();
}
Aggregations