org.eclipse.xtext.builder.impl.ToBeBuilt Java Examples

The following examples show how to use org.eclipse.xtext.builder.impl.ToBeBuilt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OutdatedPackageJsonQueue.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Return the next task that contains all the enqueued projects.
 *
 * @return the normalized task that has all the stuff that is to be done.
 */
public Task exhaust() {
	Set<String> projectNames = new LinkedHashSet<>();
	ToBeBuilt toBeBuilt = new ToBeBuilt();
	Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
	boolean forcedIndexSync = false;
	Task next = internalQueue.poll();
	while (next != null) {
		Set<URI> nextToBeUpdated = next.toBeBuilt.getToBeUpdated();
		if (next.forcedIndexSync) {
			forcedIndexSync = true;
		}
		if (nextToBeUpdated != null && !nextToBeUpdated.isEmpty()) {
			projectNames.addAll(next.projectNames);
			toBeUpdated.addAll(nextToBeUpdated);
		}
		next = internalQueue.poll();
	}
	return new Task(ImmutableSet.copyOf(projectNames), toBeBuilt, forcedIndexSync);
}
 
Example #2
Source File: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	if (storage instanceof IFile && JavaCore.isJavaLikeFileName(storage.getName())) {
		IJavaElement element = JavaCore.create(((IFile)storage).getParent());
		String fileName = storage.getName();
		String typeName = fileName.substring(0, fileName.lastIndexOf('.'));
		if (element instanceof IPackageFragmentRoot) {
			queueJavaChange(typeName);
			return true;
		} else if (element instanceof IPackageFragment) {
			IPackageFragment packageFragment = (IPackageFragment) element;
			queueJavaChange(packageFragment.getElementName() + "." + typeName);
			return true;
		}
	}
	return false;
}
 
Example #3
Source File: N4JSBuildTypeTrackingBuilder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void doBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor, BuildType type)
		throws CoreException, OperationCanceledException {
	// if we built it, we don't have to treat it as deleted first
	toBeBuilt.getToBeDeleted().removeAll(toBeBuilt.getToBeUpdated());

	OutdatedPackageJsonQueue.Task task = outdatedPackageJsonQueue.exhaust();
	try {
		if (!task.isEmpty()) {
			externalIndexSynchronizer.checkAndClearIndex(monitor);
		}
		toBeBuilt.getToBeDeleted().addAll(task.getToBeBuilt().getToBeDeleted());
		toBeBuilt.getToBeUpdated().addAll(task.getToBeBuilt().getToBeUpdated());
		RaceDetectionHelper.log("%s", toBeBuilt);
		runWithBuildType(monitor, type, (m) -> superDoBuild(toBeBuilt, removedProjects, m, type));
	} catch (Exception e) {
		task.reschedule();
		throw e;
	}
}
 
Example #4
Source File: N4JSBuildTypeTrackingBuilder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private void superDoBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor,
		BuildType type) {
	// 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;
	QueuedBuildData queuedBuildData = getQueuedBuildData();
	if (isNoop(toBeBuilt, queuedBuildData, indexingOnly))
		return;

	SubMonitor progress = toBuilderMonitor(monitor, 1);

	IProject project = getProject();
	ResourceSet resourceSet = createResourceSet(project);
	BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData,
			indexingOnly, this::needRebuild, removedProjects);
	getBuilderState().update(buildData, progress.split(1, SubMonitor.SUPPRESS_NONE));
	if (!indexingOnly) {
		try {
			project.getWorkspace().checkpoint(false);
		} catch (NoClassDefFoundError e) { // guard against broken Eclipse installations / bogus project
											// configuration
			throw new RuntimeException(e);
		}
	}
}
 
Example #5
Source File: RebuildingXtextBuilder.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void clean(final IProgressMonitor monitor) throws CoreException {
  SubMonitor progress = SubMonitor.convert(monitor, 2);
  try {
    ToBeBuilt toBeBuilt = getToBeBuiltComputer().removeProject(getProject(), progress.newChild(1));
    doClean(toBeBuilt, progress.newChild(1));
  } finally {
    if (monitor != null) {
      monitor.done();
    }
  }
}
 
Example #6
Source File: RebuildingXtextBuilder.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void fullBuild(final IProgressMonitor monitor, final boolean isRecoveryBuild) throws CoreException {
  SubMonitor progress = SubMonitor.convert(monitor, 2);

  IProject project = getProject();
  ToBeBuilt toBeBuilt = isRecoveryBuild ? getToBeBuiltComputer().updateProjectNewResourcesOnly(project, progress.newChild(1))
      : getToBeBuiltComputer().updateProject(project, progress.newChild(1));
  doBuild(toBeBuilt, progress.newChild(1), isRecoveryBuild ? BuildType.RECOVERY : BuildType.FULL);
}
 
