Skip to content

Commit

Permalink
SONARJAVA-4922 Upgrade sonar-plugin-api and fix IndexedFile issue (#4752
Browse files Browse the repository at this point in the history
)

Co-authored-by: Alban Auzeill <[email protected]>
  • Loading branch information
kaufco and alban-auzeill authored Apr 3, 2024
1 parent 38a69d4 commit 26ef2ab
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ plugin_qa_task:
<<: *ORCHESTRATOR_CACHE_PREPARATION_DEFINITION
matrix:
- env:
SQ_VERSION: LATEST_RELEASE[9.9]
SQ_VERSION: LATEST_RELEASE
orchestrator_LATEST_RELEASE_cache:
<<: *ORCHESTRATOR_CACHE_ELEMENTS_DEFINITION
- env:
Expand Down Expand Up @@ -208,7 +208,7 @@ ruling_task:
- source cirrus-env QA
- source set_maven_build_version $BUILD_NUMBER
- cd its/ruling
- mvn package "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[9.9] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
- mvn package "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository
on_failure:
actual_artifacts:
Expand Down Expand Up @@ -237,7 +237,7 @@ ruling_win_task:
- init_git_submodules its/sources
- git submodule update --init --recursive
- cd its/ruling
- mvn package "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE[9.9] -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
- mvn package "-Pit-ruling,$PROFILE" -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V -Dparallel=methods -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository

