Skip to content

Commit

Permalink
Raise min supported Gradle version to 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
remal committed May 9, 2024
1 parent 636ec49 commit 8828bb6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 26 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
java-runtime.min-version = 8
gradle-api.min-version = 7.0
gradle-api.min-version = 7.1

#disable-compilation = true
#java-runtime.version = 8
#gradle-api.version = 8.2-rc-2
#java-runtime.version = 11
#gradle-api.version = 7.0.2
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static name.remal.gradle_plugins.toolkit.ObjectUtils.isNotEmpty;
import static name.remal.gradle_plugins.toolkit.PathUtils.normalizePath;
import static name.remal.gradle_plugins.toolkit.PredicateUtils.not;
import static name.remal.gradle_plugins.toolkit.TaskUtils.doBeforeTaskExecution;
import static name.remal.gradle_plugins.toolkit.xml.DomUtils.streamNodeList;
import static name.remal.gradle_plugins.toolkit.xml.XmlUtils.parseXml;

Expand Down Expand Up @@ -174,15 +175,17 @@ public static void init(BaseSonarLint task) {
}
}));

task.onlyIf(__ -> {
doBeforeTaskExecution(task, __ -> {
task.getEnabledRules().set(canonizeRules(task.getEnabledRules().getOrNull()));
task.getDisabledRules().set(canonizeRules(task.getDisabledRules().getOrNull()));
task.getIncludedLanguages().set(canonizeLanguages(task.getIncludedLanguages().getOrNull()));
task.getExcludedLanguages().set(canonizeLanguages(task.getExcludedLanguages().getOrNull()));
task.getSonarProperties().set(canonizeProperties(task.getSonarProperties().getOrNull()));
task.getRulesProperties().set(canonizeRulesProperties(task.getRulesProperties().getOrNull()));
});

return true;
doBeforeTaskExecution(task, __ -> {
getNodeJsInfo(task);
});
}

Expand Down Expand Up @@ -255,7 +258,7 @@ public static void execute(BaseSonarLint task, SonarLintCommand command) {
}
});

