Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore scope inheritance for configs not present in the project. #6936

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.gradle.api.GradleBaseProject;
Expand Down Expand Up @@ -276,6 +278,7 @@ DependencyResult processDependencies(NbGradleProject nbgp) {
}

List<Dependency> rootDeps = new ArrayList<>();
LOG.log(Level.FINE, "** Computing dependencies for project {0}", project);
for (Scope s : allScopes) {
String cfgName = toGradleConfigName(s);
if (cfgName == null) {
Expand Down Expand Up @@ -415,7 +418,18 @@ Dependency createDependency(GradleDependency dep, List<Dependency> children) {
return ret;
}

private int level = 0;

List<Dependency> processLevel(GradleConfiguration c, GradleDependency d, Set<GradleDependency> allParents) {
level++;
try {
return processLevel0(c, d, allParents);
} finally {
level--;
}
}

List<Dependency> processLevel0(GradleConfiguration c, GradleDependency d, Set<GradleDependency> allParents) {
if (counter > DEPENDENCIES_MAX_COUNT) {
LOG.log(Level.WARNING, "Potential dependency cycle for {0} (parents: {1}), abort!", new Object[] { d, allParents });
return Collections.emptyList();
Expand All @@ -425,6 +439,14 @@ List<Dependency> processLevel(GradleConfiguration c, GradleDependency d, Set<Gra
if (deps == null) {
return Collections.emptyList();
}
if (LOG.isLoggable(Level.FINER)) {
StringBuilder indent = new StringBuilder();
for (int i = 0; i < level; i++) {
indent.append(" ");
}
String chIds = deps.stream().sequential().filter(Objects::nonNull).map(GradleDependency::getId).collect(Collectors.joining(", "));
LOG.log(Level.FINER, "Children: {0} {1} -> {2}", new Object[] { indent, d.getId(), chIds });
}
List<Dependency> res = new ArrayList<>();
if (!allParents.add(d)) {
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.netbeans.api.project.Project;
import org.netbeans.modules.gradle.api.GradleBaseProject;
Expand Down Expand Up @@ -118,10 +119,10 @@ public GradleScopes build() {

extendsFrom.getOrDefault(gs.name(), Collections.emptyList()).
stream().
map(scopes::get).forEach(data.extendsFrom::add);
map(scopes::get).filter(Objects::nonNull).forEach(data.extendsFrom::add);
inheritedInto.getOrDefault(gs.name(), Collections.emptyList()).
stream().
map(scopes::get).forEach(data.inheritedInto::add);
map(scopes::get).filter(Objects::nonNull).forEach(data.inheritedInto::add);
}

return new GradleScopes(project, scopes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1914,23 +1914,27 @@ private void runDiagnosticTasks(String uri, boolean force) {
new Exception("no NbCodeLanguageClient!").printStackTrace();
}

diagnosticTasks.computeIfAbsent(uri, u -> {
return BACKGROUND_TASKS.create(() -> {
Document originalDoc = server.getOpenedDocuments().getDocument(uri);
long originalVersion = documentVersion(originalDoc);
List<Diagnostic> errorDiags = computeDiags(u, -1, ErrorProvider.Kind.ERRORS, originalVersion);
if (documentVersion(originalDoc) == originalVersion) {
publishDiagnostics(uri, errorDiags);
BACKGROUND_TASKS.create(() -> {
List<Diagnostic> hintDiags = computeDiags(u, -1, ErrorProvider.Kind.HINTS, originalVersion);
Document doc = server.getOpenedDocuments().getDocument(uri);
if (documentVersion(doc) == originalVersion) {
publishDiagnostics(uri, hintDiags);
}
}).schedule(DELAY);
}
});
}).schedule(DELAY);
// sync needed - this can be called also from reporterControl, from other that LSP request thread. The factory function just cretaes a stopped
// Task that is executed later.
synchronized (diagnosticTasks) {
diagnosticTasks.computeIfAbsent(uri, u -> {
return BACKGROUND_TASKS.create(() -> {
Document originalDoc = server.getOpenedDocuments().getDocument(uri);
long originalVersion = documentVersion(originalDoc);
List<Diagnostic> errorDiags = computeDiags(u, -1, ErrorProvider.Kind.ERRORS, originalVersion);
if (documentVersion(originalDoc) == originalVersion) {
publishDiagnostics(uri, errorDiags);
BACKGROUND_TASKS.create(() -> {
List<Diagnostic> hintDiags = computeDiags(u, -1, ErrorProvider.Kind.HINTS, originalVersion);
Document doc = server.getOpenedDocuments().getDocument(uri);
if (documentVersion(doc) == originalVersion) {
publishDiagnostics(uri, hintDiags);
}
}).schedule(DELAY);
}
});
}).schedule(DELAY);
}
}

CompletableFuture<List<Diagnostic>> computeDiagnostics(String uri, EnumSet<ErrorProvider.Kind> types) {
Expand Down
Loading