Skip to content

Commit

Permalink
Merge branch 'hotfix/V2.24.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gquerret committed Dec 9, 2023
2 parents c9422b8 + a26a810 commit ceae6e1
Show file tree
Hide file tree
Showing 33 changed files with 408 additions and 51 deletions.
16 changes: 8 additions & 8 deletions coverage-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.rssw</groupId>
<artifactId>sonar-openedge</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</parent>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>coverage-report</artifactId>
Expand All @@ -24,37 +24,37 @@
<dependency>
<groupId>eu.rssw.openedge.rcode</groupId>
<artifactId>rcode-reader</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.sonar.openedge</groupId>
<artifactId>sonar-openedge-plugin</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>proparse</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>profiler-parser</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>database-parser</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>listing-parser</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.checks</groupId>
<artifactId>openedge-checks</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion database-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.rssw</groupId>
<artifactId>sonar-openedge</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</parent>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>database-parser</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion listing-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.rssw</groupId>
<artifactId>sonar-openedge</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</parent>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>listing-parser</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions openedge-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.rssw</groupId>
<artifactId>sonar-openedge</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</parent>
<groupId>eu.rssw.openedge.checks</groupId>
<artifactId>openedge-checks</artifactId>
Expand Down Expand Up @@ -59,12 +59,12 @@
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>database-parser</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>proparse</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
Expand Down
8 changes: 4 additions & 4 deletions openedge-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>eu.rssw</groupId>
<artifactId>sonar-openedge</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</parent>
<groupId>eu.rssw.sonar.openedge</groupId>
<artifactId>sonar-openedge-plugin</artifactId>
Expand Down Expand Up @@ -64,17 +64,17 @@
<dependency>
<groupId>eu.rssw.openedge.checks</groupId>
<artifactId>openedge-checks</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>listing-parser</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>profiler-parser</artifactId>
<version>2.24.0</version>
<version>2.24.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sonar.plugins.openedge.sensor.OpenEdgeDBColorizer;
import org.sonar.plugins.openedge.sensor.OpenEdgeDBRulesSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeDBSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeDependenciesSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeProparseSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeSensor;
import org.sonar.plugins.openedge.sensor.OpenEdgeWarningsSensor;
Expand All @@ -67,8 +68,8 @@ public void define(Context context) {
}

// Sensors
context.addExtensions(OpenEdgeSensor.class, OpenEdgeDBSensor.class, OpenEdgeWarningsSensor.class,
OpenEdgeProparseSensor.class, OpenEdgeDBRulesSensor.class);
context.addExtensions(OpenEdgeSensor.class, OpenEdgeDBSensor.class, OpenEdgeDependenciesSensor.class,
OpenEdgeWarningsSensor.class, OpenEdgeProparseSensor.class, OpenEdgeDBRulesSensor.class);

