Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
better version of needsRebuild feature
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
  • Loading branch information
cdietrich committed Mar 7, 2022
1 parent 98df118 commit 8700323
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean isSourceLevelURI(URI uri) {

@Override
public void needRebuild() {
builder.needRebuild();
builder.retriggerBuilderChainOnProject();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package org.eclipse.xtext.builder.impl;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
Expand All @@ -20,6 +22,7 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
Expand All @@ -31,6 +34,7 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.eclipse.xtext.builder.IXtextBuilderParticipant.BuildType;
Expand All @@ -48,6 +52,7 @@
import org.eclipse.xtext.ui.shared.contribution.ISharedStateContributionRegistry;
import org.eclipse.xtext.util.internal.Stopwatches;
import org.eclipse.xtext.util.internal.Stopwatches.StoppedTask;
import org.osgi.framework.Version;

import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -506,12 +511,12 @@ protected void doBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgre
// 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())
if (new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly, this::retriggerBuilderChainOnProject, 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);
BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData, indexingOnly, this::retriggerBuilderChainOnProject, removedProjects);
ImmutableList<Delta> deltas = builderState.update(buildData, progress.split(1));
if (participant != null && !indexingOnly) {
SourceLevelURICache sourceLevelURIs = buildData.getSourceLevelURICache();
Expand Down Expand Up @@ -626,6 +631,8 @@ protected void clean(IProgressMonitor monitor) throws CoreException {
private static Boolean mustCallDeprecatedDoClean = null;
@Deprecated
private static boolean wasDeprecationWarningLoggedForClean = false;

private Method buildInputChangedMethod;

protected void addInfosFromTaskAndClean(ToBeBuilt toBeBuilt, Task task, IProgressMonitor monitor) throws CoreException {
addInfosFromTask(task, toBeBuilt);
Expand Down Expand Up @@ -663,7 +670,7 @@ protected void pollQueuedBuildData() {
}
}
if(needRebuild) {
needRebuild();
retriggerBuilderChainOnProject();
}
}

Expand Down Expand Up @@ -755,5 +762,38 @@ public ISchedulingRule getRule(int kind, Map<String, String> args) {
default: throw new IllegalArgumentException();
}
}

/**
* @since 2.27
*/
public void retriggerBuilderChainOnProject() {
if (isCoreResourceGreaterOrEqual(new Version(3,17,0))) {
try {
if (buildInputChangedMethod == null) {
buildInputChangedMethod = getClass().getMethod("buildInputChanged");
}
buildInputChangedMethod.invoke(this);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
log.error("something went wrong in retriggerBuilderChainOnProject", e);
needRebuild();
}
} else {
needRebuild();
}

}

private static boolean isCoreResourceGreaterOrEqual(Version version) {
Version installed = ResourcesPlugin.getPlugin().getBundle().getVersion();
int minMajor = version.getMajor();
int minMinor = version.getMinor();
if (installed.getMajor() < minMajor) {
return false;
}
if (installed.getMajor() == minMajor && installed.getMinor() < minMinor) {
return false;
}
return true;
}

}

0 comments on commit 8700323

Please sign in to comment.