Skip to content

Commit

Permalink
Merge branch 'release/V2.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
gquerret committed Oct 15, 2020
2 parents 514081a + 5fd6cc9 commit 3d39a26
Show file tree
Hide file tree
Showing 48 changed files with 1,932 additions and 854 deletions.
2 changes: 1 addition & 1 deletion database-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>database-parser</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>

<name>OpenEdge database definition lexer and parser</name>
<description>OpenEdge dump files parser</description>
Expand Down
2 changes: 1 addition & 1 deletion listing-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>listing-parser</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>

<name>OpenEdge listing so-called parser</name>
<description>OpenEdge listing files parser</description>
Expand Down
6 changes: 3 additions & 3 deletions openedge-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>eu.rssw.openedge.checks</groupId>
<artifactId>openedge-checks</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>

<name>OpenEdge checks</name>
<description>OpenEdge checks</description>
Expand Down Expand Up @@ -54,12 +54,12 @@
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>database-parser</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>proparse</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* OpenEdge plugin for SonarQube
* Copyright (c) 2015-2019 Riverside Software
* contact AT riverside DASH software DOT fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.openedge.api;

import org.prorefactor.proparse.antlr4.ProparseListener;

public interface TreeParserRegistration {
void register(Registrar registrar);

interface Registrar {
public void registerTreeParser(Class<? extends ProparseListener> listener);
}
}
8 changes: 4 additions & 4 deletions openedge-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>eu.rssw.sonar.openedge</groupId>
<artifactId>sonar-openedge-plugin</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
<packaging>sonar-plugin</packaging>