Example #7
Source File: OutdatedPackageJsonQueue.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add the tasks again to the top of the queue.
 */
public void reschedule() {
	Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
	if (toBeUpdated != null && !toBeUpdated.isEmpty()) {
		ToBeBuilt scheduleMe = new ToBeBuilt();
		scheduleMe.getToBeUpdated().addAll(toBeUpdated);
		insert(projectNames, scheduleMe, forcedIndexSync);
	}
}
 
Example #8
Source File: ClosedProjectQueue.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the next task that contains all the enqueued projects.
 *
 * @return the normalized task that has all the stuff that is to be done.
 */
Task exhaust() {
	Set<String> projectNames = new LinkedHashSet<>();
	ToBeBuilt toBeBuilt = new ToBeBuilt();
	Task next = internalQueue.poll();
	while (next != null) {
		projectNames.addAll(next.projectNames);
		toBeBuilt.getToBeDeleted().addAll(next.toBeBuilt.getToBeDeleted());
		next = internalQueue.poll();
	}
	return new Task(ImmutableSet.copyOf(projectNames), toBeBuilt);
}
 
Example #9
Source File: ProjectStateChangeListener.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void resourceChanged(final IResourceChangeEvent event) {
	IWorkspace workspace = getWorkspace();
	if (workspace != null) {
		if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
			try {
				final Set<IProject> affectedProjects = Sets.newLinkedHashSet();
				event.getDelta().accept(projectCollector(affectedProjects));
				if (!affectedProjects.isEmpty()) {
					ToBeBuilt toBeBuilt = new ToBeBuilt();
					Set<URI> toBeUpdated = toBeBuilt.getToBeUpdated();
					Set<String> projectNames = new LinkedHashSet<>();
					for (IProject project : affectedProjects) {
						IFile file = project.getFile(N4JSGlobals.PACKAGE_JSON);
						if (file.exists()) {
							projectNames.add(project.getName());
							toBeUpdated.add(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
						}

					}
					packageJsonQueue.enqueue(projectNames, toBeBuilt, false);
					syncIndexJob.schedule();
				}
			} catch (CoreException e) {
				LOGGER.error(e.getMessage(), e);
			}
		}
	}
	super.resourceChanged(event);
}
 
Example #10
Source File: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException {
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	if (progress.isCanceled()) {
		throw new OperationCanceledException();
	}
	if (!project.isAccessible())
		return;
	IJavaProject javaProject = JavaCore.create(project);
	if (javaProject.exists()) {
		IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
		progress.setWorkRemaining(roots.length);
		final Map<String, Long> updated = Maps.newHashMap();
		ProjectOrder orderedProjects = workspace.computeProjectOrder(workspace.getRoot().getProjects());
		for (final IPackageFragmentRoot root : roots) {
			if (progress.isCanceled())
				throw new OperationCanceledException();
			if (shouldHandle(root) && !isBuiltByUpstream(root, project, orderedProjects.projects)) {
				Map<URI, IStorage> rootData = jdtUriMapperExtension.getAllEntries(root);
				for (Map.Entry<URI, IStorage> e : rootData.entrySet())
					if (uriValidator.canBuild(e.getKey(), e.getValue())) {
						toBeBuilt.getToBeDeleted().add(e.getKey());
						toBeBuilt.getToBeUpdated().add(e.getKey());
					}
			}
			progress.worked(1);
		}
		synchronized (modificationStampCache) {
			modificationStampCache.projectToModificationStamp.putAll(updated);
		}
	}
}
 
Example #11
Source File: N4JSBuildTypeTrackingBuilder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void doClean(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor)
		throws CoreException {

	IProject project = getProject();
	projectsStateHelper.clearProjectCache(project);
	runWithBuildType(monitor, BuildType.CLEAN, (m) -> super.doClean(toBeBuilt, removedProjects, m));
}
 
Example #12
Source File: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean updateStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	// nothing to do
	// structural java changes will be queued in a fine grained fashion by the JavaChangeQueueFiller
	return false;
}
 
Example #13
Source File: IgnoreMavenTargetFolderContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException {
	// nothing to do
}
 
Example #14
Source File: IgnoreMavenTargetFolderContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	return false;
}
 
Example #15
Source File: IgnoreMavenTargetFolderContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean updateStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	return false;
}
 
Example #16
Source File: JdtToBeBuiltComputer.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) {
	if (toBeBuilt.getToBeDeleted().isEmpty() && toBeBuilt.getToBeUpdated().isEmpty())
		return;
	modificationStampCache.projectToModificationStamp.clear();
}
 
Example #17
Source File: N4JSToBeBuiltComputer.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException {
	// nothing to do per project, storages are processed individually
}
 
