Skip to content

Commit 2d44724

Browse files
authored
Merge pull request github#14281 from aibaars/aibaars/java-standalone-test
Java: standalone: add basic integration tests
2 parents ffd0a72 + 722ee16 commit 2d44724

File tree

17 files changed

+283
-0
lines changed

17 files changed

+283
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
</plugins>
69+
<pluginManagement>
70+
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
71+
<plugins>
72+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
73+
<plugin>
74+
<artifactId>maven-clean-plugin</artifactId>
75+
<version>3.1.0</version>
76+
</plugin>
77+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
78+
<plugin>
79+
<artifactId>maven-resources-plugin</artifactId>
80+
<version>3.0.2</version>
81+
</plugin>
82+
<plugin>
83+
<artifactId>maven-compiler-plugin</artifactId>
84+
<version>3.8.0</version>
85+
</plugin>
86+
<plugin>
87+
<artifactId>maven-surefire-plugin</artifactId>
88+
<version>2.22.1</version>
89+
</plugin>
90+
<plugin>
91+
<artifactId>maven-jar-plugin</artifactId>
92+
<version>3.0.2</version>
93+
</plugin>
94+
<plugin>
95+
<artifactId>maven-install-plugin</artifactId>
96+
<version>2.5.2</version>
97+
</plugin>
98+
<plugin>
99+
<artifactId>maven-deploy-plugin</artifactId>
100+
<version>2.8.2</version>
101+
</plugin>
102+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
103+
<plugin>
104+
<artifactId>maven-site-plugin</artifactId>
105+
<version>3.7.1</version>
106+
</plugin>
107+
<plugin>
108+
<artifactId>maven-project-info-reports-plugin</artifactId>
109+
<version>3.0.0</version>
110+
</plugin>
111+
</plugins>
112+
</pluginManagement>
113+
</build>
114+
</project>
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
xmlFiles
2+
| pom.xml:0:0:0:0 | pom.xml |
3+
| src/main/resources/page.xml:0:0:0:0 | src/main/resources/page.xml |
4+
| src/main/resources/struts.xml:0:0:0:0 | src/main/resources/struts.xml |
5+
propertiesFiles
6+
#select
7+
| src/main/java/com/example/App.java:0:0:0:0 | App |
8+
| src/test/java/com/example/AppTest.java:0:0:0:0 | AppTest |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import sys
2+
3+
from create_database_utils import *
4+
5+
run_codeql_database_create([], lang="java", extra_env={"CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS": "true", "CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_CLASSPATH_FROM_BUILD_FILES": "true"})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java
2+
3+
from File f
4+
where f.isSourceFile()
5+
select f
6+
7+
query predicate xmlFiles(XmlFile x) { any() }
8+
9+
query predicate propertiesFiles(File f) { f.getExtension() = "properties" }
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+
}

0 commit comments

Comments
 (0)