This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git
commit 2d4c46ac1711b03002c777d511f494e31fb3a2c5 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Wed Nov 4 20:50:22 2026 +0000 Test JPMS runtime arguments in unit tests instead of ITs Drops the redundant MCOMPILER-284 and includes-excludes ITs, already covered by CompilerMojoTest and TestCompilerMojoTest. --- .../src/main/java/com/foo/MyClass.java | 21 ------- .../src/test/java/com/foo/MyTest.java | 23 -------- src/it/MCOMPILER-284/verify.groovy | 37 ------------ src/it/includes-excludes/pom.xml | 61 -------------------- .../main/java/org/apache/maven/it0055/Person.java | 31 ---------- .../java/org/apache/maven/it0055/PersonTwo.java | 31 ---------- .../java/org/apache/maven/it0055/PersonTest.java | 34 ----------- .../org/apache/maven/it0055/PersonTwoTest.java | 34 ----------- src/it/includes-excludes/verify.groovy | 66 ---------------------- src/it/jpms_add-exports/invoker.properties | 18 ------ src/it/jpms_add-exports/pom.xml | 52 ----------------- src/it/jpms_add-exports/verify.groovy | 23 -------- src/it/jpms_patch-module/invoker.properties | 19 ------- src/it/jpms_patch-module/pom.xml | 48 ---------------- src/it/jpms_patch-module/verify.groovy | 25 -------- .../maven/plugin/compiler/CompilerMojoTest.java | 24 ++++++++ .../plugin/compiler/TestCompilerMojoTest.java | 56 ++++++++++++++++++ .../compiler-jpms-add-exports/plugin-config.xml} | 42 ++++---------- .../src/main/java/module-info.java | 0 .../src/main/java/org/maven/test/Main.java | 0 .../compiler-jpms-patch-module/plugin-config.xml} | 38 +++---------- .../src/main/java/module-info.java | 0 .../src/main/java/org/maven/test/Main.java | 0 .../src/test/java/org/maven/test/MainTest.java | 0 24 files changed, 100 insertions(+), 583 deletions(-) diff --git a/src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java b/src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java deleted file mode 100644 index f646e4ae..00000000 --- a/src/it/MCOMPILER-284/src/main/java/com/foo/MyClass.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.foo; - -public class MyClass {} diff --git a/src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java b/src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java deleted file mode 100644 index 6fa76e6c..00000000 --- a/src/it/MCOMPILER-284/src/test/java/com/foo/MyTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.foo; - -public class MyTest { - private MyClass myClass = new MyClass(); -} diff --git a/src/it/MCOMPILER-284/verify.groovy b/src/it/MCOMPILER-284/verify.groovy deleted file mode 100644 index 35e28c74..00000000 --- a/src/it/MCOMPILER-284/verify.groovy +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.*; -import java.util.*; - -File mainClass = new File( basedir, "target/classes/com/foo/MyClass.class" ); -if ( mainClass.isFile() ) -{ - System.out.println( "Main class is present but was skipped: " + mainClass ); - return false; -} - -File testClass = new File( basedir, "target/test-classes/com/foo/MyTest.class" ); -if ( testClass.isFile() ) -{ - System.out.println( "Test class is present but was skipped: " + testClass ); - return false; -} - -return true; diff --git a/src/it/includes-excludes/pom.xml b/src/it/includes-excludes/pom.xml deleted file mode 100644 index 0070e04d..00000000 --- a/src/it/includes-excludes/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.compiler.it</groupId> - <artifactId>includes-excludes</artifactId> - <version>1.0-SNAPSHOT</version> - - <description> - Test that source includes/excludes with in the compiler plugin config. - This will test excludes and testExcludes... - </description> - - <dependencies> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <version>5.14.3</version> - <type>jar</type> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <excludes> - <exclude>**/PersonTwo.java</exclude> - </excludes> - <testExcludes> - <testExclude>**/PersonTwoTest.java</testExclude> - </testExcludes> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/includes-excludes/src/main/java/org/apache/maven/it0055/Person.java b/src/it/includes-excludes/src/main/java/org/apache/maven/it0055/Person.java deleted file mode 100644 index 1fa3d8cf..00000000 --- a/src/it/includes-excludes/src/main/java/org/apache/maven/it0055/Person.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.it0055; - -public class Person { - private String name; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} diff --git a/src/it/includes-excludes/src/main/java/org/apache/maven/it0055/PersonTwo.java b/src/it/includes-excludes/src/main/java/org/apache/maven/it0055/PersonTwo.java deleted file mode 100644 index 8bb36452..00000000 --- a/src/it/includes-excludes/src/main/java/org/apache/maven/it0055/PersonTwo.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.it0055; - -public class PersonTwo { - private String name; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} diff --git a/src/it/includes-excludes/src/test/java/org/apache/maven/it0055/PersonTest.java b/src/it/includes-excludes/src/test/java/org/apache/maven/it0055/PersonTest.java deleted file mode 100644 index 508a9a97..00000000 --- a/src/it/includes-excludes/src/test/java/org/apache/maven/it0055/PersonTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.it0055; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class PersonTest { - @Test - public void testPerson() { - Person person = new Person(); - - person.setName("foo"); - - assertEquals("foo", person.getName()); - } -} diff --git a/src/it/includes-excludes/src/test/java/org/apache/maven/it0055/PersonTwoTest.java b/src/it/includes-excludes/src/test/java/org/apache/maven/it0055/PersonTwoTest.java deleted file mode 100644 index 2e5ee272..00000000 --- a/src/it/includes-excludes/src/test/java/org/apache/maven/it0055/PersonTwoTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.it0055; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class PersonTwoTest { - @Test - public void testPerson() { - Person person = new Person(); - - person.setName("foo"); - - assertEquals("foo", person.getName()); - } -} diff --git a/src/it/includes-excludes/verify.groovy b/src/it/includes-excludes/verify.groovy deleted file mode 100644 index 91d79f75..00000000 --- a/src/it/includes-excludes/verify.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.*; -import java.util.*; -import java.util.regex.*; - -try -{ - File targetDir = new File( basedir, "target" ); - - File mainClass = new File( targetDir, "classes/org/apache/maven/it0055/Person.class" ); - System.out.println( "Checking for existence of: " + mainClass ); - if ( !mainClass.isFile() ) - { - System.err.println( "FAILED!" ); - return false; - } - - File excludedMainClass = new File( targetDir, "classes/org/apache/maven/it0055/PersonTwo.class" ); - System.out.println( "Checking for absence of: " + excludedMainClass ); - if ( excludedMainClass.exists() ) - { - System.err.println( "FAILED!" ); - return false; - } - - File testClass = new File( targetDir, "test-classes/org/apache/maven/it0055/PersonTest.class" ); - System.out.println( "Checking for existence of: " + testClass ); - if ( !testClass.isFile() ) - { - System.err.println( "FAILED!" ); - return false; - } - - File excludedTestClass = new File( targetDir, "test-classes/org/apache/maven/it0055/PersonTwoTest.class" ); - System.out.println( "Checking for absence of: " + excludedTestClass ); - if ( excludedTestClass.exists() ) - { - System.err.println( "FAILED!" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/src/it/jpms_add-exports/invoker.properties b/src/it/jpms_add-exports/invoker.properties deleted file mode 100644 index 95117185..00000000 --- a/src/it/jpms_add-exports/invoker.properties +++ /dev/null @@ -1,18 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -invoker.java.version = 9+ diff --git a/src/it/jpms_add-exports/pom.xml b/src/it/jpms_add-exports/pom.xml deleted file mode 100644 index 6f9b948f..00000000 --- a/src/it/jpms_add-exports/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> - -<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/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.compiler.it</groupId> - <artifactId>illegal-access</artifactId> - <version>1.0-SNAPSHOT</version> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <release>9</release> - <compilerArgs> - <arg>--add-exports</arg> - <arg>app/org.maven.test=ALL_UNNAMED</arg> - </compilerArgs> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> diff --git a/src/it/jpms_add-exports/verify.groovy b/src/it/jpms_add-exports/verify.groovy deleted file mode 100644 index 0cddccf9..00000000 --- a/src/it/jpms_add-exports/verify.groovy +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -def jpmsArgs = new File( basedir, 'target/classes/META-INF/jpms.args' ); -def lines = jpmsArgs.readLines(); -assert lines[0] == "--add-exports" -assert lines[1] == "app/org.maven.test=ALL_UNNAMED" diff --git a/src/it/jpms_patch-module/invoker.properties b/src/it/jpms_patch-module/invoker.properties deleted file mode 100644 index 416082cc..00000000 --- a/src/it/jpms_patch-module/invoker.properties +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -invoker.java.version = 9+ -invoker.goals = test-compile diff --git a/src/it/jpms_patch-module/pom.xml b/src/it/jpms_patch-module/pom.xml deleted file mode 100644 index 80bd4122..00000000 --- a/src/it/jpms_patch-module/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> - -<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/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.compiler.it</groupId> - <artifactId>patch-module</artifactId> - <version>1.0-SNAPSHOT</version> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <release>9</release> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> diff --git a/src/it/jpms_patch-module/verify.groovy b/src/it/jpms_patch-module/verify.groovy deleted file mode 100644 index 92e09722..00000000 --- a/src/it/jpms_patch-module/verify.groovy +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -def jpmsArgs = new File( basedir, 'target/test-classes/META-INF/jpms.args' ); -def lines = jpmsArgs.readLines(); -assert lines[0] == "--patch-module" -assert lines[1] == "app=_" -assert lines[2] == "--add-reads" -assert lines[3] == "app=ALL-UNNAMED" diff --git a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java index a694cfa0..6d455db2 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java @@ -20,6 +20,7 @@ package org.apache.maven.plugin.compiler; import java.io.File; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -31,6 +32,8 @@ import org.apache.maven.plugin.compiler.stubs.CompilerManagerStub; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.testing.stubs.ArtifactStub; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import static org.apache.maven.api.plugin.testing.MojoExtension.getVariableValueFromObject; import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject; @@ -337,6 +340,27 @@ class CompilerMojoTest { assertTrue(testClass.exists()); } + /** + * Tests that runtime options such as {@code --add-exports} are recorded in {@code META-INF/jpms.args} when the + * project is a module. + * + * @throws Exception + */ + @Test + @EnabledForJreRange(min = JRE.JAVA_9) + @InjectMojo(goal = COMPILE, pom = "classpath:/unit/compiler-jpms-add-exports/plugin-config.xml") + void testJpmsAddExports(CompilerMojo compilerMojo) throws Exception { + setUpCompilerMojoTestEnv(compilerMojo); + + // output of earlier runs stays under target/, so start without it + Path jpmsArgs = compilerMojo.getOutputDirectory().toPath().resolve("META-INF/jpms.args"); + Files.deleteIfExists(jpmsArgs); + + compilerMojo.execute(); + + assertEquals(Arrays.asList("--add-exports", "app/org.maven.test=ALL_UNNAMED"), Files.readAllLines(jpmsArgs)); + } + private void setUpCompilerMojoTestEnv(CompilerMojo mojo) throws Exception { setVariableValueToObject(mojo, "projectArtifact", new ArtifactStub()); setVariableValueToObject(mojo, "session", getMockMavenSession()); diff --git a/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java b/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java index 42f537d4..22cdaa9d 100644 --- a/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/compiler/TestCompilerMojoTest.java @@ -18,6 +18,9 @@ */ package org.apache.maven.plugin.compiler; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; + import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -31,7 +34,10 @@ import java.util.stream.Stream; import org.apache.maven.api.plugin.testing.InjectMojo; import org.apache.maven.api.plugin.testing.MojoTest; import org.apache.maven.plugin.compiler.stubs.CompilerManagerStub; +import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -172,6 +178,56 @@ class TestCompilerMojoTest { assertFalse(testClass.exists()); } + /** + * Tests that test sources of a module are compiled as a patch of the main module: the mojo records + * {@code --patch-module} and {@code --add-reads} in {@code META-INF/jpms.args}. + */ + @Test + @EnabledForJreRange(min = JRE.JAVA_9) + @InjectMojo(goal = TEST_COMPILE, pom = "classpath:/unit/compiler-jpms-patch-module/plugin-config.xml") + void testJpmsPatchModule(TestCompilerMojo testCompilerMojo, @TempDir Path mainClasses) throws Exception { + setUpCompilerMojoTestEnv(testCompilerMojo); + + // the test mojo reads the main module descriptor from the compiled main classes + Path fixture = Paths.get(testCompilerMojo.getCompileSourceRoots().get(0)) + .getParent() + .getParent() + .getParent(); + Path mainSources = fixture.resolve("src/main/java"); + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); + assertEquals( + 0, + javac.run( + null, + null, + null, + "--release", + "9", + "-d", + mainClasses.toString(), + mainSources.resolve("module-info.java").toString(), + mainSources.resolve("org/maven/test/Main.java").toString())); + + MavenProject project = getMockMavenProject(); + project.getBuild().setOutputDirectory(mainClasses.toString()); + setVariableValueToObject(testCompilerMojo, "project", project); + setVariableValueToObject( + testCompilerMojo, + "compileSourceRoots", + Arrays.asList(fixture.resolve("src/test/java").toString())); + setVariableValueToObject(testCompilerMojo, "testPath", Arrays.asList(mainClasses.toString())); + + // output of earlier runs stays under target/, so start without it + Path jpmsArgs = testCompilerMojo.getOutputDirectory().toPath().resolve("META-INF/jpms.args"); + Files.deleteIfExists(jpmsArgs); + + testCompilerMojo.execute(); + + assertEquals( + Arrays.asList("--patch-module", "app=_", "--add-reads", "app=ALL-UNNAMED"), + Files.readAllLines(jpmsArgs)); + } + private void setUpCompilerMojoTestEnv(TestCompilerMojo mojo) throws Exception { File buildDir = getVariableValueFromObject(mojo, "buildDirectory"); File testClassesDir = new File(buildDir, "test-classes"); diff --git a/src/it/MCOMPILER-284/pom.xml b/src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml similarity index 51% copy from src/it/MCOMPILER-284/pom.xml copy to src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml index 2959b37c..1b435b2e 100644 --- a/src/it/MCOMPILER-284/pom.xml +++ b/src/test/resources/unit/compiler-jpms-add-exports/plugin-config.xml @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more contributor license agreements. See the NOTICE file @@ -18,42 +17,25 @@ ~ under the License. --> -<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/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.compiler.it</groupId> - <artifactId>mcompiler284</artifactId> - <version>1.0-SNAPSHOT</version> - - <url>https://issues.apache.org/jira/browse/MCOMPILER-284</url> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <version>5.14.3</version> - <scope>test</scope> - </dependency> - </dependencies> - +<project> <build> <plugins> <plugin> - <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>@project.version@</version> <configuration> - <skipMain>true</skipMain> - <skip>true</skip> + <compileSourceRoots> + <compileSourceRoot>${basedir}/target/test-classes/unit/compiler-jpms-add-exports/src/main/java</compileSourceRoot> + </compileSourceRoots> + <compilerId>javac</compilerId> + <release>9</release> + <outputDirectory>${basedir}/target/test/unit/compiler-jpms-add-exports/target/classes</outputDirectory> + <buildDirectory>${basedir}/target/test/unit/compiler-jpms-add-exports/target</buildDirectory> + <compilerArgs> + <arg>--add-exports</arg> + <arg>app/org.maven.test=ALL_UNNAMED</arg> + </compilerArgs> </configuration> </plugin> </plugins> </build> - </project> diff --git a/src/it/jpms_add-exports/src/main/java/module-info.java b/src/test/resources/unit/compiler-jpms-add-exports/src/main/java/module-info.java similarity index 100% rename from src/it/jpms_add-exports/src/main/java/module-info.java rename to src/test/resources/unit/compiler-jpms-add-exports/src/main/java/module-info.java diff --git a/src/it/jpms_add-exports/src/main/java/org/maven/test/Main.java b/src/test/resources/unit/compiler-jpms-add-exports/src/main/java/org/maven/test/Main.java similarity index 100% rename from src/it/jpms_add-exports/src/main/java/org/maven/test/Main.java rename to src/test/resources/unit/compiler-jpms-add-exports/src/main/java/org/maven/test/Main.java diff --git a/src/it/MCOMPILER-284/pom.xml b/src/test/resources/unit/compiler-jpms-patch-module/plugin-config.xml similarity index 51% rename from src/it/MCOMPILER-284/pom.xml rename to src/test/resources/unit/compiler-jpms-patch-module/plugin-config.xml index 2959b37c..91ceea3e 100644 --- a/src/it/MCOMPILER-284/pom.xml +++ b/src/test/resources/unit/compiler-jpms-patch-module/plugin-config.xml @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <!-- ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more contributor license agreements. See the NOTICE file @@ -18,42 +17,21 @@ ~ under the License. --> -<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/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.compiler.it</groupId> - <artifactId>mcompiler284</artifactId> - <version>1.0-SNAPSHOT</version> - - <url>https://issues.apache.org/jira/browse/MCOMPILER-284</url> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <dependencies> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <version>5.14.3</version> - <scope>test</scope> - </dependency> - </dependencies> - +<project> <build> <plugins> <plugin> - <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>@project.version@</version> <configuration> - <skipMain>true</skipMain> - <skip>true</skip> + <compileSourceRoots> + <compileSourceRoot>${basedir}/target/test-classes/unit/compiler-jpms-patch-module/src/test/java</compileSourceRoot> + </compileSourceRoots> + <compilerId>javac</compilerId> + <release>9</release> + <outputDirectory>${basedir}/target/test/unit/compiler-jpms-patch-module/target/test-classes</outputDirectory> + <buildDirectory>${basedir}/target/test/unit/compiler-jpms-patch-module/target</buildDirectory> </configuration> </plugin> </plugins> </build> - </project> diff --git a/src/it/jpms_patch-module/src/main/java/module-info.java b/src/test/resources/unit/compiler-jpms-patch-module/src/main/java/module-info.java similarity index 100% rename from src/it/jpms_patch-module/src/main/java/module-info.java rename to src/test/resources/unit/compiler-jpms-patch-module/src/main/java/module-info.java diff --git a/src/it/jpms_patch-module/src/main/java/org/maven/test/Main.java b/src/test/resources/unit/compiler-jpms-patch-module/src/main/java/org/maven/test/Main.java similarity index 100% rename from src/it/jpms_patch-module/src/main/java/org/maven/test/Main.java rename to src/test/resources/unit/compiler-jpms-patch-module/src/main/java/org/maven/test/Main.java diff --git a/src/it/jpms_patch-module/src/test/java/org/maven/test/MainTest.java b/src/test/resources/unit/compiler-jpms-patch-module/src/test/java/org/maven/test/MainTest.java similarity index 100% rename from src/it/jpms_patch-module/src/test/java/org/maven/test/MainTest.java rename to src/test/resources/unit/compiler-jpms-patch-module/src/test/java/org/maven/test/MainTest.java