Example #18
Source File: IgnoreBuildDirContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) {
	// nothing to do
}
 
Example #19
Source File: IgnoreBuildDirContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void updateProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) throws CoreException {
	// nothing to do
}
 
Example #20
Source File: IgnoreBuildDirContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	return false;
}
 
Example #21
Source File: IgnoreBuildDirContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean updateStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	return false;
}
 
Example #22
Source File: RebuildingXtextBuilder.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Like the super implementation, except the build is not triggered if
 * both toBeDeleted and toBeUpdated are empty. {@inheritDoc}
 */
@SuppressWarnings("nls")
@Override
protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor, final BuildType type) throws CoreException {
  if (toBeBuilt.getToBeDeleted().size() != 0 || toBeBuilt.getToBeUpdated().size() != 0) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Starting " + type.name() + " build:" + "\ndeleted(" + toBeBuilt.getToBeDeleted().size() + ")=" + toBeBuilt.getToBeDeleted().toString()
          + "\nupdated(" + toBeBuilt.getToBeUpdated().size() + ")=" + toBeBuilt.getToBeUpdated().toString());
    }

    SubMonitor progress = SubMonitor.convert(monitor, 1 + 1 + 1); // build + participant + rebuild

    ResourceSet resourceSet = getResourceSetProvider().get(getProject());
    resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
    if (resourceSet instanceof ResourceSetImpl && ((ResourceSetImpl) resourceSet).getURIResourceMap() == null) {
      ((ResourceSetImpl) resourceSet).setURIResourceMap(Maps.<URI, Resource> newHashMap());
    }
    BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData);
    ImmutableList<Delta> deltas = builderState.update(buildData, progress.newChild(1));
    if (participant != null) {
      final BuildContext buildContext = new BuildContext(this, resourceSet, deltas, type);
      // remember the current workspace tree
      final ElementTree oldTree = ((Workspace) ResourcesPlugin.getWorkspace()).getElementTree();
      oldTree.immutable();
      participant.build(buildContext, progress.newChild(1));
      if (buildContext.isRebuildRequired() && rebuilds++ <= 2) {
        final ElementTree newTree = ((Workspace) ResourcesPlugin.getWorkspace()).getElementTree();
        newTree.immutable();
        final ResourceDelta generatedDelta = ResourceDeltaFactory.computeDelta((Workspace) ResourcesPlugin.getWorkspace(), oldTree, newTree, getProject().getFullPath(), -1);
        // rebuild the generated delta
        ResourcesPlugin.getWorkspace().checkpoint(false);
        incrementalBuild(generatedDelta, progress.newChild(1));
      }
    } else {
      progress.worked(2);
    }
    resourceSet.getResources().clear();
    resourceSet.eAdapters().clear();
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Build done.");
    }
  } else if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Ignoring empty " + type.name() + " build.");
  }
}
 
Example #23
Source File: IgnoreMavenTargetFolderContribution.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void removeProject(ToBeBuilt toBeBuilt, IProject project, IProgressMonitor monitor) {
	// nothing to do
}
 
Example #24
Source File: Bug349445Test.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testUpdate() {
	testMe.update(new BuildData(null, null, new ToBeBuilt(), new QueuedBuildData(null)), null);
	assertEquals(1, loadCalled);
}
 
Example #25
Source File: ClosedProjectQueue.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private Task(Set<String> projectNames, ToBeBuilt toBeBuilt) {
	this.projectNames = projectNames;
	this.toBeBuilt = toBeBuilt;
}
 
Example #26
Source File: N4JSBuildTypeTrackingBuilder.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private boolean isNoop(ToBeBuilt toBeBuilt, QueuedBuildData queuedBuildData,
		boolean indexingOnly) {
	return new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild)
			.isEmpty();
}
 
Example #27
Source File: ProjectStateChangeListener.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Enqueue an index sync
 */
public void forceIndexSync() {
	packageJsonQueue.enqueue(Collections.singleton("npm index sync"), new ToBeBuilt(), true);
}
 
Example #28
Source File: OutdatedPackageJsonQueue.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the files that need to be build.
 */
public ToBeBuilt getToBeBuilt() {
	return toBeBuilt;
}
 
Example #29
Source File: OutdatedPackageJsonQueue.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructor.
 */
protected Task(ImmutableSet<String> projectNames, ToBeBuilt toBeBuilt, boolean forcedIndexSync) {
	this.projectNames = projectNames;
	this.toBeBuilt = toBeBuilt;
	this.forcedIndexSync = forcedIndexSync;
}
 
Example #30
Source File: N4JSToBeBuiltComputer.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean removeStorage(ToBeBuilt toBeBuilt, IStorage storage, IProgressMonitor monitor) {
	// nothing to remove
	return false;
}