Skip to content

Commit 514ddc6

Browse files
committed
Deprioritize sonar.sources in the analysis search path
The previous approach (where `sonar.sources` took first priority in the analysis search path) caused some surprising/undesirable behavior in projects where there are multiple units with the same name. It becomes very hard in that scenario for a user to configure the scan in a way where the correct unit will win during import resolution, even if the search path was correct in the dproj file.
1 parent 5c2b012 commit 514ddc6

File tree

3 files changed

+3
-41
lines changed

3 files changed

+3
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- Include the global browsing path in unit import resolution.
1919
- Reprioritize the analysis search path in the following order (highest to lowest):
20-
- Analysis source files (`sonar.sources`)
2120
- Referenced project files (`DCCReference`)
2221
- Search path (`DCC_UnitSearchPath`)
2322
- Debugger source path (`Debugger_DebugSourcePath`)
2423
- Library path (`DelphiLibraryPath`/`DelphiTranslatedLibraryPath`)
2524
- Browsing path (`DelphiBrowsingPath`)
2625
- Standard library
26+
- Analysis source files (`sonar.sources`)
2727
- Empty anonymous methods are now ignored in `EmptyBlock`.
2828
- Empty anonymous methods are now flagged in `EmptyRoutine`.
2929

delphi-frontend/src/main/java/au/com/integradev/delphi/symbol/SymbolTableBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private static boolean isPasFile(Path path) {
185185
}
186186

187187
private void createUnitData(Path unitPath, boolean isSourceFile) {
188-
if (unitPaths.add(unitPath)) {
188+
if (unitPaths.add(unitPath) || isSourceFile) {
189189
String unitName = FilenameUtils.getBaseName(unitPath.toString());
190190
UnitData unitData = new UnitData(unitPath, isSourceFile);
191191

@@ -459,11 +459,10 @@ public SymbolTable build() {
459459
throw new SymbolTableConstructionException("typeFactory was not supplied.");
460460
}
461461

462-
sourceFiles.forEach(file -> this.createUnitData(file, true));
463462
referencedFiles.forEach(file -> this.createUnitData(file, false));
464463
searchPath.getRootDirectories().forEach(this::processSearchPath);
465-
466464
processStandardLibrarySearchPaths();
465+
sourceFiles.forEach(file -> this.createUnitData(file, true));
467466

468467
ProgressReport progressReport =
469468
new ProgressReport(

delphi-frontend/src/test/java/au/com/integradev/delphi/symbol/SymbolTableBuilderTest.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -159,43 +159,6 @@ void testStandardLibrarySearchPathShouldExcludeToolsUnits(
159159
assertThat(symbolTable.getUnitByPath(excludedPath.toString())).isNull();
160160
}
161161

162-
@Test
163-
void testSonarSourcesArePrioritizedOverReferencedFiles(
164-
@TempDir Path standardLibraryPath,
165-
@TempDir Path referencedFilesPath,
166-
@TempDir Path sourceFilesPath)
167-
throws IOException {
168-
createStandardLibrary(standardLibraryPath);
169-
createStandardLibrary(referencedFilesPath);
170-
createStandardLibrary(sourceFilesPath);
171-
172-
List<Path> referencedFiles;
173-
try (Stream<Path> referencedFilesStream = Files.list(referencedFilesPath)) {
174-
referencedFiles = referencedFilesStream.collect(Collectors.toUnmodifiableList());
175-
}
176-
177-
List<Path> sourceFiles;
178-
try (Stream<Path> sourceFilesStream = Files.list(sourceFilesPath)) {
179-
sourceFiles = sourceFilesStream.collect(Collectors.toUnmodifiableList());
180-
}
181-
182-
SymbolTable symbolTable =
183-
SymbolTable.builder()
184-
.preprocessorFactory(new DelphiPreprocessorFactory(Platform.WINDOWS))
185-
.typeFactory(TypeFactoryUtils.defaultFactory())
186-
.standardLibraryPath(standardLibraryPath)
187-
.referencedFiles(referencedFiles)
188-
.sourceFiles(sourceFiles)
189-
.build();
190-
191-
assertThat(symbolTable.getUnitByPath(standardLibraryPath.resolve("SysInit.pas").toString()))
192-
.isNull();
193-
assertThat(symbolTable.getUnitByPath(referencedFilesPath.resolve("SysInit.pas").toString()))
194-
.isNull();
195-
assertThat(symbolTable.getUnitByPath(sourceFilesPath.resolve("SysInit.pas").toString()))
196-
.isNotNull();
197-
}
198-
199162
@Test
200163
void testReferencedFilesArePrioritizedOverSearchPath(
201164
@TempDir Path standardLibraryPath,

0 commit comments

Comments
 (0)