diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/buildless-fetches.expected b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/buildless-fetches.expected new file mode 100644 index 000000000000..a956477896cb --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/buildless-fetches.expected @@ -0,0 +1,27 @@ +https://repo.jenkins-ci.org/releases/org/jenkins-ci/main/jenkins-war/2.249/jenkins-war-2.249.war +https://repo.maven.apache.org/maven2/com/feiniaojin/naaf/naaf-graceful-response-example/1.0/naaf-graceful-response-example-1.0.jar +https://repo.maven.apache.org/maven2/com/github/MoebiusSolutions/avro-registry-in-source/avro-registry-in-source-tests/1.8/avro-registry-in-source-tests-1.8.jar +https://repo.maven.apache.org/maven2/com/github/MoebiusSolutions/avro-registry-in-source/example-project/1.5/example-project-1.5.jar +https://repo.maven.apache.org/maven2/com/intuit/benten/benten-examples/0.1.5/benten-examples-0.1.5.jar +https://repo.maven.apache.org/maven2/com/jakewharton/twirl/sample-runtime/1.2.0/sample-runtime-1.2.0.jar +https://repo.maven.apache.org/maven2/com/mattunderscore/code/generation/specky/plugin-example/0.8.0/plugin-example-0.8.0.jar +https://repo.maven.apache.org/maven2/com/microsoft/tang/tang-test-jarAB/0.9/tang-test-jarAB-0.9.jar +https://repo.maven.apache.org/maven2/de/knutwalker/rx-redis-example_2.11/0.1.2/rx-redis-example_2.11-0.1.2.jar +https://repo.maven.apache.org/maven2/de/knutwalker/rx-redis-java-example_2.11/0.1.2/rx-redis-java-example_2.11-0.1.2.jar +https://repo.maven.apache.org/maven2/io/github/scrollsyou/example-spring-boot-starter/1.0.0/example-spring-boot-starter-1.0.0.jar +https://repo.maven.apache.org/maven2/io/streamnative/com/example/maven-central-template/server/3.0.0/server-3.0.0.jar +https://repo.maven.apache.org/maven2/junit/junit/4.11/junit-4.11.jar +https://repo.maven.apache.org/maven2/no/nav/security/token-validation-ktor-demo/3.1.0/token-validation-ktor-demo-3.1.0.jar +https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-fileupload/0.5.10/minijax-example-fileupload-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-inject/0.5.10/minijax-example-inject-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-json/0.5.10/minijax-example-json-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-mustache/0.5.10/minijax-example-mustache-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-petclinic/0.5.10/minijax-example-petclinic-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-security/0.5.10/minijax-example-security-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-ssl/0.5.10/minijax-example-ssl-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-todo-backend/0.5.10/minijax-example-todo-backend-0.5.10.jar +https://repo.maven.apache.org/maven2/org/minijax/minijax-example-websocket/0.5.10/minijax-example-websocket-0.5.10.jar +https://repo.maven.apache.org/maven2/org/scalamock/scalamock-examples_2.10/3.6.0/scalamock-examples_2.10-3.6.0.jar +https://repo.maven.apache.org/maven2/org/somda/sdc/glue-examples/4.0.0/glue-examples-4.0.0.jar +https://repo.maven.apache.org/maven2/us/fatehi/schemacrawler-examplecode/16.20.2/schemacrawler-examplecode-16.20.2.jar diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/diagnostics.expected b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/diagnostics.expected new file mode 100644 index 000000000000..1058e1528f99 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/diagnostics.expected @@ -0,0 +1,70 @@ +{ + "markdownMessage": "Java analysis used build tool Maven 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 Maven 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": "Reading the dependency graph from build files provided 3 classpath entries", + "severity": "unknown", + "source": { + "extractorName": "java", + "id": "java/autobuilder/buildless/depgraph-provided-by-maven", + "name": "Java analysis extracted precise dependency graph information from tool Maven" + }, + "visibility": { + "cliSummaryTable": true, + "statusPage": false, + "telemetry": true + } +} diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/force_sequential_test_execution b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/force_sequential_test_execution new file mode 100644 index 000000000000..dd90439bca59 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/force_sequential_test_execution @@ -0,0 +1 @@ +# Concurrent Maven processes using ~/.m2/repository is not safe, so this test must run sequentially diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/pom.xml b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/pom.xml new file mode 100644 index 000000000000..c8edf00dc006 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/pom.xml @@ -0,0 +1,144 @@ + + + + 4.0.0 + + com.example + maven-sample + 1.0-SNAPSHOT + + maven-sample + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + central + Maven Central + https://repo.maven.apache.org/maven2 + + false + + + + + maven.jenkins-ci.org + Jenkins Releases + https://repo.jenkins-ci.org/releases/ + + + + + + junit + junit + 4.11 + test + + + org.jenkins-ci.main + jenkins-war + 2.249 + executable-war + + + + * + * + + + + + + + + + exec-maven-plugin + org.codehaus.mojo + 1.1.1 + + + check-maven-version + package + + java + + + + + com.example.App + + + + com.diffplug.spotless + spotless-maven-plugin + 2.19.1 + + + + check + + compile + + + + + + /* FAIL ME */ + + + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/java/com/example/App.java b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/java/com/example/App.java new file mode 100644 index 000000000000..c9eec918587c --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/java/com/example/App.java @@ -0,0 +1,30 @@ +package com.example; + +import java.util.regex.Pattern; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + String expectedVersion = System.getenv("EXPECT_MAVEN"); + Path mavenHome = Paths.get(System.getProperty("maven.home")).normalize(); + String observedVersion = mavenHome.getFileName().toString(); + if (expectedVersion != null && !expectedVersion.equals(observedVersion)) { + System.err.println("Wrong maven version, expected '" + expectedVersion + "' but got '" + observedVersion + "'" + mavenHome); + System.exit(1); + } + String commandMatcher = System.getenv("EXPECT_COMMAND_REGEX"); + String command = System.getProperty("sun.java.command"); + if (commandMatcher != null && !Pattern.matches(commandMatcher, command)) { + System.err.println("Wrong command line, '" + command + "' does not match '" + commandMatcher + "'"); + System.exit(1); + } + } +} diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/my-app.properties b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/my-app.properties new file mode 100644 index 000000000000..e566b49a29a8 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/my-app.properties @@ -0,0 +1 @@ +version=1.0 diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/page.xml b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/page.xml new file mode 100644 index 000000000000..2bab459cb031 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/page.xml @@ -0,0 +1,8 @@ + + +A sample + + +

