From 834594fe98f31710b125345e45b77b2ed4f06231 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 17 Mar 2025 22:25:21 +0000 Subject: [PATCH] Java: add integration test for failed Gradle download --- .../.gitattributes | 6 ++ .../.gitignore | 5 + .../build.gradle | 30 ++++++ .../diagnostics.expected | 98 +++++++++++++++++++ .../settings.gradle | 19 ++++ .../source_archive.expected | 2 + .../src/main/java/com/example/App.java | 14 +++ .../src/test/java/com/example/AppTest.java | 14 +++ .../test.py | 17 ++++ 9 files changed, 205 insertions(+) create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitattributes create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitignore create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/build.gradle create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/diagnostics.expected create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/settings.gradle create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/source_archive.expected create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/main/java/com/example/App.java create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/test/java/com/example/AppTest.java create mode 100644 java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/test.py diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitattributes b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitattributes new file mode 100644 index 000000000000..00a51aff5e5a --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitattributes @@ -0,0 +1,6 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# These are explicitly windows files and should use crlf +*.bat text eol=crlf + diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitignore b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitignore new file mode 100644 index 000000000000..1b6985c0094c --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/.gitignore @@ -0,0 +1,5 @@ +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/build.gradle b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/build.gradle new file mode 100644 index 000000000000..071a12b7691c --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/build.gradle @@ -0,0 +1,30 @@ +/* + * This build file was auto generated by running the Gradle 'init' task + * by 'arthur' at '28/11/20 22:29' with Gradle 3.0 + * + * This generated file contains a sample Java project to get you started. + * For more details take a look at the Java Quickstart chapter in the Gradle + * user guide available at https://docs.gradle.org/3.0/userguide/tutorial_java_projects.html + */ + +// Apply the java plugin to add support for Java +apply plugin: 'java' + +// In this section you declare where to find the dependencies of your project +repositories { + // Use 'jcenter' for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() +} + +// In this section you declare the dependencies for your production and test code +dependencies { + // The production code uses the SLF4J logging API at compile time + compile 'org.slf4j:slf4j-api:1.7.21' + + // Declare the dependency for your favourite test framework you want to use in your tests. + // TestNG is also supported by the Gradle Test task. Just change the + // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add + // 'test.useTestNG()' to your build script. + testCompile 'junit:junit:4.12' +} diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/diagnostics.expected b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/diagnostics.expected new file mode 100644 index 000000000000..8e5fb7fc737e --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/diagnostics.expected @@ -0,0 +1,98 @@ +{ + "markdownMessage": "Build tool(s) should have been able to provide a recommended classpath but the attempt failed. Extraction will continue, but external dependencies will be inferred from the Java package names used. Consider troubleshooting the build tool error or using a build mode other than 'none'.", + "severity": "note", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/classpath-from-tool-failed", + "name": "Failed to extract dependency information from build tool tool Gradle" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": true, + "telemetry": true + } +} +{ + "markdownMessage": "Built a Gradle project without the [Gradle wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html). This may use an incompatible version of Gradle.", + "severity": "warning", + "source": { + "extractorName": "java", + "id": "java/autobuilder/guessed-gradle-version", + "name": "Required Gradle version not specified" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": true, + "telemetry": true + } +} +{ + "markdownMessage": "Java analysis used build tool Gradle to pick a JDK version and/or to recommend external dependencies.", + "severity": "unknown", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/using-build-tool-advice", + "name": "Java analysis used build tool Gradle to pick a JDK version and/or to recommend external dependencies" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": false, + "telemetry": true + } +} +{ + "markdownMessage": "Java analysis used the system default JDK.", + "severity": "unknown", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/jdk-system-default", + "name": "Java analysis used the system default JDK" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": false, + "telemetry": true + } +} +{ + "markdownMessage": "Java analysis with build-mode 'none' completed.", + "severity": "unknown", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/complete", + "name": "Java analysis with build-mode 'none' completed" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": false, + "telemetry": true + } +} +{ + "markdownMessage": "Java was extracted with build-mode set to 'none'. This means that all Java source in the working directory will be scanned, with build tools such as Maven and Gradle only contributing information about external dependencies.", + "severity": "note", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/mode-active", + "name": "Java was extracted with build-mode set to 'none'" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": true, + "telemetry": true + } +} +{ + "markdownMessage": "Running the Gradle plugin `org.gradle:github-dependency-graph-gradle-plugin` failed. This means precise dependency information will be unavailable, and so dependencies will be guessed based on Java package names. Consider investigating why this plugin fails to run.", + "severity": "note", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/github-dependency-graph-gradle-plugin-failed", + "name": "Java analysis failed to extract a dependency graph from Gradle" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": true, + "telemetry": true + } +} diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/settings.gradle b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/settings.gradle new file mode 100644 index 000000000000..233410459f60 --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/settings.gradle @@ -0,0 +1,19 @@ +/* + * This settings file was auto generated by the Gradle buildInit task + * by 'arthur' at '28/11/20 22:29' with Gradle 3.0 + * + * The settings file is used to specify which projects to include in your build. + * In a single project build this file can be empty or even removed. + * + * Detailed information about configuring a multi-project build in Gradle can be found + * in the user guide at https://docs.gradle.org/3.0/userguide/multi_project_builds.html + */ + +/* +// To declare projects as part of a multi-project build use the 'include' method +include 'shared' +include 'api' +include 'services:webservice' +*/ + +rootProject.name = 'gradle-sample' diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/source_archive.expected b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/source_archive.expected new file mode 100644 index 000000000000..9862217a0594 --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/source_archive.expected @@ -0,0 +1,2 @@ +src/main/java/com/example/App.java +src/test/java/com/example/AppTest.java diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/main/java/com/example/App.java b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/main/java/com/example/App.java new file mode 100644 index 000000000000..1c13f7d885e5 --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/main/java/com/example/App.java @@ -0,0 +1,14 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package com.example; + +public class App { + public String getGreeting() { + return "Hello world."; + } + + public static void main(String[] args) { + System.out.println(new App().getGreeting()); + } +} diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/test/java/com/example/AppTest.java b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/test/java/com/example/AppTest.java new file mode 100644 index 000000000000..813bc5e1a2ae --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/src/test/java/com/example/AppTest.java @@ -0,0 +1,14 @@ +/* + * This Java source file was generated by the Gradle 'init' task. + */ +package com.example; + +import org.junit.Test; +import static org.junit.Assert.*; + +public class AppTest { + @Test public void testAppHasAGreeting() { + App classUnderTest = new App(); + assertNotNull("app should have a greeting", classUnderTest.getGreeting()); + } +} diff --git a/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/test.py b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/test.py new file mode 100644 index 000000000000..e59277f3ea36 --- /dev/null +++ b/java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/test.py @@ -0,0 +1,17 @@ +import tempfile +import runs_on +import pathlib + + +# The version of gradle used doesn't work on java 17 +def test(codeql, use_java_11, java, environment): + gradle_override_dir = pathlib.Path(tempfile.mkdtemp()) + if runs_on.windows: + (gradle_override_dir / "gradle.bat").write_text("@echo off\nexit /b 2\n") + else: + gradlepath = gradle_override_dir / "gradle" + gradlepath.write_text("#!/bin/bash\nexit 1\n") + gradlepath.chmod(0o0755) + + environment.add_path(gradle_override_dir) + codeql.database.create(build_mode = "none")