// Decorators
context.addExtensions(CommonMetricsDecorator.class, CommonDBMetricsDecorator.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
Expand All @@ -35,6 +36,8 @@
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarProduct;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Status;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.config.Configuration;
Expand Down Expand Up @@ -75,6 +78,7 @@ public class OpenEdgeComponents {
private boolean initialized = false;
private String analytics = "";
private int ncLoc = 0;
private Map<String, List<String>> includeDependencies = new HashMap<>();

public OpenEdgeComponents() {
this(null, null, null, null);
Expand Down Expand Up @@ -179,6 +183,29 @@ public int getNcLoc() {
return ncLoc;
}

public void addIncludeDependency(String uri, List<String> dependencies) {
includeDependencies.put(uri, dependencies);
}

public List<String> getIncludeDependencies(String uri) {
return includeDependencies.getOrDefault(uri, Arrays.asList());
}

/**
* Return true if main file or one of its include files has changed
*/
public boolean isChanged(SensorContext context, InputFile file) {
if ((file.status() == Status.ADDED) || (file.status() == Status.CHANGED))
return true;
for (String str : getIncludeDependencies(file.uri().toString())) {
InputFile target = context.fileSystem().inputFile(context.fileSystem().predicates().hasRelativePath(str));
if ((target != null) && ((target.status() == Status.ADDED) || (target.status() == Status.CHANGED)))
return true;
}

return false;
}

public Map<ActiveRule, OpenEdgeProparseCheck> getProparseRules() {
return Collections.unmodifiableMap(ppChecksMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarEdition;
import org.sonar.api.SonarProduct;
import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.config.Configuration;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.utils.Version;
import org.sonar.plugins.openedge.api.Constants;
import org.sonar.plugins.openedge.api.objects.DatabaseWrapper;
import org.sonarsource.api.sonarlint.SonarLintSide;
Expand Down Expand Up @@ -499,6 +501,14 @@ public ITypeInfo getRCode2(String fileName) {
return null;
}

public Path getPctIncludeFile(InputFile file) {
String relPath = getRelativePathToSourceDirs(file);
if (Strings.isNullOrEmpty(relPath))
return null;
else
return getPathFromPctDirs(relPath + ".inc");
}

public File getWarningsFile(InputFile file) {
String relPath = getRelativePathToSourceDirs(file);
if (Strings.isNullOrEmpty(relPath))
Expand Down Expand Up @@ -530,6 +540,15 @@ public File getListingFile(InputFile file) {
return rtbCompatibility ? getFileFromRtbListDir(relPath, ".l") : getFileFromPctDirs(relPath);
}

public boolean skipUnchangedFiles() {
if (runtime.getProduct() != SonarProduct.SONARQUBE)
return false;
boolean developerOrMore = ((runtime.getEdition() == SonarEdition.DEVELOPER)
|| (runtime.getEdition() == SonarEdition.ENTERPRISE) || (runtime.getEdition() == SonarEdition.DATACENTER));
boolean version99OrMore = runtime.getApiVersion().isGreaterThanOrEqual(Version.create(9, 9));
return developerOrMore && version99OrMore && config.get("sonar.pullrequest.branch").isPresent();
}

private File getFileFromRtbListDir(String fileName, String extension) {
Path path = Paths.get(fileName);
int lastPeriodPos = path.getFileName().toString().lastIndexOf('.');
Expand All @@ -549,6 +568,16 @@ private File getFileFromRtbListDir(String fileName, String extension) {
return null;
}

private Path getPathFromPctDirs(String relPath) {
for (Path dir : pctDirs) {
Path path = dir.resolve(relPath);
if (java.nio.file.Files.exists(path))
return path;
}

return null;
}

private File getFileFromPctDirs(String relPath) {
for (Path dir : pctDirs) {
Path path = dir.resolve(relPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@
import org.sonar.plugins.openedge.api.Constants;
import org.sonar.plugins.openedge.foundation.IRefactorSessionEnv;
import org.sonar.plugins.openedge.foundation.InputFileUtils;
import org.sonar.plugins.openedge.foundation.OpenEdgeComponents;
import org.sonar.plugins.openedge.foundation.OpenEdgeSettings;

public class OpenEdgeCPDSensor implements Sensor {
private static final Logger LOG = LoggerFactory.getLogger(OpenEdgeCPDSensor.class);

// IoC
private final OpenEdgeSettings settings;
private final OpenEdgeComponents components;

public OpenEdgeCPDSensor(OpenEdgeSettings settings) {
public OpenEdgeCPDSensor(OpenEdgeSettings settings, OpenEdgeComponents components) {
this.settings = settings;
this.components = components;
}

@Override
Expand All @@ -66,10 +69,16 @@ public void execute(SensorContext context) {
return;
settings.init();
IRefactorSessionEnv sessions = settings.getProparseSessions();
boolean skipUnchangedFiles = settings.skipUnchangedFiles();

for (InputFile file : context.fileSystem().inputFiles(
context.fileSystem().predicates().hasLanguage(Constants.LANGUAGE_KEY))) {
LOG.debug("CPD on {}", file);
if (skipUnchangedFiles && !components.isChanged(context, file)) {
LOG.debug("Skip {} as it is unchanged in this branch", file);
continue;
}

IProparseEnvironment session = sessions.getSession(file.toString());
try {
processFile(context, session, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.SonarProduct;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextPointer;
import org.sonar.api.batch.sensor.Sensor;
Expand All @@ -41,16 +42,20 @@
import org.sonar.plugins.openedge.api.Constants;
import org.sonar.plugins.openedge.foundation.IRefactorSessionEnv;
import org.sonar.plugins.openedge.foundation.InputFileUtils;
import org.sonar.plugins.openedge.foundation.OpenEdgeComponents;
import org.sonar.plugins.openedge.foundation.OpenEdgeSettings;

@DependsUpon(value = {"PctDependencies"})
public class OpenEdgeCodeColorizer implements Sensor {
private static final Logger LOG = LoggerFactory.getLogger(OpenEdgeCodeColorizer.class);

// IoC
private final OpenEdgeSettings settings;

public OpenEdgeCodeColorizer(OpenEdgeSettings settings) {
private final OpenEdgeComponents components;

public OpenEdgeCodeColorizer(OpenEdgeSettings settings, OpenEdgeComponents components) {
this.settings = settings;
this.components = components;
}

@Override
Expand All @@ -64,9 +69,13 @@ public void execute(SensorContext context) {
return;
settings.init();
IRefactorSessionEnv sessions = settings.getProparseSessions();

boolean skipUnchangedFiles = settings.skipUnchangedFiles();
for (InputFile file : context.fileSystem().inputFiles(
context.fileSystem().predicates().hasLanguage(Constants.LANGUAGE_KEY))) {
if (skipUnchangedFiles && !components.isChanged(context, file)) {
LOG.debug("Skip {} as it is unchanged in this branch", file);
continue;
}
LOG.debug("Syntax highlight on {}", file);
IProparseEnvironment session = sessions.getSession(file.toString());
try {
Expand Down
Loading

0 comments on commit ceae6e1

Please sign in to comment.