Skip to content

Commit

Permalink
Merge branch 'release/V2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gquerret committed Apr 30, 2019
2 parents 33253bd + baccb03 commit fe2ceae
Show file tree
Hide file tree
Showing 44 changed files with 431 additions and 134 deletions.
11 changes: 10 additions & 1 deletion BaseTokenTypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1232,4 +1232,13 @@ OPTIONSFILE=1234
SINGLERUN=1235
SINGLETON=1236
PROCESSARCHITECTURE=1237
Last_Token_Number=1238
NONSERIALIZABLE=1238
CHECKED=1239
SENSITIVE=1240
HIDDEN=1241
VISIBLE=1242
CHARSET=1243
SCREENVALUE=1244
XOR=1245
DYNAMICPROPERTY=1246
Last_Token_Number=1247
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenEdge plugin for SonarQube
# CABL - Code Analyzer for ABL

The OpenEdge plugin for SonarQube enables analysis of OpenEdge procedural and object-oriented code, and reports:
CABL enables analysis of OpenEdge procedural and object-oriented code on the SonarQube platform, by reporting:
* Metrics (lines of code, comment density, complexity, shared objects, ...)
* Issues found in the source code and DF files, such as performance killers, usage of deprecated keywords, ...
* Code coverage from unit tests
Expand Down
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.3.2</version>
<version>2.4.0</version>

<name>OpenEdge database definition lexer and parser</name>
<description>OpenEdge dump files parser</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public Void visitIndexField(IndexFieldContext ctx) {
}
if (table != null) {
IndexField idxFld = new IndexField(table.getField(ctx.field.getText()),
"ascending".equalsIgnoreCase(ctx.order.getText()));
((ctx.order == null) || "ascending".equalsIgnoreCase(ctx.order.getText())));
indexes.peek().addField(idxFld);
} else {
// Log error ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ public void testSerialize() throws IOException {
assertEquals(db2.getTable("Order").getIndex("CustOrder").getFields().size(), 2);
}

@Test
public void testAscIndex() throws IOException {
// Delete triggers on table
DatabaseDescription db = DumpFileUtils.getDatabaseDescription(new File("src/test/resources/ascIndex.df"));
assertNotNull(db.getTable("Tab1"));
assertNotNull(db.getTable("Tab1").getIndex("Idx1"));
assertNotNull(db.getTable("Tab1").getIndex("Idx1").getFields());
assertEquals(db.getTable("Tab1").getIndex("Idx1").getFields().size(), 3);
assertTrue(db.getTable("Tab1").getIndex("Idx1").getFields().get(0).isAscending());
assertTrue(db.getTable("Tab1").getIndex("Idx1").getFields().get(1).isAscending());
assertFalse(db.getTable("Tab1").getIndex("Idx1").getFields().get(2).isAscending());
}
}
23 changes: 23 additions & 0 deletions database-parser/src/test/resources/ascIndex.df
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ADD TABLE "Tab1"
DESCRIPTION "XYZ"
FROZEN
DUMP-NAME "Tab1"

ADD FIELD "Fld1" OF "Tab1" AS character
FORMAT "x(24)"
MANDATORY

ADD FIELD "Fld2" OF "Tab1" AS character
FORMAT "x(24)"
MANDATORY

ADD FIELD "Fld2" OF "Tab1" AS character
FORMAT "x(24)"
MANDATORY

ADD INDEX "Idx1" ON "Tab1"
PRIMARY
INDEX-FIELD "Fld1"
INDEX-FIELD "Fld2" ASCENDING
INDEX-FIELD "Fld3" DESCENDING
.
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.3.2</version>
<version>2.4.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.3.2</version>
<version>2.4.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.3.2</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>proparse</artifactId>
<version>2.3.2</version>
<version>2.4.0</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 @@ -4,7 +4,7 @@

<groupId>eu.rssw.sonar.openedge</groupId>
<artifactId>sonar-openedge-plugin</artifactId>
<version>2.3.2</version>
<version>2.4.0</version>
<packaging>sonar-plugin</packaging>

