Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions build-support/FrontendDependencyValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* SonarQube Java
* Copyright (C) SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* You can redistribute and/or modify this program under the terms of
* the Sonar Source-Available License Version 1, as published by SonarSource Sàrl.
*
* 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 Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public final class FrontendDependencyValidator {
private FrontendDependencyValidator() {
}

public static void main(String[] args) throws IOException {
if (args.length != 1) {
throw new IllegalArgumentException("Expected the packaged plugin JAR path");
}
try (var input = Files.newInputStream(Path.of(args[0]))) {
inspect(input, args[0]);
}
System.out.println("Packaged frontend contains no ECJ or JDT core classes");
}

private static void inspect(InputStream input, String path) throws IOException {
try (var zip = new ZipInputStream(input)) {
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
String name = entry.getName();
String location = path + "!/" + name;
if (name.contains("jdt-package") || name.contains("org.eclipse.jdt.core") || name.matches(".*(?:^|/)ecj[-./].*")) {
throw new IllegalStateException("Forbidden compiler artifact: " + location);
}
if (name.endsWith(".class") && name.contains("org/eclipse/jdt/") && !name.contains("org/eclipse/jdt/annotation/")) {
throw new IllegalStateException("Forbidden compiler class: " + location);
}
if (name.endsWith(".jar")) {
inspect(new ByteArrayInputStream(zip.readAllBytes()), location);
} else if (name.endsWith(".class")) {
String bytes = new String(zip.readAllBytes(), StandardCharsets.ISO_8859_1);
for (String prefix : java.util.List.of("org/eclipse/jdt/core/", "org/eclipse/jdt/internal/", "org.eclipse.jdt.core.", "org.eclipse.jdt.internal.")) {
if (bytes.contains(prefix)) {
throw new IllegalStateException("Forbidden compiler reference: " + location);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@

class InternalCheckVerifierTest {

@Test
void normal_scanner_uses_selected_backend() {
CheckVerifier.newVerifier().onFile(TEST_FILE).withCheck(new JavaFileScanner() {
@Override
public void scanFile(JavaFileScannerContext context) {
var tree = (org.sonar.java.model.JavaTree.CompilationUnitTreeImpl) context.getTree();
String expected = "JSema";
assertThat(tree.sema.getClass().getSimpleName()).isEqualTo(expected);
}
}).verifyNoIssues();
}

@Nested
class TestingCheckVerifierInitialConfiguration {

Expand Down
5 changes: 0 additions & 5 deletions java-frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
</repositories>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jdt-package</artifactId>
<version>1.9.0.1840</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-psi</artifactId>
Expand Down
132 changes: 0 additions & 132 deletions java-frontend/src/main/java/org/eclipse/jdt/core/dom/ASTUtils.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.stream.StreamSupport;
import javax.annotation.Nullable;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.eclipse.core.runtime.OperationCanceledException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
Expand Down Expand Up @@ -116,7 +117,6 @@ private void scan(Iterable<? extends InputFile> inputFiles, Consumer<Compilation
this::analysisCancelled,
analysisProgress,
(i, r) -> simpleScan(i, r,
// Due to a bug in ECJ, JAR files remain locked after the analysis on Windows, we unlock them manually. See SONARJAVA-3609.
JavaAstScanner::cleanUpAst,
modifyCompilationUnit));
} finally {
Expand Down Expand Up @@ -229,7 +229,9 @@ public boolean shouldFailAnalysis() {

public void checkInterrupted(Exception e) {
Throwable cause = ExceptionUtils.getRootCause(e);
if (cause instanceof InterruptedException
if (Thread.currentThread().isInterrupted()
|| ExceptionUtils.getThrowableList(e).stream().anyMatch(OperationCanceledException.class::isInstance)
|| cause instanceof InterruptedException
|| cause instanceof InterruptedIOException
|| cause instanceof CancellationException
|| analysisCancelled()) {
Expand Down

This file was deleted.

Loading
Loading