<name>OpenEdge plugin for SonarQube</name>
Expand Down Expand Up @@ -59,17 +59,17 @@
<dependency>
<groupId>eu.rssw.openedge.checks</groupId>
<artifactId>openedge-checks</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>listing-parser</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>profiler-parser</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ClumsySyntax extends OpenEdgeProparseCheck {

@Override
public void execute(InputFile file, ParseUnit unit) {
if (unit.getRootScope().isInterface() || unit.getRootScope().isAbstractClass()) {
if (unit.isInterface() || unit.isAbstractClass()) {
for (JPNode node : unit.getTopNode().queryStateHead(ABLNodeType.METHOD)) {
JPNode lastChild = node.getLastDescendant();
if (lastChild.getNodeType() == ABLNodeType.LEXCOLON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.prorefactor.proparse.antlr4.ProparseListener;
import org.sonar.api.SonarProduct;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.sensor.SensorContext;
Expand All @@ -48,6 +50,7 @@
import org.sonar.plugins.openedge.api.LicenseRegistration;
import org.sonar.plugins.openedge.api.LicenseRegistration.License;
import org.sonar.plugins.openedge.api.LicenseRegistration.LicenseType;
import org.sonar.plugins.openedge.api.TreeParserRegistration;
import org.sonar.plugins.openedge.api.checks.OpenEdgeCheck;
import org.sonar.plugins.openedge.api.checks.OpenEdgeCheck.CheckType;
import org.sonar.plugins.openedge.api.checks.OpenEdgeDumpFileCheck;
Expand All @@ -68,28 +71,59 @@ public class OpenEdgeComponents {
private final Server server;
private final CheckRegistrar checkRegistrar = new CheckRegistrar();
private final LicenseRegistrar licenseRegistrar = new LicenseRegistrar();
private final TreeParserRegistrar parserRegistrar = new TreeParserRegistrar();

private boolean initialized = false;

public OpenEdgeComponents() {
this(null, null, null, null);
}

public OpenEdgeComponents(Server server) {
this(server, null, null);
this(server, null, null, null);
}

public OpenEdgeComponents(CheckRegistration[] checkRegistrars) {
this(null, checkRegistrars, null, null);
}

public OpenEdgeComponents(Server server, CheckRegistration[] checkRegistrars) {
this(server, checkRegistrars, null);
this(server, checkRegistrars, null, null);
}

public OpenEdgeComponents(LicenseRegistration[] licRegistrars) {
this(null, null, licRegistrars, null);
}

public OpenEdgeComponents(Server server, LicenseRegistration[] licRegistrars) {
this(server, null, licRegistrars);
this(server, null, licRegistrars, null);
}

public OpenEdgeComponents(CheckRegistration[] checkRegistrars, LicenseRegistration[] licRegistrars) {
this(null, checkRegistrars, licRegistrars, null);
}

public OpenEdgeComponents(Server server, CheckRegistration[] checkRegistrars, LicenseRegistration[] licRegistrars) {
this(server, checkRegistrars, licRegistrars, null);
}

public OpenEdgeComponents(CheckRegistration[] checkRegistrars, LicenseRegistration[] licRegistrars,
TreeParserRegistration[] tpRegistrars) {
this(null, checkRegistrars, licRegistrars, tpRegistrars);
}

public OpenEdgeComponents(Server server, CheckRegistration[] checkRegistrars, LicenseRegistration[] licRegistrars,
TreeParserRegistration[] tpRegistrars) {
this.server = server;
if (checkRegistrars != null) {
registerChecks(checkRegistrars);
}
if (licRegistrars != null) {
registerLicences(licRegistrars);
}
if (tpRegistrars != null) {
registerTreeParser(tpRegistrars);
}
}

private void registerChecks(CheckRegistration[] registrations) {
Expand All @@ -104,6 +138,16 @@ private void registerLicences(LicenseRegistration[] registrations) {
}
}

private void registerTreeParser(TreeParserRegistration[] registrations) {
for (TreeParserRegistration registration : registrations) {
registration.register(parserRegistrar);
}
}

public Iterable<Class<? extends ProparseListener>> getProparseListeners() {
return Collections.unmodifiableList(parserRegistrar.allListeners);
}

public Collection<License> getLicenses() {
return licenseRegistrar.getLicenses();
}
Expand Down Expand Up @@ -148,15 +192,16 @@ public void initializeChecks(SensorContext context) {
initialized = true;
}

public Map<ActiveRule, OpenEdgeProparseCheck> getProparseRules() {
public Map<ActiveRule, OpenEdgeProparseCheck> getProparseRules() {
return Collections.unmodifiableMap(ppChecksMap);
}

public Map<ActiveRule, OpenEdgeDumpFileCheck> getDumpFileRules() {
public Map<ActiveRule, OpenEdgeDumpFileCheck> getDumpFileRules() {
return Collections.unmodifiableMap(dfChecksMap);
}

private OpenEdgeCheck<?> initializeCheck(SensorContext context, ActiveRule rule, SonarProduct product, String permId) {
private OpenEdgeCheck<?> initializeCheck(SensorContext context, ActiveRule rule, SonarProduct product,
String permId) {
RuleKey ruleKey = rule.ruleKey();
// AFAIK, no way to be sure if a rule is based on a template or not
String clsName = rule.templateRuleKey() == null ? ruleKey.rule() : rule.templateRuleKey();
Expand Down Expand Up @@ -240,6 +285,9 @@ private static Field getField(Object check, String key) {
}

public String getServerId() {
if (server == null)
return "";

String str = server.getId();
int dashIndex = str.indexOf('-');

Expand All @@ -256,8 +304,8 @@ public void registerLicense(String permanentId, String customerName, String salt
repoName, type, signature, expirationDate);
}

public void registerLicense(String permanentId, SonarProduct product, String customerName, String salt, String repoName,
LicenseRegistration.LicenseType type, byte[] signature, long expirationDate) {
public void registerLicense(String permanentId, SonarProduct product, String customerName, String salt,
String repoName, LicenseRegistration.LicenseType type, byte[] signature, long expirationDate) {
if (Strings.isNullOrEmpty(repoName))
return;
LOG.debug("Found {} license - Permanent ID '{}' - Customer '{}' - Repository '{}' - Expiration date {}",
Expand Down Expand Up @@ -294,11 +342,14 @@ private License getLicense(SonarProduct product, String permId, String repoName)
if ((permId == null) || (repoName == null))
return null;
for (License lic : licenses) {
if (((lic.getType() == LicenseType.COMMERCIAL) || (lic.getType() == LicenseType.PARTNER)) && (lic.getProduct() == product) && repoName.equals(lic.getRepositoryName()) && permId.equals(lic.getPermanentId()))
if (((lic.getType() == LicenseType.COMMERCIAL) || (lic.getType() == LicenseType.PARTNER))
&& (lic.getProduct() == product) && repoName.equals(lic.getRepositoryName())
&& permId.equals(lic.getPermanentId()))
return lic;
}
for (License lic : licenses) {
if ((lic.getType() == LicenseType.EVALUATION) && (lic.getProduct() == product) && repoName.equals(lic.getRepositoryName()))
if ((lic.getType() == LicenseType.EVALUATION) && (lic.getProduct() == product)
&& repoName.equals(lic.getRepositoryName()))
return lic;
}
return null;
Expand Down Expand Up @@ -327,4 +378,14 @@ public Class<? extends OpenEdgeCheck<?>> getCheck(String className) {
return null;
}
}

private static class TreeParserRegistrar implements TreeParserRegistration.Registrar {
private final List<Class<? extends ProparseListener>> allListeners = new ArrayList<>();

@Override
public void registerTreeParser(Class<? extends ProparseListener> listener) {
allListeners.add(listener);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ public void define(Context context) {
// Manually created rule for proparse errors
NewRule proparseRule = repository.createRule(PROPARSE_ERROR_RULEKEY).setName("Proparse error").setSeverity(
Priority.INFO.name());
proparseRule.setDebtRemediationFunction(proparseRule.debtRemediationFunctions().constantPerIssue("3h"));
proparseRule.setType(RuleType.BUG);
proparseRule.setHtmlDescription(getClass().getResource(String.format(HTML_DOC_PATH, Constants.LANGUAGE_KEY,
Constants.STD_REPOSITORY_KEY, proparseRule.key())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public class OpenEdgeSettings {
private RefactorSession defaultSession;
private String oePluginVersion;

public OpenEdgeSettings(Configuration config, FileSystem fileSystem, SonarRuntime runtime) {
this(config, fileSystem, runtime, null);
}

public OpenEdgeSettings(Configuration config, FileSystem fileSystem, SonarRuntime runtime, Server server) {
this.config = config;
this.fileSystem = fileSystem;
Expand All @@ -124,7 +128,7 @@ public final void init() {

oePluginVersion = readPluginVersion(this.getClass().getClassLoader(), "sonar-openedge.txt");
LOG.info("OpenEdge plugin version: {}", oePluginVersion);
LOG.info("Loading OpenEdge settings for server ID '{}'", server.getId());
LOG.info("Loading OpenEdge settings for server ID '{}'", server == null ? "" : server.getId());
initializeDirectories(config, fileSystem);
initializePropathDlc(config);
initializeDefaultPropath(config, fileSystem);
Expand Down Expand Up @@ -204,7 +208,7 @@ private final List<File> readPropath(FileSystem fileSystem, String propValue) {
List<File> retVal = new ArrayList<>();
LOG.info("Using PROPATH : {}", propValue);
for (String str : Splitter.on(',').trimResults().split(propValue)) {
File entry = fileSystem.resolvePath(str);
File entry = resolvePath(str);
LOG.debug("Adding {} to PROPATH", entry.getAbsolutePath());
retVal.add(entry);
}
Expand Down Expand Up @@ -384,7 +388,7 @@ private void parseLibrary(File lib) {
}

public File getSonarLintXrefDir() {
return fileSystem.resolvePath(config.get(Constants.SLINT_XREF).orElse(""));
return resolvePath(config.get(Constants.SLINT_XREF).orElse(""));
}

public File getPctDir() {
Expand Down Expand Up @@ -597,6 +601,8 @@ public String getOpenEdgePluginVersion() {
}

public String getServerId() {
if (server == null)
return "";
String str = server.getId();
int dashIndex = str.indexOf('-');

Expand Down Expand Up @@ -731,8 +737,8 @@ private Collection<IDatabase> readSchemaFromProp1(FileSystem fileSystem, String
str = str.substring(0, colonPos);
}

LOG.debug("Parsing {} with alias {}", fileSystem.resolvePath(str), dbName);
File dfFile = fileSystem.resolvePath(str);
LOG.debug("Parsing {} with alias {}", resolvePath(str), dbName);
File dfFile = resolvePath(str);
File serFile = new File(fileSystem.baseDir(),
".sonarlint/" + str.replace(':', '_').replace('\\', '_').replace('/', '_') + ".bin");
serFile.getParentFile().mkdir();
Expand All @@ -747,7 +753,7 @@ private Collection<IDatabase> readSchemaFromProp1(FileSystem fileSystem, String
}
} else {
try {
desc = DumpFileUtils.getDatabaseDescription(fileSystem.resolvePath(str), dbName);
desc = DumpFileUtils.getDatabaseDescription(resolvePath(str), dbName);
} catch (IOException caught) {
// Interrupt SonarLint analysis as this is the only way to have a notification for invalid DF file
// By default, analysis log is not visible
Expand Down Expand Up @@ -831,6 +837,19 @@ public String readPluginVersion(ClassLoader cl, String file) {
return retVal;
}

private File resolvePath(String path) {
File file = new File(path);
if (file.isAbsolute())
return file;

try {
file = new File(fileSystem.baseDir(), path).getCanonicalFile();
} catch (IOException e) {
throw new IllegalArgumentException("Unable to resolve path '" + path + "'", e);
}
return file;
}

private class RCodeInjectorService {
AtomicInteger numClasses = new AtomicInteger(0);
AtomicInteger numMethods = new AtomicInteger(0);
Expand Down
Loading

0 comments on commit 3d39a26

Please sign in to comment.