val nodeJsInfo = getNodeJsInfo(task);
val nodeJsInfo = getNodeJsInfoAndLogIssues(task);
val additionalExcludedLanguages = new ArrayList<String>();
if (task instanceof SourceTask && nodeJsInfo == null) {
additionalExcludedLanguages.addAll(LANGUAGES_REQUIRING_NODEJS);
Expand Down Expand Up @@ -384,13 +387,8 @@ private static void addRuleByPathIgnore(
}

@Nullable
private static NodeJsFound getNodeJsInfo(BaseSonarLint task) {
val hasFilesRequiringNodeJs = defaultTrue(task.get$internals().getHasFilesRequiringNodeJs().getOrNull());
if (!hasFilesRequiringNodeJs) {
return null;
}

val nodeJsInfo = task.get$internals().getNodeJsInfo().getOrNull();
private static NodeJsFound getNodeJsInfoAndLogIssues(BaseSonarLint task) {
val nodeJsInfo = getNodeJsInfo(task);
if (nodeJsInfo != null) {
return nodeJsInfo;
}
Expand Down Expand Up @@ -455,6 +453,16 @@ private static NodeJsFound getNodeJsInfo(BaseSonarLint task) {
return null;
}

@Nullable
private static NodeJsFound getNodeJsInfo(BaseSonarLint task) {
val hasFilesRequiringNodeJs = defaultTrue(task.get$internals().getHasFilesRequiringNodeJs().getOrNull());
if (!hasFilesRequiringNodeJs) {
return null;
}

return task.get$internals().getNodeJsInfo().getOrNull();
}

private static boolean isIgnoreFailures(BaseSonarLint task) {
if (task instanceof VerificationTask) {
return ((VerificationTask) task).getIgnoreFailures();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nullable;
import javax.inject.Inject;
import lombok.CustomLog;
import lombok.Getter;
import lombok.val;
import name.remal.gradle_plugins.sonarlint.internal.NodeJsFound;
Expand All @@ -43,6 +44,7 @@
import org.gradle.workers.WorkerExecutor;

@Getter
@CustomLog
abstract class BaseSonarLintInternals {

@Internal
Expand Down Expand Up @@ -89,10 +91,12 @@ public BaseSonarLintInternals(BaseSonarLint task) {
getHasFilesRequiringNodeJs().set(getProviders().provider(() ->
calculateHasFilesRequiringNodeJs(task)
));
getHasFilesRequiringNodeJs().finalizeValueOnRead();

getNodeJsInfo().set(getProviders().provider(() ->
calculateNodeJsInfo(task, rootDir, getObjects())
));
getNodeJsInfo().finalizeValueOnRead();
}

private static boolean calculateHasFilesRequiringNodeJs(BaseSonarLint task) {
Expand Down Expand Up @@ -185,8 +189,7 @@ private static NodeJsFound calculateNodeJsInfo(

val nodeJsDetectors = objects.newInstance(NodeJsDetectors.class, rootDir);
task.getLogger().info("Detecting Node.js of any supported version");
val nodeJsInfo = nodeJsDetectors.detectDefaultNodeJsExecutable();

val nodeJsInfo = nodeJsDetectors.detectNodeJsExecutable();
if (nodeJsInfo != null) {
task.getLogger().info("Detected Node.js: {}", nodeJsInfo);
return nodeJsInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
abstract class NodeJsDetector implements Comparable<NodeJsDetector> {

@Nullable
public abstract NodeJsFound detectDefaultNodeJsExecutable();
public abstract NodeJsFound detectNodeJsExecutable();


protected final Logger logger = Logging.getLogger(unwrapGeneratedSubclass(getClass()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ abstract class NodeJsDetectorOfficial extends NodeJsDetector
@Override
@SneakyThrows
@SuppressWarnings("java:S3776")
public NodeJsFound detectDefaultNodeJsExecutable() {
public NodeJsFound detectNodeJsExecutable() {
addNodeJsRepository();

File rootDir = this.rootDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class NodeJsDetectorOnPath extends NodeJsDetector {

@Nullable
@Override
public NodeJsFound detectDefaultNodeJsExecutable() {
public NodeJsFound detectNodeJsExecutable() {
if (isInTest()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class NodeJsDetectorPublished extends NodeJsDetector {
@Nullable
@Override
@SneakyThrows
public NodeJsFound detectDefaultNodeJsExecutable() {
public NodeJsFound detectNodeJsExecutable() {
val os = osDetector.getDetectedOs().os;
val arch = osDetector.getDetectedOs().arch;
val isPublished = PUBLISHED_NODEJS_OS.getOrDefault(os, emptySet()).contains(arch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.Nullable;
import javax.inject.Inject;
import lombok.CustomLog;
Expand All @@ -25,22 +27,34 @@
@CustomLog
abstract class NodeJsDetectors {


private final File rootDir;


private static final Lock DETECT_LOCK = new ReentrantLock();

private final List<NodeJsDetector> detectors = loadNodeJsDetectors();

@Nullable
public NodeJsFound detectDefaultNodeJsExecutable() {
synchronized (NodeJsDetectors.class) {
return detectors.stream()
.map(NodeJsDetector::detectDefaultNodeJsExecutable)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
public NodeJsFound detectNodeJsExecutable() {
DETECT_LOCK.lock();
try {
return detectNodeJsExecutableImpl();

} finally {
DETECT_LOCK.unlock();
}
}

@Nullable
private NodeJsFound detectNodeJsExecutableImpl() {
return detectors.stream()
.map(NodeJsDetector::detectNodeJsExecutable)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}


@SuppressWarnings("java:S3864")
private List<NodeJsDetector> loadNodeJsDetectors() {
Expand Down

0 comments on commit 8828bb6

Please sign in to comment.