Hello world!

+ + diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/struts.xml b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/struts.xml new file mode 100644 index 000000000000..73fc0c6b9cb6 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/main/resources/struts.xml @@ -0,0 +1,4 @@ + + +This is a sample file + diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/test/java/com/example/AppTest.java b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/test/java/com/example/AppTest.java new file mode 100644 index 000000000000..22a94ca6f01c --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/src/test/java/com/example/AppTest.java @@ -0,0 +1,20 @@ +package com.example; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.expected b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.expected new file mode 100644 index 000000000000..cbd09bcf554e --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.expected @@ -0,0 +1,10 @@ +#select +| src/main/java/com/example/App.java:0:0:0:0 | App | +| src/test/java/com/example/AppTest.java:0:0:0:0 | AppTest | +xmlFiles +| pom.xml:0:0:0:0 | pom.xml | +| src/main/resources/page.xml:0:0:0:0 | src/main/resources/page.xml | +| src/main/resources/struts.xml:0:0:0:0 | src/main/resources/struts.xml | +propertiesFiles +| src/main/resources/my-app.properties:0:0:0:0 | src/main/resources/my-app.properties | +| test-db/log/ext/javac.properties:0:0:0:0 | test-db/log/ext/javac.properties | diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.py b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.py new file mode 100644 index 000000000000..bfff65b2fc20 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.py @@ -0,0 +1,8 @@ +from create_database_utils import * +from diagnostics_test_utils import * +from buildless_test_utils import * + +run_codeql_database_create([], lang="java", extra_env={"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS": "true", "CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_CLASSPATH_FROM_BUILD_FILES": "true"}) + +check_diagnostics() +check_buildless_fetches() diff --git a/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.ql b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.ql new file mode 100644 index 000000000000..25cd26fdd142 --- /dev/null +++ b/java/ql/integration-tests/all-platforms/java/buildless-maven-executable-war/test.ql @@ -0,0 +1,9 @@ +import java + +from File f +where f.isSourceFile() +select f + +query predicate xmlFiles(XmlFile x) { any() } + +query predicate propertiesFiles(File f) { f.getExtension() = "properties" }