<name>OpenEdge plugin for SonarQube</name>
Expand Down Expand Up @@ -62,17 +62,17 @@
<dependency>
<groupId>eu.rssw.openedge.checks</groupId>
<artifactId>openedge-checks</artifactId>
<version>2.3.2</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>listing-parser</artifactId>
<version>2.3.2</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>eu.rssw.openedge.parsers</groupId>
<artifactId>profiler-parser</artifactId>
<version>2.3.2</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,18 @@
*/
package org.sonar.plugins.openedge.foundation;

import java.util.List;

import org.sonar.api.resources.AbstractLanguage;
import org.sonar.plugins.openedge.api.Constants;

import com.google.common.collect.ImmutableList;

public class OpenEdgeDB extends AbstractLanguage {
public final List<String> extensions;

public OpenEdgeDB() {
super(Constants.DB_LANGUAGE_KEY, "OpenEdgeDB");
extensions = ImmutableList.of(".df");
}

@Override
public String[] getFileSuffixes() {
return extensions.toArray(new String[] {});
return new String[] { ".df" };
}

/**
* Returns the list of managed extensions
*
* @return A non-null List
*/
public List<String> getFileSuffixesList() {
return extensions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class OpenEdgeSettings {
private final SonarRuntime runtime;

// Internal use
private boolean init = false;
private final List<Path> sourcePaths = new ArrayList<>();
private final List<Path> binariesDirs = new ArrayList<>();
private final List<Path> pctDirs = new ArrayList<>();
Expand All @@ -105,6 +106,11 @@ public OpenEdgeSettings(Configuration config, FileSystem fileSystem, SonarRuntim
this.config = config;
this.fileSystem = fileSystem;
this.runtime = runtime;
}

public final void init() {
if (init)
return;

LOG.info("Loading OpenEdge settings for server ID '{}' '{}'", config.get(CoreProperties.SERVER_ID).orElse(""),
config.get(CoreProperties.PERMANENT_SERVER_ID).orElse(""));
Expand All @@ -118,6 +124,7 @@ public OpenEdgeSettings(Configuration config, FileSystem fileSystem, SonarRuntim
if (useXrefFilter()) {
LOG.info("XML XREF filter activated [{}]", getXrefBytesAsString());
}
init = true;
}

private final void initializeDirectories(Configuration config, FileSystem fileSystem) {
Expand Down Expand Up @@ -635,7 +642,14 @@ private Collection<IDatabase> readSchemaFromProp1(Configuration config, FileSyst
try {
desc = DumpFileUtils.getDatabaseDescription(fileSystem.resolvePath(str), dbName);
} catch (IOException caught) {
LOG.error("Unable to parse " + str, 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
if (runtime.getProduct() == SonarProduct.SONARLINT) {
throw new RuntimeException("Unable to read database schema from '" + dfFile.getName()
+ "', please check value of property '" + Constants.DATABASES + "'", caught);
} else {
LOG.error("Unable to parse " + str, caught);
}
}
if ((desc != null) && (runtime.getProduct() == SonarProduct.SONARLINT)) {
try (OutputStream os = new FileOutputStream(serFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void describe(SensorDescriptor descriptor) {
public void execute(SensorContext context) {
if (context.runtime().getProduct() == SonarProduct.SONARLINT)
return;

settings.init();
RefactorSession session = settings.getProparseSession();

for (InputFile file : context.fileSystem().inputFiles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void describe(SensorDescriptor descriptor) {
public void execute(SensorContext context) {
if (settings.skipProparseSensor())
return;

settings.init();
components.initializeLicense(context);
components.initializeChecks(context);
for (Map.Entry<ActiveRule, OpenEdgeProparseCheck> entry : components.getProparseRules().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void describe(SensorDescriptor descriptor) {
public void execute(SensorContext context) {
if (context.runtime().getProduct() == SonarProduct.SONARLINT)
return;

settings.init();
int warningsImportNum = 0;
final RuleKey defaultWarningRuleKey = RuleKey.of(Constants.STD_REPOSITORY_KEY,
OpenEdgeRulesDefinition.COMPILER_WARNING_RULEKEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public void initContext() throws IOException {
@Test
public void test1() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd01.p");
ParseUnit unit = getParseUnit(inputFile);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();

Expand All @@ -77,9 +79,11 @@ public void test1() {
@Test
public void test2() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd02.p");
ParseUnit unit = getParseUnit(inputFile);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();

Expand All @@ -97,9 +101,11 @@ public void test2() {
@Test
public void test3() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd03.p");
ParseUnit unit = getParseUnit(inputFile);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();

Expand All @@ -114,9 +120,11 @@ public void test3() {
@Test
public void testNoProperties() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd04.p");
ParseUnit unit = getParseUnit(inputFile);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();
List<TokensLine> lines = context.cpdTokens(inputFile.key());
Expand All @@ -127,10 +135,12 @@ public void testNoProperties() {
@Test
public void testAnnotations() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
context.settings().setProperty(Constants.CPD_ANNOTATIONS, "Generated");
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd04.p");
ParseUnit unit = getParseUnit(inputFile);
context.settings().setProperty(Constants.CPD_ANNOTATIONS, "Generated");
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();

Expand All @@ -142,10 +152,12 @@ public void testAnnotations() {
@Test
public void testProcedures() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
context.settings().setProperty(Constants.CPD_PROCEDURES, "p1,p4,p3");
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd04.p");
ParseUnit unit = getParseUnit(inputFile);
context.settings().setProperty(Constants.CPD_PROCEDURES, "p1,p4,p3");
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();

Expand All @@ -157,11 +169,13 @@ public void testProcedures() {
@Test
public void testAnnotationsAndProcedures() {
SensorContextTester context = SensorContextTester.create(new File(BASEDIR));
InputFile inputFile = getInputFile(context, "cpd04.p");
ParseUnit unit = getParseUnit(inputFile);
context.settings().setProperty(Constants.CPD_ANNOTATIONS, "Generated");
context.settings().setProperty(Constants.CPD_PROCEDURES, "p1,p4,p5");
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER)), unit);
OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
settings.init();
InputFile inputFile = getInputFile(context, "cpd04.p");
ParseUnit unit = getParseUnit(inputFile);
ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit);
unit.getTopNode().walk(callback);
callback.getResult().save();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import org.prorefactor.refactor.settings.ProparseSettings.OperatingSystem;
import org.sonar.api.SonarQubeSide;
Expand Down Expand Up @@ -126,4 +127,31 @@ public void testPreprocessorSettings02() throws Exception {
assertEquals(oeSettings.getProparseSession().getProparseSettings().getProversion(), "11.7");
}

@Test
public void testInvalidDBInSonarLint() throws Exception {
SensorContextTester context = TestProjectSensorContext.createContext();
context.settings().setProperty(Constants.DATABASES, "src/schema/invalid.df");

OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarLint(VERSION));
try {
oeSettings.getProparseSession();
fail("RuntimeException should have been thrown");
} catch (RuntimeException caught) {

}
}

@Test
public void testInvalidDBInSonarQube() throws Exception {
SensorContextTester context = TestProjectSensorContext.createContext();
context.settings().setProperty(Constants.DATABASES, "src/schema/invalid.df");

OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), SonarRuntimeImpl.forSonarQube(VERSION, SonarQubeSide.SCANNER));
try {
oeSettings.getProparseSession();
} catch (RuntimeException caught) {
fail("No RuntimeException should have been thrown");
}
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>eu.rssw</groupId>
<artifactId>sonar-openedge</artifactId>
<packaging>pom</packaging>
<version>2.3.2</version>
<version>2.4.0</version>
<name>OpenEdge plugin for SonarQube</name>
<url>http://www.riverside-software.fr/</url>
<description>Open source code analysis for OpenEdge</description>
Expand Down
Loading

0 comments on commit fe2ceae

Please sign in to comment.