Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Extract storage in a seprate module (wip)
  • Loading branch information
henryju committed Nov 30, 2021
1 parent a3a2ebe commit 6d7d4f5
Show file tree
Hide file tree
Showing 49 changed files with 1,281 additions and 699 deletions.
77 changes: 1 addition & 76 deletions core/pom.xml
Expand Up @@ -33,15 +33,10 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonarlint-plugin-api</artifactId>
<artifactId>sonarlint-local-storage</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonarlint-slf4j-sonar-log</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-ws</artifactId>
Expand Down Expand Up @@ -80,11 +75,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.15</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-markdown</artifactId>
Expand All @@ -97,27 +87,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-classloader</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${sonarqube.version}</version>
</dependency>
<!-- For RulesDefinitionXmlLoader, can be removed after upgrading sonar-plugin-api to 9.0 (SONAR-14882) -->
<dependency>
<groupId>com.fasterxml.staxmate</groupId>
<artifactId>staxmate</artifactId>
<version>2.4.0</version>
</dependency>

<!-- unit tests -->
<dependency>
Expand Down Expand Up @@ -200,55 +169,11 @@
<filtering>false</filtering>
</resource>
</resources>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-slf4j-sonar-log</id>
<phase>process-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>sonarlint-slf4j-sonar-log</artifactId>
<version>${project.version}</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.outputDirectory}/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<stripVersion>true</stripVersion>
</configuration>
</execution>
<execution>
<id>copy-sonar-plugins</id>
<phase>generate-test-resources</phase>
Expand Down
Expand Up @@ -62,17 +62,6 @@ enum State {

void removeStateListener(StateListener listener);

/**
* Return global rule details (not specific to any quality profile).
*/
ConnectedRuleDetails getRuleDetails(String ruleKey);

/**
* Return rule details in the context of a given project (severity may have been overriden in the quality profile).
* @param projectKey if null, the default QP will be considered
*/
ConnectedRuleDetails getActiveRuleDetails(String ruleKey, @Nullable String projectKey);

/**
* Trigger an analysis
*/
Expand Down
Expand Up @@ -117,7 +117,6 @@ protected void doBeforeStart() {
IssueDownloader.class,
IssueApi.class,
SourceApi.class,
IssueStoreFactory.class,
ProjectStoragePaths.class,
StorageReader.class,
ProjectStorageStatusReader.class);
Expand Down
Expand Up @@ -26,11 +26,11 @@
import java.util.stream.Collectors;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonarsource.sonarlint.core.analysis.api.Language;
import org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration;
import org.sonarsource.sonarlint.core.client.api.connected.SonarAnalyzer;
import org.sonarsource.sonarlint.core.container.connected.validate.PluginVersionChecker;
import org.sonarsource.sonarlint.core.container.model.DefaultSonarAnalyzer;
import org.sonarsource.sonarlint.core.plugin.common.Language;
import org.sonarsource.sonarlint.core.serverapi.ServerApiHelper;
import org.sonarsource.sonarlint.core.util.VersionUtils;

Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -24,8 +24,11 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.CheckForNull;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonarsource.sonarlint.core.proto.Sonarlint;
import org.sonarsource.sonarlint.core.storage.issuetracking.IssueStore;

public class PersistentIssueTrackerCache implements IssueTrackerCache {

Expand Down Expand Up @@ -59,7 +62,7 @@ protected boolean removeEldestEntry(Map.Entry<String, Collection<Trackable>> eld
String key = eldest.getKey();
try {
LOGGER.debug("Persisting issues for " + key);
store.save(key, eldest.getValue());
store.save(key, eldest.getValue(), PersistentIssueTrackerCache::transform);
} catch (IOException e) {
throw new IllegalStateException(String.format("Error persisting issues for %s", key), e);
}
Expand Down Expand Up @@ -93,7 +96,7 @@ public synchronized Collection<Trackable> getCurrentTrackables(String file) {
}

try {
Collection<Trackable> storedTrackables = store.read(file);
Collection<Trackable> storedTrackables = store.read(file, PersistentIssueTrackerCache::transform);
if (storedTrackables != null) {
return Collections.unmodifiableCollection(storedTrackables);
}
Expand Down Expand Up @@ -122,7 +125,7 @@ public synchronized void flushAll() {
LOGGER.debug("Persisting all issues");
cache.forEach((path, trackables) -> {
try {
store.save(path, trackables);
store.save(path, trackables, PersistentIssueTrackerCache::transform);
} catch (IOException e) {
throw new IllegalStateException("Failed to flush cache", e);
}
Expand All @@ -133,4 +136,33 @@ public synchronized void flushAll() {
public synchronized void shutdown() {
flushAll();
}

private static Trackable transform(Sonarlint.Issues.Issue issue) {
return new ProtobufIssueTrackable(issue);
}

@CheckForNull
private static Sonarlint.Issues.Issue transform(Trackable localIssue) {
Sonarlint.Issues.Issue.Builder builder = Sonarlint.Issues.Issue.newBuilder()
.setRuleKey(localIssue.getRuleKey())
.setMessage(localIssue.getMessage())
.setResolved(localIssue.isResolved());

if (localIssue.getAssignee() != null) {
builder.setAssignee(localIssue.getAssignee());
}
if (localIssue.getCreationDate() != null) {
builder.setCreationDate(localIssue.getCreationDate());
}
if (localIssue.getLineHash() != null) {
builder.setChecksum(localIssue.getLineHash());
}
if (localIssue.getServerIssueKey() != null) {
builder.setServerIssueKey(localIssue.getServerIssueKey());
}
if (localIssue.getLine() != null) {
builder.setLine(localIssue.getLine());
}
return builder.build();
}
}

0 comments on commit 6d7d4f5

Please sign in to comment.