Skip to content

Commit b196f0c

Browse files
Merge pull request #22347 from github/andersfugmann/fix-maven-enforcer-property-version
Java: test Maven Enforcer project property expansion
2 parents 6d0f21d + 668f4e8 commit b196f0c

10 files changed

Lines changed: 228 additions & 0 deletions

File tree

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
<maven.version>3.9.1</maven.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.11</version>
26+
<scope>test</scope>
27+
</dependency>
28+
</dependencies>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<artifactId>exec-maven-plugin</artifactId>
34+
<groupId>org.codehaus.mojo</groupId>
35+
<version>1.1.1</version>
36+
<executions>
37+
<execution>
38+
<id>check-maven-version</id>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>java</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
<configuration>
46+
<mainClass>com.example.App</mainClass>
47+
</configuration>
48+
</plugin>
49+
<plugin>
50+
<groupId>com.diffplug.spotless</groupId>
51+
<artifactId>spotless-maven-plugin</artifactId>
52+
<version>2.19.1</version>
53+
<executions>
54+
<execution>
55+
<goals>
56+
<goal>check</goal>
57+
</goals>
58+
<phase>compile</phase>
59+
</execution>
60+
</executions>
61+
<configuration>
62+
<java>
63+
<licenseHeader>
64+
<content>/* FAIL ME */</content>
65+
</licenseHeader>
66+
</java>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-enforcer-plugin</artifactId>
72+
<executions>
73+
<execution>
74+
<id>enforce-maven</id>
75+
<goals>
76+
<goal>enforce</goal>
77+
</goals>
78+
<configuration>
79+
<rules>
80+
<requireMavenVersion>
81+
<version>${maven.version}</version>
82+
</requireMavenVersion>
83+
</rules>
84+
</configuration>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
</plugins>
89+
<pluginManagement>
90+
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
91+
<plugins>
92+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
93+
<plugin>
94+
<artifactId>maven-clean-plugin</artifactId>
95+
<version>3.1.0</version>
96+
</plugin>
97+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
98+
<plugin>
99+
<artifactId>maven-resources-plugin</artifactId>
100+
<version>3.0.2</version>
101+
</plugin>
102+
<plugin>
103+
<artifactId>maven-compiler-plugin</artifactId>
104+
<version>3.8.0</version>
105+
</plugin>
106+
<plugin>
107+
<artifactId>maven-surefire-plugin</artifactId>
108+
<version>2.22.1</version>
109+
</plugin>
110+
<plugin>
111+
<artifactId>maven-jar-plugin</artifactId>
112+
<version>3.0.2</version>
113+
</plugin>
114+
<plugin>
115+
<artifactId>maven-install-plugin</artifactId>
116+
<version>2.5.2</version>
117+
</plugin>
118+
<plugin>
119+
<artifactId>maven-deploy-plugin</artifactId>
120+
<version>2.8.2</version>
121+
</plugin>
122+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
123+
<plugin>
124+
<artifactId>maven-site-plugin</artifactId>
125+
<version>3.7.1</version>
126+
</plugin>
127+
<plugin>
128+
<artifactId>maven-project-info-reports-plugin</artifactId>
129+
<version>3.0.0</version>
130+
</plugin>
131+
</plugins>
132+
</pluginManagement>
133+
</build>
134+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<settings>
2+
<mirrors>
3+
<mirror>
4+
<id>google-maven-central</id>
5+
<name>GCS Maven Central mirror</name>
6+
<url>https://maven-central.storage-download.googleapis.com/maven2/</url>
7+
<mirrorOf>central</mirrorOf>
8+
</mirror>
9+
</mirrors>
10+
</settings>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pom.xml
2+
settings.xml
3+
src/main/java/com/example/App.java
4+
src/main/resources/my-app.properties
5+
src/main/resources/page.xml
6+
src/main/resources/struts.xml
7+
src/test/java/com/example/AppTest.java
8+
target/classes/my-app.properties
9+
target/classes/page.xml
10+
target/classes/struts.xml
11+
target/maven-archiver/pom.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+
}
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
3+
def test(codeql, java):
4+
codeql.database.create(
5+
_env={
6+
"EXPECT_MAVEN": "apache-maven-3.9.16",
7+
"LGTM_INDEX_MAVEN_SETTINGS_FILE": os.path.join(os.path.dirname(os.path.realpath(__file__)), "settings.xml"),
8+
},
9+
)

java/ql/integration-tests/java/maven-enforcer-single-version/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
def test(codeql, java):
44
codeql.database.create(
55
_env={
6+
"EXPECT_MAVEN": "apache-maven-3.9.16",
67
"LGTM_INDEX_MAVEN_SETTINGS_FILE": os.path.join(os.path.dirname(os.path.realpath(__file__)), "settings.xml"),
78
},
89
)

0 commit comments

Comments
 (0)