Skip to content

Commit b026160

Browse files
wip
1 parent ded41d2 commit b026160

File tree

15 files changed

+1050
-0
lines changed

15 files changed

+1050
-0
lines changed

backend/commons/src/main/java/org/sonarsource/sonarlint/core/commons/storage/SonarLintDatabase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import java.sql.Connection;
2525
import java.sql.SQLException;
2626
import java.util.Set;
27+
import java.util.function.Consumer;
2728
import org.apache.commons.lang3.StringUtils;
2829
import org.flywaydb.core.Flyway;
2930
import org.h2.jdbcx.JdbcConnectionPool;
31+
import org.jooq.Configuration;
3032
import org.jooq.DSLContext;
3133
import org.jooq.SQLDialect;
3234
import org.jooq.impl.DSL;
@@ -96,6 +98,10 @@ public Connection getConnection() throws SQLException {
9698
return dataSource.getConnection();
9799
}
98100

101+
public void withTransaction(Consumer<Configuration> transaction) {
102+
dsl.transaction(transaction::accept);
103+
}
104+
99105
public void shutdown() {
100106
try {
101107
dataSource.dispose();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.nio.file.Path;
23+
import java.time.Instant;
24+
import java.util.Map;
25+
import java.util.UUID;
26+
import javax.annotation.Nullable;
27+
import org.sonarsource.sonarlint.core.commons.ImpactSeverity;
28+
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
29+
import org.sonarsource.sonarlint.core.commons.IssueStatus;
30+
import org.sonarsource.sonarlint.core.commons.RuleType;
31+
import org.sonarsource.sonarlint.core.commons.SoftwareQuality;
32+
33+
public record FileLevelServerIssue(UUID id, String serverKey, boolean resolved, @Nullable IssueStatus resolutionStatus,
34+
String ruleKey, String message, Path filePath, Instant creationDate,
35+
@Nullable IssueSeverity userSeverity, RuleType type,
36+
Map<SoftwareQuality, ImpactSeverity> impacts) implements ServerIssue {
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.nio.file.Path;
23+
import java.time.Instant;
24+
import java.util.Map;
25+
import java.util.UUID;
26+
import javax.annotation.Nullable;
27+
import org.sonarsource.sonarlint.core.commons.ImpactSeverity;
28+
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
29+
import org.sonarsource.sonarlint.core.commons.IssueStatus;
30+
import org.sonarsource.sonarlint.core.commons.RuleType;
31+
import org.sonarsource.sonarlint.core.commons.SoftwareQuality;
32+
33+
public record LineLevelServerIssue(UUID id, String serverKey, boolean resolved, @Nullable IssueStatus resolutionStatus,
34+
String ruleKey, String message, Path filePath, Instant creationDate,
35+
@Nullable IssueSeverity userSeverity, RuleType type,
36+
Map<SoftwareQuality, ImpactSeverity> impacts, int line, String lineHash) implements ServerIssue {
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.nio.file.Path;
23+
import java.time.Instant;
24+
import java.util.Map;
25+
import java.util.UUID;
26+
import javax.annotation.Nullable;
27+
import org.sonarsource.sonarlint.core.commons.ImpactSeverity;
28+
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
29+
import org.sonarsource.sonarlint.core.commons.IssueStatus;
30+
import org.sonarsource.sonarlint.core.commons.RuleType;
31+
import org.sonarsource.sonarlint.core.commons.SoftwareQuality;
32+
import org.sonarsource.sonarlint.core.commons.api.TextRangeWithHash;
33+
34+
public record RangeLevelServerIssue(UUID id, String serverKey, boolean resolved, @Nullable IssueStatus resolutionStatus,
35+
String ruleKey, String message, Path filePath, Instant creationDate,
36+
@Nullable IssueSeverity userSeverity, RuleType type,
37+
Map<SoftwareQuality, ImpactSeverity> impacts, TextRangeWithHash textRange) implements ServerIssue {
38+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.List;
25+
import java.util.UUID;
26+
import javax.annotation.Nullable;
27+
28+
public record ServerDependencyRisk(UUID key, Type type, Severity severity, SoftwareQuality quality,
29+
Status status, String packageName, String packageVersion, @Nullable String vulnerabilityId,
30+
@Nullable String cvssScore, List<Transition> transitions) {
31+
32+
public ServerDependencyRisk withStatus(Status newStatus) {
33+
var newTransitions = new ArrayList<>(Arrays.asList(Transition.values()));
34+
newTransitions.remove(Transition.FIXED);
35+
newTransitions.remove(newStatus.equals(Status.OPEN) ? Transition.REOPEN : Transition.valueOf(newStatus.name()));
36+
return new ServerDependencyRisk(key, type, severity, quality, newStatus, packageName, packageVersion,
37+
vulnerabilityId, cvssScore, newTransitions);
38+
}
39+
40+
public enum Severity {
41+
INFO, LOW, MEDIUM, HIGH, BLOCKER
42+
}
43+
44+
public enum SoftwareQuality {
45+
MAINTAINABILITY,
46+
RELIABILITY,
47+
SECURITY
48+
}
49+
50+
public enum Type {
51+
VULNERABILITY, PROHIBITED_LICENSE
52+
}
53+
54+
public enum Status {
55+
OPEN, CONFIRM, ACCEPT, SAFE, FIXED
56+
}
57+
58+
public enum Transition {
59+
CONFIRM, REOPEN, SAFE, FIXED, ACCEPT
60+
}
61+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
public interface ServerFinding {
23+
String getRuleKey();
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
public enum ServerFindingType {
23+
ISSUE,
24+
HOTSPOT,
25+
TAINT
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.nio.file.Path;
23+
import java.time.Instant;
24+
import java.util.UUID;
25+
import javax.annotation.Nullable;
26+
import org.sonarsource.sonarlint.core.commons.HotspotReviewStatus;
27+
import org.sonarsource.sonarlint.core.commons.VulnerabilityProbability;
28+
import org.sonarsource.sonarlint.core.commons.api.TextRange;
29+
30+
public record ServerHotspot(UUID id,
31+
String key,
32+
String ruleKey,
33+
String message,
34+
Path filePath,
35+
TextRange textRange,
36+
Instant creationDate,
37+
HotspotReviewStatus status,
38+
VulnerabilityProbability vulnerabilityProbability,
39+
@Nullable String assignee) {
40+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.nio.file.Path;
23+
import java.time.Instant;
24+
import java.util.Map;
25+
import java.util.UUID;
26+
import javax.annotation.Nullable;
27+
import org.sonarsource.sonarlint.core.commons.ImpactSeverity;
28+
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
29+
import org.sonarsource.sonarlint.core.commons.IssueStatus;
30+
import org.sonarsource.sonarlint.core.commons.RuleType;
31+
import org.sonarsource.sonarlint.core.commons.SoftwareQuality;
32+
33+
public sealed interface ServerIssue extends ServerFinding permits FileLevelServerIssue, LineLevelServerIssue, RangeLevelServerIssue {
34+
UUID id();
35+
String serverKey();
36+
boolean resolved();
37+
@Nullable IssueStatus resolutionStatus();
38+
String ruleKey();
39+
String message();
40+
Path filePath();
41+
Instant creationDate();
42+
@Nullable IssueSeverity userSeverity();
43+
RuleType type();
44+
Map<SoftwareQuality, ImpactSeverity> impacts();
45+
46+
@Override
47+
default String getRuleKey() {
48+
return ruleKey();
49+
}
50+
}
51+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* SonarLint Core - Commons
3+
* Copyright (C) 2016-2025 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 3 of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
package org.sonarsource.sonarlint.core.commons.storage.model;
21+
22+
import java.nio.file.Path;
23+
import java.time.Instant;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.UUID;
27+
import javax.annotation.Nullable;
28+
import org.sonarsource.sonarlint.core.commons.CleanCodeAttribute;
29+
import org.sonarsource.sonarlint.core.commons.ImpactSeverity;
30+
import org.sonarsource.sonarlint.core.commons.IssueSeverity;
31+
import org.sonarsource.sonarlint.core.commons.IssueStatus;
32+
import org.sonarsource.sonarlint.core.commons.RuleType;
33+
import org.sonarsource.sonarlint.core.commons.SoftwareQuality;
34+
import org.sonarsource.sonarlint.core.commons.api.TextRangeWithHash;
35+
36+
public record ServerTaintIssue(UUID id, String key, boolean resolved, @Nullable IssueStatus resolutionStatus, String ruleKey,
37+
String message, Path filePath, Instant creationDate, IssueSeverity severity, RuleType type,
38+
@Nullable TextRangeWithHash textRange, @Nullable String ruleDescriptionContextKey, @Nullable CleanCodeAttribute cleanCodeAttribute,
39+
Map<SoftwareQuality, ImpactSeverity> impacts, List<Flow> flows) implements ServerFinding {
40+
@Override
41+
public String getRuleKey() {
42+
return ruleKey;
43+
}
44+
45+
public record Flow(List<ServerIssueLocation> locations) { }
46+
47+
public record ServerIssueLocation(@Nullable Path filePath, @Nullable TextRangeWithHash textRange, @Nullable String message) { }
48+
}

0 commit comments

Comments
 (0)