autoscan_task:
Expand All @@ -262,7 +262,7 @@ autoscan_task:
- source set_maven_build_version $BUILD_NUMBER
- JAVA_HOME="${JAVA_21_HOME}" mvn clean compile --projects java-checks-test-sources --also-make-dependents
- cd its/autoscan
- mvn clean package --batch-mode --errors --show-version --activate-profiles it-autoscan -Dsonar.runtimeVersion=LATEST_RELEASE[9.9] -Dmaven.test.redirectTestOutputToFile=false -Dparallel=methods -DuseUnlimitedThreads=true
- mvn clean package --batch-mode --errors --show-version --activate-profiles it-autoscan -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -Dparallel=methods -DuseUnlimitedThreads=true
cleanup_before_cache_script: cleanup_maven_repository
on_failure:
actual_artifacts:
Expand Down
10 changes: 5 additions & 5 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
java-frontend/src/test/files/highlighter/SonarSymTable.java eol=lf
java-checks/src/test/files/checks/NonEmptyFile.java eol=cr
java-frontend/src/test/java/org/sonar/java/model/TreeTokenCompletenessTest.java eol=lf
java-checks/src/main/java/org/sonar/java/checks/helpers/ExpressionEvaluator.java eol=lf
its/ruling/src/test/resources/autoscan/autoscan-diff-by-rules.json eol=lf
java-checks-test-sources/src/main/java/checks/CounterModeIVShouldNotBeReusedCheck.java eol=lf
java-checks/src/main/java/org/sonar/java/checks/helpers/ExpressionEvaluator.java eol=lf
java-checks/src/main/java/org/sonar/java/checks/helpers/HardcodedStringExpressionChecker.java eol=lf
its/ruling/src/test/resources/autoscan/autoscan-diff-by-rules.json eol=lf
java-checks/src/test/files/checks/NonEmptyFile.java eol=cr
java-frontend/src/test/files/highlighter/*.java eol=lf
java-frontend/src/test/java/org/sonar/java/model/TreeTokenCompletenessTest.java eol=lf
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ try removing the Maven nature of the 'jdt' module.
To run integration tests, you will need to create a properties file like the one shown below, and set the URL pointing to its location in an environment variable named `ORCHESTRATOR_CONFIG_URL`.

# version of SonarQube Server
sonar.runtimeVersion=7.9
sonar.runtimeVersion=LATEST_RELEASE

orchestrator.updateCenterUrl=http://update.sonarsource.org/update-center-dev.properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,8 @@ public void setUp() {
@Test
void sonar_symbol_table() throws Exception {
File source = new File("src/test/files/highlighter/SonarSymTable.java");
File target = temp.newFile().getAbsoluteFile();
InputFile inputFile = TestUtils.inputFile(source);

String content = Files.asCharSource(source, StandardCharsets.UTF_8)
.read()
.replaceAll("\\r\\n", "\n")
.replaceAll("\\r", "\n")
.replaceAll("\\n", EOL);
Files.asCharSink(target, StandardCharsets.UTF_8).write(content);

InputFile inputFile = TestUtils.inputFile(target);
JavaAstScanner.scanSingleFileForTests(inputFile, new VisitorsBridge(Collections.emptyList(), sonarComponents.getJavaClasspath(), sonarComponents));
String componentKey = inputFile.key();
verifyUsages(componentKey, 1, 17, reference(5,2), reference(9,10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,7 @@ private void scan(InputFile inputFile) {
}

private InputFile generateTestFile(String sourceFile) throws IOException {
File source = new File(sourceFile);
File target = new File(temp.newFolder(), source.getName()).getAbsoluteFile();
String content = Files.asCharSource(source, StandardCharsets.UTF_8)
.read()
.replaceAll("\\r\\n", "\n")
.replaceAll("\\r", "\n")
.replaceAll("\\n", eol);
Files.asCharSink(target, StandardCharsets.UTF_8).write(content);
return TestUtils.inputFile(target);
return TestUtils.inputFile(new File(sourceFile));
}

private void verifyHighlighting(InputFile inputFile) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.TestInputFileBuilder;
import org.sonar.java.checks.verifier.FilesUtils;
import org.sonar.java.checks.verifier.internal.InternalInputFile;
import org.sonar.java.model.DefaultJavaFileScannerContext;
import org.sonar.java.model.JavaTree;
import org.sonar.java.model.JavaVersionImpl;
Expand Down Expand Up @@ -57,7 +58,7 @@ public static SymbolicExecutionVisitor createSymbolicExecutionVisitor(String fil
}

public static Pair<SymbolicExecutionVisitor, Sema> createSymbolicExecutionVisitorAndSemantic(String fileName, SECheck... checks) {
InputFile inputFile = inputFile(fileName);
InputFile inputFile = InternalInputFile.inputFile("", new File(fileName));
JavaTree.CompilationUnitTreeImpl cut = (JavaTree.CompilationUnitTreeImpl) JParserTestUtils.parse(inputFile.file(), CLASS_PATH);
Sema semanticModel = cut.sema;
SymbolicExecutionVisitor sev = new SymbolicExecutionVisitor(Arrays.asList(checks));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.java.checks.verifier.TestUtils;
import org.sonar.java.checks.verifier.internal.InternalInputFile;
import org.sonar.java.model.DefaultJavaFileScannerContext;
import org.sonar.java.model.JavaTree.CompilationUnitTreeImpl;
import org.sonar.java.model.JavaVersionImpl;
Expand Down Expand Up @@ -187,7 +188,7 @@ void hardcoded_behaviors() throws Exception {
TestUtils.mainCodeSourcesPath("symbolicexecution/behaviorcache/EclipseAssert.java"))
.stream()
.map(File::new)
.map(SETestUtils::inputFile)
.map(it -> InternalInputFile.inputFile("", it))
.toList();

for (InputFile inputFile : inputFiles) {
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@

<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>

<sonar.version>9.9.1.69595</sonar.version>
<sonar.plugin.api.version>10.1.0.809</sonar.plugin.api.version>
<sonarlint.plugin.api.version>8.18.0.70939</sonarlint.plugin.api.version>
<analyzer.commons.version>2.7.0.1482</analyzer.commons.version>
<sonar.version>10.4.1.88267</sonar.version>
<sonar.plugin.api.version>10.7.0.2191</sonar.plugin.api.version>
<sonarlint.plugin.api.version>9.8.0.76914</sonarlint.plugin.api.version>
<analyzer.commons.version>2.8.0.2699</analyzer.commons.version>
<orchestrator.version>3.40.0.183</orchestrator.version>
<sslr.version>1.24.0.633</sslr.version>
<argLine>-Xmx512m</argLine>
Expand Down

0 comments on commit 26ef2ab

Please sign in to comment.