Skip to content

Commit cd0aebe

Browse files
committed
Add integration test for failure to download a particular Maven version
1 parent ca6f3ff commit cd0aebe

File tree

10 files changed

+307
-0
lines changed

10 files changed

+307
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"markdownMessage": "Java analysis used build tool Maven to pick a JDK version and/or to recommend external dependencies.",
3+
"severity": "unknown",
4+
"source": {
5+
"extractorName": "java",
6+
"id": "java/autobuilder/buildless/using-build-tool-advice",
7+
"name": "Java analysis used build tool Maven to pick a JDK version and/or to recommend external dependencies"
8+
},
9+
"visibility": {
10+
"cliSummaryTable": true,
11+
"statusPage": false,
12+
"telemetry": true
13+
}
14+
}
15+
{
16+
"markdownMessage": "Java analysis used the system default JDK.",
17+
"severity": "unknown",
18+
"source": {
19+
"extractorName": "java",
20+
"id": "java/autobuilder/buildless/jdk-system-default",
21+
"name": "Java analysis used the system default JDK"
22+
},
23+
"visibility": {
24+
"cliSummaryTable": true,
25+
"statusPage": false,
26+
"telemetry": true
27+
}
28+
}
29+
{
30+
"markdownMessage": "Java analysis with build-mode 'none' completed.",
31+
"severity": "unknown",
32+
"source": {
33+
"extractorName": "java",
34+
"id": "java/autobuilder/buildless/complete",
35+
"name": "Java analysis with build-mode 'none' completed"
36+
},
37+
"visibility": {
38+
"cliSummaryTable": true,
39+
"statusPage": false,
40+
"telemetry": true
41+
}
42+
}
43+
{
44+
"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.",
45+
"severity": "note",
46+
"source": {
47+
"extractorName": "java",
48+
"id": "java/autobuilder/buildless/mode-active",
49+
"name": "Java was extracted with build-mode set to 'none'"
50+
},
51+
"visibility": {
52+
"cliSummaryTable": true,
53+
"statusPage": true,
54+
"telemetry": true
55+
}
56+
}
57+
{
58+
"markdownMessage": "Reading the dependency graph from build files provided 2 classpath entries",
59+
"severity": "unknown",
60+
"source": {
61+
"extractorName": "java",
62+
"id": "java/autobuilder/buildless/depgraph-provided-by-maven",
63+
"name": "Java analysis extracted precise dependency graph information from tool Maven"
64+
},
65+
"visibility": {
66+
"cliSummaryTable": true,
67+
"statusPage": false,
68+
"telemetry": true
69+
}
70+
}
71+
{
72+
"markdownMessage": "The maven-enforcer-plugin recommended a specific Maven version be used. Trying to download it failed; extraction will continue, but retrieving dependency information from Maven may fail if the system default version is incompatible with project build scripts. Consider checking if a firewall configuration or similar is preventing downloading the required version.",
73+
"severity": "note",
74+
"source": {
75+
"extractorName": "java",
76+
"id": "java/autobuilder/buildless/maven-download-failed",
77+
"name": "Java analysis failed to download a Maven version recommended by the maven-enforcer-plugin"
78+
},
79+
"visibility": {
80+
"cliSummaryTable": true,
81+
"statusPage": true,
82+
"telemetry": true
83+
}
84+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
>&2 echo "Running mvn wrapper script"
4+
5+
if [ "$1" == "dependency:copy" ]; then
6+
>&2 echo "Arguments ($@) look like a dependency:copy command; failing"
7+
exit 1
8+
fi
9+
10+
${REAL_MVN_PATH} "$@"
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>maven-sample</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<name>maven-sample</name>
11+
<!-- FIXME change it to the project's website -->
12+
<url>http://www.example.com</url>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.source>1.7</maven.compiler.source>
17+
<maven.compiler.target>1.7</maven.compiler.target>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>4.11</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<artifactId>exec-maven-plugin</artifactId>
33+
<groupId>org.codehaus.mojo</groupId>
34+
<version>1.1.1</version>
35+
<executions>
36+
<execution>
37+
<id>check-maven-version</id>
38+
<phase>package</phase>
39+
<goals>
40+
<goal>java</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
<configuration>
45+
<mainClass>com.example.App</mainClass>
46+
</configuration>
47+
</plugin>
48+
<plugin>
49+
<groupId>com.diffplug.spotless</groupId>
50+
<artifactId>spotless-maven-plugin</artifactId>
51+
<version>2.19.1</version>
52+
<executions>
53+
<execution>
54+
<goals>
55+
<goal>check</goal>
56+
</goals>
57+
<phase>compile</phase>
58+
</execution>
59+
</executions>
60+
<configuration>
61+
<java>
62+
<licenseHeader>
63+
<content>/* FAIL ME */</content>
64+
</licenseHeader>
65+
</java>
66+
</configuration>
67+
</plugin>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-enforcer-plugin</artifactId>
71+
<executions>
72+
<execution>
73+
<id>enforce-maven</id>
74+
<goals>
75+
<goal>enforce</goal>
76+
</goals>
77+
<configuration>
78+
<rules>
79+
<requireMavenVersion>
80+
<version>[3.1.1,)</version>
81+
</requireMavenVersion>
82+
</rules>
83+
</configuration>
84+
</execution>
85+
</executions>
86+
</plugin>
87+
</plugins>
88+
<pluginManagement>
89+
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
90+
<plugins>
91+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
92+
<plugin>
93+
<artifactId>maven-clean-plugin</artifactId>
94+
<version>3.1.0</version>
95+
</plugin>
96+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
97+
<plugin>
98+
<artifactId>maven-resources-plugin</artifactId>
99+
<version>3.0.2</version>
100+
</plugin>
101+
<plugin>
102+
<artifactId>maven-compiler-plugin</artifactId>
103+
<version>3.8.0</version>
104+
</plugin>
105+
<plugin>
106+
<artifactId>maven-surefire-plugin</artifactId>
107+
<version>2.22.1</version>
108+
</plugin>
109+
<plugin>
110+
<artifactId>maven-jar-plugin</artifactId>
111+
<version>3.0.2</version>
112+
</plugin>
113+
<plugin>
114+
<artifactId>maven-install-plugin</artifactId>
115+
<version>2.5.2</version>
116+
</plugin>
117+
<plugin>
118+
<artifactId>maven-deploy-plugin</artifactId>
119+
<version>2.8.2</version>
120+
</plugin>
121+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
122+
<plugin>
123+
<artifactId>maven-site-plugin</artifactId>
124+
<version>3.7.1</version>
125+
</plugin>
126+
<plugin>
127+
<artifactId>maven-project-info-reports-plugin</artifactId>
128+
<version>3.0.0</version>
129+
</plugin>
130+
</plugins>
131+
</pluginManagement>
132+
</build>
133+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pom.xml
2+
src/main/java/com/example/App.java
3+
src/main/resources/my-app.properties
4+
src/main/resources/page.xml
5+
src/main/resources/struts.xml
6+
src/test/java/com/example/AppTest.java
7+
test-db/working/settings.xml
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.example;
2+
3+
import java.util.regex.Pattern;
4+
import java.nio.file.Path;
5+
import java.nio.file.Paths;
6+
7+
/**
8+
* Hello world!
9+
*
10+
*/
11+
public class App
12+
{
13+
public static void main( String[] args )
14+
{
15+
System.out.println( "Hello World!" );
16+
String expectedVersion = System.getenv("EXPECT_MAVEN");
17+
Path mavenHome = Paths.get(System.getProperty("maven.home")).normalize();
18+
String observedVersion = mavenHome.getFileName().toString();
19+
if (expectedVersion != null && !expectedVersion.equals(observedVersion)) {
20+
System.err.println("Wrong maven version, expected '" + expectedVersion + "' but got '" + observedVersion + "'" + mavenHome);
21+
System.exit(1);
22+
}
23+
String commandMatcher = System.getenv("EXPECT_COMMAND_REGEX");
24+
String command = System.getProperty("sun.java.command");
25+
if (commandMatcher != null && !Pattern.matches(commandMatcher, command)) {
26+
System.err.println("Wrong command line, '" + command + "' does not match '" + commandMatcher + "'");
27+
System.exit(1);
28+
}
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=1.0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>A sample</title>
4+
</head>
5+
<body>
6+
<p>Hello world!</p>
7+
</body>
8+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<struts>
3+
This is a sample file
4+
</struts>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
{
12+
/**
13+
* Rigorous Test :-)
14+
*/
15+
@Test
16+
public void shouldAnswerWithTrue()
17+
{
18+
assertTrue( true );
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
import os.path
3+
import shutil
4+
5+
def test(codeql, java, check_diagnostics):
6+
runenv = {
7+
"PATH": os.path.realpath(os.path.dirname(__file__)) + os.pathsep + os.getenv("PATH"),
8+
"REAL_MVN_PATH": shutil.which("mvn"),
9+
}
10+
codeql.database.create(build_mode = "none", _env = runenv)

0 commit comments

Comments
 (0)