goutamadwant commented on code in PR #1127:
URL: 
https://github.com/apache/maven-compiler-plugin/pull/1127#discussion_r4090008661


##########
src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTestCase.java:
##########
@@ -420,6 +422,61 @@ public void testCompileSkipTest(
         assertOutputFileDoesNotExist(compileMojo, "foo", 
"TestSkipTestCompile0Test.class");
     }
 
+    @Test
+    @Basedir("${basedir}/target/test-classes/unit/compiler-existing-output")
+    public void testMainOutput(@InjectMojo(goal = "compile", pom = 
"plugin-config.xml") CompilerMojo mojo)
+            throws Exception {
+        compileWithExistingOutput(mojo, false);
+    }
+
+    @Test
+    @Basedir("${basedir}/target/test-classes/unit/compiler-existing-output")
+    public void testMainOutputForked(@InjectMojo(goal = "compile", pom = 
"plugin-config.xml") CompilerMojo mojo)
+            throws Exception {
+        compileWithExistingOutput(mojo, true);
+    }
+
+    @Test
+    @Basedir("${basedir}/target/test-classes/unit/compiler-existing-output")
+    public void testTestOutput(
+            @InjectMojo(goal = "testCompile", pom = "plugin-config.xml")
+                    @MojoParameter(name = "compileSourceRoots", value = 
"${project.basedir}/src/test/java")
+                    TestCompilerMojo mojo)
+            throws Exception {
+        compileWithExistingOutput(mojo, false);
+    }
+
+    @Test
+    @Basedir("${basedir}/target/test-classes/unit/compiler-existing-output")
+    public void testTestOutputForked(
+            @InjectMojo(goal = "testCompile", pom = "plugin-config.xml")
+                    @MojoParameter(name = "compileSourceRoots", value = 
"${project.basedir}/src/test/java")
+                    TestCompilerMojo mojo)
+            throws Exception {
+        compileWithExistingOutput(mojo, true);
+    }
+
+    private static void compileWithExistingOutput(AbstractCompilerMojo mojo, 
boolean fork) throws Exception {
+        mojo.fork = fork;
+        if (fork) {
+            mojo.executable =
+                    Path.of(System.getProperty("java.home"), "bin", 
"javac").toString();
+        }
+        Path output = Files.createDirectories(mojo.getOutputDirectory());
+        String helperName = mojo instanceof TestCompilerMojo ? "TestHelper" : 
"MainHelper";
+        Path helper = mojo.basedir.resolve(helperName + ".java");
+        Files.writeString(
+                helper, "public class " + helperName + " { public static 
String value() { return \"existing\"; } }");
+        assertEquals(
+                0,
+                ToolProvider.getSystemJavaCompiler().run(null, null, null, 
"-d", output.toString(), helper.toString()));
+        Files.delete(helper);
+        Files.deleteIfExists(output.resolve("Consumer.class"));
+        mojo.execute();
+        assertTrue(Files.isRegularFile(output.resolve(helperName + ".class")));
+        assertTrue(Files.isRegularFile(output.resolve("Consumer.class")));
+    }
+
     @Provides
     @Singleton
     @SuppressWarnings("unused")

Review Comment:
   Agreed that this needs a regression. I reproduced the deleted-source case 
with the existing `mcompiler-21_class-remove` integration test and a removed 
secondary top-level class case. The cleanup design still has ownership gaps, so 
I marked the PR Draft and described the cases needing maintainer direction 
here: 
https://github.com/apache/maven-compiler-plugin/pull/1127#issuecomment-5807814172.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to